summaryrefslogtreecommitdiffabout
Unidiff
Diffstat (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js32
1 files changed, 14 insertions, 18 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 34cfd3e..f30daee 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -377,559 +377,555 @@ var fireflix = {
377 var ld = t.lastIndexOf('.'); 377 var ld = t.lastIndexOf('.');
378 if(ld>0) t = t.substr(0,ld); 378 if(ld>0) t = t.substr(0,ld);
379 this.files.push( { 379 this.files.push( {
380 file: f, 380 file: f,
381 title: t, 381 title: t,
382 tags: '', 382 tags: '',
383 is_public: true, is_friend: false, is_family: false, 383 is_public: true, is_friend: false, is_family: false,
384 state: 'pending' 384 state: 'pending'
385 } ); 385 } );
386 this.rowCount = this.files.length; 386 this.rowCount = this.files.length;
387 this.tree.rowCountChanged(this.rowCount-1,1); 387 this.tree.rowCountChanged(this.rowCount-1,1);
388 }, 388 },
389 389
390 upload_worker: function() { 390 upload_worker: function() {
391 for(var f in this.files) { 391 for(var f in this.files) {
392 if(this.files[f].state=='pending') { 392 if(this.files[f].state=='pending') {
393 var ff = this.files[f]; 393 var ff = this.files[f];
394 this.on_file_upload(ff); 394 this.on_file_upload(ff);
395 ff.state='uploading'; 395 ff.state='uploading';
396 this.tree.invalidate(); 396 this.tree.invalidate();
397 var _this = this; 397 var _this = this;
398 this.fireflix.flickr.upload_file( 398 this.fireflix.flickr.upload_file(
399 ff.file, { 399 ff.file, {
400 title: ff.title, tags: ff.tags, 400 title: ff.title, tags: ff.tags,
401 is_public: ff.is_public?'1':'0', 401 is_public: ff.is_public?'1':'0',
402 is_friend: ff.is_friend?'1':'0', 402 is_friend: ff.is_friend?'1':'0',
403 is_family: ff.is_family?'1':'0' 403 is_family: ff.is_family?'1':'0'
404 }, function(x,p) { 404 }, function(x,p) {
405 ff.photoid = p; 405 ff.photoid = p;
406 _this.batch_ids.push(p); 406 _this.batch_ids.push(p);
407 ff.state='completed'; 407 ff.state='completed';
408 _this.tree.invalidate(); 408 _this.tree.invalidate();
409 window.setTimeout(_this.upload_to,0,_this); 409 window.setTimeout(_this.upload_to,0,_this);
410 }, function(x,s,c,m) { 410 }, function(x,s,c,m) {
411 ff.state='failed'; 411 ff.state='failed';
412 ff.flickr_errcode = c; 412 ff.flickr_errcode = c;
413 ff.flickr_errmsg = m; 413 ff.flickr_errmsg = m;
414 _this.tree.invalidate(); 414 _this.tree.invalidate();
415 window.setTimeout(_this.upload_to,0,_this); 415 window.setTimeout(_this.upload_to,0,_this);
416 } 416 }
417 ); 417 );
418 return; 418 return;
419 } 419 }
420 } 420 }
421 this.on_finish_upload(); 421 this.on_finish_upload();
422 }, 422 },
423 upload_to: function(_this) { _this.upload_worker(); }, 423 upload_to: function(_this) { _this.upload_worker(); },
424 on_file_upload: function(f) { 424 on_file_upload: function(f) {
425 this.cmd_uploads_upload.setAttribute('disabled','true'); 425 this.cmd_uploads_upload.setAttribute('disabled','true');
426 for(var fi in this.files) { 426 for(var fi in this.files) {
427 if(this.files[fi].file==f.file) { 427 if(this.files[fi].file==f.file) {
428 this.tree.ensureRowIsVisible(fi); 428 this.tree.ensureRowIsVisible(fi);
429 this.selection.rangedSelect(fi,fi,false); 429 this.selection.rangedSelect(fi,fi,false);
430 this.selection.currentIndex = fi; 430 this.selection.currentIndex = fi;
431 this.selToProps(); 431 this.selToProps();
432 break; 432 break;
433 } 433 }
434 } 434 }
435 }, 435 },
436 on_finish_upload: function() { 436 on_finish_upload: function() {
437 if(this.batch_ids.length) { 437 if(this.batch_ids.length) {
438 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 438 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
439 if(psn!=null) { 439 if(psn!=null) {
440 var pids = this.batch_ids.join(','); 440 var pids = this.batch_ids.join(',');
441 var ppid = this.batch_ids[0]; 441 var ppid = this.batch_ids[0];
442 var that = this; 442 var that = this;
443 this.fireflix.flickr.api_call_json( 443 this.fireflix.flickr.api_call_json(
444 { 444 {
445 method: 'flickr.photosets.create', 445 method: 'flickr.photosets.create',
446 auth_token: 'default', 446 auth_token: 'default',
447 title: psn, 447 title: psn,
448 primary_photo_id: ppid 448 primary_photo_id: ppid
449 }, function(x,j) { 449 }, function(x,j) {
450 var npid = j.photoset.id; 450 var npid = j.photoset.id;
451 that.fireflix.flickr.api_call_json( 451 that.fireflix.flickr.api_call_json(
452 { 452 {
453 method: 'flickr.photosets.editPhotos', 453 method: 'flickr.photosets.editPhotos',
454 auth_token: 'default', 454 auth_token: 'default',
455 photoset_id: npid, 455 photoset_id: npid,
456 primary_photo_id: ppid, 456 primary_photo_id: ppid,
457 photo_ids: pids 457 photo_ids: pids
458 }, function(x,j) { 458 }, function(x,j) {
459 that.fireflix.refresh_sets(); 459 that.fireflix.refresh_sets();
460 }, function(x,s,c,m) { 460 }, function(x,s,c,m) {
461 that.fireflix.flickr_failure(x,s,c,m); 461 that.fireflix.flickr_failure(x,s,c,m);
462 } 462 }
463 ); 463 );
464 }, function(x,s,c,m) { 464 }, function(x,s,c,m) {
465 that.fireflix.flickr_failure(x,s,c,m); 465 that.fireflix.flickr_failure(x,s,c,m);
466 } 466 }
467 ); 467 );
468 } 468 }
469 } 469 }
470 this.selection.clearSelection(); 470 this.selection.clearSelection();
471 this.cmd_uploads_upload.setAttribute('disabled','false'); 471 this.cmd_uploads_upload.setAttribute('disabled','false');
472 this.upload_progress.setAttribute('hidden','true'); 472 this.upload_progress.setAttribute('hidden','true');
473 }, 473 },
474 474
475 clear_list: function() { 475 clear_list: function() {
476 this.tree.beginUpdateBatch(); 476 this.tree.beginUpdateBatch();
477 this.rowCount = 0; 477 this.rowCount = 0;
478 this.files = new Array(); 478 this.files = new Array();
479 this.tree.endUpdateBatch(); 479 this.tree.endUpdateBatch();
480 this.selToProps(); 480 this.selToProps();
481 }, 481 },
482 selectionChanged: function() { 482 selectionChanged: function() {
483 this.selToProps(); 483 this.selToProps();
484 }, 484 },
485 disableProps: function() { 485 disableProps: function() {
486 this.upload_filename.value=''; 486 this.upload_filename.value='';
487 this.upload_filename.disabled = true; 487 this.upload_filename.disabled = true;
488 this.upload_title.value=''; 488 this.upload_title.value='';
489 this.upload_title.disabled = true; 489 this.upload_title.disabled = true;
490 this.upload_file_preview.src = null; 490 this.upload_file_preview.src = null;
491 this.upload_tags.value=''; 491 this.upload_tags.value='';
492 this.upload_tags.disabled = true; 492 this.upload_tags.disabled = true;
493 this.upload_is_public.disabled = true; 493 this.upload_is_public.disabled = true;
494 this.upload_is_friends.disabled = true; 494 this.upload_is_friends.disabled = true;
495 this.upload_is_family.disabled = true; 495 this.upload_is_family.disabled = true;
496 /* this.upload_file_props.hidden = true; */ 496 /* this.upload_file_props.hidden = true; */
497 }, 497 },
498 selToProps: function() { 498 selToProps: function() {
499 if(!this.selection.count) { 499 if(!this.selection.count) {
500 this.disableProps(); 500 this.disableProps();
501 this.upload_file_props.hidden = true; 501 this.upload_file_props.hidden = true;
502 }else if(this.selection.count==1) { 502 }else if(this.selection.count==1) {
503 var f=this.files[this.selection.currentIndex]; 503 var f=this.files[this.selection.currentIndex];
504 if(f==null) { 504 if(f==null) {
505 this.disableProps(); 505 this.disableProps();
506 this.upload_file_props.hidden = true; 506 this.upload_file_props.hidden = true;
507 }else{ 507 }else{
508 var inactives = f.state!='pending'; 508 var inactives = f.state!='pending';
509 this.upload_filename.value = f.file; this.upload_filename.disabled = inactives; 509 this.upload_filename.value = f.file; this.upload_filename.disabled = inactives;
510 this.upload_title.value = f.title; this.upload_title.disabled = inactives; 510 this.upload_title.value = f.title; this.upload_title.disabled = inactives;
511 this.upload_file_preview.src = 'file:///'+f.file; 511 this.upload_file_preview.src = 'file:///'+f.file;
512 this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives; 512 this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives;
513 this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives; 513 this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives;
514 this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives; 514 this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives;
515 this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives; 515 this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives;
516 if(f.state=='failed') { 516 if(f.state=='failed') {
517 this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg; 517 this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg;
518 this.upload_failure.hidden = false; 518 this.upload_failure.hidden = false;
519 }else{ 519 }else{
520 this.upload_failure.hidden = true; 520 this.upload_failure.hidden = true;
521 } 521 }
522 this.upload_file_props.hidden = false; 522 this.upload_file_props.hidden = false;
523 } 523 }
524 }else{ 524 }else{
525 var ftitle = null; var onetitle = true; 525 var ftitle = null; var onetitle = true;
526 var ftags = null; var onetag = true; 526 var ftags = null; var onetag = true;
527 var fs = 0; 527 var fs = 0;
528 for(var ff in this.files) { 528 for(var ff in this.files) {
529 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 529 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
530 ++fs; 530 ++fs;
531 if(ftitle==null) { 531 if(ftitle==null) {
532 ftitle = this.files[ff].title; 532 ftitle = this.files[ff].title;
533 }else if(ftitle!=this.files[ff].title) { 533 }else if(ftitle!=this.files[ff].title) {
534 onetitle = false; 534 onetitle = false;
535 } 535 }
536 if(ftags==null) { 536 if(ftags==null) {
537 ftags = this.files[ff].tags; 537 ftags = this.files[ff].tags;
538 }else if(ftags!=this.files[ff].tags) { 538 }else if(ftags!=this.files[ff].tags) {
539 onetag = false; 539 onetag = false;
540 } 540 }
541 } 541 }
542 } 542 }
543 if(fs) { 543 if(fs) {
544 this.upload_filename.value=''; 544 this.upload_filename.value='';
545 this.upload_filename.disabled = true; 545 this.upload_filename.disabled = true;
546 if(onetitle) 546 if(onetitle)
547 this.upload_title.value = ftitle; 547 this.upload_title.value = ftitle;
548 this.upload_title.disabled = false; 548 this.upload_title.disabled = false;
549 if(onetag) 549 if(onetag)
550 this.upload_tags.value = ftags; 550 this.upload_tags.value = ftags;
551 this.upload_tags.disabled = false; 551 this.upload_tags.disabled = false;
552 this.upload_file_preview.src = null; 552 this.upload_file_preview.src = null;
553 this.upload_failure.hidden = true; 553 this.upload_failure.hidden = true;
554 this.upload_file_props.hidden = false; 554 this.upload_file_props.hidden = false;
555 }else 555 }else
556 this.disableProps(); 556 this.disableProps();
557 this.upload_file_props.hidden = true; 557 this.upload_file_props.hidden = true;
558 } 558 }
559 }, 559 },
560 propsToSel: function(prop) { 560 propsToSel: function(prop) {
561 if(this.selection.count<=0) return; 561 if(this.selection.count<=0) return;
562 for(var ff in this.files) { 562 for(var ff in this.files) {
563 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 563 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
564 if(prop=='filename') this.files[ff].file = this.upload_filename.value; 564 if(prop=='filename') this.files[ff].file = this.upload_filename.value;
565 if(prop=='title') this.files[ff].title = this.upload_title.value; 565 if(prop=='title') this.files[ff].title = this.upload_title.value;
566 if(prop=='tags') this.files[ff].tags = this.upload_tags.value; 566 if(prop=='tags') this.files[ff].tags = this.upload_tags.value;
567 if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked; 567 if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked;
568 if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked; 568 if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked;
569 if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked; 569 if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked;
570 this.tree.invalidateRow(ff); 570 this.tree.invalidateRow(ff);
571 } 571 }
572 } 572 }
573 }, 573 },
574 574
575 on_upload: function() { 575 on_upload: function() {
576 this.selToProps(); 576 this.selToProps();
577 this.batch_ids = new Array(); 577 this.batch_ids = new Array();
578 this.upload_progress.value=0; 578 this.upload_progress.value=0;
579 this.upload_progress.setAttribute('hidden','false'); 579 this.upload_progress.setAttribute('hidden','false');
580 this.upload_worker(); 580 this.upload_worker();
581 }, 581 },
582 on_clear: function() { 582 on_clear: function() {
583 this.clear_list(); 583 this.clear_list();
584 }, 584 },
585 on_remove: function() { 585 on_remove: function() {
586 if(this.selection.count) { 586 if(this.selection.count) {
587 this.tree.beginUpdateBatch(); 587 this.tree.beginUpdateBatch();
588 for(var i=this.files.length-1;i>=0;--i) { 588 for(var i=this.files.length-1;i>=0;--i) {
589 if(this.selection.isSelected(i)) { 589 if(this.selection.isSelected(i)) {
590 this.files.splice(i,1); 590 this.files.splice(i,1);
591 this.rowCount--; 591 this.rowCount--;
592 } 592 }
593 } 593 }
594 this.tree.endUpdateBatch(); 594 this.tree.endUpdateBatch();
595 this.selection.clearSelection(); 595 this.selection.clearSelection();
596 } 596 }
597 }, 597 },
598 on_add: function() { 598 on_add: function() {
599 var ifp = Components.interfaces.nsIFilePicker; 599 var ifp = Components.interfaces.nsIFilePicker;
600 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 600 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
601 fp.init(window, "Select a File", ifp.modeOpenMultiple); 601 fp.init(window, "Select a File", ifp.modeOpenMultiple);
602 fp.appendFilters(ifp.filterImages); 602 fp.appendFilters(ifp.filterImages);
603 var rv = fp.show(); 603 var rv = fp.show();
604 if(rv==ifp.returnOK) { 604 if(rv==ifp.returnOK) {
605 var ff = fp.files; 605 var ff = fp.files;
606 while(ff.hasMoreElements()) { 606 while(ff.hasMoreElements()) {
607 var f = ff.getNext(); 607 var f = ff.getNext();
608 f.QueryInterface(Components.interfaces.nsIFile); 608 f.QueryInterface(Components.interfaces.nsIFile);
609 this.add(f.path); 609 this.add(f.path);
610 } 610 }
611 } 611 }
612 }, 612 },
613 on_cmd_open: function(ev) { 613 on_cmd_open: function(ev) {
614 if(this.selection.currentIndex<0) return; 614 if(this.selection.currentIndex<0) return;
615 var f = this.files[this.selection.currentIndex]; 615 var f = this.files[this.selection.currentIndex];
616 if(f.photoid) { 616 if(f.photoid) {
617 this.fireflix.openTab( 617 this.fireflix.openTab(
618 this.fireflix.flickr.make_uploader_edit_url(f.photoid) 618 this.fireflix.flickr.make_uploader_edit_url(f.photoid)
619 ); 619 );
620 }else{ 620 }else{
621 this.fireflix.openTab( 'file://'+f.file); 621 this.fireflix.openTab( 'file://'+f.file);
622 } 622 }
623 } 623 }
624 }, 624 },
625 625
626 on_set_props: function() { 626 on_set_props: function() {
627 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 627 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
628 window.openDialog( 628 window.openDialog(
629 "chrome://fireflix/content/photoset-props.xul", 629 "chrome://fireflix/content/photoset-props.xul",
630 null, "dependent,modal,dialog,chrome", this, 630 null, "dependent,modal,dialog,chrome", this,
631 pset ); 631 pset );
632 if(pset.dirty) { 632 if(pset.dirty) {
633 var _this = this; 633 var that = this;
634 this.flickr.api_call( 634 this.flickr.api_call_json(
635 { 635 {
636 method: 'flickr.photosets.editMeta', 636 method: 'flickr.photosets.editMeta',
637 auth_token: 'default', 637 auth_token: 'default',
638 photoset_id: pset.id, 638 photoset_id: pset.id,
639 title: pset.title, 639 title: pset.title,
640 description: pset.description 640 description: pset.description
641 }, function(xr) { 641 }, function(x,j) {
642 pset.dirty = false; 642 pset.dirty = false;
643 _this.flickr.api_call( 643 that.flickr.api_call_json(
644 { 644 {
645 method: 'flickr.photosets.getPhotos', 645 method: 'flickr.photosets.getPhotos',
646 auth_token: 'default', 646 auth_token: 'default',
647 photoset_id: pset.id 647 photoset_id: pset.id
648 }, function(xr) { 648 }, function(x,j) {
649 var x = xr.responseXML; 649 var pp = j.photoset.photo;
650 var xp = x.evaluate(
651 '/rsp/photoset/photo', x, null,
652 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
653 var phids = new Array(); 650 var phids = new Array();
654 var priph = null; 651 var priph = null;
655 var n; while(n=xp.iterateNext()) { 652 for(var i in pp) {
656 var pid = n.getAttribute('id'); 653 var pid = pp[i].id;
657 phids.push( pid ); 654 phids.push(pid);
658 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 655 if(pid==pset.primary && pp[i].isprimary) priph = pid;
659 priph = pid;
660 } 656 }
661 if(priph) { 657 if(priph) {
662 _this.flickr.api_call( 658 that.flickr.api_call_json(
663 { 659 {
664 method: 'flickr.photosets.editPhotos', 660 method: 'flickr.photosets.editPhotos',
665 auth_token: 'default', 661 auth_token: 'default',
666 photoset_id: pset.id, 662 photoset_id: pset.id,
667 primary_photo_id: priph, 663 primary_photo_id: priph,
668 photo_ids: phids.join(',') 664 photo_ids: phids.join(',')
669 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 665 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
670 _this.flickr_failure(x,s,c,m); 666 that.flickr_failure(x,s,c,m);
671 } 667 }
672 ); 668 );
673 } 669 }
674 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 670 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
675 _this.flickr_failure(x,s,c,m); 671 that.flickr_failure(x,s,c,m);
676 } 672 }
677 ); 673 );
678 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 674 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
679 _this.flickr_failure(x,s,c,m); 675 that.flickr_failure(x,s,c,m);
680 } 676 }
681 ); 677 );
682 } 678 }
683 }, 679 },
684 on_refresh_sets: function() { 680 on_refresh_sets: function() {
685 this.refresh_sets(); 681 this.refresh_sets();
686 }, 682 },
687 on_cmd_sets_html: function(csfx,ev) { 683 on_cmd_sets_html: function(csfx,ev) {
688 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 684 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
689 var rv = this.build_html(this.photoset.photos,uti,utl); 685 var rv = this.build_html(this.photoset.photos,uti,utl);
690 this.popup_content(rv); 686 this.popup_content(rv);
691 }, 687 },
692 on_cmd_setphotos_html: function(csfx,ev) { 688 on_cmd_setphotos_html: function(csfx,ev) {
693 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 689 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
694 var rv = ''; 690 var rv = '';
695 for(var p in this.photoset.photos) { 691 for(var p in this.photoset.photos) {
696 if(this.photoset.selection.isSelected(p)) 692 if(this.photoset.selection.isSelected(p))
697 rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n'; 693 rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n';
698 } 694 }
699 this.popup_content(rv); 695 this.popup_content(rv);
700 }, 696 },
701 697
702 on_cmd_uploads_html: function(csfx,ev) { 698 on_cmd_uploads_html: function(csfx,ev) {
703 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 699 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
704 var pids = new Array(); 700 var pids = new Array();
705 for(var f in this.uploads.files) { 701 for(var f in this.uploads.files) {
706 if(this.uploads.selection.isSelected(f)) 702 if(this.uploads.selection.isSelected(f))
707 if(this.uploads.files[f].photoid) 703 if(this.uploads.files[f].photoid)
708 pids.push(this.uploads.files[f].photoid); 704 pids.push(this.uploads.files[f].photoid);
709 } 705 }
710 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; 706 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
711 var _this = this; 707 var _this = this;
712 this.flickr.api_call( 708 this.flickr.api_call(
713 { 709 {
714 method: 'flickr.photos.search', 710 method: 'flickr.photos.search',
715 auth_token: 'default', 711 auth_token: 'default',
716 extras: 'original_format', 712 extras: 'original_format',
717 user_id: 'me', 713 user_id: 'me',
718 per_page: pp 714 per_page: pp
719 }, 715 },
720 function(xr) { 716 function(xr) {
721 var x = xr.responseXML; 717 var x = xr.responseXML;
722 var rv = ''; 718 var rv = '';
723 for(var pn in pids) { 719 for(var pn in pids) {
724 var p = pids[pn]; 720 var p = pids[pn];
725 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); 721 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
726 rv += _this.photo_html(pp,uti,utl)+'\n'; 722 rv += _this.photo_html(pp,uti,utl)+'\n';
727 } 723 }
728 _this.popup_content(rv); 724 _this.popup_content(rv);
729 }, function(x,s,c,m) { 725 }, function(x,s,c,m) {
730 _this.flickr_failure(x,s,c,m); 726 _this.flickr_failure(x,s,c,m);
731 } 727 }
732 ); 728 );
733 }, 729 },
734 730
735 /* 731 /*
736 * 732 *
737 */ 733 */
738 foundphotos: { 734 foundphotos: {
739 fireflix: null, 735 fireflix: null,
740 init: function(f) { 736 init: function(f) {
741 this.fireflix = f; 737 this.fireflix = f;
742 pull_elements(this,document,[ 738 pull_elements(this,document,[
743 'search_for','search_tags','search_mine', 739 'search_for','search_tags','search_mine',
744 'searchresult_props','search_photo', 740 'searchresult_props','search_photo',
745 'searchresult_title','searchresult_description', 741 'searchresult_title','searchresult_description',
746 'search_page','cmd_search_prev_page','cmd_search_next_page' 742 'search_page','cmd_search_prev_page','cmd_search_next_page'
747 ]); 743 ]);
748 document.getElementById('searchresults').view = this; 744 document.getElementById('searchresults').view = this;
749 }, 745 },
750 photos: new Array(), 746 photos: new Array(),
751 rowCount: 0, 747 rowCount: 0,
752 getCellText: function(r,c) { 748 getCellText: function(r,c) {
753 var p = this.photos[r]; 749 var p = this.photos[r];
754 if(c.id=='sr_title') return p.title; 750 if(c.id=='sr_title') return p.title;
755 return c.id; 751 return c.id;
756 }, 752 },
757 setTree: function(t) { this.tree = t }, 753 setTree: function(t) { this.tree = t },
758 isContainer: function(r) { return false }, 754 isContainer: function(r) { return false },
759 isSeparator: function(r) { return false }, 755 isSeparator: function(r) { return false },
760 isSorted: function(r) { return false }, 756 isSorted: function(r) { return false },
761 getLevel: function(r) { return 0 }, 757 getLevel: function(r) { return 0 },
762 getImageSrc: function(r,c) { return null }, 758 getImageSrc: function(r,c) { return null },
763 getRowProperties: function(r,p) { }, 759 getRowProperties: function(r,p) { },
764 getCellProperties: function(cid,cel,p) { }, 760 getCellProperties: function(cid,cel,p) { },
765 getColumnProperties: function(cid,cel,p) { }, 761 getColumnProperties: function(cid,cel,p) { },
766 cycleHeader: function(cid,e) { }, 762 cycleHeader: function(cid,e) { },
767 getParentIndex: function(r) { return -1 }, 763 getParentIndex: function(r) { return -1 },
768 drop: function(r,o) { }, 764 drop: function(r,o) { },
769 canDropBeforeAfter: function(r,b) { return false }, 765 canDropBeforeAfter: function(r,b) { return false },
770 766
771 import_json: function(jp) { 767 import_json: function(jp) {
772 this.selection.clearSelection(); 768 this.selection.clearSelection();
773 this.selection.currentIndex=-1; 769 this.selection.currentIndex=-1;
774 this.searchresult_props.hidden=true; 770 this.searchresult_props.hidden=true;
775 this.tree.beginUpdateBatch(); 771 this.tree.beginUpdateBatch();
776 this.photos = new Array(); 772 this.photos = new Array();
777 for(var i in jp) { 773 for(var i in jp) {
778 this.photos.push(new Photo(jp[i])); 774 this.photos.push(new Photo(jp[i]));
779 } 775 }
780 this.rowCount = this.photos.length; 776 this.rowCount = this.photos.length;
781 this.tree.endUpdateBatch(); 777 this.tree.endUpdateBatch();
782 }, 778 },
783 paging: { 779 paging: {
784 pars: null, 780 pars: null,
785 page: null, pages: null, perpage: null, total: null 781 page: null, pages: null, perpage: null, total: null
786 }, 782 },
787 search_photos: function() { 783 search_photos: function() {
788 var pars = { 784 var pars = {
789 method: 'flickr.photos.search', 785 method: 'flickr.photos.search',
790 auth_token: 'default', 786 auth_token: 'default',
791 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 787 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
792 }; 788 };
793 if(this.search_mine.checked) 789 if(this.search_mine.checked)
794 pars.user_id='me'; 790 pars.user_id='me';
795 if(this.search_tags.checked) { 791 if(this.search_tags.checked) {
796 pars.tags=this.search_for.value.split(/ +/).join(','); 792 pars.tags=this.search_for.value.split(/ +/).join(',');
797 }else{ 793 }else{
798 pars.text=this.search_for.value; 794 pars.text=this.search_for.value;
799 } 795 }
800 this.paging.pars = new Object(); 796 this.paging.pars = new Object();
801 this.paging.page = null; this.paging.pages = null; 797 this.paging.page = null; this.paging.pages = null;
802 this.paging.perpage = null; this.paging.total = null; 798 this.paging.perpage = null; this.paging.total = null;
803 for(var p in pars) this.paging.pars[p] = pars[p]; 799 for(var p in pars) this.paging.pars[p] = pars[p];
804 this.perform_search(pars); 800 this.perform_search(pars);
805 }, 801 },
806 perform_search: function(p) { 802 perform_search: function(p) {
807 var that = this; 803 var that = this;
808 this.fireflix.flickr.api_call_json( p, 804 this.fireflix.flickr.api_call_json( p,
809 function(x,j) { 805 function(x,j) {
810 that.import_json(j.photos.photo); 806 that.import_json(j.photos.photo);
811 that.tree.ensureRowIsVisible(0); 807 that.tree.ensureRowIsVisible(0);
812 var pp=j.photos; 808 var pp=j.photos;
813 that.paging.page = pp.page; that.paging.pages = pp.pages; 809 that.paging.page = pp.page; that.paging.pages = pp.pages;
814 that.paging.perpage = pp.perpage; 810 that.paging.perpage = pp.perpage;
815 that.paging.total = pp.total; 811 that.paging.total = pp.total;
816 that.update_paging(); 812 that.update_paging();
817 that.on_select(); 813 that.on_select();
818 }, function(x,s,c,m) { 814 }, function(x,s,c,m) {
819 that.fireflix.flickr_failure(x,s,c,m); 815 that.fireflix.flickr_failure(x,s,c,m);
820 } 816 }
821 ); 817 );
822 }, 818 },
823 on_cmd_prev: function(ev) { 819 on_cmd_prev: function(ev) {
824 var pars = new Object(); 820 var pars = new Object();
825 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 821 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
826 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; 822 pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
827 this.perform_search(pars); 823 this.perform_search(pars);
828 }, 824 },
829 on_cmd_next: function(ev) { 825 on_cmd_next: function(ev) {
830 var pars = new Object(); 826 var pars = new Object();
831 for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; 827 for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
832 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; 828 pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
833 this.perform_search(pars); 829 this.perform_search(pars);
834 }, 830 },
835 update_paging: function() { 831 update_paging: function() {
836 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { 832 if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
837 this.search_page.value=''; this.search_page.hidden = true; 833 this.search_page.value=''; this.search_page.hidden = true;
838 this.cmd_search_prev_page.setAttribute('disabled','true'); 834 this.cmd_search_prev_page.setAttribute('disabled','true');
839 this.cmd_search_next_page.setAttribute('disabled','true'); 835 this.cmd_search_next_page.setAttribute('disabled','true');
840 }else{ 836 }else{
841 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); 837 this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
842 this.search_page.hidden=false; 838 this.search_page.hidden=false;
843 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); 839 this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
844 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); 840 this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true');
845 } 841 }
846 }, 842 },
847 render_description_frame: function(content) { 843 render_description_frame: function(content) {
848 this.searchresult_description.innerHTML = ''; 844 this.searchresult_description.innerHTML = '';
849 if(content) { 845 if(content) {
850 var dp = new DOMParser(); 846 var dp = new DOMParser();
851 var pd = dp.parseFromString( 847 var pd = dp.parseFromString(
852 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); 848 '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' );
853 var de = pd.documentElement; 849 var de = pd.documentElement;
854 if(de.tagName=='parsererror') 850 if(de.tagName=='parsererror')
855 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); 851 this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description');
856 else 852 else
857 this.searchresult_description.appendChild(de); 853 this.searchresult_description.appendChild(de);
858 /* of all linking elements flickr only allows a */ 854 /* of all linking elements flickr only allows a */
859 var as = this.searchresult_description.getElementsByTagName('a'); 855 var as = this.searchresult_description.getElementsByTagName('a');
860 for(var a=0;a<as.length;++a) 856 for(var a=0;a<as.length;++a)
861 as.item(a).setAttribute('target','_blank'); 857 as.item(a).setAttribute('target','_blank');
862 } 858 }
863 }, 859 },
864 on_select: function() { 860 on_select: function() {
865 if(this.selection.currentIndex<0) { 861 if(this.selection.currentIndex<0) {
866 this.searchresult_props.hidden = true; 862 this.searchresult_props.hidden = true;
867 }else{ 863 }else{
868 var p = this.photos[this.selection.currentIndex]; 864 var p = this.photos[this.selection.currentIndex];
869 if(!p) { 865 if(!p) {
870 this.searchresult_props.hidden = true; 866 this.searchresult_props.hidden = true;
871 }else{ 867 }else{
872 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); 868 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
873 this.searchresult_title.value = p.title; 869 this.searchresult_title.value = p.title;
874 this.searchresult_title.tooltipText = p.title; 870 this.searchresult_title.tooltipText = p.title;
875 this.render_description_frame(null); 871 this.render_description_frame(null);
876 if(p.description==null && p.description==undefined) { 872 if(p.description==null && p.description==undefined) {
877 var pid = p.id; 873 var pid = p.id;
878 var ci = this.selection.currentIndex; 874 var ci = this.selection.currentIndex;
879 var that = this; 875 var that = this;
880 this.fireflix.flickr.api_call_json( 876 this.fireflix.flickr.api_call_json(
881 { 877 {
882 method: 'flickr.photos.getInfo', 878 method: 'flickr.photos.getInfo',
883 auth_token: 'default', 879 auth_token: 'default',
884 photo_id: p.id, 880 photo_id: p.id,
885 secret: p.secret 881 secret: p.secret
886 }, function(x,j) { 882 }, function(x,j) {
887 var pp = that.photos[ci]; 883 var pp = that.photos[ci];
888 if(ci==that.selection.currentIndex && pp.id==pid) { 884 if(ci==that.selection.currentIndex && pp.id==pid) {
889 pp.fromJSON_(j.photo); 885 pp.fromJSON_(j.photo);
890 that.render_description_frame(pp.description); 886 that.render_description_frame(pp.description);
891 } 887 }
892 }, function(x,s,c,m) { 888 }, function(x,s,c,m) {
893 that.fireflix.flickr_failure(x,s,c,m); 889 that.fireflix.flickr_failure(x,s,c,m);
894 } 890 }
895 ); 891 );
896 this.searchresult_props.hidden = false; 892 this.searchresult_props.hidden = false;
897 }else{ 893 }else{
898 this.render_description_frame(p.description); 894 this.render_description_frame(p.description);
899 } 895 }
900 } 896 }
901 } 897 }
902 }, 898 },
903 on_cmd_open: function(ev) { 899 on_cmd_open: function(ev) {
904 if(this.selection.currentIndex<0) return; 900 if(this.selection.currentIndex<0) return;
905 var p = this.photos[this.selection.currentIndex]; 901 var p = this.photos[this.selection.currentIndex];
906 if(!p.id) return; 902 if(!p.id) return;
907 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 903 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
908 } 904 }
909 }, 905 },
910 906
911 photo_html: function(p,i,l) { 907 photo_html: function(p,i,l) {
912 // TODO: add alt/title when possible 908 // TODO: add alt/title when possible
913 var rv = 909 var rv =
914 '<a href="'+this.flickr.make_photo_url(p,l)+'">' + 910 '<a href="'+this.flickr.make_photo_url(p,l)+'">' +
915 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ 911 '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+
916 '</a>'; 912 '</a>';
917 return rv; 913 return rv;
918 }, 914 },
919 build_html: function(photos,uti,utl) { 915 build_html: function(photos,uti,utl) {
920 var rv = ''; 916 var rv = '';
921 for(var i in photos) { 917 for(var i in photos) {
922 var p = photos[i]; 918 var p = photos[i];
923 rv += this.photo_html(p,uti,utl)+'\n'; 919 rv += this.photo_html(p,uti,utl)+'\n';
924 } 920 }
925 return rv; 921 return rv;
926 }, 922 },
927 923
928 popup_content: function(s) { 924 popup_content: function(s) {
929 window.openDialog( 925 window.openDialog(
930 "chrome://fireflix/content/generated-content.xul", 926 "chrome://fireflix/content/generated-content.xul",
931 null, "dialog,chrome", this, s ); 927 null, "dialog,chrome", this, s );
932 }, 928 },
933 copy_to_clipboard: function(s) { 929 copy_to_clipboard: function(s) {
934 var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] 930 var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"]
935 .getService(Components.interfaces.nsIClipboardHelper); 931 .getService(Components.interfaces.nsIClipboardHelper);