summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
Unidiff
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js36
1 files changed, 14 insertions, 22 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index daf4929..98b6d41 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,120 +1,116 @@
1function splitascii(s) { 1function splitascii(s) {
2 var rv=''; 2 var rv='';
3 for(var i=0;i<s.length;++i) { 3 for(var i=0;i<s.length;++i) {
4 var w = s.charCodeAt(i); 4 var w = s.charCodeAt(i);
5 rv += String.fromCharCode( 5 rv += String.fromCharCode(
6 w&0xff, (w>>8)&0xff ); 6 w&0xff, (w>>8)&0xff );
7 } 7 }
8 return rv; 8 return rv;
9} 9}
10 10
11 11
12var fireflix = { 12var fireflix = {
13 flickr: new Flickr(), 13 flickr: new Flickr(),
14 init: function() { 14 init: function() {
15 this.cmd_auth_auth = document.getElementById('cmd_auth_auth'); 15 pull_elements(this,document,[
16 this.cmd_auth_done = document.getElementById('cmd_auth_done'); 16 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth',
17 this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth'); 17 'menu_auth_done','b_auth','b_auth_done','auth_info',
18 this.menu_auth_done = document.getElementById('menu_auth_done'); 18 'loc_strings','cmd_set_props'
19 this.b_auth = document.getElementById('b_auth'); 19 ]);
20 this.b_auth_done = document.getElementById('b_auth_done');
21 this.auth_info = document.getElementById('auth_info');
22 this.loc_strings = document.getElementById('loc_strings');
23 this.build_menus(); 20 this.build_menus();
24 this.cmd_set_props = document.getElementById('cmd_set_props');
25 this.foundphotos.init(this); 21 this.foundphotos.init(this);
26 this.photosets.init(this); 22 this.photosets.init(this);
27 this.photoset.init(this); 23 this.photoset.init(this);
28 this.uploads.init(this); 24 this.uploads.init(this);
29 this.uploadObserver.init(this); 25 this.uploadObserver.init(this);
30 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; 26 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
31 this.flickr.api_shs = '9c33c9e2f0f0cfd5'; 27 this.flickr.api_shs = '9c33c9e2f0f0cfd5';
32 this.flickr.prefs_root = 'net.klever.kin.fireflix'; 28 this.flickr.prefs_root = 'net.klever.kin.fireflix';
33 this.flickr.load_token(); 29 this.flickr.load_token();
34 document.getElementById('setslist').view = this.photosets; 30 document.getElementById('setslist').view = this.photosets;
35 document.getElementById('setphotos').view = this.photoset; 31 document.getElementById('setphotos').view = this.photoset;
36 document.getElementById('uploadlist').view = this.uploads; 32 document.getElementById('uploadlist').view = this.uploads;
37 this.no_auth_info_label = this.auth_info.value; 33 this.no_auth_info_label = this.auth_info.value;
38 this.set_auth_state(this.flickr.token,false); 34 this.set_auth_state(this.flickr.token,false);
39 if(this.flickr.token) { 35 if(this.flickr.token) {
40 this.refresh_stuff(); 36 this.refresh_stuff();
41 }else{ 37 }else{
42 this.on_cmd_auth(); 38 this.on_cmd_auth();
43 } 39 }
44 }, 40 },
45 set_auth_state: function(au,inp) { /* authorized, in progress */ 41 set_auth_state: function(au,inp) { /* authorized, in progress */
46 this.cmd_auth_unauth.disabled = !au; 42 this.cmd_auth_unauth.disabled = !au;
47 this.b_auth.hidden = au || inp; 43 this.b_auth.hidden = au || inp;
48 this.b_auth_done.hidden = !inp; 44 this.b_auth_done.hidden = !inp;
49 this.menu_auth_done.hidden = !inp; 45 this.menu_auth_done.hidden = !inp;
50 this.cmd_auth_done.setAttribute('disabled',!inp); 46 this.cmd_auth_done.setAttribute('disabled',!inp);
51 this.auth_info.disabled = !au; 47 this.auth_info.disabled = !au;
52 if(au) { 48 if(au) {
53 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 */
54 }else{ 50 }else{
55 this.auth_info.value = this.no_auth_info_label; 51 this.auth_info.value = this.no_auth_info_label;
56 } 52 }
57 }, 53 },
58 on_cmd_auth: function() { 54 on_cmd_auth: function() {
59 var _this = this; 55 var _this = this;
60 this.flickr.authorize_0( 56 this.flickr.authorize_0(
61 function() { 57 function() {
62 _this.set_auth_state(_this.flickr.token,true); 58 _this.set_auth_state(_this.flickr.token,true);
63 }, function(x,s,c,m) { 59 }, function(x,s,c,m) {
64 _this.flickr_failure(x,s,c,m); 60 _this.flickr_failure(x,s,c,m);
65 } 61 }
66 ); 62 );
67 }, 63 },
68 on_cmd_auth_done: function() { 64 on_cmd_auth_done: function() {
69 this.set_auth_state(this.flickr.token,false); 65 this.set_auth_state(this.flickr.token,false);
70 var _this = this; 66 var _this = this;
71 this.flickr.authorize_1( 67 this.flickr.authorize_1(
72 function() { 68 function() {
73 _this.flickr.save_token(); 69 _this.flickr.save_token();
74 _this.refresh_stuff(); 70 _this.refresh_stuff();
75 _this.set_auth_state(_this.flickr.token,false); 71 _this.set_auth_state(_this.flickr.token,false);
76 _this.auth_info.value = 72 _this.auth_info.value =
77 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; 73 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
78 }, function(x,s,c,m) { 74 }, function(x,s,c,m) {
79 _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? */
80 _this.flickr_failure(x,s,c,m); 76 _this.flickr_failure(x,s,c,m);
81 } 77 }
82 ); 78 );
83 }, 79 },
84 on_cmd_auth_unauth: function() { 80 on_cmd_auth_unauth: function() {
85 this.flickr.reset_token(); 81 this.flickr.reset_token();
86 this.set_auth_state(false,false); 82 this.set_auth_state(false,false);
87 }, 83 },
88 84
89 refresh_sets: function() { this.photosets.refresh_sets(); }, 85 refresh_sets: function() { this.photosets.refresh_sets(); },
90 refresh_stuff: function() { 86 refresh_stuff: function() {
91 this.refresh_sets(); 87 this.refresh_sets();
92 this.refresh_user_tags(); 88 this.refresh_user_tags();
93 }, 89 },
94 90
95 /* photoset treeview */ 91 /* photoset treeview */
96 photoset: { 92 photoset: {
97 photos: new Array(), 93 photos: new Array(),
98 fireflix: null, 94 fireflix: null,
99 init: function(f) { 95 init: function(f) {
100 this.fireflix = f; 96 this.fireflix = f;
101 }, 97 },
102 rowCount: 0, 98 rowCount: 0,
103 getCellText: function(r,c) { 99 getCellText: function(r,c) {
104 var p = this.photos[r]; 100 var p = this.photos[r];
105 if(c.id=='sp_title') return p.title; 101 if(c.id=='sp_title') return p.title;
106 if(c.id=='sp_taken') return p.datetaken; 102 if(c.id=='sp_taken') return p.datetaken;
107 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ 103 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */
108 return c.id; 104 return c.id;
109 }, 105 },
110 setTree: function(t) { this.tree = t }, 106 setTree: function(t) { this.tree = t },
111 isContainer: function(r) { return false; }, 107 isContainer: function(r) { return false; },
112 isSeparator: function(r) { return false; }, 108 isSeparator: function(r) { return false; },
113 isSorted: function(r) { return false; }, 109 isSorted: function(r) { return false; },
114 getLevel: function(r) { return 0; }, 110 getLevel: function(r) { return 0; },
115 getImageSrc: function(r,c) { return null }, 111 getImageSrc: function(r,c) { return null },
116 getRowProperties: function(r,p) {}, 112 getRowProperties: function(r,p) {},
117 getCellProperties: function(cid,cel,p) {}, 113 getCellProperties: function(cid,cel,p) {},
118 getColumnProperties: function(cid,cel,p) { }, 114 getColumnProperties: function(cid,cel,p) { },
119 cycleHeader: function(cid,e) { }, 115 cycleHeader: function(cid,e) { },
120 getParentIndex: function(r) { return -1; }, 116 getParentIndex: function(r) { return -1; },
@@ -219,198 +215,196 @@ var fireflix = {
219 if(this.selection.count==1) { 215 if(this.selection.count==1) {
220 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 216 this.fireflix.cmd_set_props.setAttribute('disabled','false');
221 var s = this.sets[this.selection.currentIndex]; 217 var s = this.sets[this.selection.currentIndex];
222 this.fireflix.photoset.load_photos(s.id); 218 this.fireflix.photoset.load_photos(s.id);
223 }else{ 219 }else{
224 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 220 this.fireflix.cmd_set_props.setAttribute('disabled','true');
225 } 221 }
226 } 222 }
227 }, 223 },
228 224
229 refresh_user_tags: function() { 225 refresh_user_tags: function() {
230 var lb = document.getElementById('tagslist'); 226 var lb = document.getElementById('tagslist');
231 var _this = this; 227 var _this = this;
232 this.flickr.api_call( 228 this.flickr.api_call(
233 { 229 {
234 method: 'flickr.tags.getListUser', 230 method: 'flickr.tags.getListUser',
235 auth_token: 'default', 231 auth_token: 'default',
236 }, function(xr) { 232 }, function(xr) {
237 var x = xr.responseXML; 233 var x = xr.responseXML;
238 var xp = x.evaluate( 234 var xp = x.evaluate(
239 '/rsp/who/tags/tag', x, null, 235 '/rsp/who/tags/tag', x, null,
240 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 236 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
241 // TODO: clear list 237 // TODO: clear list
242 var n; while(n=xp.iterateNext()) { 238 var n; while(n=xp.iterateNext()) {
243 lb.appendItem(n.firstChild.nodeValue); 239 lb.appendItem(n.firstChild.nodeValue);
244 } 240 }
245 }, function(x,s,c,m) { 241 }, function(x,s,c,m) {
246 _this.flickr_failure(x,s,c,m); 242 _this.flickr_failure(x,s,c,m);
247 } 243 }
248 ); 244 );
249 }, 245 },
250 246
251 uploadObserver: { 247 uploadObserver: {
252 fireflix: null, 248 fireflix: null,
253 init: function(f) { 249 init: function(f) {
254 this.fireflix = f; 250 this.fireflix = f;
255 }, 251 },
256 getSupportedFlavours: function() { 252 getSupportedFlavours: function() {
257 var rv = new FlavourSet(); 253 var rv = new FlavourSet();
258 rv.appendFlavour('application/x-moz-file','nsIFile'); 254 rv.appendFlavour('application/x-moz-file','nsIFile');
259 rv.appendFlavour('application/x-moz-url'); 255 rv.appendFlavour('application/x-moz-url');
260 rv.appendFlavour('text/uri-list'); 256 rv.appendFlavour('text/uri-list');
261 rv.appendFlavour('text/unicode'); 257 rv.appendFlavour('text/unicode');
262 return rv; 258 return rv;
263 }, 259 },
264 canHandleMultipleItems: true, 260 canHandleMultipleItems: true,
265 onDragOver: function(ev,fl,sess) { 261 onDragOver: function(ev,fl,sess) {
266 return true; 262 return true;
267 }, 263 },
268 onDrop: function(ev,dd,s) { 264 onDrop: function(ev,dd,s) {
269 var ldf = null; 265 var ldf = null;
270 for(var i in dd.dataList) { 266 for(var i in dd.dataList) {
271 var di = dd.dataList[i]; 267 var di = dd.dataList[i];
272 var dif = di.first; 268 var dif = di.first;
273 if( 269 if(
274 ldf==null 270 ldf==null
275 || ldf.flavour.contentType!=dif.flavour.contentType 271 || ldf.flavour.contentType!=dif.flavour.contentType
276 || ldf.contentLength!=dif.contentLength 272 || ldf.contentLength!=dif.contentLength
277 || ldf.data!=dif.data ) 273 || ldf.data!=dif.data )
278 this.drop_item(ev,di,s); 274 this.drop_item(ev,di,s);
279 ldf = dif; 275 ldf = dif;
280 } 276 }
281 }, 277 },
282 drop_item: function(ev,di,s) { 278 drop_item: function(ev,di,s) {
283 var d = di.first; 279 var d = di.first;
284 switch(d.flavour.contentType) { 280 switch(d.flavour.contentType) {
285 case 'text/unicode': 281 case 'text/unicode':
286 this.drop_urilist(ev,d.data,s); 282 this.drop_urilist(ev,d.data,s);
287 break; 283 break;
288 case 'application/x-moz-file': 284 case 'application/x-moz-file':
289 this.fireflix.uploads.add(d.data.path); 285 this.fireflix.uploads.add(d.data.path);
290 document.getElementById('fireflix_tabs').selectedTab 286 document.getElementById('fireflix_tabs').selectedTab
291 = document.getElementById('tab_upload'); 287 = document.getElementById('tab_upload');
292 break; 288 break;
293 case 'text/uri-list': 289 case 'text/uri-list':
294 // is it ascii or could it be utf8? 290 // is it ascii or could it be utf8?
295 this.drop_urilist(ev,splitascii(d.data),s); 291 this.drop_urilist(ev,splitascii(d.data),s);
296 break; 292 break;
297 default: alert(d.flavour.contentType+':'+d.data); break; 293 default: alert(d.flavour.contentType+':'+d.data); break;
298 }; 294 };
299 }, 295 },
300 drop_urilist: function(ev,ul,s) { 296 drop_urilist: function(ev,ul,s) {
301 // TODO: check for being a file? 297 // TODO: check for being a file?
302 var us = decodeURIComponent(ul).split(/[\r\n]/); 298 var us = decodeURIComponent(ul).split(/[\r\n]/);
303 for(var ui in us) 299 for(var ui in us)
304 if(/\S/.test(us[ui])) 300 if(/\S/.test(us[ui]))
305 this.fireflix.uploads.add(us[ui]); 301 this.fireflix.uploads.add(us[ui]);
306 document.getElementById('fireflix_tabs').selectedTab 302 document.getElementById('fireflix_tabs').selectedTab
307 = document.getElementById('tab_upload'); 303 = document.getElementById('tab_upload');
308 } 304 }
309 }, 305 },
310 306
311 uploads: { 307 uploads: {
312 fireflix: null, 308 fireflix: null,
313 init: function(f) { 309 init: function(f) {
314 this.fireflix=f; 310 this.fireflix=f;
315 this.upload_filename = document.getElementById('upload_filename'); 311 pull_elements(this,document,[
316 this.upload_title = document.getElementById('upload_title'); 312 'upload_filename','upload_title','upload_file_preview',
317 this.upload_file_preview = document.getElementById('upload_file_preview'); 313 'upload_file_props','upload_progress','upload_tags'
318 this.upload_file_props = document.getElementById('upload_file_props'); 314 ]);
319 this.upload_progress = document.getElementById('upload_progress');
320 this.upload_tags = document.getElementById('upload_tags');
321 }, 315 },
322 files: new Array(), 316 files: new Array(),
323 rowCount: 0, 317 rowCount: 0,
324 getCellText: function(r,c) { 318 getCellText: function(r,c) {
325 var f = this.files[r]; 319 var f = this.files[r];
326 if(c.id=='up_file') return f.file; 320 if(c.id=='up_file') return f.file;
327 if(c.id=='up_title') return f.title; 321 if(c.id=='up_title') return f.title;
328 if(c.id=='up_status') return f.state; 322 if(c.id=='up_status') return f.state;
329 return c.id; 323 return c.id;
330 }, 324 },
331 setTree: function(t) { this.tree = t }, 325 setTree: function(t) { this.tree = t },
332 isContainer: function(r) { return false; }, 326 isContainer: function(r) { return false; },
333 isSeparator: function(r) { return false; }, 327 isSeparator: function(r) { return false; },
334 isSorted: function(r) { return false; }, 328 isSorted: function(r) { return false; },
335 getLevel: function(r) { return 0; }, 329 getLevel: function(r) { return 0; },
336 getImageSrc: function(r,c) { return null }, 330 getImageSrc: function(r,c) { return null },
337 getRowProperties: function(r,p) { 331 getRowProperties: function(r,p) {
338 try { 332 try {
339 if(!Components) return; 333 if(!Components) return;
340 }catch(e) { return } 334 }catch(e) { return }
341 var f = this.files[r]; 335 var f = this.files[r];
342 var as = Components.classes['@mozilla.org/atom-service;1']. 336 var as = Components.classes['@mozilla.org/atom-service;1'].
343 getService(Components.interfaces.nsIAtomService); 337 getService(Components.interfaces.nsIAtomService);
344 p.AppendElement(as.getAtom(f.state)); 338 p.AppendElement(as.getAtom(f.state));
345 }, 339 },
346 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 340 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
347 getColumnProperties: function(c,p) { }, 341 getColumnProperties: function(c,p) { },
348 cycleHeader: function(cid,e) { }, 342 cycleHeader: function(cid,e) { },
349 getParentIndex: function(r) { return -1; }, 343 getParentIndex: function(r) { return -1; },
350 drop: function(r,o) { }, 344 drop: function(r,o) { },
351 canDropBeforeAfter: function(r,b) { return false }, 345 canDropBeforeAfter: function(r,b) { return false },
352 346
353 add: function(f) { 347 add: function(f) {
354 if(f.indexOf('file:/')==0) { 348 if(f.indexOf('file:/')==0) {
355 f = f.substr(5); 349 f = f.substr(5);
356 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 350 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
357 f = f.substr(1); 351 f = f.substr(1);
358 } 352 }
359 } 353 }
360 var t = f; 354 var t = f;
361 var ls = t.lastIndexOf('/'); 355 var ls = t.lastIndexOf('/');
362 if(ls>0) t = t.substr(ls+1); 356 if(ls>0) t = t.substr(ls+1);
363 ls = t.lastIndexOf('\\'); 357 ls = t.lastIndexOf('\\');
364 if(ls>0) t = t.substr(ls+1); 358 if(ls>0) t = t.substr(ls+1);
365 var ld = t.lastIndexOf('.'); 359 var ld = t.lastIndexOf('.');
366 if(ld>0) t = t.substr(0,ld); 360 if(ld>0) t = t.substr(0,ld);
367 this.files.push( { 361 this.files.push( {
368 file: f, 362 file: f,
369 title: t, 363 title: t,
370 tags: '', 364 tags: '',
371 state: 'pending' 365 state: 'pending'
372 } ); 366 } );
373 this.rowCount = this.files.length; 367 this.rowCount = this.files.length;
374 this.tree.rowCountChanged(this.rowCount-1,1); 368 this.tree.rowCountChanged(this.rowCount-1,1);
375 }, 369 },
376 370
377 upload_worker: function() { 371 upload_worker: function() {
378 for(var f in this.files) { 372 for(var f in this.files) {
379 if(this.files[f].state=='pending') { 373 if(this.files[f].state=='pending') {
380 var ff = this.files[f]; 374 var ff = this.files[f];
381 dump('upload '+ff.file+'\n'); 375 dump('upload '+ff.file+'\n');
382 this.on_file_upload(ff); 376 this.on_file_upload(ff);
383 ff.state='uploading'; 377 ff.state='uploading';
384 this.tree.invalidate(); 378 this.tree.invalidate();
385 var _this = this; 379 var _this = this;
386 this.fireflix.flickr.upload_file( 380 this.fireflix.flickr.upload_file(
387 ff.file, { title: ff.title, tags: ff.tags }, 381 ff.file, { title: ff.title, tags: ff.tags },
388 function(x,p) { 382 function(x,p) {
389 ff.photoid = p; 383 ff.photoid = p;
390 _this.batch_ids.push(p); 384 _this.batch_ids.push(p);
391 ff.state='completed'; 385 ff.state='completed';
392 _this.tree.invalidate(); 386 _this.tree.invalidate();
393 window.setTimeout(_this.upload_to,0,_this); 387 window.setTimeout(_this.upload_to,0,_this);
394 }, function(x,s,c,m) { 388 }, function(x,s,c,m) {
395 ff.state='failed'; 389 ff.state='failed';
396 ff.flickr_errcode = c; 390 ff.flickr_errcode = c;
397 ff.flickr_errmsg = m; 391 ff.flickr_errmsg = m;
398 _this.tree.invalidate(); 392 _this.tree.invalidate();
399 window.setTimeout(_this.upload_to,0,_this); 393 window.setTimeout(_this.upload_to,0,_this);
400 } 394 }
401 ); 395 );
402 return; 396 return;
403 } 397 }
404 } 398 }
405 dump('uploading done\n'); 399 dump('uploading done\n');
406 this.on_finish_upload(); 400 this.on_finish_upload();
407 }, 401 },
408 upload_to: function(_this) { _this.upload_worker(); }, 402 upload_to: function(_this) { _this.upload_worker(); },
409 on_file_upload: function(f) { 403 on_file_upload: function(f) {
410 document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); 404 document.getElementById('cmd_uploads_upload').setAttribute('disabled','true');
411 for(var fi in this.files) { 405 for(var fi in this.files) {
412 if(this.files[fi].file==f.file) { 406 if(this.files[fi].file==f.file) {
413 this.tree.ensureRowIsVisible(fi); 407 this.tree.ensureRowIsVisible(fi);
414 this.selection.rangedSelect(fi,fi,false); 408 this.selection.rangedSelect(fi,fi,false);
415 this.selection.currentIndex = fi; 409 this.selection.currentIndex = fi;
416 this.selToProps(); 410 this.selToProps();
@@ -598,200 +592,198 @@ var fireflix = {
598 auth_token: 'default', 592 auth_token: 'default',
599 photoset_id: pset.id, 593 photoset_id: pset.id,
600 title: pset.title, 594 title: pset.title,
601 description: pset.description 595 description: pset.description
602 }, function(xr) { 596 }, function(xr) {
603 pset.dirty = false; 597 pset.dirty = false;
604 _this.flickr.api_call( 598 _this.flickr.api_call(
605 { 599 {
606 method: 'flickr.photosets.getPhotos', 600 method: 'flickr.photosets.getPhotos',
607 auth_token: 'default', 601 auth_token: 'default',
608 photoset_id: pset.id 602 photoset_id: pset.id
609 }, function(xr) { 603 }, function(xr) {
610 var x = xr.responseXML; 604 var x = xr.responseXML;
611 var xp = x.evaluate( 605 var xp = x.evaluate(
612 '/rsp/photoset/photo', x, null, 606 '/rsp/photoset/photo', x, null,
613 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 607 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
614 var phids = new Array(); 608 var phids = new Array();
615 var priph = null; 609 var priph = null;
616 var n; while(n=xp.iterateNext()) { 610 var n; while(n=xp.iterateNext()) {
617 var pid = n.getAttribute('id'); 611 var pid = n.getAttribute('id');
618 phids.push( pid ); 612 phids.push( pid );
619 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 613 if(pid==pset.primary && n.getAttribute('isprimary')!='1')
620 priph = pid; 614 priph = pid;
621 } 615 }
622 if(priph) { 616 if(priph) {
623 _this.flickr.api_call( 617 _this.flickr.api_call(
624 { 618 {
625 method: 'flickr.photosets.editPhotos', 619 method: 'flickr.photosets.editPhotos',
626 auth_token: 'default', 620 auth_token: 'default',
627 photoset_id: pset.id, 621 photoset_id: pset.id,
628 primary_photo_id: priph, 622 primary_photo_id: priph,
629 photo_ids: phids.join(',') 623 photo_ids: phids.join(',')
630 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 624 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
631 _this.flickr_failure(x,s,c,m); 625 _this.flickr_failure(x,s,c,m);
632 } 626 }
633 ); 627 );
634 } 628 }
635 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 629 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
636 _this.flickr_failure(x,s,c,m); 630 _this.flickr_failure(x,s,c,m);
637 } 631 }
638 ); 632 );
639 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 633 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
640 _this.flickr_failure(x,s,c,m); 634 _this.flickr_failure(x,s,c,m);
641 } 635 }
642 ); 636 );
643 } 637 }
644 }, 638 },
645 on_refresh_sets: function() { 639 on_refresh_sets: function() {
646 this.refresh_sets(); 640 this.refresh_sets();
647 }, 641 },
648 on_cmd_sets_html: function(csfx,ev) { 642 on_cmd_sets_html: function(csfx,ev) {
649 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 643 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
650 var rv = this.build_html(this.photoset.photos,uti,utl); 644 var rv = this.build_html(this.photoset.photos,uti,utl);
651 this.popup_content(rv); 645 this.popup_content(rv);
652 }, 646 },
653 647
654 on_cmd_uploads_html: function(csfx,ev) { 648 on_cmd_uploads_html: function(csfx,ev) {
655 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 649 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
656 var pids = new Array(); 650 var pids = new Array();
657 for(var f in this.uploads.files) { 651 for(var f in this.uploads.files) {
658 if(this.uploads.selection.isSelected(f)) 652 if(this.uploads.selection.isSelected(f))
659 if(this.uploads.files[f].photoid) 653 if(this.uploads.files[f].photoid)
660 pids.push(this.uploads.files[f].photoid); 654 pids.push(this.uploads.files[f].photoid);
661 } 655 }
662 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; 656 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
663 var _this = this; 657 var _this = this;
664 this.flickr.api_call( 658 this.flickr.api_call(
665 { 659 {
666 method: 'flickr.photos.search', 660 method: 'flickr.photos.search',
667 auth_token: 'default', 661 auth_token: 'default',
668 extras: 'original_format', 662 extras: 'original_format',
669 user_id: 'me', 663 user_id: 'me',
670 per_page: pp 664 per_page: pp
671 }, 665 },
672 function(xr) { 666 function(xr) {
673 var x = xr.responseXML; 667 var x = xr.responseXML;
674 var rv = ''; 668 var rv = '';
675 for(var pn in pids) { 669 for(var pn in pids) {
676 var p = pids[pn]; 670 var p = pids[pn];
677 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); 671 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
678 rv += _this.photo_html(pp,uti,utl)+'\n'; 672 rv += _this.photo_html(pp,uti,utl)+'\n';
679 } 673 }
680 _this.popup_content(rv); 674 _this.popup_content(rv);
681 }, function(x,s,c,m) { 675 }, function(x,s,c,m) {
682 _this.flickr_failure(x,s,c,m); 676 _this.flickr_failure(x,s,c,m);
683 } 677 }
684 ); 678 );
685 }, 679 },
686 680
687 /* 681 /*
688 * 682 *
689 */ 683 */
690 foundphotos: { 684 foundphotos: {
691 fireflix: null, 685 fireflix: null,
692 init: function(f) { 686 init: function(f) {
693 this.fireflix = f; 687 this.fireflix = f;
694 this.search_for = document.getElementById('search_for'); 688 pull_elements(this,document,[
695 this.search_tags= document.getElementById('search_tags'); 689 'search_for','search_tags','search_mine',
696 this.search_mine = document.getElementById('search_mine'); 690 'searchresult_props','search_photo',
691 'searchresult_title','searchresult_description'
692 ]);
697 document.getElementById('searchresults').view = this; 693 document.getElementById('searchresults').view = this;
698 this.searchresult_props = document.getElementById('searchresult_props');
699 this.search_photo = document.getElementById('search_photo');
700 this.searchresult_title = document.getElementById('searchresult_title');
701 this.searchresult_description = document.getElementById('searchresult_description');
702 }, 694 },
703 photos: new Array(), 695 photos: new Array(),
704 rowCount: 0, 696 rowCount: 0,
705 getCellText: function(r,c) { 697 getCellText: function(r,c) {
706 var p = this.photos[r]; 698 var p = this.photos[r];
707 if(c.id=='sr_title') return p.title; 699 if(c.id=='sr_title') return p.title;
708 return c.id; 700 return c.id;
709 }, 701 },
710 setTree: function(t) { this.tree = t }, 702 setTree: function(t) { this.tree = t },
711 isContainer: function(r) { return false }, 703 isContainer: function(r) { return false },
712 isSeparator: function(r) { return false }, 704 isSeparator: function(r) { return false },
713 isSorted: function(r) { return false }, 705 isSorted: function(r) { return false },
714 getLevel: function(r) { return 0 }, 706 getLevel: function(r) { return 0 },
715 getImageSrc: function(r,c) { return null }, 707 getImageSrc: function(r,c) { return null },
716 getRowProperties: function(r,p) { }, 708 getRowProperties: function(r,p) { },
717 getCellProperties: function(cid,cel,p) { }, 709 getCellProperties: function(cid,cel,p) { },
718 getColumnProperties: function(cid,cel,p) { }, 710 getColumnProperties: function(cid,cel,p) { },
719 cycleHeader: function(cid,e) { }, 711 cycleHeader: function(cid,e) { },
720 getParentIndex: function(r) { return -1 }, 712 getParentIndex: function(r) { return -1 },
721 drop: function(r,o) { }, 713 drop: function(r,o) { },
722 canDropBeforeAfter: function(r,b) { return false }, 714 canDropBeforeAfter: function(r,b) { return false },
723 715
724 importXPR: function(xp) { 716 importXPR: function(xp) {
725 this.selection.clearSelection(); 717 this.selection.clearSelection();
726 this.selection.currentIndex = -1; 718 this.selection.currentIndex = -1;
727 this.searchresult_props.hidden = true; 719 this.searchresult_props.hidden = true;
728 this.tree.beginUpdateBatch(); 720 this.tree.beginUpdateBatch();
729 this.photos = new Array(); 721 this.photos = new Array();
730 var n; while(n=xp.iterateNext()) { 722 var n; while(n=xp.iterateNext()) {
731 this.photos.push(new Photo(n)); 723 this.photos.push(new Photo(n));
732 } 724 }
733 this.rowCount = this.photos.length; 725 this.rowCount = this.photos.length;
734 this.tree.endUpdateBatch(); 726 this.tree.endUpdateBatch();
735 }, 727 },
736 search_photos: function() { 728 search_photos: function() {
737 var pars = { 729 var pars = {
738 method: 'flickr.photos.search', 730 method: 'flickr.photos.search',
739 auth_token: 'default', 731 auth_token: 'default',
740 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 732 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
741 }; 733 };
742 if(this.search_mine.checked) 734 if(this.search_mine.checked)
743 pars.user_id='me'; 735 pars.user_id='me';
744 if(this.search_tags.checked) { 736 if(this.search_tags.checked) {
745 pars.tags=this.search_for.value.split(/ +/).join(','); 737 pars.tags=this.search_for.value.split(/ +/).join(',');
746 }else{ 738 }else{
747 pars.text=this.search_for.value; 739 pars.text=this.search_for.value;
748 } 740 }
749 var _this = this; 741 var _this = this;
750 this.fireflix.flickr.api_call( pars, 742 this.fireflix.flickr.api_call( pars,
751 function(xr) { 743 function(xr) {
752 var x = xr.responseXML; 744 var x = xr.responseXML;
753 var xp = x.evaluate( 745 var xp = x.evaluate(
754 '/rsp/photos/photo', x, null, 746 '/rsp/photos/photo', x, null,
755 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 747 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
756 _this.importXPR(xp); 748 _this.importXPR(xp);
757 _this.on_select(); 749 _this.on_select();
758 }, function(x,s,c,m) { 750 }, function(x,s,c,m) {
759 _this.fireflix.flickr_failure(x,s,c,m); 751 _this.fireflix.flickr_failure(x,s,c,m);
760 } 752 }
761 ); 753 );
762 }, 754 },
763 on_select: function() { 755 on_select: function() {
764 if(this.selection.currentIndex<0) { 756 if(this.selection.currentIndex<0) {
765 this.searchresult_props.hidden = true; 757 this.searchresult_props.hidden = true;
766 }else{ 758 }else{
767 var p = this.photos[this.selection.currentIndex]; 759 var p = this.photos[this.selection.currentIndex];
768 if(!p) { 760 if(!p) {
769 this.searchresult_props.hidden = true; 761 this.searchresult_props.hidden = true;
770 }else{ 762 }else{
771 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); 763 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
772 this.searchresult_title.value = p.title; 764 this.searchresult_title.value = p.title;
773 this.searchresult_description.value = null; 765 this.searchresult_description.value = null;
774 if(p.description==null && p.description==undefined) { 766 if(p.description==null && p.description==undefined) {
775 var pid = p.id; 767 var pid = p.id;
776 var ci = this.selection.currentIndex; 768 var ci = this.selection.currentIndex;
777 var _this = this; 769 var _this = this;
778 this.fireflix.flickr.api_call( 770 this.fireflix.flickr.api_call(
779 { 771 {
780 method: 'flickr.photos.getInfo', 772 method: 'flickr.photos.getInfo',
781 auth_token: 'default', 773 auth_token: 'default',
782 photo_id: p.id, 774 photo_id: p.id,
783 secret: p.secret 775 secret: p.secret
784 }, function(xr) { 776 }, function(xr) {
785 var pp = _this.photos[ci]; 777 var pp = _this.photos[ci];
786 if(ci==_this.selection.currentIndex && pp.id==pid) { 778 if(ci==_this.selection.currentIndex && pp.id==pid) {
787 var n = xp_node('/rsp/photo',xr.responseXML); 779 var n = xp_node('/rsp/photo',xr.responseXML);
788 pp.fromNode_(n); 780 pp.fromNode_(n);
789 _this.searchresult_description.value=pp.description?pp.description:null; 781 _this.searchresult_description.value=pp.description?pp.description:null;
790 } 782 }
791 }, function(x,s,c,m) { 783 }, function(x,s,c,m) {
792 _this.fireflix.flickr_failure(x,s,c,m); 784 _this.fireflix.flickr_failure(x,s,c,m);
793 } 785 }
794 ); 786 );
795 this.searchresult_props.hidden = false; 787 this.searchresult_props.hidden = false;
796 }else{ 788 }else{
797 this.searchresult_description.value=p.description?p.description:null; 789 this.searchresult_description.value=p.description?p.description:null;