summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
Unidiff
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js2
1 files changed, 0 insertions, 2 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index a4f13b6..0f51397 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -129,537 +129,535 @@ var fireflix = {
129 this.photos = new Array(); 129 this.photos = new Array();
130 var n; while(n=xp.iterateNext()) { 130 var n; while(n=xp.iterateNext()) {
131 this.photos.push(new Photo(n)); 131 this.photos.push(new Photo(n));
132 } 132 }
133 this.rowCount = this.photos.length; 133 this.rowCount = this.photos.length;
134 this.tree.endUpdateBatch(); 134 this.tree.endUpdateBatch();
135 }, 135 },
136 load_photos: function(psid) { 136 load_photos: function(psid) {
137 var _this = this; 137 var _this = this;
138 this.fireflix.flickr.api_call( 138 this.fireflix.flickr.api_call(
139 { 139 {
140 method: 'flickr.photosets.getPhotos', 140 method: 'flickr.photosets.getPhotos',
141 auth_token: 'default', 141 auth_token: 'default',
142 photoset_id: psid, 142 photoset_id: psid,
143 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' 143 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
144 }, function(xr) { 144 }, function(xr) {
145 var x = xr.responseXML; 145 var x = xr.responseXML;
146 var xp = x.evaluate( 146 var xp = x.evaluate(
147 '/rsp/photoset/photo', x, null, 147 '/rsp/photoset/photo', x, null,
148 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 148 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
149 _this.importXPR(xp); 149 _this.importXPR(xp);
150 }, function(x,s,c,m) { 150 }, function(x,s,c,m) {
151 _this.fireflix.flickr_failure(x,s,c,m); 151 _this.fireflix.flickr_failure(x,s,c,m);
152 } 152 }
153 ); 153 );
154 }, 154 },
155 on_select: function() { 155 on_select: function() {
156 if(this.selection.count==1) { 156 if(this.selection.count==1) {
157 var p = this.photos[this.selection.currentIndex]; 157 var p = this.photos[this.selection.currentIndex];
158 this.set_photo.src = 158 this.set_photo.src =
159 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); 159 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
160 this.set_photo.hidden = false; 160 this.set_photo.hidden = false;
161 }else{ 161 }else{
162 this.set_photo.hidden = true; 162 this.set_photo.hidden = true;
163 } 163 }
164 } 164 }
165 }, 165 },
166 166
167 /* photosets treeview */ 167 /* photosets treeview */
168 photosets: { 168 photosets: {
169 sets: new Array(), 169 sets: new Array(),
170 fireflix: null, 170 fireflix: null,
171 init: function(f) { 171 init: function(f) {
172 this.fireflix = f; 172 this.fireflix = f;
173 document.getElementById('setslist').view = this; 173 document.getElementById('setslist').view = this;
174 }, 174 },
175 rowCount: 0, 175 rowCount: 0,
176 getCellText: function(r,c) { 176 getCellText: function(r,c) {
177 var s = this.sets[r]; 177 var s = this.sets[r];
178 if(c.id=='sl_name') return s.title; 178 if(c.id=='sl_name') return s.title;
179 if(c.id=='sl_photos') return s.photos; 179 if(c.id=='sl_photos') return s.photos;
180 return c.id; 180 return c.id;
181 }, 181 },
182 setTree: function(t) { this.tree = t }, 182 setTree: function(t) { this.tree = t },
183 isContainer: function(r) { return false; }, 183 isContainer: function(r) { return false; },
184 isSeparator: function(r) { return false; }, 184 isSeparator: function(r) { return false; },
185 isSorted: function() { return false; }, 185 isSorted: function() { return false; },
186 getLevel: function(r) { return 0; }, 186 getLevel: function(r) { return 0; },
187 getImageSrc: function(r,c) { return null }, 187 getImageSrc: function(r,c) { return null },
188 getRowProperties: function(r,p) {}, 188 getRowProperties: function(r,p) {},
189 getCellProperties: function(cid,cel,p) { }, 189 getCellProperties: function(cid,cel,p) { },
190 getColumnProperties: function(cid,cel,p) { }, 190 getColumnProperties: function(cid,cel,p) { },
191 cycleHeader: function(cid,e) { }, 191 cycleHeader: function(cid,e) { },
192 getParentIndex: function(r) { return -1; }, 192 getParentIndex: function(r) { return -1; },
193 drop: function(r,o) { }, 193 drop: function(r,o) { },
194 canDropBeforeAfter: function(r,b) { return false }, 194 canDropBeforeAfter: function(r,b) { return false },
195 195
196 importXPR: function(xp) { 196 importXPR: function(xp) {
197 this.tree.beginUpdateBatch(); 197 this.tree.beginUpdateBatch();
198 this.sets = new Array(); 198 this.sets = new Array();
199 var n; while(n=xp.iterateNext()) { 199 var n; while(n=xp.iterateNext()) {
200 this.sets.push(new Photoset(n)); 200 this.sets.push(new Photoset(n));
201 } 201 }
202 this.rowCount = this.sets.length; 202 this.rowCount = this.sets.length;
203 this.tree.endUpdateBatch(); 203 this.tree.endUpdateBatch();
204 }, 204 },
205 refresh_sets: function() { 205 refresh_sets: function() {
206 var _this = this; 206 var _this = this;
207 this.fireflix.flickr.api_call( 207 this.fireflix.flickr.api_call(
208 { 208 {
209 method: 'flickr.photosets.getList', 209 method: 'flickr.photosets.getList',
210 auth_token: 'default' 210 auth_token: 'default'
211 }, function(xr) { 211 }, function(xr) {
212 var x = xr.responseXML; 212 var x = xr.responseXML;
213 var xp = x.evaluate( 213 var xp = x.evaluate(
214 '/rsp/photosets/photoset', x, null, 214 '/rsp/photosets/photoset', x, null,
215 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 215 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
216 _this.importXPR(xp); 216 _this.importXPR(xp);
217 }, function(x,s,c,m) { 217 }, function(x,s,c,m) {
218 _this.fireflix.flickr_failure(x,s,c,m); 218 _this.fireflix.flickr_failure(x,s,c,m);
219 } 219 }
220 ); 220 );
221 }, 221 },
222 on_select: function() { 222 on_select: function() {
223 if(this.selection.count==1) { 223 if(this.selection.count==1) {
224 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 224 this.fireflix.cmd_set_props.setAttribute('disabled','false');
225 var s = this.sets[this.selection.currentIndex]; 225 var s = this.sets[this.selection.currentIndex];
226 this.fireflix.photoset.load_photos(s.id); 226 this.fireflix.photoset.load_photos(s.id);
227 }else{ 227 }else{
228 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 228 this.fireflix.cmd_set_props.setAttribute('disabled','true');
229 } 229 }
230 } 230 }
231 }, 231 },
232 232
233 refresh_user_tags: function() { 233 refresh_user_tags: function() {
234 var lb = document.getElementById('tagslist'); 234 var lb = document.getElementById('tagslist');
235 var _this = this; 235 var _this = this;
236 this.flickr.api_call( 236 this.flickr.api_call(
237 { 237 {
238 method: 'flickr.tags.getListUser', 238 method: 'flickr.tags.getListUser',
239 auth_token: 'default', 239 auth_token: 'default',
240 }, function(xr) { 240 }, function(xr) {
241 var x = xr.responseXML; 241 var x = xr.responseXML;
242 var xp = x.evaluate( 242 var xp = x.evaluate(
243 '/rsp/who/tags/tag', x, null, 243 '/rsp/who/tags/tag', x, null,
244 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 244 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
245 // TODO: clear list 245 // TODO: clear list
246 var n; while(n=xp.iterateNext()) { 246 var n; while(n=xp.iterateNext()) {
247 lb.appendItem(n.firstChild.nodeValue); 247 lb.appendItem(n.firstChild.nodeValue);
248 } 248 }
249 }, function(x,s,c,m) { 249 }, function(x,s,c,m) {
250 _this.flickr_failure(x,s,c,m); 250 _this.flickr_failure(x,s,c,m);
251 } 251 }
252 ); 252 );
253 }, 253 },
254 254
255 uploadObserver: { 255 uploadObserver: {
256 fireflix: null, 256 fireflix: null,
257 init: function(f) { 257 init: function(f) {
258 this.fireflix = f; 258 this.fireflix = f;
259 }, 259 },
260 getSupportedFlavours: function() { 260 getSupportedFlavours: function() {
261 var rv = new FlavourSet(); 261 var rv = new FlavourSet();
262 rv.appendFlavour('application/x-moz-file','nsIFile'); 262 rv.appendFlavour('application/x-moz-file','nsIFile');
263 rv.appendFlavour('application/x-moz-url'); 263 rv.appendFlavour('application/x-moz-url');
264 rv.appendFlavour('text/uri-list'); 264 rv.appendFlavour('text/uri-list');
265 rv.appendFlavour('text/unicode'); 265 rv.appendFlavour('text/unicode');
266 return rv; 266 return rv;
267 }, 267 },
268 canHandleMultipleItems: true, 268 canHandleMultipleItems: true,
269 onDragOver: function(ev,fl,sess) { 269 onDragOver: function(ev,fl,sess) {
270 return true; 270 return true;
271 }, 271 },
272 onDrop: function(ev,dd,s) { 272 onDrop: function(ev,dd,s) {
273 var ldf = null; 273 var ldf = null;
274 for(var i in dd.dataList) { 274 for(var i in dd.dataList) {
275 var di = dd.dataList[i]; 275 var di = dd.dataList[i];
276 var dif = di.first; 276 var dif = di.first;
277 if( 277 if(
278 ldf==null 278 ldf==null
279 || ldf.flavour.contentType!=dif.flavour.contentType 279 || ldf.flavour.contentType!=dif.flavour.contentType
280 || ldf.contentLength!=dif.contentLength 280 || ldf.contentLength!=dif.contentLength
281 || ldf.data!=dif.data ) 281 || ldf.data!=dif.data )
282 this.drop_item(ev,di,s); 282 this.drop_item(ev,di,s);
283 ldf = dif; 283 ldf = dif;
284 } 284 }
285 }, 285 },
286 drop_item: function(ev,di,s) { 286 drop_item: function(ev,di,s) {
287 var d = di.first; 287 var d = di.first;
288 switch(d.flavour.contentType) { 288 switch(d.flavour.contentType) {
289 case 'text/unicode': 289 case 'text/unicode':
290 this.drop_urilist(ev,d.data,s); 290 this.drop_urilist(ev,d.data,s);
291 break; 291 break;
292 case 'application/x-moz-file': 292 case 'application/x-moz-file':
293 this.fireflix.uploads.add(d.data.path); 293 this.fireflix.uploads.add(d.data.path);
294 document.getElementById('fireflix_tabs').selectedTab 294 document.getElementById('fireflix_tabs').selectedTab
295 = document.getElementById('tab_upload'); 295 = document.getElementById('tab_upload');
296 break; 296 break;
297 case 'text/uri-list': 297 case 'text/uri-list':
298 // is it ascii or could it be utf8? 298 // is it ascii or could it be utf8?
299 this.drop_urilist(ev,splitascii(d.data),s); 299 this.drop_urilist(ev,splitascii(d.data),s);
300 break; 300 break;
301 default: alert(d.flavour.contentType+':'+d.data); break; 301 default: alert(d.flavour.contentType+':'+d.data); break;
302 }; 302 };
303 }, 303 },
304 drop_urilist: function(ev,ul,s) { 304 drop_urilist: function(ev,ul,s) {
305 // TODO: check for being a file? 305 // TODO: check for being a file?
306 var us = decodeURIComponent(ul).split(/[\r\n]/); 306 var us = decodeURIComponent(ul).split(/[\r\n]/);
307 for(var ui in us) 307 for(var ui in us)
308 if(/\S/.test(us[ui])) 308 if(/\S/.test(us[ui]))
309 this.fireflix.uploads.add(us[ui]); 309 this.fireflix.uploads.add(us[ui]);
310 document.getElementById('fireflix_tabs').selectedTab 310 document.getElementById('fireflix_tabs').selectedTab
311 = document.getElementById('tab_upload'); 311 = document.getElementById('tab_upload');
312 } 312 }
313 }, 313 },
314 314
315 uploads: { 315 uploads: {
316 fireflix: null, 316 fireflix: null,
317 init: function(f) { 317 init: function(f) {
318 this.fireflix=f; 318 this.fireflix=f;
319 pull_elements(this,document,[ 319 pull_elements(this,document,[
320 'upload_filename','upload_title','upload_file_preview', 320 'upload_filename','upload_title','upload_file_preview',
321 'upload_file_props','upload_progress','upload_tags', 321 'upload_file_props','upload_progress','upload_tags',
322 'cmd_uploads_upload' 322 'cmd_uploads_upload'
323 ]); 323 ]);
324 document.getElementById('uploadlist').view = this; 324 document.getElementById('uploadlist').view = this;
325 }, 325 },
326 files: new Array(), 326 files: new Array(),
327 rowCount: 0, 327 rowCount: 0,
328 getCellText: function(r,c) { 328 getCellText: function(r,c) {
329 var f = this.files[r]; 329 var f = this.files[r];
330 if(c.id=='up_file') return f.file; 330 if(c.id=='up_file') return f.file;
331 if(c.id=='up_title') return f.title; 331 if(c.id=='up_title') return f.title;
332 if(c.id=='up_status') return f.state; 332 if(c.id=='up_status') return f.state;
333 return c.id; 333 return c.id;
334 }, 334 },
335 setTree: function(t) { this.tree = t }, 335 setTree: function(t) { this.tree = t },
336 isContainer: function(r) { return false; }, 336 isContainer: function(r) { return false; },
337 isSeparator: function(r) { return false; }, 337 isSeparator: function(r) { return false; },
338 isSorted: function(r) { return false; }, 338 isSorted: function(r) { return false; },
339 getLevel: function(r) { return 0; }, 339 getLevel: function(r) { return 0; },
340 getImageSrc: function(r,c) { return null }, 340 getImageSrc: function(r,c) { return null },
341 getRowProperties: function(r,p) { 341 getRowProperties: function(r,p) {
342 try { 342 try {
343 if(!Components) return; 343 if(!Components) return;
344 }catch(e) { return } 344 }catch(e) { return }
345 var f = this.files[r]; 345 var f = this.files[r];
346 var as = Components.classes['@mozilla.org/atom-service;1']. 346 var as = Components.classes['@mozilla.org/atom-service;1'].
347 getService(Components.interfaces.nsIAtomService); 347 getService(Components.interfaces.nsIAtomService);
348 p.AppendElement(as.getAtom(f.state)); 348 p.AppendElement(as.getAtom(f.state));
349 }, 349 },
350 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 350 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
351 getColumnProperties: function(c,p) { }, 351 getColumnProperties: function(c,p) { },
352 cycleHeader: function(cid,e) { }, 352 cycleHeader: function(cid,e) { },
353 getParentIndex: function(r) { return -1; }, 353 getParentIndex: function(r) { return -1; },
354 drop: function(r,o) { }, 354 drop: function(r,o) { },
355 canDropBeforeAfter: function(r,b) { return false }, 355 canDropBeforeAfter: function(r,b) { return false },
356 356
357 add: function(f) { 357 add: function(f) {
358 if(f.indexOf('file:/')==0) { 358 if(f.indexOf('file:/')==0) {
359 f = f.substr(5); 359 f = f.substr(5);
360 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 360 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
361 f = f.substr(1); 361 f = f.substr(1);
362 } 362 }
363 } 363 }
364 var t = f; 364 var t = f;
365 var ls = t.lastIndexOf('/'); 365 var ls = t.lastIndexOf('/');
366 if(ls>0) t = t.substr(ls+1); 366 if(ls>0) t = t.substr(ls+1);
367 ls = t.lastIndexOf('\\'); 367 ls = t.lastIndexOf('\\');
368 if(ls>0) t = t.substr(ls+1); 368 if(ls>0) t = t.substr(ls+1);
369 var ld = t.lastIndexOf('.'); 369 var ld = t.lastIndexOf('.');
370 if(ld>0) t = t.substr(0,ld); 370 if(ld>0) t = t.substr(0,ld);
371 this.files.push( { 371 this.files.push( {
372 file: f, 372 file: f,
373 title: t, 373 title: t,
374 tags: '', 374 tags: '',
375 state: 'pending' 375 state: 'pending'
376 } ); 376 } );
377 this.rowCount = this.files.length; 377 this.rowCount = this.files.length;
378 this.tree.rowCountChanged(this.rowCount-1,1); 378 this.tree.rowCountChanged(this.rowCount-1,1);
379 }, 379 },
380 380
381 upload_worker: function() { 381 upload_worker: function() {
382 for(var f in this.files) { 382 for(var f in this.files) {
383 if(this.files[f].state=='pending') { 383 if(this.files[f].state=='pending') {
384 var ff = this.files[f]; 384 var ff = this.files[f];
385 dump('upload '+ff.file+'\n');
386 this.on_file_upload(ff); 385 this.on_file_upload(ff);
387 ff.state='uploading'; 386 ff.state='uploading';
388 this.tree.invalidate(); 387 this.tree.invalidate();
389 var _this = this; 388 var _this = this;
390 this.fireflix.flickr.upload_file( 389 this.fireflix.flickr.upload_file(
391 ff.file, { title: ff.title, tags: ff.tags }, 390 ff.file, { title: ff.title, tags: ff.tags },
392 function(x,p) { 391 function(x,p) {
393 ff.photoid = p; 392 ff.photoid = p;
394 _this.batch_ids.push(p); 393 _this.batch_ids.push(p);
395 ff.state='completed'; 394 ff.state='completed';
396 _this.tree.invalidate(); 395 _this.tree.invalidate();
397 window.setTimeout(_this.upload_to,0,_this); 396 window.setTimeout(_this.upload_to,0,_this);
398 }, function(x,s,c,m) { 397 }, function(x,s,c,m) {
399 ff.state='failed'; 398 ff.state='failed';
400 ff.flickr_errcode = c; 399 ff.flickr_errcode = c;
401 ff.flickr_errmsg = m; 400 ff.flickr_errmsg = m;
402 _this.tree.invalidate(); 401 _this.tree.invalidate();
403 window.setTimeout(_this.upload_to,0,_this); 402 window.setTimeout(_this.upload_to,0,_this);
404 } 403 }
405 ); 404 );
406 return; 405 return;
407 } 406 }
408 } 407 }
409 dump('uploading done\n');
410 this.on_finish_upload(); 408 this.on_finish_upload();
411 }, 409 },
412 upload_to: function(_this) { _this.upload_worker(); }, 410 upload_to: function(_this) { _this.upload_worker(); },
413 on_file_upload: function(f) { 411 on_file_upload: function(f) {
414 this.cmd_uploads_upload.setAttribute('disabled','true'); 412 this.cmd_uploads_upload.setAttribute('disabled','true');
415 for(var fi in this.files) { 413 for(var fi in this.files) {
416 if(this.files[fi].file==f.file) { 414 if(this.files[fi].file==f.file) {
417 this.tree.ensureRowIsVisible(fi); 415 this.tree.ensureRowIsVisible(fi);
418 this.selection.rangedSelect(fi,fi,false); 416 this.selection.rangedSelect(fi,fi,false);
419 this.selection.currentIndex = fi; 417 this.selection.currentIndex = fi;
420 this.selToProps(); 418 this.selToProps();
421 break; 419 break;
422 } 420 }
423 } 421 }
424 }, 422 },
425 on_finish_upload: function() { 423 on_finish_upload: function() {
426 if(this.batch_ids.length) { 424 if(this.batch_ids.length) {
427 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 425 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
428 if(psn!=null) { 426 if(psn!=null) {
429 var pids = this.batch_ids.join(','); 427 var pids = this.batch_ids.join(',');
430 var ppid = this.batch_ids[0]; 428 var ppid = this.batch_ids[0];
431 var _this = this; 429 var _this = this;
432 this.fireflix.flickr.api_call( 430 this.fireflix.flickr.api_call(
433 { 431 {
434 method: 'flickr.photosets.create', 432 method: 'flickr.photosets.create',
435 auth_token: 'default', 433 auth_token: 'default',
436 title: psn, 434 title: psn,
437 primary_photo_id: ppid 435 primary_photo_id: ppid
438 }, function(x) { 436 }, function(x) {
439 var npid = 437 var npid =
440 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 438 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
441 _this.fireflix.flickr.api_call( 439 _this.fireflix.flickr.api_call(
442 { 440 {
443 method: 'flickr.photosets.editPhotos', 441 method: 'flickr.photosets.editPhotos',
444 auth_token: 'default', 442 auth_token: 'default',
445 photoset_id: npid, 443 photoset_id: npid,
446 primary_photo_id: ppid, 444 primary_photo_id: ppid,
447 photo_ids: pids 445 photo_ids: pids
448 }, function(x) { 446 }, function(x) {
449 _this.fireflix.refresh_sets(); 447 _this.fireflix.refresh_sets();
450 }, function(x,s,c,m) { 448 }, function(x,s,c,m) {
451 _this.fireflix.flickr_failure(x,s,c,m); 449 _this.fireflix.flickr_failure(x,s,c,m);
452 } 450 }
453 ); 451 );
454 }, function(x,s,c,m) { 452 }, function(x,s,c,m) {
455 _this.fireflix.flickr_failure(x,s,c,m); 453 _this.fireflix.flickr_failure(x,s,c,m);
456 } 454 }
457 ); 455 );
458 } 456 }
459 } 457 }
460 this.selection.clearSelection(); 458 this.selection.clearSelection();
461 this.cmd_uploads_upload.setAttribute('disabled','false'); 459 this.cmd_uploads_upload.setAttribute('disabled','false');
462 this.upload_progress.setAttribute('hidden','true'); 460 this.upload_progress.setAttribute('hidden','true');
463 }, 461 },
464 462
465 clear_list: function() { 463 clear_list: function() {
466 this.tree.beginUpdateBatch(); 464 this.tree.beginUpdateBatch();
467 this.rowCount = 0; 465 this.rowCount = 0;
468 this.files = new Array(); 466 this.files = new Array();
469 this.tree.endUpdateBatch(); 467 this.tree.endUpdateBatch();
470 this.selToProps(); 468 this.selToProps();
471 }, 469 },
472 selectionChanged: function() { 470 selectionChanged: function() {
473 this.selToProps(); 471 this.selToProps();
474 }, 472 },
475 disableProps: function() { 473 disableProps: function() {
476 this.upload_filename.value=''; 474 this.upload_filename.value='';
477 this.upload_filename.disabled = true; 475 this.upload_filename.disabled = true;
478 this.upload_title.value=''; 476 this.upload_title.value='';
479 this.upload_title.disabled = true; 477 this.upload_title.disabled = true;
480 this.upload_file_preview.src = null; 478 this.upload_file_preview.src = null;
481 this.upload_file_props.hidden = true; 479 this.upload_file_props.hidden = true;
482 this.upload_tags.value=''; 480 this.upload_tags.value='';
483 this.upload_tags.disabled = true; 481 this.upload_tags.disabled = true;
484 }, 482 },
485 selToProps: function() { 483 selToProps: function() {
486 if(!this.selection.count) { 484 if(!this.selection.count) {
487 this.disableProps(); 485 this.disableProps();
488 }else if(this.selection.count==1) { 486 }else if(this.selection.count==1) {
489 var f=this.files[this.selection.currentIndex]; 487 var f=this.files[this.selection.currentIndex];
490 if(f==null || f.state!='pending') { 488 if(f==null || f.state!='pending') {
491 this.disableProps(); 489 this.disableProps();
492 }else{ 490 }else{
493 this.upload_filename.value = f.file; 491 this.upload_filename.value = f.file;
494 this.upload_filename.disabled = false; 492 this.upload_filename.disabled = false;
495 this.upload_title.value = f.title; 493 this.upload_title.value = f.title;
496 this.upload_title.disabled = false; 494 this.upload_title.disabled = false;
497 this.upload_file_preview.src = 'file:///'+f.file; 495 this.upload_file_preview.src = 'file:///'+f.file;
498 this.upload_file_props.hidden = false; 496 this.upload_file_props.hidden = false;
499 this.upload_tags.value = f.tags; 497 this.upload_tags.value = f.tags;
500 this.upload_tags.disabled = false; 498 this.upload_tags.disabled = false;
501 } 499 }
502 }else{ 500 }else{
503 var ftitle = null; var onetitle = true; 501 var ftitle = null; var onetitle = true;
504 var ftags = null; var onetag = true; 502 var ftags = null; var onetag = true;
505 var fs = 0; 503 var fs = 0;
506 for(var ff in this.files) { 504 for(var ff in this.files) {
507 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 505 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
508 ++fs; 506 ++fs;
509 if(ftitle==null) { 507 if(ftitle==null) {
510 ftitle = this.files[ff].title; 508 ftitle = this.files[ff].title;
511 }else if(ftitle!=this.files[ff].title) { 509 }else if(ftitle!=this.files[ff].title) {
512 onetitle = false; 510 onetitle = false;
513 } 511 }
514 if(ftags==null) { 512 if(ftags==null) {
515 ftags = this.files[ff].tags; 513 ftags = this.files[ff].tags;
516 }else if(ftags!=this.files[ff].tags) { 514 }else if(ftags!=this.files[ff].tags) {
517 onetag = false; 515 onetag = false;
518 } 516 }
519 } 517 }
520 } 518 }
521 if(fs) { 519 if(fs) {
522 this.upload_filename.value=''; 520 this.upload_filename.value='';
523 this.upload_filename.disabled = true; 521 this.upload_filename.disabled = true;
524 if(onetitle) 522 if(onetitle)
525 this.upload_title.value = ftitle; 523 this.upload_title.value = ftitle;
526 this.upload_title.disabled = false; 524 this.upload_title.disabled = false;
527 if(onetag) 525 if(onetag)
528 this.upload_tags.value = ftags; 526 this.upload_tags.value = ftags;
529 this.upload_tags.disabled = false; 527 this.upload_tags.disabled = false;
530 this.upload_file_preview.src = null; 528 this.upload_file_preview.src = null;
531 this.upload_file_props.hidden = false; 529 this.upload_file_props.hidden = false;
532 }else 530 }else
533 this.disableProps(); 531 this.disableProps();
534 } 532 }
535 }, 533 },
536 propsToSel: function(prop) { 534 propsToSel: function(prop) {
537 if(this.selection.count<=0) return; 535 if(this.selection.count<=0) return;
538 for(var ff in this.files) { 536 for(var ff in this.files) {
539 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 537 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
540 if(prop=='filename') 538 if(prop=='filename')
541 this.files[ff].file = this.upload_filename.value; 539 this.files[ff].file = this.upload_filename.value;
542 if(prop=='title') 540 if(prop=='title')
543 this.files[ff].title = this.upload_title.value; 541 this.files[ff].title = this.upload_title.value;
544 if(prop=='tags') 542 if(prop=='tags')
545 this.files[ff].tags = this.upload_tags.value; 543 this.files[ff].tags = this.upload_tags.value;
546 this.tree.invalidateRow(ff); 544 this.tree.invalidateRow(ff);
547 } 545 }
548 } 546 }
549 }, 547 },
550 548
551 on_upload: function() { 549 on_upload: function() {
552 this.selToProps(); 550 this.selToProps();
553 this.batch_ids = new Array(); 551 this.batch_ids = new Array();
554 this.upload_progress.value=0; 552 this.upload_progress.value=0;
555 this.upload_progress.setAttribute('hidden','false'); 553 this.upload_progress.setAttribute('hidden','false');
556 this.upload_worker(); 554 this.upload_worker();
557 }, 555 },
558 on_clear: function() { 556 on_clear: function() {
559 this.clear_list(); 557 this.clear_list();
560 }, 558 },
561 on_remove: function() { 559 on_remove: function() {
562 if(this.selection.count) { 560 if(this.selection.count) {
563 this.tree.beginUpdateBatch(); 561 this.tree.beginUpdateBatch();
564 for(var i=this.files.length-1;i>=0;--i) { 562 for(var i=this.files.length-1;i>=0;--i) {
565 if(this.selection.isSelected(i)) { 563 if(this.selection.isSelected(i)) {
566 this.files.splice(i,1); 564 this.files.splice(i,1);
567 this.rowCount--; 565 this.rowCount--;
568 } 566 }
569 } 567 }
570 this.tree.endUpdateBatch(); 568 this.tree.endUpdateBatch();
571 this.selection.clearSelection(); 569 this.selection.clearSelection();
572 } 570 }
573 }, 571 },
574 on_add: function() { 572 on_add: function() {
575 var ifp = Components.interfaces.nsIFilePicker; 573 var ifp = Components.interfaces.nsIFilePicker;
576 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 574 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
577 fp.init(window, "Select a File", ifp.modeOpenMultiple); 575 fp.init(window, "Select a File", ifp.modeOpenMultiple);
578 fp.appendFilters(ifp.filterImages); 576 fp.appendFilters(ifp.filterImages);
579 var rv = fp.show(); 577 var rv = fp.show();
580 if(rv==ifp.returnOK) { 578 if(rv==ifp.returnOK) {
581 var ff = fp.files; 579 var ff = fp.files;
582 while(ff.hasMoreElements()) { 580 while(ff.hasMoreElements()) {
583 var f = ff.getNext(); 581 var f = ff.getNext();
584 f.QueryInterface(Components.interfaces.nsIFile); 582 f.QueryInterface(Components.interfaces.nsIFile);
585 this.add(f.path); 583 this.add(f.path);
586 } 584 }
587 } 585 }
588 } 586 }
589 }, 587 },
590 588
591 on_set_props: function() { 589 on_set_props: function() {
592 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 590 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
593 window.openDialog( 591 window.openDialog(
594 "chrome://fireflix/content/photoset-props.xul", 592 "chrome://fireflix/content/photoset-props.xul",
595 null, "dependent,modal,dialog,chrome", this, 593 null, "dependent,modal,dialog,chrome", this,
596 pset ); 594 pset );
597 if(pset.dirty) { 595 if(pset.dirty) {
598 var _this = this; 596 var _this = this;
599 this.flickr.api_call( 597 this.flickr.api_call(
600 { 598 {
601 method: 'flickr.photosets.editMeta', 599 method: 'flickr.photosets.editMeta',
602 auth_token: 'default', 600 auth_token: 'default',
603 photoset_id: pset.id, 601 photoset_id: pset.id,
604 title: pset.title, 602 title: pset.title,
605 description: pset.description 603 description: pset.description
606 }, function(xr) { 604 }, function(xr) {
607 pset.dirty = false; 605 pset.dirty = false;
608 _this.flickr.api_call( 606 _this.flickr.api_call(
609 { 607 {
610 method: 'flickr.photosets.getPhotos', 608 method: 'flickr.photosets.getPhotos',
611 auth_token: 'default', 609 auth_token: 'default',
612 photoset_id: pset.id 610 photoset_id: pset.id
613 }, function(xr) { 611 }, function(xr) {
614 var x = xr.responseXML; 612 var x = xr.responseXML;
615 var xp = x.evaluate( 613 var xp = x.evaluate(
616 '/rsp/photoset/photo', x, null, 614 '/rsp/photoset/photo', x, null,
617 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 615 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
618 var phids = new Array(); 616 var phids = new Array();
619 var priph = null; 617 var priph = null;
620 var n; while(n=xp.iterateNext()) { 618 var n; while(n=xp.iterateNext()) {
621 var pid = n.getAttribute('id'); 619 var pid = n.getAttribute('id');
622 phids.push( pid ); 620 phids.push( pid );
623 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 621 if(pid==pset.primary && n.getAttribute('isprimary')!='1')
624 priph = pid; 622 priph = pid;
625 } 623 }
626 if(priph) { 624 if(priph) {
627 _this.flickr.api_call( 625 _this.flickr.api_call(
628 { 626 {
629 method: 'flickr.photosets.editPhotos', 627 method: 'flickr.photosets.editPhotos',
630 auth_token: 'default', 628 auth_token: 'default',
631 photoset_id: pset.id, 629 photoset_id: pset.id,
632 primary_photo_id: priph, 630 primary_photo_id: priph,
633 photo_ids: phids.join(',') 631 photo_ids: phids.join(',')
634 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 632 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
635 _this.flickr_failure(x,s,c,m); 633 _this.flickr_failure(x,s,c,m);
636 } 634 }
637 ); 635 );
638 } 636 }
639 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 637 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
640 _this.flickr_failure(x,s,c,m); 638 _this.flickr_failure(x,s,c,m);
641 } 639 }
642 ); 640 );
643 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 641 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
644 _this.flickr_failure(x,s,c,m); 642 _this.flickr_failure(x,s,c,m);
645 } 643 }
646 ); 644 );
647 } 645 }
648 }, 646 },
649 on_refresh_sets: function() { 647 on_refresh_sets: function() {
650 this.refresh_sets(); 648 this.refresh_sets();
651 }, 649 },
652 on_cmd_sets_html: function(csfx,ev) { 650 on_cmd_sets_html: function(csfx,ev) {
653 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 651 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
654 var rv = this.build_html(this.photoset.photos,uti,utl); 652 var rv = this.build_html(this.photoset.photos,uti,utl);
655 this.popup_content(rv); 653 this.popup_content(rv);
656 }, 654 },
657 655
658 on_cmd_uploads_html: function(csfx,ev) { 656 on_cmd_uploads_html: function(csfx,ev) {
659 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 657 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
660 var pids = new Array(); 658 var pids = new Array();
661 for(var f in this.uploads.files) { 659 for(var f in this.uploads.files) {
662 if(this.uploads.selection.isSelected(f)) 660 if(this.uploads.selection.isSelected(f))
663 if(this.uploads.files[f].photoid) 661 if(this.uploads.files[f].photoid)
664 pids.push(this.uploads.files[f].photoid); 662 pids.push(this.uploads.files[f].photoid);
665 } 663 }