-rw-r--r-- | content/fireflix.js | 50 |
1 files changed, 45 insertions, 5 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index e144aae..92c42f4 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -599,257 +599,297 @@ var fireflix = { | |||
599 | description: pset.description | 599 | description: pset.description |
600 | }, function(xr) { | 600 | }, function(xr) { |
601 | pset.dirty = false; | 601 | pset.dirty = false; |
602 | _this.flickr.api_call( | 602 | _this.flickr.api_call( |
603 | { | 603 | { |
604 | method: 'flickr.photosets.getPhotos', | 604 | method: 'flickr.photosets.getPhotos', |
605 | auth_token: 'default', | 605 | auth_token: 'default', |
606 | photoset_id: pset.id | 606 | photoset_id: pset.id |
607 | }, function(xr) { | 607 | }, function(xr) { |
608 | var x = xr.responseXML; | 608 | var x = xr.responseXML; |
609 | var xp = x.evaluate( | 609 | var xp = x.evaluate( |
610 | '/rsp/photoset/photo', x, null, | 610 | '/rsp/photoset/photo', x, null, |
611 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 611 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
612 | var phids = new Array(); | 612 | var phids = new Array(); |
613 | var priph = null; | 613 | var priph = null; |
614 | var n; while(n=xp.iterateNext()) { | 614 | var n; while(n=xp.iterateNext()) { |
615 | var pid = n.getAttribute('id'); | 615 | var pid = n.getAttribute('id'); |
616 | phids.push( pid ); | 616 | phids.push( pid ); |
617 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 617 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') |
618 | priph = pid; | 618 | priph = pid; |
619 | } | 619 | } |
620 | if(priph) { | 620 | if(priph) { |
621 | _this.flickr.api_call( | 621 | _this.flickr.api_call( |
622 | { | 622 | { |
623 | method: 'flickr.photosets.editPhotos', | 623 | method: 'flickr.photosets.editPhotos', |
624 | auth_token: 'default', | 624 | auth_token: 'default', |
625 | photoset_id: pset.id, | 625 | photoset_id: pset.id, |
626 | primary_photo_id: priph, | 626 | primary_photo_id: priph, |
627 | photo_ids: phids.join(',') | 627 | photo_ids: phids.join(',') |
628 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 628 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
629 | _this.flickr_failure(x,s,c,m); | 629 | _this.flickr_failure(x,s,c,m); |
630 | } | 630 | } |
631 | ); | 631 | ); |
632 | } | 632 | } |
633 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 633 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
634 | _this.flickr_failure(x,s,c,m); | 634 | _this.flickr_failure(x,s,c,m); |
635 | } | 635 | } |
636 | ); | 636 | ); |
637 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 637 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
638 | _this.flickr_failure(x,s,c,m); | 638 | _this.flickr_failure(x,s,c,m); |
639 | } | 639 | } |
640 | ); | 640 | ); |
641 | } | 641 | } |
642 | }, | 642 | }, |
643 | on_refresh_sets: function() { | 643 | on_refresh_sets: function() { |
644 | this.refresh_sets(); | 644 | this.refresh_sets(); |
645 | }, | 645 | }, |
646 | on_cmd_sets_html: function(csfx,ev) { | 646 | on_cmd_sets_html: function(csfx,ev) { |
647 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 647 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
648 | var rv = this.build_html(this.photoset.photos,uti,utl); | 648 | var rv = this.build_html(this.photoset.photos,uti,utl); |
649 | this.popup_content(rv); | 649 | this.popup_content(rv); |
650 | }, | 650 | }, |
651 | 651 | ||
652 | on_cmd_uploads_html: function(csfx,ev) { | 652 | on_cmd_uploads_html: function(csfx,ev) { |
653 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 653 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
654 | var pids = new Array(); | 654 | var pids = new Array(); |
655 | for(var f in this.uploads.files) { | 655 | for(var f in this.uploads.files) { |
656 | if(this.uploads.selection.isSelected(f)) | 656 | if(this.uploads.selection.isSelected(f)) |
657 | if(this.uploads.files[f].photoid) | 657 | if(this.uploads.files[f].photoid) |
658 | pids.push(this.uploads.files[f].photoid); | 658 | pids.push(this.uploads.files[f].photoid); |
659 | } | 659 | } |
660 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 660 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
661 | var _this = this; | 661 | var _this = this; |
662 | this.flickr.api_call( | 662 | this.flickr.api_call( |
663 | { | 663 | { |
664 | method: 'flickr.photos.search', | 664 | method: 'flickr.photos.search', |
665 | auth_token: 'default', | 665 | auth_token: 'default', |
666 | extras: 'original_format', | 666 | extras: 'original_format', |
667 | user_id: 'me', | 667 | user_id: 'me', |
668 | per_page: pp | 668 | per_page: pp |
669 | }, | 669 | }, |
670 | function(xr) { | 670 | function(xr) { |
671 | var x = xr.responseXML; | 671 | var x = xr.responseXML; |
672 | var rv = ''; | 672 | var rv = ''; |
673 | for(var pn in pids) { | 673 | for(var pn in pids) { |
674 | var p = pids[pn]; | 674 | var p = pids[pn]; |
675 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 675 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
676 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 676 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
677 | } | 677 | } |
678 | _this.popup_content(rv); | 678 | _this.popup_content(rv); |
679 | }, function(x,s,c,m) { | 679 | }, function(x,s,c,m) { |
680 | _this.flickr_failure(x,s,c,m); | 680 | _this.flickr_failure(x,s,c,m); |
681 | } | 681 | } |
682 | ); | 682 | ); |
683 | }, | 683 | }, |
684 | 684 | ||
685 | /* | 685 | /* |
686 | * | 686 | * |
687 | */ | 687 | */ |
688 | foundphotos: { | 688 | foundphotos: { |
689 | fireflix: null, | 689 | fireflix: null, |
690 | init: function(f) { | 690 | init: function(f) { |
691 | this.fireflix = f; | 691 | this.fireflix = f; |
692 | pull_elements(this,document,[ | 692 | pull_elements(this,document,[ |
693 | 'search_for','search_tags','search_mine', | 693 | 'search_for','search_tags','search_mine', |
694 | 'searchresult_props','search_photo', | 694 | 'searchresult_props','search_photo', |
695 | 'searchresult_title','searchresult_description' | 695 | 'searchresult_title','searchresult_description', |
696 | 'search_page','cmd_search_prev_page','cmd_search_next_page' | ||
696 | ]); | 697 | ]); |
697 | document.getElementById('searchresults').view = this; | 698 | document.getElementById('searchresults').view = this; |
698 | }, | 699 | }, |
699 | photos: new Array(), | 700 | photos: new Array(), |
700 | rowCount: 0, | 701 | rowCount: 0, |
701 | getCellText: function(r,c) { | 702 | getCellText: function(r,c) { |
702 | var p = this.photos[r]; | 703 | var p = this.photos[r]; |
703 | if(c.id=='sr_title') return p.title; | 704 | if(c.id=='sr_title') return p.title; |
704 | return c.id; | 705 | return c.id; |
705 | }, | 706 | }, |
706 | setTree: function(t) { this.tree = t }, | 707 | setTree: function(t) { this.tree = t }, |
707 | isContainer: function(r) { return false }, | 708 | isContainer: function(r) { return false }, |
708 | isSeparator: function(r) { return false }, | 709 | isSeparator: function(r) { return false }, |
709 | isSorted: function(r) { return false }, | 710 | isSorted: function(r) { return false }, |
710 | getLevel: function(r) { return 0 }, | 711 | getLevel: function(r) { return 0 }, |
711 | getImageSrc: function(r,c) { return null }, | 712 | getImageSrc: function(r,c) { return null }, |
712 | getRowProperties: function(r,p) { }, | 713 | getRowProperties: function(r,p) { }, |
713 | getCellProperties: function(cid,cel,p) { }, | 714 | getCellProperties: function(cid,cel,p) { }, |
714 | getColumnProperties: function(cid,cel,p) { }, | 715 | getColumnProperties: function(cid,cel,p) { }, |
715 | cycleHeader: function(cid,e) { }, | 716 | cycleHeader: function(cid,e) { }, |
716 | getParentIndex: function(r) { return -1 }, | 717 | getParentIndex: function(r) { return -1 }, |
717 | drop: function(r,o) { }, | 718 | drop: function(r,o) { }, |
718 | canDropBeforeAfter: function(r,b) { return false }, | 719 | canDropBeforeAfter: function(r,b) { return false }, |
719 | 720 | ||
720 | importXPR: function(xp) { | 721 | importXPR: function(xp) { |
721 | this.selection.clearSelection(); | 722 | this.selection.clearSelection(); |
722 | this.selection.currentIndex = -1; | 723 | this.selection.currentIndex = -1; |
723 | this.searchresult_props.hidden = true; | 724 | this.searchresult_props.hidden = true; |
724 | this.tree.beginUpdateBatch(); | 725 | this.tree.beginUpdateBatch(); |
725 | this.photos = new Array(); | 726 | this.photos = new Array(); |
726 | var n; while(n=xp.iterateNext()) { | 727 | var n; while(n=xp.iterateNext()) { |
727 | this.photos.push(new Photo(n)); | 728 | this.photos.push(new Photo(n)); |
728 | } | 729 | } |
729 | this.rowCount = this.photos.length; | 730 | this.rowCount = this.photos.length; |
730 | this.tree.endUpdateBatch(); | 731 | this.tree.endUpdateBatch(); |
731 | }, | 732 | }, |
733 | paging: { | ||
734 | pars: null, | ||
735 | page: null, pages: null, perpage: null, total: null | ||
736 | }, | ||
732 | search_photos: function() { | 737 | search_photos: function() { |
733 | var pars = { | 738 | var pars = { |
734 | method: 'flickr.photos.search', | 739 | method: 'flickr.photos.search', |
735 | auth_token: 'default', | 740 | auth_token: 'default', |
736 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 741 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
737 | }; | 742 | }; |
738 | if(this.search_mine.checked) | 743 | if(this.search_mine.checked) |
739 | pars.user_id='me'; | 744 | pars.user_id='me'; |
740 | if(this.search_tags.checked) { | 745 | if(this.search_tags.checked) { |
741 | pars.tags=this.search_for.value.split(/ +/).join(','); | 746 | pars.tags=this.search_for.value.split(/ +/).join(','); |
742 | }else{ | 747 | }else{ |
743 | pars.text=this.search_for.value; | 748 | pars.text=this.search_for.value; |
744 | } | 749 | } |
750 | this.paging.pars = new Object(); | ||
751 | this.paging.page = null; this.paging.pages = null; | ||
752 | this.paging.perpage = null; this.paging.total = null; | ||
753 | for(var p in pars) this.paging.pars[p] = pars[p]; | ||
754 | this.perform_search(pars); | ||
755 | }, | ||
756 | perform_search: function(p) { | ||
745 | var _this = this; | 757 | var _this = this; |
746 | this.fireflix.flickr.api_call( pars, | 758 | this.fireflix.flickr.api_call( p, |
747 | function(xr) { | 759 | function(xr) { |
748 | var x = xr.responseXML; | 760 | var x = xr.responseXML; |
749 | var xp = x.evaluate( | 761 | var xp = xp_nodes('/rsp/photos/photo',x); |
750 | '/rsp/photos/photo', x, null, | ||
751 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
752 | _this.importXPR(xp); | 762 | _this.importXPR(xp); |
753 | _this.tree.ensureRowIsVisible(0); | 763 | _this.tree.ensureRowIsVisible(0); |
764 | xp = xp_node('/rsp/photos',x); | ||
765 | _this.paging.page = parseInt(xp.getAttribute('page')); | ||
766 | _this.paging.pages = parseInt(xp.getAttribute('pages')); | ||
767 | _this.paging.perpage = parseInt(xp.getAttribute('perpage')); | ||
768 | _this.paging.total = parseInt(xp.getAttribute('total')); | ||
769 | _this.update_paging(); | ||
754 | _this.on_select(); | 770 | _this.on_select(); |
755 | }, function(x,s,c,m) { | 771 | }, function(x,s,c,m) { |
756 | _this.fireflix.flickr_failure(x,s,c,m); | 772 | _this.fireflix.flickr_failure(x,s,c,m); |
757 | } | 773 | } |
758 | ); | 774 | ); |
759 | }, | 775 | }, |
776 | on_cmd_prev: function(ev) { | ||
777 | var pars = new Object(); | ||
778 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | ||
779 | pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; | ||
780 | this.perform_search(pars); | ||
781 | }, | ||
782 | on_cmd_next: function(ev) { | ||
783 | var pars = new Object(); | ||
784 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | ||
785 | pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; | ||
786 | this.perform_search(pars); | ||
787 | }, | ||
788 | update_paging: function() { | ||
789 | if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { | ||
790 | this.search_page.value=''; this.search_page.hidden = true; | ||
791 | this.cmd_search_prev_page.setAttribute('disabled','true'); | ||
792 | this.cmd_search_next_page.setAttribute('disabled','true'); | ||
793 | }else{ | ||
794 | this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); | ||
795 | this.search_page.hidden=false; | ||
796 | this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); | ||
797 | this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); | ||
798 | } | ||
799 | }, | ||
760 | render_description_frame: function(content) { | 800 | render_description_frame: function(content) { |
761 | if(!content) { | 801 | if(!content) { |
762 | this.searchresult_description.innerHTML = ''; | 802 | this.searchresult_description.innerHTML = ''; |
763 | }else{ | 803 | }else{ |
764 | this.searchresult_description.innerHTML = content?content:''; | 804 | this.searchresult_description.innerHTML = content?content:''; |
765 | /* of all linking elements flickr only allows a */ | 805 | /* of all linking elements flickr only allows a */ |
766 | var as = this.searchresult_description.getElementsByTagName('a'); | 806 | var as = this.searchresult_description.getElementsByTagName('a'); |
767 | for(var a=0;a<as.length;++a) | 807 | for(var a=0;a<as.length;++a) |
768 | as.item(a).setAttribute('target','_blank'); | 808 | as.item(a).setAttribute('target','_blank'); |
769 | } | 809 | } |
770 | }, | 810 | }, |
771 | on_select: function() { | 811 | on_select: function() { |
772 | if(this.selection.currentIndex<0) { | 812 | if(this.selection.currentIndex<0) { |
773 | this.searchresult_props.hidden = true; | 813 | this.searchresult_props.hidden = true; |
774 | }else{ | 814 | }else{ |
775 | var p = this.photos[this.selection.currentIndex]; | 815 | var p = this.photos[this.selection.currentIndex]; |
776 | if(!p) { | 816 | if(!p) { |
777 | this.searchresult_props.hidden = true; | 817 | this.searchresult_props.hidden = true; |
778 | }else{ | 818 | }else{ |
779 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 819 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
780 | this.searchresult_title.value = p.title; | 820 | this.searchresult_title.value = p.title; |
781 | this.searchresult_title.tooltipText = p.title; | 821 | this.searchresult_title.tooltipText = p.title; |
782 | this.render_description_frame(null); | 822 | this.render_description_frame(null); |
783 | if(p.description==null && p.description==undefined) { | 823 | if(p.description==null && p.description==undefined) { |
784 | var pid = p.id; | 824 | var pid = p.id; |
785 | var ci = this.selection.currentIndex; | 825 | var ci = this.selection.currentIndex; |
786 | var _this = this; | 826 | var _this = this; |
787 | this.fireflix.flickr.api_call( | 827 | this.fireflix.flickr.api_call( |
788 | { | 828 | { |
789 | method: 'flickr.photos.getInfo', | 829 | method: 'flickr.photos.getInfo', |
790 | auth_token: 'default', | 830 | auth_token: 'default', |
791 | photo_id: p.id, | 831 | photo_id: p.id, |
792 | secret: p.secret | 832 | secret: p.secret |
793 | }, function(xr) { | 833 | }, function(xr) { |
794 | var pp = _this.photos[ci]; | 834 | var pp = _this.photos[ci]; |
795 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 835 | if(ci==_this.selection.currentIndex && pp.id==pid) { |
796 | var n = xp_node('/rsp/photo',xr.responseXML); | 836 | var n = xp_node('/rsp/photo',xr.responseXML); |
797 | pp.fromNode_(n); | 837 | pp.fromNode_(n); |
798 | _this.render_description_frame(pp.description); | 838 | _this.render_description_frame(pp.description); |
799 | } | 839 | } |
800 | }, function(x,s,c,m) { | 840 | }, function(x,s,c,m) { |
801 | _this.fireflix.flickr_failure(x,s,c,m); | 841 | _this.fireflix.flickr_failure(x,s,c,m); |
802 | } | 842 | } |
803 | ); | 843 | ); |
804 | this.searchresult_props.hidden = false; | 844 | this.searchresult_props.hidden = false; |
805 | }else{ | 845 | }else{ |
806 | this.render_description_frame(p.description); | 846 | this.render_description_frame(p.description); |
807 | } | 847 | } |
808 | } | 848 | } |
809 | } | 849 | } |
810 | }, | 850 | }, |
811 | on_cmd_open: function(ev) { | 851 | on_cmd_open: function(ev) { |
812 | if(this.selection.currentIndex<0) | 852 | if(this.selection.currentIndex<0) |
813 | return; | 853 | return; |
814 | var p = this.photos[this.selection.currentIndex]; | 854 | var p = this.photos[this.selection.currentIndex]; |
815 | if(!p.id) | 855 | if(!p.id) |
816 | return; | 856 | return; |
817 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 857 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
818 | } | 858 | } |
819 | }, | 859 | }, |
820 | 860 | ||
821 | photo_html: function(p,i,l) { | 861 | photo_html: function(p,i,l) { |
822 | // TODO: add alt/title when possible | 862 | // TODO: add alt/title when possible |
823 | var rv = | 863 | var rv = |
824 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 864 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
825 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 865 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
826 | '</a>'; | 866 | '</a>'; |
827 | return rv; | 867 | return rv; |
828 | }, | 868 | }, |
829 | build_html: function(photos,uti,utl) { | 869 | build_html: function(photos,uti,utl) { |
830 | var rv = ''; | 870 | var rv = ''; |
831 | for(var i in photos) { | 871 | for(var i in photos) { |
832 | var p = photos[i]; | 872 | var p = photos[i]; |
833 | rv += this.photo_html(p,utl,uti)+'\n'; | 873 | rv += this.photo_html(p,utl,uti)+'\n'; |
834 | } | 874 | } |
835 | return rv; | 875 | return rv; |
836 | }, | 876 | }, |
837 | 877 | ||
838 | popup_content: function(s) { | 878 | popup_content: function(s) { |
839 | window.openDialog( | 879 | window.openDialog( |
840 | "chrome://fireflix/content/generated-content.xul", | 880 | "chrome://fireflix/content/generated-content.xul", |
841 | null, "dialog,chrome", this, s ); | 881 | null, "dialog,chrome", this, s ); |
842 | }, | 882 | }, |
843 | copy_to_clipboard: function(s) { | 883 | copy_to_clipboard: function(s) { |
844 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 884 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
845 | .getService(Components.interfaces.nsIClipboardHelper); | 885 | .getService(Components.interfaces.nsIClipboardHelper); |
846 | ch.copyString(s); | 886 | ch.copyString(s); |
847 | }, | 887 | }, |
848 | openTab: function(l) { | 888 | openTab: function(l) { |
849 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 889 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
850 | Components.interfaces.nsIWindowMediator ); | 890 | Components.interfaces.nsIWindowMediator ); |
851 | var bw = wm.getMostRecentWindow('navigator:browser'); | 891 | var bw = wm.getMostRecentWindow('navigator:browser'); |
852 | var b = bw.getBrowser(); | 892 | var b = bw.getBrowser(); |
853 | var t = b.addTab(l); | 893 | var t = b.addTab(l); |
854 | b.selectedTab = t; | 894 | b.selectedTab = t; |
855 | }, | 895 | }, |