author | Michael Krelin <hacker@klever.net> | 2006-09-30 18:21:31 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-09-30 18:21:31 (UTC) |
commit | 4f5e775ff24baf34b3425e93bfeac4a436b4b525 (patch) (unidiff) | |
tree | 3dcde487352a9dd8bcef852adeb18f118cbe20c5 /content | |
parent | 74a277c2d7ac5416c3b55565e6d5e8e5a15b389d (diff) | |
download | fireflix-4f5e775ff24baf34b3425e93bfeac4a436b4b525.zip fireflix-4f5e775ff24baf34b3425e93bfeac4a436b4b525.tar.gz fireflix-4f5e775ff24baf34b3425e93bfeac4a436b4b525.tar.bz2 |
minor code beauty/performance enhancements
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@170 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix.js | 14 |
1 files changed, 8 insertions, 6 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 98b6d41..337354e 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -49,155 +49,156 @@ var fireflix = { | |||
49 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ | 49 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ |
50 | }else{ | 50 | }else{ |
51 | this.auth_info.value = this.no_auth_info_label; | 51 | this.auth_info.value = this.no_auth_info_label; |
52 | } | 52 | } |
53 | }, | 53 | }, |
54 | on_cmd_auth: function() { | 54 | on_cmd_auth: function() { |
55 | var _this = this; | 55 | var _this = this; |
56 | this.flickr.authorize_0( | 56 | this.flickr.authorize_0( |
57 | function() { | 57 | function() { |
58 | _this.set_auth_state(_this.flickr.token,true); | 58 | _this.set_auth_state(_this.flickr.token,true); |
59 | }, function(x,s,c,m) { | 59 | }, function(x,s,c,m) { |
60 | _this.flickr_failure(x,s,c,m); | 60 | _this.flickr_failure(x,s,c,m); |
61 | } | 61 | } |
62 | ); | 62 | ); |
63 | }, | 63 | }, |
64 | on_cmd_auth_done: function() { | 64 | on_cmd_auth_done: function() { |
65 | this.set_auth_state(this.flickr.token,false); | 65 | this.set_auth_state(this.flickr.token,false); |
66 | var _this = this; | 66 | var _this = this; |
67 | this.flickr.authorize_1( | 67 | this.flickr.authorize_1( |
68 | function() { | 68 | function() { |
69 | _this.flickr.save_token(); | 69 | _this.flickr.save_token(); |
70 | _this.refresh_stuff(); | 70 | _this.refresh_stuff(); |
71 | _this.set_auth_state(_this.flickr.token,false); | 71 | _this.set_auth_state(_this.flickr.token,false); |
72 | _this.auth_info.value = | 72 | _this.auth_info.value = |
73 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 73 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
74 | }, function(x,s,c,m) { | 74 | }, function(x,s,c,m) { |
75 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ | 75 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ |
76 | _this.flickr_failure(x,s,c,m); | 76 | _this.flickr_failure(x,s,c,m); |
77 | } | 77 | } |
78 | ); | 78 | ); |
79 | }, | 79 | }, |
80 | on_cmd_auth_unauth: function() { | 80 | on_cmd_auth_unauth: function() { |
81 | this.flickr.reset_token(); | 81 | this.flickr.reset_token(); |
82 | this.set_auth_state(false,false); | 82 | this.set_auth_state(false,false); |
83 | }, | 83 | }, |
84 | 84 | ||
85 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 85 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
86 | refresh_stuff: function() { | 86 | refresh_stuff: function() { |
87 | this.refresh_sets(); | 87 | this.refresh_sets(); |
88 | this.refresh_user_tags(); | 88 | this.refresh_user_tags(); |
89 | }, | 89 | }, |
90 | 90 | ||
91 | /* photoset treeview */ | 91 | /* photoset treeview */ |
92 | photoset: { | 92 | photoset: { |
93 | photos: new Array(), | 93 | photos: new Array(), |
94 | fireflix: null, | 94 | fireflix: null, |
95 | init: function(f) { | 95 | init: function(f) { |
96 | this.fireflix = f; | 96 | this.fireflix = f; |
97 | pull_elements(this,document,[ 'set_photo' ]); | ||
97 | }, | 98 | }, |
98 | rowCount: 0, | 99 | rowCount: 0, |
99 | getCellText: function(r,c) { | 100 | getCellText: function(r,c) { |
100 | var p = this.photos[r]; | 101 | var p = this.photos[r]; |
101 | if(c.id=='sp_title') return p.title; | 102 | if(c.id=='sp_title') return p.title; |
102 | if(c.id=='sp_taken') return p.datetaken; | 103 | if(c.id=='sp_taken') return p.datetaken; |
103 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ | 104 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ |
104 | return c.id; | 105 | return c.id; |
105 | }, | 106 | }, |
106 | setTree: function(t) { this.tree = t }, | 107 | setTree: function(t) { this.tree = t }, |
107 | isContainer: function(r) { return false; }, | 108 | isContainer: function(r) { return false; }, |
108 | isSeparator: function(r) { return false; }, | 109 | isSeparator: function(r) { return false; }, |
109 | isSorted: function(r) { return false; }, | 110 | isSorted: function(r) { return false; }, |
110 | getLevel: function(r) { return 0; }, | 111 | getLevel: function(r) { return 0; }, |
111 | getImageSrc: function(r,c) { return null }, | 112 | getImageSrc: function(r,c) { return null }, |
112 | getRowProperties: function(r,p) {}, | 113 | getRowProperties: function(r,p) {}, |
113 | getCellProperties: function(cid,cel,p) {}, | 114 | getCellProperties: function(cid,cel,p) {}, |
114 | getColumnProperties: function(cid,cel,p) { }, | 115 | getColumnProperties: function(cid,cel,p) { }, |
115 | cycleHeader: function(cid,e) { }, | 116 | cycleHeader: function(cid,e) { }, |
116 | getParentIndex: function(r) { return -1; }, | 117 | getParentIndex: function(r) { return -1; }, |
117 | drop: function(r,o) { }, | 118 | drop: function(r,o) { }, |
118 | canDropBeforeAfter: function(r,b) { return false }, | 119 | canDropBeforeAfter: function(r,b) { return false }, |
119 | 120 | ||
120 | importXPR: function(xp) { | 121 | importXPR: function(xp) { |
121 | this.tree.beginUpdateBatch(); | 122 | this.tree.beginUpdateBatch(); |
122 | this.photos = new Array(); | 123 | this.photos = new Array(); |
123 | var n; while(n=xp.iterateNext()) { | 124 | var n; while(n=xp.iterateNext()) { |
124 | this.photos.push(new Photo(n)); | 125 | this.photos.push(new Photo(n)); |
125 | } | 126 | } |
126 | this.rowCount = this.photos.length; | 127 | this.rowCount = this.photos.length; |
127 | this.tree.endUpdateBatch(); | 128 | this.tree.endUpdateBatch(); |
128 | }, | 129 | }, |
129 | load_photos: function(psid) { | 130 | load_photos: function(psid) { |
130 | var _this = this; | 131 | var _this = this; |
131 | this.fireflix.flickr.api_call( | 132 | this.fireflix.flickr.api_call( |
132 | { | 133 | { |
133 | method: 'flickr.photosets.getPhotos', | 134 | method: 'flickr.photosets.getPhotos', |
134 | auth_token: 'default', | 135 | auth_token: 'default', |
135 | photoset_id: psid, | 136 | photoset_id: psid, |
136 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 137 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
137 | }, function(xr) { | 138 | }, function(xr) { |
138 | var x = xr.responseXML; | 139 | var x = xr.responseXML; |
139 | var xp = x.evaluate( | 140 | var xp = x.evaluate( |
140 | '/rsp/photoset/photo', x, null, | 141 | '/rsp/photoset/photo', x, null, |
141 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 142 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
142 | _this.importXPR(xp); | 143 | _this.importXPR(xp); |
143 | }, function(x,s,c,m) { | 144 | }, function(x,s,c,m) { |
144 | _this.fireflix.flickr_failure(x,s,c,m); | 145 | _this.fireflix.flickr_failure(x,s,c,m); |
145 | } | 146 | } |
146 | ); | 147 | ); |
147 | }, | 148 | }, |
148 | on_select: function() { | 149 | on_select: function() { |
149 | if(this.selection.count==1) { | 150 | if(this.selection.count==1) { |
150 | var p = this.photos[this.selection.currentIndex]; | 151 | var p = this.photos[this.selection.currentIndex]; |
151 | document.getElementById('set_photo').src = | 152 | this.set_photo.src = |
152 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); | 153 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); |
153 | document.getElementById('set_photo').hidden = false; | 154 | this.set_photo.hidden = false; |
154 | }else{ | 155 | }else{ |
155 | document.getElementById('set_photo').hidden = true; | 156 | this.set_photo.hidden = true; |
156 | } | 157 | } |
157 | } | 158 | } |
158 | }, | 159 | }, |
159 | 160 | ||
160 | /* photosets treeview */ | 161 | /* photosets treeview */ |
161 | photosets: { | 162 | photosets: { |
162 | sets: new Array(), | 163 | sets: new Array(), |
163 | fireflix: null, | 164 | fireflix: null, |
164 | init: function(f) { | 165 | init: function(f) { |
165 | this.fireflix = f; | 166 | this.fireflix = f; |
166 | }, | 167 | }, |
167 | rowCount: 0, | 168 | rowCount: 0, |
168 | getCellText: function(r,c) { | 169 | getCellText: function(r,c) { |
169 | var s = this.sets[r]; | 170 | var s = this.sets[r]; |
170 | if(c.id=='sl_name') return s.title; | 171 | if(c.id=='sl_name') return s.title; |
171 | if(c.id=='sl_photos') return s.photos; | 172 | if(c.id=='sl_photos') return s.photos; |
172 | return c.id; | 173 | return c.id; |
173 | }, | 174 | }, |
174 | setTree: function(t) { this.tree = t }, | 175 | setTree: function(t) { this.tree = t }, |
175 | isContainer: function(r) { return false; }, | 176 | isContainer: function(r) { return false; }, |
176 | isSeparator: function(r) { return false; }, | 177 | isSeparator: function(r) { return false; }, |
177 | isSorted: function() { return false; }, | 178 | isSorted: function() { return false; }, |
178 | getLevel: function(r) { return 0; }, | 179 | getLevel: function(r) { return 0; }, |
179 | getImageSrc: function(r,c) { return null }, | 180 | getImageSrc: function(r,c) { return null }, |
180 | getRowProperties: function(r,p) {}, | 181 | getRowProperties: function(r,p) {}, |
181 | getCellProperties: function(cid,cel,p) { }, | 182 | getCellProperties: function(cid,cel,p) { }, |
182 | getColumnProperties: function(cid,cel,p) { }, | 183 | getColumnProperties: function(cid,cel,p) { }, |
183 | cycleHeader: function(cid,e) { }, | 184 | cycleHeader: function(cid,e) { }, |
184 | getParentIndex: function(r) { return -1; }, | 185 | getParentIndex: function(r) { return -1; }, |
185 | drop: function(r,o) { }, | 186 | drop: function(r,o) { }, |
186 | canDropBeforeAfter: function(r,b) { return false }, | 187 | canDropBeforeAfter: function(r,b) { return false }, |
187 | 188 | ||
188 | importXPR: function(xp) { | 189 | importXPR: function(xp) { |
189 | this.tree.beginUpdateBatch(); | 190 | this.tree.beginUpdateBatch(); |
190 | this.sets = new Array(); | 191 | this.sets = new Array(); |
191 | var n; while(n=xp.iterateNext()) { | 192 | var n; while(n=xp.iterateNext()) { |
192 | this.sets.push(new Photoset(n)); | 193 | this.sets.push(new Photoset(n)); |
193 | } | 194 | } |
194 | this.rowCount = this.sets.length; | 195 | this.rowCount = this.sets.length; |
195 | this.tree.endUpdateBatch(); | 196 | this.tree.endUpdateBatch(); |
196 | }, | 197 | }, |
197 | refresh_sets: function() { | 198 | refresh_sets: function() { |
198 | var _this = this; | 199 | var _this = this; |
199 | this.fireflix.flickr.api_call( | 200 | this.fireflix.flickr.api_call( |
200 | { | 201 | { |
201 | method: 'flickr.photosets.getList', | 202 | method: 'flickr.photosets.getList', |
202 | auth_token: 'default' | 203 | auth_token: 'default' |
203 | }, function(xr) { | 204 | }, function(xr) { |
@@ -265,235 +266,236 @@ var fireflix = { | |||
265 | var ldf = null; | 266 | var ldf = null; |
266 | for(var i in dd.dataList) { | 267 | for(var i in dd.dataList) { |
267 | var di = dd.dataList[i]; | 268 | var di = dd.dataList[i]; |
268 | var dif = di.first; | 269 | var dif = di.first; |
269 | if( | 270 | if( |
270 | ldf==null | 271 | ldf==null |
271 | || ldf.flavour.contentType!=dif.flavour.contentType | 272 | || ldf.flavour.contentType!=dif.flavour.contentType |
272 | || ldf.contentLength!=dif.contentLength | 273 | || ldf.contentLength!=dif.contentLength |
273 | || ldf.data!=dif.data ) | 274 | || ldf.data!=dif.data ) |
274 | this.drop_item(ev,di,s); | 275 | this.drop_item(ev,di,s); |
275 | ldf = dif; | 276 | ldf = dif; |
276 | } | 277 | } |
277 | }, | 278 | }, |
278 | drop_item: function(ev,di,s) { | 279 | drop_item: function(ev,di,s) { |
279 | var d = di.first; | 280 | var d = di.first; |
280 | switch(d.flavour.contentType) { | 281 | switch(d.flavour.contentType) { |
281 | case 'text/unicode': | 282 | case 'text/unicode': |
282 | this.drop_urilist(ev,d.data,s); | 283 | this.drop_urilist(ev,d.data,s); |
283 | break; | 284 | break; |
284 | case 'application/x-moz-file': | 285 | case 'application/x-moz-file': |
285 | this.fireflix.uploads.add(d.data.path); | 286 | this.fireflix.uploads.add(d.data.path); |
286 | document.getElementById('fireflix_tabs').selectedTab | 287 | document.getElementById('fireflix_tabs').selectedTab |
287 | = document.getElementById('tab_upload'); | 288 | = document.getElementById('tab_upload'); |
288 | break; | 289 | break; |
289 | case 'text/uri-list': | 290 | case 'text/uri-list': |
290 | // is it ascii or could it be utf8? | 291 | // is it ascii or could it be utf8? |
291 | this.drop_urilist(ev,splitascii(d.data),s); | 292 | this.drop_urilist(ev,splitascii(d.data),s); |
292 | break; | 293 | break; |
293 | default: alert(d.flavour.contentType+':'+d.data); break; | 294 | default: alert(d.flavour.contentType+':'+d.data); break; |
294 | }; | 295 | }; |
295 | }, | 296 | }, |
296 | drop_urilist: function(ev,ul,s) { | 297 | drop_urilist: function(ev,ul,s) { |
297 | // TODO: check for being a file? | 298 | // TODO: check for being a file? |
298 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 299 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
299 | for(var ui in us) | 300 | for(var ui in us) |
300 | if(/\S/.test(us[ui])) | 301 | if(/\S/.test(us[ui])) |
301 | this.fireflix.uploads.add(us[ui]); | 302 | this.fireflix.uploads.add(us[ui]); |
302 | document.getElementById('fireflix_tabs').selectedTab | 303 | document.getElementById('fireflix_tabs').selectedTab |
303 | = document.getElementById('tab_upload'); | 304 | = document.getElementById('tab_upload'); |
304 | } | 305 | } |
305 | }, | 306 | }, |
306 | 307 | ||
307 | uploads: { | 308 | uploads: { |
308 | fireflix: null, | 309 | fireflix: null, |
309 | init: function(f) { | 310 | init: function(f) { |
310 | this.fireflix=f; | 311 | this.fireflix=f; |
311 | pull_elements(this,document,[ | 312 | pull_elements(this,document,[ |
312 | 'upload_filename','upload_title','upload_file_preview', | 313 | 'upload_filename','upload_title','upload_file_preview', |
313 | 'upload_file_props','upload_progress','upload_tags' | 314 | 'upload_file_props','upload_progress','upload_tags', |
315 | 'cmd_uploads_upload' | ||
314 | ]); | 316 | ]); |
315 | }, | 317 | }, |
316 | files: new Array(), | 318 | files: new Array(), |
317 | rowCount: 0, | 319 | rowCount: 0, |
318 | getCellText: function(r,c) { | 320 | getCellText: function(r,c) { |
319 | var f = this.files[r]; | 321 | var f = this.files[r]; |
320 | if(c.id=='up_file') return f.file; | 322 | if(c.id=='up_file') return f.file; |
321 | if(c.id=='up_title') return f.title; | 323 | if(c.id=='up_title') return f.title; |
322 | if(c.id=='up_status') return f.state; | 324 | if(c.id=='up_status') return f.state; |
323 | return c.id; | 325 | return c.id; |
324 | }, | 326 | }, |
325 | setTree: function(t) { this.tree = t }, | 327 | setTree: function(t) { this.tree = t }, |
326 | isContainer: function(r) { return false; }, | 328 | isContainer: function(r) { return false; }, |
327 | isSeparator: function(r) { return false; }, | 329 | isSeparator: function(r) { return false; }, |
328 | isSorted: function(r) { return false; }, | 330 | isSorted: function(r) { return false; }, |
329 | getLevel: function(r) { return 0; }, | 331 | getLevel: function(r) { return 0; }, |
330 | getImageSrc: function(r,c) { return null }, | 332 | getImageSrc: function(r,c) { return null }, |
331 | getRowProperties: function(r,p) { | 333 | getRowProperties: function(r,p) { |
332 | try { | 334 | try { |
333 | if(!Components) return; | 335 | if(!Components) return; |
334 | }catch(e) { return } | 336 | }catch(e) { return } |
335 | var f = this.files[r]; | 337 | var f = this.files[r]; |
336 | var as = Components.classes['@mozilla.org/atom-service;1']. | 338 | var as = Components.classes['@mozilla.org/atom-service;1']. |
337 | getService(Components.interfaces.nsIAtomService); | 339 | getService(Components.interfaces.nsIAtomService); |
338 | p.AppendElement(as.getAtom(f.state)); | 340 | p.AppendElement(as.getAtom(f.state)); |
339 | }, | 341 | }, |
340 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 342 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
341 | getColumnProperties: function(c,p) { }, | 343 | getColumnProperties: function(c,p) { }, |
342 | cycleHeader: function(cid,e) { }, | 344 | cycleHeader: function(cid,e) { }, |
343 | getParentIndex: function(r) { return -1; }, | 345 | getParentIndex: function(r) { return -1; }, |
344 | drop: function(r,o) { }, | 346 | drop: function(r,o) { }, |
345 | canDropBeforeAfter: function(r,b) { return false }, | 347 | canDropBeforeAfter: function(r,b) { return false }, |
346 | 348 | ||
347 | add: function(f) { | 349 | add: function(f) { |
348 | if(f.indexOf('file:/')==0) { | 350 | if(f.indexOf('file:/')==0) { |
349 | f = f.substr(5); | 351 | f = f.substr(5); |
350 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 352 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
351 | f = f.substr(1); | 353 | f = f.substr(1); |
352 | } | 354 | } |
353 | } | 355 | } |
354 | var t = f; | 356 | var t = f; |
355 | var ls = t.lastIndexOf('/'); | 357 | var ls = t.lastIndexOf('/'); |
356 | if(ls>0) t = t.substr(ls+1); | 358 | if(ls>0) t = t.substr(ls+1); |
357 | ls = t.lastIndexOf('\\'); | 359 | ls = t.lastIndexOf('\\'); |
358 | if(ls>0) t = t.substr(ls+1); | 360 | if(ls>0) t = t.substr(ls+1); |
359 | var ld = t.lastIndexOf('.'); | 361 | var ld = t.lastIndexOf('.'); |
360 | if(ld>0) t = t.substr(0,ld); | 362 | if(ld>0) t = t.substr(0,ld); |
361 | this.files.push( { | 363 | this.files.push( { |
362 | file: f, | 364 | file: f, |
363 | title: t, | 365 | title: t, |
364 | tags: '', | 366 | tags: '', |
365 | state: 'pending' | 367 | state: 'pending' |
366 | } ); | 368 | } ); |
367 | this.rowCount = this.files.length; | 369 | this.rowCount = this.files.length; |
368 | this.tree.rowCountChanged(this.rowCount-1,1); | 370 | this.tree.rowCountChanged(this.rowCount-1,1); |
369 | }, | 371 | }, |
370 | 372 | ||
371 | upload_worker: function() { | 373 | upload_worker: function() { |
372 | for(var f in this.files) { | 374 | for(var f in this.files) { |
373 | if(this.files[f].state=='pending') { | 375 | if(this.files[f].state=='pending') { |
374 | var ff = this.files[f]; | 376 | var ff = this.files[f]; |
375 | dump('upload '+ff.file+'\n'); | 377 | dump('upload '+ff.file+'\n'); |
376 | this.on_file_upload(ff); | 378 | this.on_file_upload(ff); |
377 | ff.state='uploading'; | 379 | ff.state='uploading'; |
378 | this.tree.invalidate(); | 380 | this.tree.invalidate(); |
379 | var _this = this; | 381 | var _this = this; |
380 | this.fireflix.flickr.upload_file( | 382 | this.fireflix.flickr.upload_file( |
381 | ff.file, { title: ff.title, tags: ff.tags }, | 383 | ff.file, { title: ff.title, tags: ff.tags }, |
382 | function(x,p) { | 384 | function(x,p) { |
383 | ff.photoid = p; | 385 | ff.photoid = p; |
384 | _this.batch_ids.push(p); | 386 | _this.batch_ids.push(p); |
385 | ff.state='completed'; | 387 | ff.state='completed'; |
386 | _this.tree.invalidate(); | 388 | _this.tree.invalidate(); |
387 | window.setTimeout(_this.upload_to,0,_this); | 389 | window.setTimeout(_this.upload_to,0,_this); |
388 | }, function(x,s,c,m) { | 390 | }, function(x,s,c,m) { |
389 | ff.state='failed'; | 391 | ff.state='failed'; |
390 | ff.flickr_errcode = c; | 392 | ff.flickr_errcode = c; |
391 | ff.flickr_errmsg = m; | 393 | ff.flickr_errmsg = m; |
392 | _this.tree.invalidate(); | 394 | _this.tree.invalidate(); |
393 | window.setTimeout(_this.upload_to,0,_this); | 395 | window.setTimeout(_this.upload_to,0,_this); |
394 | } | 396 | } |
395 | ); | 397 | ); |
396 | return; | 398 | return; |
397 | } | 399 | } |
398 | } | 400 | } |
399 | dump('uploading done\n'); | 401 | dump('uploading done\n'); |
400 | this.on_finish_upload(); | 402 | this.on_finish_upload(); |
401 | }, | 403 | }, |
402 | upload_to: function(_this) { _this.upload_worker(); }, | 404 | upload_to: function(_this) { _this.upload_worker(); }, |
403 | on_file_upload: function(f) { | 405 | on_file_upload: function(f) { |
404 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); | 406 | this.cmd_uploads_upload.setAttribute('disabled','true'); |
405 | for(var fi in this.files) { | 407 | for(var fi in this.files) { |
406 | if(this.files[fi].file==f.file) { | 408 | if(this.files[fi].file==f.file) { |
407 | this.tree.ensureRowIsVisible(fi); | 409 | this.tree.ensureRowIsVisible(fi); |
408 | this.selection.rangedSelect(fi,fi,false); | 410 | this.selection.rangedSelect(fi,fi,false); |
409 | this.selection.currentIndex = fi; | 411 | this.selection.currentIndex = fi; |
410 | this.selToProps(); | 412 | this.selToProps(); |
411 | break; | 413 | break; |
412 | } | 414 | } |
413 | } | 415 | } |
414 | }, | 416 | }, |
415 | on_finish_upload: function() { | 417 | on_finish_upload: function() { |
416 | if(this.batch_ids.length) { | 418 | if(this.batch_ids.length) { |
417 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 419 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
418 | if(psn!=null) { | 420 | if(psn!=null) { |
419 | var pids = this.batch_ids.join(','); | 421 | var pids = this.batch_ids.join(','); |
420 | var ppid = this.batch_ids[0]; | 422 | var ppid = this.batch_ids[0]; |
421 | var _this = this; | 423 | var _this = this; |
422 | this.fireflix.flickr.api_call( | 424 | this.fireflix.flickr.api_call( |
423 | { | 425 | { |
424 | method: 'flickr.photosets.create', | 426 | method: 'flickr.photosets.create', |
425 | auth_token: 'default', | 427 | auth_token: 'default', |
426 | title: psn, | 428 | title: psn, |
427 | primary_photo_id: ppid | 429 | primary_photo_id: ppid |
428 | }, function(x) { | 430 | }, function(x) { |
429 | var npid = | 431 | var npid = |
430 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); | 432 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); |
431 | _this.fireflix.flickr.api_call( | 433 | _this.fireflix.flickr.api_call( |
432 | { | 434 | { |
433 | method: 'flickr.photosets.editPhotos', | 435 | method: 'flickr.photosets.editPhotos', |
434 | auth_token: 'default', | 436 | auth_token: 'default', |
435 | photoset_id: npid, | 437 | photoset_id: npid, |
436 | primary_photo_id: ppid, | 438 | primary_photo_id: ppid, |
437 | photo_ids: pids | 439 | photo_ids: pids |
438 | }, function(x) { | 440 | }, function(x) { |
439 | _this.fireflix.refresh_sets(); | 441 | _this.fireflix.refresh_sets(); |
440 | }, function(x,s,c,m) { | 442 | }, function(x,s,c,m) { |
441 | _this.fireflix.flickr_failure(x,s,c,m); | 443 | _this.fireflix.flickr_failure(x,s,c,m); |
442 | } | 444 | } |
443 | ); | 445 | ); |
444 | }, function(x,s,c,m) { | 446 | }, function(x,s,c,m) { |
445 | _this.fireflix.flickr_failure(x,s,c,m); | 447 | _this.fireflix.flickr_failure(x,s,c,m); |
446 | } | 448 | } |
447 | ); | 449 | ); |
448 | } | 450 | } |
449 | } | 451 | } |
450 | this.selection.clearSelection(); | 452 | this.selection.clearSelection(); |
451 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); | 453 | this.cmd_uploads_upload.setAttribute('disabled','false'); |
452 | this.upload_progress.setAttribute('hidden','true'); | 454 | this.upload_progress.setAttribute('hidden','true'); |
453 | }, | 455 | }, |
454 | 456 | ||
455 | clear_list: function() { | 457 | clear_list: function() { |
456 | this.tree.beginUpdateBatch(); | 458 | this.tree.beginUpdateBatch(); |
457 | this.rowCount = 0; | 459 | this.rowCount = 0; |
458 | this.files = new Array(); | 460 | this.files = new Array(); |
459 | this.tree.endUpdateBatch(); | 461 | this.tree.endUpdateBatch(); |
460 | this.selToProps(); | 462 | this.selToProps(); |
461 | }, | 463 | }, |
462 | selectionChanged: function() { | 464 | selectionChanged: function() { |
463 | this.selToProps(); | 465 | this.selToProps(); |
464 | }, | 466 | }, |
465 | disableProps: function() { | 467 | disableProps: function() { |
466 | this.upload_filename.value=''; | 468 | this.upload_filename.value=''; |
467 | this.upload_filename.disabled = true; | 469 | this.upload_filename.disabled = true; |
468 | this.upload_title.value=''; | 470 | this.upload_title.value=''; |
469 | this.upload_title.disabled = true; | 471 | this.upload_title.disabled = true; |
470 | this.upload_file_preview.src = null; | 472 | this.upload_file_preview.src = null; |
471 | this.upload_file_props.hidden = true; | 473 | this.upload_file_props.hidden = true; |
472 | this.upload_tags.value=''; | 474 | this.upload_tags.value=''; |
473 | this.upload_tags.disabled = true; | 475 | this.upload_tags.disabled = true; |
474 | }, | 476 | }, |
475 | selToProps: function() { | 477 | selToProps: function() { |
476 | if(!this.selection.count) { | 478 | if(!this.selection.count) { |
477 | this.disableProps(); | 479 | this.disableProps(); |
478 | }else if(this.selection.count==1) { | 480 | }else if(this.selection.count==1) { |
479 | var f=this.files[this.selection.currentIndex]; | 481 | var f=this.files[this.selection.currentIndex]; |
480 | if(f==null || f.state!='pending') { | 482 | if(f==null || f.state!='pending') { |
481 | this.disableProps(); | 483 | this.disableProps(); |
482 | }else{ | 484 | }else{ |
483 | this.upload_filename.value = f.file; | 485 | this.upload_filename.value = f.file; |
484 | this.upload_filename.disabled = false; | 486 | this.upload_filename.disabled = false; |
485 | this.upload_title.value = f.title; | 487 | this.upload_title.value = f.title; |
486 | this.upload_title.disabled = false; | 488 | this.upload_title.disabled = false; |
487 | this.upload_file_preview.src = 'file:///'+f.file; | 489 | this.upload_file_preview.src = 'file:///'+f.file; |
488 | this.upload_file_props.hidden = false; | 490 | this.upload_file_props.hidden = false; |
489 | this.upload_tags.value = f.tags; | 491 | this.upload_tags.value = f.tags; |
490 | this.upload_tags.disabled = false; | 492 | this.upload_tags.disabled = false; |
491 | } | 493 | } |
492 | }else{ | 494 | }else{ |
493 | var ftitle = null; var onetitle = true; | 495 | var ftitle = null; var onetitle = true; |
494 | var ftags = null; var onetag = true; | 496 | var ftags = null; var onetag = true; |
495 | var fs = 0; | 497 | var fs = 0; |
496 | for(var ff in this.files) { | 498 | for(var ff in this.files) { |
497 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 499 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
498 | ++fs; | 500 | ++fs; |
499 | if(ftitle==null) { | 501 | if(ftitle==null) { |