@@ -15,8 +15,10 @@ Alloy.Globals.Map = require('ti.map');
15
15
Alloy . Globals . osName = Ti . Platform . osname ;
16
16
Alloy . Globals . filesDownload = { } ;
17
17
Alloy . Globals . updateCount = 0 ;
18
+ Alloy . Globals . isAndroidTablet = false ;
18
19
switch ( Alloy . Globals . osName ) {
19
20
case 'android' :
21
+ Alloy . Globals . isAndroidTablet = ( Ti . Platform . Android . getPhysicalSizeCategory ( ) == Ti . Platform . Android . PHYSICAL_SIZE_CATEGORY_LARGE || Ti . Platform . Android . getPhysicalSizeCategory ( ) == Ti . Platform . Android . PHYSICAL_SIZE_CATEGORY_XLARGE ) ;
20
22
Alloy . Globals . museo_slab_500 = 'museo_slab_500' ;
21
23
Alloy . Globals . museo_slab_700 = 'museo_slab_700' ;
22
24
Alloy . Globals . museosans_300 = 'museosans_300' ;
@@ -97,6 +99,15 @@ updateData = function(type){
97
99
if ( typeof mapping != 'undefined' ) {
98
100
for ( var key in node ) {
99
101
if ( typeof mapping [ key ] != 'undefined' ) {
102
+ if ( node [ key ] != "" ) {
103
+ if ( typeof mapping [ key ] [ 'type' ] != 'undefined' && mapping [ key ] [ 'type' ] == 'file' && typeof mapping [ key ] [ 'callback' ] != 'undefined' ) {
104
+ object [ mapping [ key ] [ 'field' ] ] = ( typeof mapping [ key ] [ 'callback' ] != 'undefined' ) ? mapping [ key ] [ 'callback' ] ( node [ key ] , type ) : node [ key ] ;
105
+ }
106
+ else {
107
+ object [ mapping [ key ] [ 'field' ] ] = ( typeof mapping [ key ] [ 'callback' ] != 'undefined' ) ? mapping [ key ] [ 'callback' ] ( node [ key ] ) : node [ key ] ;
108
+ }
109
+ }
110
+ /*
100
111
if(typeof mapping[key]['type'] != 'undefined' && mapping[key]['type'] == 'file' && typeof mapping[key]['callback'] != 'undefined' && node[key] != ""){
101
112
file = true;
102
113
files[files.length] = {
@@ -109,6 +120,7 @@ updateData = function(type){
109
120
else if(node[key] != ""){
110
121
object[mapping[key]['field']] = (typeof mapping[key]['callback'] != 'undefined') ? mapping[key]['callback'](node[key]) : node[key];
111
122
}
123
+ */
112
124
}
113
125
}
114
126
}
@@ -120,6 +132,10 @@ updateData = function(type){
120
132
var currentCollection = collection . get ( object [ id ] ) ;
121
133
if ( typeof object [ 'changed' ] == 'undefined' || ( typeof currentCollection != 'undefined' && object [ 'changed' ] > currentCollection . get ( 'changed' ) ) || typeof currentCollection == 'undefined' ) {
122
134
ids [ ids . length ] = object [ id ] ;
135
+ Ti . API . info ( JSON . stringify ( object ) ) ;
136
+ var row = Alloy . createModel ( type , object ) ;
137
+ row . save ( ) ;
138
+ /*
123
139
if(file){
124
140
if(typeof Alloy.Globals.filesDownload[type] == 'undefined'){
125
141
Alloy.Globals.filesDownload[type] = new Array();
@@ -130,6 +146,7 @@ updateData = function(type){
130
146
var row = Alloy.createModel(type,object);
131
147
row.save();
132
148
}
149
+ */
133
150
}
134
151
}
135
152
}
@@ -163,11 +180,17 @@ updateData = function(type){
163
180
client . open ( "GET" , url ) ;
164
181
client . send ( ) ;
165
182
} ;
166
- function getImageBlob ( url , data , field , type , files ) {
183
+ function getImageBlob ( url , type ) {
167
184
Alloy . Globals . updateCount ++ ;
185
+ var filename = url . substring ( url . lastIndexOf ( '/' ) + 1 ) ;
186
+ var f = Ti . Filesystem . getFile ( Ti . Filesystem . applicationDataDirectory , filename ) ;
168
187
var xhr = Titanium . Network . createHTTPClient ( {
169
188
onload : function ( e ) {
170
189
if ( xhr . status == 200 ) {
190
+ f . write ( this . responseData ) ; // write to the file
191
+ var type = this . _properties [ 'type' ] ;
192
+ // this.responseData
193
+ /*
171
194
var data = this._properties['data'];
172
195
var field = this._properties['field'];
173
196
var files = this._properties['files'];
@@ -181,12 +204,15 @@ function getImageBlob(url, data, field, type, files){
181
204
var currentFile = files.shift();
182
205
currentFile.callback(currentFile.value, data, currentFile.field, type, files);
183
206
}
207
+ */
184
208
}
185
209
event = { } ;
186
210
event . type = type ;
187
211
Ti . App . fireEvent ( 'updateDataEnd' , event ) ;
188
212
} ,
189
213
onerror : function ( e ) {
214
+ var type = this . _properties [ 'type' ] ;
215
+ /*
190
216
var data = this._properties['data'];
191
217
var field = this._properties['field'];
192
218
var files = this._properties['files'];
@@ -200,20 +226,26 @@ function getImageBlob(url, data, field, type, files){
200
226
var currentFile = files.shift();
201
227
currentFile.callback(currentFile.value, data, currentFile.field, type, files);
202
228
}
229
+ */
203
230
event = { } ;
204
231
event . type = type ;
205
232
Ti . App . fireEvent ( 'updateDataEnd' , event ) ;
206
233
} ,
207
234
} ) ;
208
-
235
+ xhr . applyProperties ( {
236
+ 'type' : type ,
237
+ } ) ;
238
+ /*
209
239
xhr.applyProperties({
210
240
'data' : data,
211
241
'field' : field,
212
242
'type' : type,
213
243
'files' : files
214
244
});
245
+ */
215
246
xhr . open ( 'GET' , url ) ;
216
247
xhr . send ( ) ;
248
+ return f . nativePath ;
217
249
}
218
250
function getSponsorType ( sponsorType ) {
219
251
var sponsorTypes = {
@@ -530,4 +562,3 @@ function twitterShare(data){
530
562
} ) ;
531
563
532
564
}
533
- Alloy . Globals . isAndroidTablet = ( Ti . Platform . osname == "android" && ( Ti . Platform . Android . getPhysicalSizeCategory ( ) == Ti . Platform . Android . PHYSICAL_SIZE_CATEGORY_LARGE || Ti . Platform . Android . getPhysicalSizeCategory ( ) == Ti . Platform . Android . PHYSICAL_SIZE_CATEGORY_XLARGE ) ) ;
0 commit comments