author | Michael Krelin <hacker@klever.net> | 2011-08-28 12:17:34 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2011-08-28 12:17:34 (UTC) |
commit | aa13caca14bac3ed268ac6fb62f0270e40b24e48 (patch) (unidiff) | |
tree | edcfd094407b87cf9c49e9275c6d4b847fc82f29 /content/fireflix.js | |
parent | 4152a504609522fab4a269dc88d13a1078a09452 (diff) | |
download | fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.zip fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.gz fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.bz2 |
made api calls mostly json-based
Signed-off-by: Michael Krelin <hacker@klever.net>
-rw-r--r-- | content/fireflix.js | 90 |
1 files changed, 37 insertions, 53 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 225e21c..283e930 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -111,58 +111,52 @@ var fireflix = { | |||
111 | return c.id; | 111 | return c.id; |
112 | }, | 112 | }, |
113 | setTree: function(t) { this.tree = t }, | 113 | setTree: function(t) { this.tree = t }, |
114 | isContainer: function(r) { return false; }, | 114 | isContainer: function(r) { return false; }, |
115 | isSeparator: function(r) { return false; }, | 115 | isSeparator: function(r) { return false; }, |
116 | isSorted: function(r) { return false; }, | 116 | isSorted: function(r) { return false; }, |
117 | getLevel: function(r) { return 0; }, | 117 | getLevel: function(r) { return 0; }, |
118 | getImageSrc: function(r,c) { return null }, | 118 | getImageSrc: function(r,c) { return null }, |
119 | getRowProperties: function(r,p) {}, | 119 | getRowProperties: function(r,p) {}, |
120 | getCellProperties: function(cid,cel,p) {}, | 120 | getCellProperties: function(cid,cel,p) {}, |
121 | getColumnProperties: function(cid,cel,p) { }, | 121 | getColumnProperties: function(cid,cel,p) { }, |
122 | cycleHeader: function(cid,e) { }, | 122 | cycleHeader: function(cid,e) { }, |
123 | getParentIndex: function(r) { return -1; }, | 123 | getParentIndex: function(r) { return -1; }, |
124 | drop: function(r,o) { }, | 124 | drop: function(r,o) { }, |
125 | canDropBeforeAfter: function(r,b) { return false }, | 125 | canDropBeforeAfter: function(r,b) { return false }, |
126 | 126 | ||
127 | importXPR: function(xp) { | 127 | import_json: function(jp) { |
128 | this.tree.beginUpdateBatch(); | 128 | this.tree.beginUpdateBatch(); |
129 | this.photos = new Array(); | 129 | this.photos = new Array(); |
130 | var n; while(n=xp.iterateNext()) { | 130 | for(var i in jp) this.photos.push(new Photo(jp[i])); |
131 | this.photos.push(new Photo(n)); | ||
132 | } | ||
133 | this.rowCount = this.photos.length; | 131 | this.rowCount = this.photos.length; |
134 | this.tree.endUpdateBatch(); | 132 | this.tree.endUpdateBatch(); |
135 | this.selection.clearSelection(); | 133 | this.selection.clearSelection(); |
136 | }, | 134 | }, |
137 | load_photos: function(psid) { | 135 | load_photos: function(psid) { |
138 | var _this = this; | 136 | var that = this; |
139 | this.fireflix.flickr.api_call( | 137 | this.fireflix.flickr.api_call_json( |
140 | { | 138 | { |
141 | method: 'flickr.photosets.getPhotos', | 139 | method: 'flickr.photosets.getPhotos', |
142 | auth_token: 'default', | 140 | auth_token: 'default', |
143 | photoset_id: psid, | 141 | photoset_id: psid, |
144 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 142 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
145 | }, function(xr) { | 143 | }, function(x,j) { |
146 | var x = xr.responseXML; | 144 | that.import_json(j.photoset.photo); |
147 | var xp = x.evaluate( | ||
148 | '/rsp/photoset/photo', x, null, | ||
149 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
150 | _this.importXPR(xp); | ||
151 | }, function(x,s,c,m) { | 145 | }, function(x,s,c,m) { |
152 | _this.fireflix.flickr_failure(x,s,c,m); | 146 | that.fireflix.flickr_failure(x,s,c,m); |
153 | } | 147 | } |
154 | ); | 148 | ); |
155 | }, | 149 | }, |
156 | on_select: function() { | 150 | on_select: function() { |
157 | if(this.selection.count==1) { | 151 | if(this.selection.count==1) { |
158 | var p = this.photos[this.selection.currentIndex]; | 152 | var p = this.photos[this.selection.currentIndex]; |
159 | this.set_photo.src = | 153 | this.set_photo.src = |
160 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); | 154 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); |
161 | this.set_photo_props.hidden = false; | 155 | this.set_photo_props.hidden = false; |
162 | }else{ | 156 | }else{ |
163 | this.set_photo_props.hidden = true; | 157 | this.set_photo_props.hidden = true; |
164 | } | 158 | } |
165 | }, | 159 | }, |
166 | on_cmd_open: function(ev) { | 160 | on_cmd_open: function(ev) { |
167 | if(this.selection.currentIndex<0) return; | 161 | if(this.selection.currentIndex<0) return; |
168 | var p = this.photos[this.selection.currentIndex]; | 162 | var p = this.photos[this.selection.currentIndex]; |
@@ -187,55 +181,49 @@ var fireflix = { | |||
187 | return c.id; | 181 | return c.id; |
188 | }, | 182 | }, |
189 | setTree: function(t) { this.tree = t }, | 183 | setTree: function(t) { this.tree = t }, |
190 | isContainer: function(r) { return false; }, | 184 | isContainer: function(r) { return false; }, |
191 | isSeparator: function(r) { return false; }, | 185 | isSeparator: function(r) { return false; }, |
192 | isSorted: function() { return false; }, | 186 | isSorted: function() { return false; }, |
193 | getLevel: function(r) { return 0; }, | 187 | getLevel: function(r) { return 0; }, |
194 | getImageSrc: function(r,c) { return null }, | 188 | getImageSrc: function(r,c) { return null }, |
195 | getRowProperties: function(r,p) {}, | 189 | getRowProperties: function(r,p) {}, |
196 | getCellProperties: function(cid,cel,p) { }, | 190 | getCellProperties: function(cid,cel,p) { }, |
197 | getColumnProperties: function(cid,cel,p) { }, | 191 | getColumnProperties: function(cid,cel,p) { }, |
198 | cycleHeader: function(cid,e) { }, | 192 | cycleHeader: function(cid,e) { }, |
199 | getParentIndex: function(r) { return -1; }, | 193 | getParentIndex: function(r) { return -1; }, |
200 | drop: function(r,o) { }, | 194 | drop: function(r,o) { }, |
201 | canDropBeforeAfter: function(r,b) { return false }, | 195 | canDropBeforeAfter: function(r,b) { return false }, |
202 | 196 | ||
203 | importXPR: function(xp) { | 197 | import_json: function(j) { |
204 | this.tree.beginUpdateBatch(); | 198 | this.tree.beginUpdateBatch(); |
205 | this.sets = new Array(); | 199 | this.sets = new Array(); |
206 | var n; while(n=xp.iterateNext()) { | 200 | for(var i in j) this.sets.push(new Photoset(j[i])); |
207 | this.sets.push(new Photoset(n)); | ||
208 | } | ||
209 | this.rowCount = this.sets.length; | 201 | this.rowCount = this.sets.length; |
210 | this.tree.endUpdateBatch(); | 202 | this.tree.endUpdateBatch(); |
211 | }, | 203 | }, |
212 | refresh_sets: function() { | 204 | refresh_sets: function() { |
213 | var _this = this; | 205 | var that = this; |
214 | this.fireflix.flickr.api_call( | 206 | this.fireflix.flickr.api_call_json( |
215 | { | 207 | { |
216 | method: 'flickr.photosets.getList', | 208 | method: 'flickr.photosets.getList', |
217 | auth_token: 'default' | 209 | auth_token: 'default' |
218 | }, function(xr) { | 210 | }, function(x,j) { |
219 | var x = xr.responseXML; | 211 | that.import_json(j.photosets.photoset); |
220 | var xp = x.evaluate( | ||
221 | '/rsp/photosets/photoset', x, null, | ||
222 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
223 | _this.importXPR(xp); | ||
224 | }, function(x,s,c,m) { | 212 | }, function(x,s,c,m) { |
225 | _this.fireflix.flickr_failure(x,s,c,m); | 213 | that.fireflix.flickr_failure(x,s,c,m); |
226 | } | 214 | } |
227 | ); | 215 | ); |
228 | }, | 216 | }, |
229 | on_select: function() { | 217 | on_select: function() { |
230 | if(this.selection.count==1) { | 218 | if(this.selection.count==1) { |
231 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 219 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
232 | var s = this.sets[this.selection.currentIndex]; | 220 | var s = this.sets[this.selection.currentIndex]; |
233 | this.fireflix.photoset.load_photos(s.id); | 221 | this.fireflix.photoset.load_photos(s.id); |
234 | }else{ | 222 | }else{ |
235 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 223 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
236 | } | 224 | } |
237 | }, | 225 | }, |
238 | on_cmd_open_in_flickr: function(ev) { | 226 | on_cmd_open_in_flickr: function(ev) { |
239 | if(this.selection.currentIndex<0) return; | 227 | if(this.selection.currentIndex<0) return; |
240 | var p = this.sets[this.selection.currentIndex]; | 228 | var p = this.sets[this.selection.currentIndex]; |
241 | if(!p.id) return; | 229 | if(!p.id) return; |
@@ -774,84 +762,81 @@ var fireflix = { | |||
774 | return c.id; | 762 | return c.id; |
775 | }, | 763 | }, |
776 | setTree: function(t) { this.tree = t }, | 764 | setTree: function(t) { this.tree = t }, |
777 | isContainer: function(r) { return false }, | 765 | isContainer: function(r) { return false }, |
778 | isSeparator: function(r) { return false }, | 766 | isSeparator: function(r) { return false }, |
779 | isSorted: function(r) { return false }, | 767 | isSorted: function(r) { return false }, |
780 | getLevel: function(r) { return 0 }, | 768 | getLevel: function(r) { return 0 }, |
781 | getImageSrc: function(r,c) { return null }, | 769 | getImageSrc: function(r,c) { return null }, |
782 | getRowProperties: function(r,p) { }, | 770 | getRowProperties: function(r,p) { }, |
783 | getCellProperties: function(cid,cel,p) { }, | 771 | getCellProperties: function(cid,cel,p) { }, |
784 | getColumnProperties: function(cid,cel,p) { }, | 772 | getColumnProperties: function(cid,cel,p) { }, |
785 | cycleHeader: function(cid,e) { }, | 773 | cycleHeader: function(cid,e) { }, |
786 | getParentIndex: function(r) { return -1 }, | 774 | getParentIndex: function(r) { return -1 }, |
787 | drop: function(r,o) { }, | 775 | drop: function(r,o) { }, |
788 | canDropBeforeAfter: function(r,b) { return false }, | 776 | canDropBeforeAfter: function(r,b) { return false }, |
789 | 777 | ||
790 | importXPR: function(xp) { | 778 | import_json: function(jp) { |
791 | this.selection.clearSelection(); | 779 | this.selection.clearSelection(); |
792 | this.selection.currentIndex = -1; | 780 | this.selection.currentIndex = -1; |
793 | this.searchresult_props.hidden = true; | 781 | this.searchresult_props.hidden = true; |
794 | this.tree.beginUpdateBatch(); | 782 | this.tree.beginUpdateBatch(); |
795 | this.photos = new Array(); | 783 | this.photos = new Array(); |
796 | var n; while(n=xp.iterateNext()) { | 784 | for(var i in jp) { |
797 | this.photos.push(new Photo(n)); | 785 | this.photos.push(new Photo(jp[i])); |
798 | } | 786 | } |
799 | this.rowCount = this.photos.length; | 787 | this.rowCount = this.photos.length; |
800 | this.tree.endUpdateBatch(); | 788 | this.tree.endUpdateBatch(); |
801 | }, | 789 | }, |
802 | paging: { | 790 | paging: { |
803 | pars: null, | 791 | pars: null, |
804 | page: null, pages: null, perpage: null, total: null | 792 | page: null, pages: null, perpage: null, total: null |
805 | }, | 793 | }, |
806 | search_photos: function() { | 794 | search_photos: function() { |
807 | var pars = { | 795 | var pars = { |
808 | method: 'flickr.photos.search', | 796 | method: 'flickr.photos.search', |
809 | auth_token: 'default', | 797 | auth_token: 'default', |
810 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 798 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
811 | }; | 799 | }; |
812 | if(this.search_mine.checked) | 800 | if(this.search_mine.checked) |
813 | pars.user_id='me'; | 801 | pars.user_id='me'; |
814 | if(this.search_tags.checked) { | 802 | if(this.search_tags.checked) { |
815 | pars.tags=this.search_for.value.split(/ +/).join(','); | 803 | pars.tags=this.search_for.value.split(/ +/).join(','); |
816 | }else{ | 804 | }else{ |
817 | pars.text=this.search_for.value; | 805 | pars.text=this.search_for.value; |
818 | } | 806 | } |
819 | this.paging.pars = new Object(); | 807 | this.paging.pars = new Object(); |
820 | this.paging.page = null; this.paging.pages = null; | 808 | this.paging.page = null; this.paging.pages = null; |
821 | this.paging.perpage = null; this.paging.total = null; | 809 | this.paging.perpage = null; this.paging.total = null; |
822 | for(var p in pars) this.paging.pars[p] = pars[p]; | 810 | for(var p in pars) this.paging.pars[p] = pars[p]; |
823 | this.perform_search(pars); | 811 | this.perform_search(pars); |
824 | }, | 812 | }, |
825 | perform_search: function(p) { | 813 | perform_search: function(p) { |
826 | var _this = this; | 814 | var that = this; |
827 | this.fireflix.flickr.api_call( p, | 815 | this.fireflix.flickr.api_call_json( p, |
828 | function(xr) { | 816 | function(x,j) { |
829 | var x = xr.responseXML; | 817 | that.import_json(j.photos.photo); |
830 | var xp = xp_nodes('/rsp/photos/photo',x); | 818 | that.tree.ensureRowIsVisible(0); |
831 | _this.importXPR(xp); | 819 | var pp=j.photos; |
832 | _this.tree.ensureRowIsVisible(0); | 820 | that.paging.page = pp.page; that.paging.pages = pp.pages; |
833 | xp = xp_node('/rsp/photos',x); | 821 | that.paging.perpage = pp.perpage; |
834 | _this.paging.page = parseInt(xp.getAttribute('page')); | 822 | that.paging.total = pp.total; |
835 | _this.paging.pages = parseInt(xp.getAttribute('pages')); | 823 | that.update_paging(); |
836 | _this.paging.perpage = parseInt(xp.getAttribute('perpage')); | 824 | that.on_select(); |
837 | _this.paging.total = parseInt(xp.getAttribute('total')); | ||
838 | _this.update_paging(); | ||
839 | _this.on_select(); | ||
840 | }, function(x,s,c,m) { | 825 | }, function(x,s,c,m) { |
841 | _this.fireflix.flickr_failure(x,s,c,m); | 826 | that.fireflix.flickr_failure(x,s,c,m); |
842 | } | 827 | } |
843 | ); | 828 | ); |
844 | }, | 829 | }, |
845 | on_cmd_prev: function(ev) { | 830 | on_cmd_prev: function(ev) { |
846 | var pars = new Object(); | 831 | var pars = new Object(); |
847 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | 832 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; |
848 | pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; | 833 | pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; |
849 | this.perform_search(pars); | 834 | this.perform_search(pars); |
850 | }, | 835 | }, |
851 | on_cmd_next: function(ev) { | 836 | on_cmd_next: function(ev) { |
852 | var pars = new Object(); | 837 | var pars = new Object(); |
853 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | 838 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; |
854 | pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; | 839 | pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; |
855 | this.perform_search(pars); | 840 | this.perform_search(pars); |
856 | }, | 841 | }, |
857 | update_paging: function() { | 842 | update_paging: function() { |
@@ -885,48 +870,47 @@ var fireflix = { | |||
885 | }, | 870 | }, |
886 | on_select: function() { | 871 | on_select: function() { |
887 | if(this.selection.currentIndex<0) { | 872 | if(this.selection.currentIndex<0) { |
888 | this.searchresult_props.hidden = true; | 873 | this.searchresult_props.hidden = true; |
889 | }else{ | 874 | }else{ |
890 | var p = this.photos[this.selection.currentIndex]; | 875 | var p = this.photos[this.selection.currentIndex]; |
891 | if(!p) { | 876 | if(!p) { |
892 | this.searchresult_props.hidden = true; | 877 | this.searchresult_props.hidden = true; |
893 | }else{ | 878 | }else{ |
894 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 879 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
895 | this.searchresult_title.value = p.title; | 880 | this.searchresult_title.value = p.title; |
896 | this.searchresult_title.tooltipText = p.title; | 881 | this.searchresult_title.tooltipText = p.title; |
897 | this.render_description_frame(null); | 882 | this.render_description_frame(null); |
898 | if(p.description==null && p.description==undefined) { | 883 | if(p.description==null && p.description==undefined) { |
899 | var pid = p.id; | 884 | var pid = p.id; |
900 | var ci = this.selection.currentIndex; | 885 | var ci = this.selection.currentIndex; |
901 | var _this = this; | 886 | var that = this; |
902 | this.fireflix.flickr.api_call( | 887 | this.fireflix.flickr.api_call_json( |
903 | { | 888 | { |
904 | method: 'flickr.photos.getInfo', | 889 | method: 'flickr.photos.getInfo', |
905 | auth_token: 'default', | 890 | auth_token: 'default', |
906 | photo_id: p.id, | 891 | photo_id: p.id, |
907 | secret: p.secret | 892 | secret: p.secret |
908 | }, function(xr) { | 893 | }, function(x,j) { |
909 | var pp = _this.photos[ci]; | 894 | var pp = that.photos[ci]; |
910 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 895 | if(ci==that.selection.currentIndex && pp.id==pid) { |
911 | var n = xp_node('/rsp/photo',xr.responseXML); | 896 | pp.fromJSON_(j.photo); |
912 | pp.fromNode_(n); | 897 | that.render_description_frame(pp.description); |
913 | _this.render_description_frame(pp.description); | ||
914 | } | 898 | } |
915 | }, function(x,s,c,m) { | 899 | }, function(x,s,c,m) { |
916 | _this.fireflix.flickr_failure(x,s,c,m); | 900 | that.fireflix.flickr_failure(x,s,c,m); |
917 | } | 901 | } |
918 | ); | 902 | ); |
919 | this.searchresult_props.hidden = false; | 903 | this.searchresult_props.hidden = false; |
920 | }else{ | 904 | }else{ |
921 | this.render_description_frame(p.description); | 905 | this.render_description_frame(p.description); |
922 | } | 906 | } |
923 | } | 907 | } |
924 | } | 908 | } |
925 | }, | 909 | }, |
926 | on_cmd_open: function(ev) { | 910 | on_cmd_open: function(ev) { |
927 | if(this.selection.currentIndex<0) return; | 911 | if(this.selection.currentIndex<0) return; |
928 | var p = this.photos[this.selection.currentIndex]; | 912 | var p = this.photos[this.selection.currentIndex]; |
929 | if(!p.id) return; | 913 | if(!p.id) return; |
930 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 914 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
931 | } | 915 | } |
932 | }, | 916 | }, |