-rw-r--r-- | content/fireflix.js | 96 |
1 files changed, 40 insertions, 56 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 225e21c..283e930 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -1,1024 +1,1008 @@ | |||
1 | function splitascii(s) { | 1 | function 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 | ||
12 | var fireflix = { | 12 | var fireflix = { |
13 | flickr: new Flickr(), | 13 | flickr: new Flickr(), |
14 | init: function() { | 14 | init: function() { |
15 | pull_elements(this,document,[ | 15 | pull_elements(this,document,[ |
16 | 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', | 16 | 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', |
17 | 'menu_auth_done','b_auth','b_auth_done','auth_info', | 17 | 'menu_auth_done','b_auth','b_auth_done','auth_info', |
18 | 'loc_strings','cmd_set_props' | 18 | 'loc_strings','cmd_set_props' |
19 | ]); | 19 | ]); |
20 | this.build_menus(); | 20 | this.build_menus(); |
21 | this.foundphotos.init(this); | 21 | this.foundphotos.init(this); |
22 | this.photosets.init(this); | 22 | this.photosets.init(this); |
23 | this.photoset.init(this); | 23 | this.photoset.init(this); |
24 | this.uploads.init(this); | 24 | this.uploads.init(this); |
25 | this.uploadObserver.init(this); | 25 | this.uploadObserver.init(this); |
26 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; | 26 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; |
27 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; | 27 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; |
28 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; | 28 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; |
29 | this.flickr.load_token(); | 29 | this.flickr.load_token(); |
30 | this.no_auth_info_label = this.auth_info.value; | 30 | this.no_auth_info_label = this.auth_info.value; |
31 | this.set_auth_state(this.flickr.token,false); | 31 | this.set_auth_state(this.flickr.token,false); |
32 | if(this.flickr.token) { | 32 | if(this.flickr.token) { |
33 | this.refresh_stuff(); | 33 | this.refresh_stuff(); |
34 | }else{ | 34 | }else{ |
35 | this.on_cmd_auth(); | 35 | this.on_cmd_auth(); |
36 | } | 36 | } |
37 | }, | 37 | }, |
38 | set_auth_state: function(au,inp) { /* authorized, in progress */ | 38 | set_auth_state: function(au,inp) { /* authorized, in progress */ |
39 | this.cmd_auth_unauth.disabled = !au; | 39 | this.cmd_auth_unauth.disabled = !au; |
40 | this.b_auth.hidden = au || inp; | 40 | this.b_auth.hidden = au || inp; |
41 | this.b_auth_done.hidden = !inp; | 41 | this.b_auth_done.hidden = !inp; |
42 | this.menu_auth_done.hidden = !inp; | 42 | this.menu_auth_done.hidden = !inp; |
43 | this.cmd_auth_done.setAttribute('disabled',!inp); | 43 | this.cmd_auth_done.setAttribute('disabled',!inp); |
44 | this.auth_info.disabled = !au; | 44 | this.auth_info.disabled = !au; |
45 | if(au) { | 45 | if(au) { |
46 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ | 46 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ |
47 | }else{ | 47 | }else{ |
48 | this.auth_info.value = this.no_auth_info_label; | 48 | this.auth_info.value = this.no_auth_info_label; |
49 | } | 49 | } |
50 | }, | 50 | }, |
51 | on_cmd_auth: function() { | 51 | on_cmd_auth: function() { |
52 | var _this = this; | 52 | var _this = this; |
53 | this.flickr.authorize_0( | 53 | this.flickr.authorize_0( |
54 | 'delete', | 54 | 'delete', |
55 | function(x,f,u) { | 55 | function(x,f,u) { |
56 | _this.openTab(u); | 56 | _this.openTab(u); |
57 | _this.set_auth_state(_this.flickr.token,true); | 57 | _this.set_auth_state(_this.flickr.token,true); |
58 | }, function(x,s,c,m) { | 58 | }, function(x,s,c,m) { |
59 | _this.flickr_failure(x,s,c,m); | 59 | _this.flickr_failure(x,s,c,m); |
60 | } | 60 | } |
61 | ); | 61 | ); |
62 | }, | 62 | }, |
63 | on_cmd_auth_done: function() { | 63 | on_cmd_auth_done: function() { |
64 | this.set_auth_state(this.flickr.token,false); | 64 | this.set_auth_state(this.flickr.token,false); |
65 | var _this = this; | 65 | var _this = this; |
66 | this.flickr.authorize_1( | 66 | this.flickr.authorize_1( |
67 | function() { | 67 | function() { |
68 | _this.flickr.save_token(); | 68 | _this.flickr.save_token(); |
69 | _this.refresh_stuff(); | 69 | _this.refresh_stuff(); |
70 | _this.set_auth_state(_this.flickr.token,false); | 70 | _this.set_auth_state(_this.flickr.token,false); |
71 | _this.auth_info.value = | 71 | _this.auth_info.value = |
72 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 72 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
73 | }, function(x,s,c,m) { | 73 | }, function(x,s,c,m) { |
74 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ | 74 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ |
75 | _this.flickr_failure(x,s,c,m); | 75 | _this.flickr_failure(x,s,c,m); |
76 | } | 76 | } |
77 | ); | 77 | ); |
78 | }, | 78 | }, |
79 | on_cmd_auth_unauth: function() { | 79 | on_cmd_auth_unauth: function() { |
80 | this.flickr.reset_token(); | 80 | this.flickr.reset_token(); |
81 | this.set_auth_state(false,false); | 81 | this.set_auth_state(false,false); |
82 | }, | 82 | }, |
83 | 83 | ||
84 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 84 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
85 | refresh_stuff: function() { | 85 | refresh_stuff: function() { |
86 | this.refresh_sets(); | 86 | this.refresh_sets(); |
87 | this.refresh_user_tags(); | 87 | this.refresh_user_tags(); |
88 | }, | 88 | }, |
89 | 89 | ||
90 | /* photoset treeview */ | 90 | /* photoset treeview */ |
91 | photoset: { | 91 | photoset: { |
92 | photos: new Array(), | 92 | photos: new Array(), |
93 | fireflix: null, | 93 | fireflix: null, |
94 | init: function(f) { | 94 | init: function(f) { |
95 | this.fireflix = f; | 95 | this.fireflix = f; |
96 | pull_elements(this,document,[ 'set_photo', 'set_photo_props' ]); | 96 | pull_elements(this,document,[ 'set_photo', 'set_photo_props' ]); |
97 | document.getElementById('setphotos').view = this; | 97 | document.getElementById('setphotos').view = this; |
98 | }, | 98 | }, |
99 | rowCount: 0, | 99 | rowCount: 0, |
100 | getCellText: function(r,c) { | 100 | getCellText: function(r,c) { |
101 | var p = this.photos[r]; | 101 | var p = this.photos[r]; |
102 | if(c.id=='sp_title') return p.title; | 102 | if(c.id=='sp_title') return p.title; |
103 | if(c.id=='sp_taken') return p.datetaken; | 103 | if(c.id=='sp_taken') return p.datetaken; |
104 | if(c.id=='sp_upload') { | 104 | if(c.id=='sp_upload') { |
105 | var du = new Date(p.dateupload*1000); | 105 | var du = new Date(p.dateupload*1000); |
106 | var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate() | 106 | var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate() |
107 | +' '+ | 107 | +' '+ |
108 | du.getHours()+':'+du.getMinutes()+':'+du.getSeconds(); | 108 | du.getHours()+':'+du.getMinutes()+':'+du.getSeconds(); |
109 | return rv.replace(/(\D)(\d)(\D)/,'$10$2$3'); | 109 | return rv.replace(/(\D)(\d)(\D)/,'$10$2$3'); |
110 | } | 110 | } |
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)); | 131 | this.rowCount =this.photos.length; |
132 | } | ||
133 | 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]; |
169 | if(!p.id) return; | 163 | if(!p.id) return; |
170 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 164 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
171 | } | 165 | } |
172 | }, | 166 | }, |
173 | 167 | ||
174 | /* photosets treeview */ | 168 | /* photosets treeview */ |
175 | photosets: { | 169 | photosets: { |
176 | sets: new Array(), | 170 | sets: new Array(), |
177 | fireflix: null, | 171 | fireflix: null, |
178 | init: function(f) { | 172 | init: function(f) { |
179 | this.fireflix = f; | 173 | this.fireflix = f; |
180 | document.getElementById('setslist').view = this; | 174 | document.getElementById('setslist').view = this; |
181 | }, | 175 | }, |
182 | rowCount: 0, | 176 | rowCount: 0, |
183 | getCellText: function(r,c) { | 177 | getCellText: function(r,c) { |
184 | var s = this.sets[r]; | 178 | var s = this.sets[r]; |
185 | if(c.id=='sl_name') return s.title; | 179 | if(c.id=='sl_name') return s.title; |
186 | if(c.id=='sl_photos') return s.photos; | 180 | if(c.id=='sl_photos') return s.photos; |
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; |
242 | this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p)); | 230 | this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p)); |
243 | } | 231 | } |
244 | }, | 232 | }, |
245 | 233 | ||
246 | refresh_user_tags: function() { | 234 | refresh_user_tags: function() { |
247 | var lb = document.getElementById('tagslist'); | 235 | var lb = document.getElementById('tagslist'); |
248 | var _this = this; | 236 | var _this = this; |
249 | this.flickr.api_call( | 237 | this.flickr.api_call( |
250 | { | 238 | { |
251 | method: 'flickr.tags.getListUser', | 239 | method: 'flickr.tags.getListUser', |
252 | auth_token: 'default', | 240 | auth_token: 'default', |
253 | }, function(xr) { | 241 | }, function(xr) { |
254 | var x = xr.responseXML; | 242 | var x = xr.responseXML; |
255 | var xp = x.evaluate( | 243 | var xp = x.evaluate( |
256 | '/rsp/who/tags/tag', x, null, | 244 | '/rsp/who/tags/tag', x, null, |
257 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 245 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
258 | // TODO: clear list | 246 | // TODO: clear list |
259 | var n; while(n=xp.iterateNext()) { | 247 | var n; while(n=xp.iterateNext()) { |
260 | lb.appendItem(n.firstChild.nodeValue); | 248 | lb.appendItem(n.firstChild.nodeValue); |
261 | } | 249 | } |
262 | }, function(x,s,c,m) { | 250 | }, function(x,s,c,m) { |
263 | _this.flickr_failure(x,s,c,m); | 251 | _this.flickr_failure(x,s,c,m); |
264 | } | 252 | } |
265 | ); | 253 | ); |
266 | }, | 254 | }, |
267 | 255 | ||
268 | uploadObserver: { | 256 | uploadObserver: { |
269 | fireflix: null, | 257 | fireflix: null, |
270 | init: function(f) { | 258 | init: function(f) { |
271 | this.fireflix = f; | 259 | this.fireflix = f; |
272 | }, | 260 | }, |
273 | getSupportedFlavours: function() { | 261 | getSupportedFlavours: function() { |
274 | var rv = new FlavourSet(); | 262 | var rv = new FlavourSet(); |
275 | rv.appendFlavour('application/x-moz-file','nsIFile'); | 263 | rv.appendFlavour('application/x-moz-file','nsIFile'); |
276 | rv.appendFlavour('application/x-moz-url'); | 264 | rv.appendFlavour('application/x-moz-url'); |
277 | rv.appendFlavour('text/uri-list'); | 265 | rv.appendFlavour('text/uri-list'); |
278 | rv.appendFlavour('text/unicode'); | 266 | rv.appendFlavour('text/unicode'); |
279 | return rv; | 267 | return rv; |
280 | }, | 268 | }, |
281 | canHandleMultipleItems: true, | 269 | canHandleMultipleItems: true, |
282 | onDragOver: function(ev,fl,sess) { | 270 | onDragOver: function(ev,fl,sess) { |
283 | return true; | 271 | return true; |
284 | }, | 272 | }, |
285 | onDrop: function(ev,dd,s) { | 273 | onDrop: function(ev,dd,s) { |
286 | var ldf = null; | 274 | var ldf = null; |
287 | for(var i in dd.dataList) { | 275 | for(var i in dd.dataList) { |
288 | var di = dd.dataList[i]; | 276 | var di = dd.dataList[i]; |
289 | var dif = di.first; | 277 | var dif = di.first; |
290 | if( | 278 | if( |
291 | ldf==null | 279 | ldf==null |
292 | || ldf.flavour.contentType!=dif.flavour.contentType | 280 | || ldf.flavour.contentType!=dif.flavour.contentType |
293 | || ldf.contentLength!=dif.contentLength | 281 | || ldf.contentLength!=dif.contentLength |
294 | || ldf.data!=dif.data ) | 282 | || ldf.data!=dif.data ) |
295 | this.drop_item(ev,di,s); | 283 | this.drop_item(ev,di,s); |
296 | ldf = dif; | 284 | ldf = dif; |
297 | } | 285 | } |
298 | }, | 286 | }, |
299 | drop_item: function(ev,di,s) { | 287 | drop_item: function(ev,di,s) { |
300 | var d = di.first; | 288 | var d = di.first; |
301 | switch(d.flavour.contentType) { | 289 | switch(d.flavour.contentType) { |
302 | case 'text/unicode': | 290 | case 'text/unicode': |
303 | this.drop_urilist(ev,d.data,s); | 291 | this.drop_urilist(ev,d.data,s); |
304 | break; | 292 | break; |
305 | case 'application/x-moz-file': | 293 | case 'application/x-moz-file': |
306 | this.fireflix.uploads.add(d.data.path); | 294 | this.fireflix.uploads.add(d.data.path); |
307 | document.getElementById('fireflix_tabs').selectedTab | 295 | document.getElementById('fireflix_tabs').selectedTab |
308 | = document.getElementById('tab_upload'); | 296 | = document.getElementById('tab_upload'); |
309 | break; | 297 | break; |
310 | case 'text/uri-list': | 298 | case 'text/uri-list': |
311 | // is it ascii or could it be utf8? | 299 | // is it ascii or could it be utf8? |
312 | this.drop_urilist(ev,splitascii(d.data),s); | 300 | this.drop_urilist(ev,splitascii(d.data),s); |
313 | break; | 301 | break; |
314 | default: alert(d.flavour.contentType+':'+d.data); break; | 302 | default: alert(d.flavour.contentType+':'+d.data); break; |
315 | }; | 303 | }; |
316 | }, | 304 | }, |
317 | drop_urilist: function(ev,ul,s) { | 305 | drop_urilist: function(ev,ul,s) { |
318 | // TODO: check for being a file? | 306 | // TODO: check for being a file? |
319 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 307 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
320 | for(var ui in us) | 308 | for(var ui in us) |
321 | if(/\S/.test(us[ui])) | 309 | if(/\S/.test(us[ui])) |
322 | this.fireflix.uploads.add(us[ui]); | 310 | this.fireflix.uploads.add(us[ui]); |
323 | document.getElementById('fireflix_tabs').selectedTab | 311 | document.getElementById('fireflix_tabs').selectedTab |
324 | = document.getElementById('tab_upload'); | 312 | = document.getElementById('tab_upload'); |
325 | } | 313 | } |
326 | }, | 314 | }, |
327 | 315 | ||
328 | uploads: { | 316 | uploads: { |
329 | fireflix: null, | 317 | fireflix: null, |
330 | init: function(f) { | 318 | init: function(f) { |
331 | this.fireflix=f; | 319 | this.fireflix=f; |
332 | pull_elements(this,document,[ | 320 | pull_elements(this,document,[ |
333 | 'upload_filename','upload_title','upload_file_preview', | 321 | 'upload_filename','upload_title','upload_file_preview', |
334 | 'upload_file_props','upload_progress','upload_tags', | 322 | 'upload_file_props','upload_progress','upload_tags', |
335 | 'cmd_uploads_upload', 'upload_failure', 'upload_is_public', | 323 | 'cmd_uploads_upload', 'upload_failure', 'upload_is_public', |
336 | 'upload_is_friends', 'upload_is_family' | 324 | 'upload_is_friends', 'upload_is_family' |
337 | ]); | 325 | ]); |
338 | document.getElementById('uploadlist').view = this; | 326 | document.getElementById('uploadlist').view = this; |
339 | this.upload_is_public.addEventListener( | 327 | this.upload_is_public.addEventListener( |
340 | 'CheckboxStateChange', { that: this, | 328 | 'CheckboxStateChange', { that: this, |
341 | handleEvent: function(ev) { this.that.propsToSel('is_public'); } | 329 | handleEvent: function(ev) { this.that.propsToSel('is_public'); } |
342 | }, false ); | 330 | }, false ); |
343 | this.upload_is_friends.addEventListener( | 331 | this.upload_is_friends.addEventListener( |
344 | 'CheckboxStateChange', { that: this, | 332 | 'CheckboxStateChange', { that: this, |
345 | handleEvent: function(ev) { this.that.propsToSel('is_friends'); } | 333 | handleEvent: function(ev) { this.that.propsToSel('is_friends'); } |
346 | }, false ); | 334 | }, false ); |
347 | this.upload_is_family.addEventListener( | 335 | this.upload_is_family.addEventListener( |
348 | 'CheckboxStateChange', { that: this, | 336 | 'CheckboxStateChange', { that: this, |
349 | handleEvent: function(ev) { this.that.propsToSel('is_family'); } | 337 | handleEvent: function(ev) { this.that.propsToSel('is_family'); } |
350 | }, false ); | 338 | }, false ); |
351 | }, | 339 | }, |
352 | files: new Array(), | 340 | files: new Array(), |
353 | rowCount: 0, | 341 | rowCount: 0, |
354 | getCellText: function(r,c) { | 342 | getCellText: function(r,c) { |
355 | var f = this.files[r]; | 343 | var f = this.files[r]; |
356 | if(c.id=='up_file') return f.file; | 344 | if(c.id=='up_file') return f.file; |
357 | if(c.id=='up_title') return f.title; | 345 | if(c.id=='up_title') return f.title; |
358 | if(c.id=='up_status') return f.state; | 346 | if(c.id=='up_status') return f.state; |
359 | return c.id; | 347 | return c.id; |
360 | }, | 348 | }, |
361 | setTree: function(t) { this.tree = t }, | 349 | setTree: function(t) { this.tree = t }, |
362 | isContainer: function(r) { return false; }, | 350 | isContainer: function(r) { return false; }, |
363 | isSeparator: function(r) { return false; }, | 351 | isSeparator: function(r) { return false; }, |
364 | isSorted: function(r) { return false; }, | 352 | isSorted: function(r) { return false; }, |
365 | getLevel: function(r) { return 0; }, | 353 | getLevel: function(r) { return 0; }, |
366 | getImageSrc: function(r,c) { return null }, | 354 | getImageSrc: function(r,c) { return null }, |
367 | getRowProperties: function(r,p) { | 355 | getRowProperties: function(r,p) { |
368 | try { | 356 | try { |
369 | if(!Components) return; | 357 | if(!Components) return; |
370 | }catch(e) { return } | 358 | }catch(e) { return } |
371 | var f = this.files[r]; | 359 | var f = this.files[r]; |
372 | var as = Components.classes['@mozilla.org/atom-service;1']. | 360 | var as = Components.classes['@mozilla.org/atom-service;1']. |
373 | getService(Components.interfaces.nsIAtomService); | 361 | getService(Components.interfaces.nsIAtomService); |
374 | p.AppendElement(as.getAtom(f.state)); | 362 | p.AppendElement(as.getAtom(f.state)); |
375 | }, | 363 | }, |
376 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 364 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
377 | getColumnProperties: function(c,p) { }, | 365 | getColumnProperties: function(c,p) { }, |
378 | cycleHeader: function(cid,e) { }, | 366 | cycleHeader: function(cid,e) { }, |
379 | getParentIndex: function(r) { return -1; }, | 367 | getParentIndex: function(r) { return -1; }, |
380 | drop: function(r,o) { }, | 368 | drop: function(r,o) { }, |
381 | canDropBeforeAfter: function(r,b) { return false }, | 369 | canDropBeforeAfter: function(r,b) { return false }, |
382 | 370 | ||
383 | add: function(f) { | 371 | add: function(f) { |
384 | if(f.indexOf('file:/')==0) { | 372 | if(f.indexOf('file:/')==0) { |
385 | f = f.substr(5); | 373 | f = f.substr(5); |
386 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 374 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
387 | f = f.substr(1); | 375 | f = f.substr(1); |
388 | } | 376 | } |
389 | } | 377 | } |
390 | var t = f; | 378 | var t = f; |
391 | var ls = t.lastIndexOf('/'); | 379 | var ls = t.lastIndexOf('/'); |
392 | if(ls>0) t = t.substr(ls+1); | 380 | if(ls>0) t = t.substr(ls+1); |
393 | ls = t.lastIndexOf('\\'); | 381 | ls = t.lastIndexOf('\\'); |
394 | if(ls>0) t = t.substr(ls+1); | 382 | if(ls>0) t = t.substr(ls+1); |
395 | var ld = t.lastIndexOf('.'); | 383 | var ld = t.lastIndexOf('.'); |
396 | if(ld>0) t = t.substr(0,ld); | 384 | if(ld>0) t = t.substr(0,ld); |
397 | this.files.push( { | 385 | this.files.push( { |
398 | file: f, | 386 | file: f, |
399 | title: t, | 387 | title: t, |
400 | tags: '', | 388 | tags: '', |
401 | is_public: true, is_friend: false, is_family: false, | 389 | is_public: true, is_friend: false, is_family: false, |
402 | state: 'pending' | 390 | state: 'pending' |
403 | } ); | 391 | } ); |
404 | this.rowCount = this.files.length; | 392 | this.rowCount = this.files.length; |
405 | this.tree.rowCountChanged(this.rowCount-1,1); | 393 | this.tree.rowCountChanged(this.rowCount-1,1); |
406 | }, | 394 | }, |
407 | 395 | ||
408 | upload_worker: function() { | 396 | upload_worker: function() { |
409 | for(var f in this.files) { | 397 | for(var f in this.files) { |
410 | if(this.files[f].state=='pending') { | 398 | if(this.files[f].state=='pending') { |
411 | var ff = this.files[f]; | 399 | var ff = this.files[f]; |
412 | this.on_file_upload(ff); | 400 | this.on_file_upload(ff); |
413 | ff.state='uploading'; | 401 | ff.state='uploading'; |
414 | this.tree.invalidate(); | 402 | this.tree.invalidate(); |
415 | var _this = this; | 403 | var _this = this; |
416 | this.fireflix.flickr.upload_file( | 404 | this.fireflix.flickr.upload_file( |
417 | ff.file, { | 405 | ff.file, { |
418 | title: ff.title, tags: ff.tags, | 406 | title: ff.title, tags: ff.tags, |
419 | is_public: ff.is_public?'1':'0', | 407 | is_public: ff.is_public?'1':'0', |
420 | is_friend: ff.is_friend?'1':'0', | 408 | is_friend: ff.is_friend?'1':'0', |
421 | is_family: ff.is_family?'1':'0' | 409 | is_family: ff.is_family?'1':'0' |
422 | }, function(x,p) { | 410 | }, function(x,p) { |
423 | ff.photoid = p; | 411 | ff.photoid = p; |
424 | _this.batch_ids.push(p); | 412 | _this.batch_ids.push(p); |
425 | ff.state='completed'; | 413 | ff.state='completed'; |
426 | _this.tree.invalidate(); | 414 | _this.tree.invalidate(); |
427 | window.setTimeout(_this.upload_to,0,_this); | 415 | window.setTimeout(_this.upload_to,0,_this); |
428 | }, function(x,s,c,m) { | 416 | }, function(x,s,c,m) { |
429 | ff.state='failed'; | 417 | ff.state='failed'; |
430 | ff.flickr_errcode = c; | 418 | ff.flickr_errcode = c; |
431 | ff.flickr_errmsg = m; | 419 | ff.flickr_errmsg = m; |
432 | _this.tree.invalidate(); | 420 | _this.tree.invalidate(); |
433 | window.setTimeout(_this.upload_to,0,_this); | 421 | window.setTimeout(_this.upload_to,0,_this); |
434 | } | 422 | } |
435 | ); | 423 | ); |
436 | return; | 424 | return; |
437 | } | 425 | } |
438 | } | 426 | } |
439 | this.on_finish_upload(); | 427 | this.on_finish_upload(); |
440 | }, | 428 | }, |
441 | upload_to: function(_this) { _this.upload_worker(); }, | 429 | upload_to: function(_this) { _this.upload_worker(); }, |
442 | on_file_upload: function(f) { | 430 | on_file_upload: function(f) { |
443 | this.cmd_uploads_upload.setAttribute('disabled','true'); | 431 | this.cmd_uploads_upload.setAttribute('disabled','true'); |
444 | for(var fi in this.files) { | 432 | for(var fi in this.files) { |
445 | if(this.files[fi].file==f.file) { | 433 | if(this.files[fi].file==f.file) { |
446 | this.tree.ensureRowIsVisible(fi); | 434 | this.tree.ensureRowIsVisible(fi); |
447 | this.selection.rangedSelect(fi,fi,false); | 435 | this.selection.rangedSelect(fi,fi,false); |
448 | this.selection.currentIndex = fi; | 436 | this.selection.currentIndex = fi; |
449 | this.selToProps(); | 437 | this.selToProps(); |
450 | break; | 438 | break; |
451 | } | 439 | } |
452 | } | 440 | } |
453 | }, | 441 | }, |
454 | on_finish_upload: function() { | 442 | on_finish_upload: function() { |
455 | if(this.batch_ids.length) { | 443 | if(this.batch_ids.length) { |
456 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 444 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
457 | if(psn!=null) { | 445 | if(psn!=null) { |
458 | var pids = this.batch_ids.join(','); | 446 | var pids = this.batch_ids.join(','); |
459 | var ppid = this.batch_ids[0]; | 447 | var ppid = this.batch_ids[0]; |
460 | var _this = this; | 448 | var _this = this; |
461 | this.fireflix.flickr.api_call( | 449 | this.fireflix.flickr.api_call( |
462 | { | 450 | { |
463 | method: 'flickr.photosets.create', | 451 | method: 'flickr.photosets.create', |
464 | auth_token: 'default', | 452 | auth_token: 'default', |
465 | title: psn, | 453 | title: psn, |
466 | primary_photo_id: ppid | 454 | primary_photo_id: ppid |
467 | }, function(x) { | 455 | }, function(x) { |
468 | var npid = | 456 | var npid = |
469 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); | 457 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); |
470 | _this.fireflix.flickr.api_call( | 458 | _this.fireflix.flickr.api_call( |
471 | { | 459 | { |
472 | method: 'flickr.photosets.editPhotos', | 460 | method: 'flickr.photosets.editPhotos', |
473 | auth_token: 'default', | 461 | auth_token: 'default', |
474 | photoset_id: npid, | 462 | photoset_id: npid, |
475 | primary_photo_id: ppid, | 463 | primary_photo_id: ppid, |
476 | photo_ids: pids | 464 | photo_ids: pids |
477 | }, function(x) { | 465 | }, function(x) { |
478 | _this.fireflix.refresh_sets(); | 466 | _this.fireflix.refresh_sets(); |
479 | }, function(x,s,c,m) { | 467 | }, function(x,s,c,m) { |
480 | _this.fireflix.flickr_failure(x,s,c,m); | 468 | _this.fireflix.flickr_failure(x,s,c,m); |
481 | } | 469 | } |
482 | ); | 470 | ); |
483 | }, function(x,s,c,m) { | 471 | }, function(x,s,c,m) { |
484 | _this.fireflix.flickr_failure(x,s,c,m); | 472 | _this.fireflix.flickr_failure(x,s,c,m); |
485 | } | 473 | } |
486 | ); | 474 | ); |
487 | } | 475 | } |
488 | } | 476 | } |
489 | this.selection.clearSelection(); | 477 | this.selection.clearSelection(); |
490 | this.cmd_uploads_upload.setAttribute('disabled','false'); | 478 | this.cmd_uploads_upload.setAttribute('disabled','false'); |
491 | this.upload_progress.setAttribute('hidden','true'); | 479 | this.upload_progress.setAttribute('hidden','true'); |
492 | }, | 480 | }, |
493 | 481 | ||
494 | clear_list: function() { | 482 | clear_list: function() { |
495 | this.tree.beginUpdateBatch(); | 483 | this.tree.beginUpdateBatch(); |
496 | this.rowCount = 0; | 484 | this.rowCount = 0; |
497 | this.files = new Array(); | 485 | this.files = new Array(); |
498 | this.tree.endUpdateBatch(); | 486 | this.tree.endUpdateBatch(); |
499 | this.selToProps(); | 487 | this.selToProps(); |
500 | }, | 488 | }, |
501 | selectionChanged: function() { | 489 | selectionChanged: function() { |
502 | this.selToProps(); | 490 | this.selToProps(); |
503 | }, | 491 | }, |
504 | disableProps: function() { | 492 | disableProps: function() { |
505 | this.upload_filename.value=''; | 493 | this.upload_filename.value=''; |
506 | this.upload_filename.disabled = true; | 494 | this.upload_filename.disabled = true; |
507 | this.upload_title.value=''; | 495 | this.upload_title.value=''; |
508 | this.upload_title.disabled = true; | 496 | this.upload_title.disabled = true; |
509 | this.upload_file_preview.src = null; | 497 | this.upload_file_preview.src = null; |
510 | this.upload_tags.value=''; | 498 | this.upload_tags.value=''; |
511 | this.upload_tags.disabled = true; | 499 | this.upload_tags.disabled = true; |
512 | this.upload_is_public.disabled = true; | 500 | this.upload_is_public.disabled = true; |
513 | this.upload_is_friends.disabled = true; | 501 | this.upload_is_friends.disabled = true; |
514 | this.upload_is_family.disabled = true; | 502 | this.upload_is_family.disabled = true; |
515 | /* this.upload_file_props.hidden = true; */ | 503 | /* this.upload_file_props.hidden = true; */ |
516 | }, | 504 | }, |
517 | selToProps: function() { | 505 | selToProps: function() { |
518 | if(!this.selection.count) { | 506 | if(!this.selection.count) { |
519 | this.disableProps(); | 507 | this.disableProps(); |
520 | this.upload_file_props.hidden = true; | 508 | this.upload_file_props.hidden = true; |
521 | }else if(this.selection.count==1) { | 509 | }else if(this.selection.count==1) { |
522 | var f=this.files[this.selection.currentIndex]; | 510 | var f=this.files[this.selection.currentIndex]; |
523 | if(f==null) { | 511 | if(f==null) { |
524 | this.disableProps(); | 512 | this.disableProps(); |
525 | this.upload_file_props.hidden = true; | 513 | this.upload_file_props.hidden = true; |
526 | }else{ | 514 | }else{ |
527 | var inactives = f.state!='pending'; | 515 | var inactives = f.state!='pending'; |
528 | this.upload_filename.value = f.file; this.upload_filename.disabled = inactives; | 516 | this.upload_filename.value = f.file; this.upload_filename.disabled = inactives; |
529 | this.upload_title.value = f.title; this.upload_title.disabled = inactives; | 517 | this.upload_title.value = f.title; this.upload_title.disabled = inactives; |
530 | this.upload_file_preview.src = 'file:///'+f.file; | 518 | this.upload_file_preview.src = 'file:///'+f.file; |
531 | this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives; | 519 | this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives; |
532 | this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives; | 520 | this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives; |
533 | this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives; | 521 | this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives; |
534 | this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives; | 522 | this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives; |
535 | if(f.state=='failed') { | 523 | if(f.state=='failed') { |
536 | this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg; | 524 | this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg; |
537 | this.upload_failure.hidden = false; | 525 | this.upload_failure.hidden = false; |
538 | }else{ | 526 | }else{ |
539 | this.upload_failure.hidden = true; | 527 | this.upload_failure.hidden = true; |
540 | } | 528 | } |
541 | this.upload_file_props.hidden = false; | 529 | this.upload_file_props.hidden = false; |
542 | } | 530 | } |
543 | }else{ | 531 | }else{ |
544 | var ftitle = null; var onetitle = true; | 532 | var ftitle = null; var onetitle = true; |
545 | var ftags = null; var onetag = true; | 533 | var ftags = null; var onetag = true; |
546 | var fs = 0; | 534 | var fs = 0; |
547 | for(var ff in this.files) { | 535 | for(var ff in this.files) { |
548 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 536 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
549 | ++fs; | 537 | ++fs; |
550 | if(ftitle==null) { | 538 | if(ftitle==null) { |
551 | ftitle = this.files[ff].title; | 539 | ftitle = this.files[ff].title; |
552 | }else if(ftitle!=this.files[ff].title) { | 540 | }else if(ftitle!=this.files[ff].title) { |
553 | onetitle = false; | 541 | onetitle = false; |
554 | } | 542 | } |
555 | if(ftags==null) { | 543 | if(ftags==null) { |
556 | ftags = this.files[ff].tags; | 544 | ftags = this.files[ff].tags; |
557 | }else if(ftags!=this.files[ff].tags) { | 545 | }else if(ftags!=this.files[ff].tags) { |
558 | onetag = false; | 546 | onetag = false; |
559 | } | 547 | } |
560 | } | 548 | } |
561 | } | 549 | } |
562 | if(fs) { | 550 | if(fs) { |
563 | this.upload_filename.value=''; | 551 | this.upload_filename.value=''; |
564 | this.upload_filename.disabled = true; | 552 | this.upload_filename.disabled = true; |
565 | if(onetitle) | 553 | if(onetitle) |
566 | this.upload_title.value = ftitle; | 554 | this.upload_title.value = ftitle; |
567 | this.upload_title.disabled = false; | 555 | this.upload_title.disabled = false; |
568 | if(onetag) | 556 | if(onetag) |
569 | this.upload_tags.value = ftags; | 557 | this.upload_tags.value = ftags; |
570 | this.upload_tags.disabled = false; | 558 | this.upload_tags.disabled = false; |
571 | this.upload_file_preview.src = null; | 559 | this.upload_file_preview.src = null; |
572 | this.upload_failure.hidden = true; | 560 | this.upload_failure.hidden = true; |
573 | this.upload_file_props.hidden = false; | 561 | this.upload_file_props.hidden = false; |
574 | }else | 562 | }else |
575 | this.disableProps(); | 563 | this.disableProps(); |
576 | this.upload_file_props.hidden = true; | 564 | this.upload_file_props.hidden = true; |
577 | } | 565 | } |
578 | }, | 566 | }, |
579 | propsToSel: function(prop) { | 567 | propsToSel: function(prop) { |
580 | if(this.selection.count<=0) return; | 568 | if(this.selection.count<=0) return; |
581 | for(var ff in this.files) { | 569 | for(var ff in this.files) { |
582 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { | 570 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { |
583 | if(prop=='filename') this.files[ff].file = this.upload_filename.value; | 571 | if(prop=='filename') this.files[ff].file = this.upload_filename.value; |
584 | if(prop=='title') this.files[ff].title = this.upload_title.value; | 572 | if(prop=='title') this.files[ff].title = this.upload_title.value; |
585 | if(prop=='tags') this.files[ff].tags = this.upload_tags.value; | 573 | if(prop=='tags') this.files[ff].tags = this.upload_tags.value; |
586 | if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked; | 574 | if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked; |
587 | if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked; | 575 | if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked; |
588 | if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked; | 576 | if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked; |
589 | this.tree.invalidateRow(ff); | 577 | this.tree.invalidateRow(ff); |
590 | } | 578 | } |
591 | } | 579 | } |
592 | }, | 580 | }, |
593 | 581 | ||
594 | on_upload: function() { | 582 | on_upload: function() { |
595 | this.selToProps(); | 583 | this.selToProps(); |
596 | this.batch_ids = new Array(); | 584 | this.batch_ids = new Array(); |
597 | this.upload_progress.value=0; | 585 | this.upload_progress.value=0; |
598 | this.upload_progress.setAttribute('hidden','false'); | 586 | this.upload_progress.setAttribute('hidden','false'); |
599 | this.upload_worker(); | 587 | this.upload_worker(); |
600 | }, | 588 | }, |
601 | on_clear: function() { | 589 | on_clear: function() { |
602 | this.clear_list(); | 590 | this.clear_list(); |
603 | }, | 591 | }, |
604 | on_remove: function() { | 592 | on_remove: function() { |
605 | if(this.selection.count) { | 593 | if(this.selection.count) { |
606 | this.tree.beginUpdateBatch(); | 594 | this.tree.beginUpdateBatch(); |
607 | for(var i=this.files.length-1;i>=0;--i) { | 595 | for(var i=this.files.length-1;i>=0;--i) { |
608 | if(this.selection.isSelected(i)) { | 596 | if(this.selection.isSelected(i)) { |
609 | this.files.splice(i,1); | 597 | this.files.splice(i,1); |
610 | this.rowCount--; | 598 | this.rowCount--; |
611 | } | 599 | } |
612 | } | 600 | } |
613 | this.tree.endUpdateBatch(); | 601 | this.tree.endUpdateBatch(); |
614 | this.selection.clearSelection(); | 602 | this.selection.clearSelection(); |
615 | } | 603 | } |
616 | }, | 604 | }, |
617 | on_add: function() { | 605 | on_add: function() { |
618 | var ifp = Components.interfaces.nsIFilePicker; | 606 | var ifp = Components.interfaces.nsIFilePicker; |
619 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); | 607 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); |
620 | fp.init(window, "Select a File", ifp.modeOpenMultiple); | 608 | fp.init(window, "Select a File", ifp.modeOpenMultiple); |
621 | fp.appendFilters(ifp.filterImages); | 609 | fp.appendFilters(ifp.filterImages); |
622 | var rv = fp.show(); | 610 | var rv = fp.show(); |
623 | if(rv==ifp.returnOK) { | 611 | if(rv==ifp.returnOK) { |
624 | var ff = fp.files; | 612 | var ff = fp.files; |
625 | while(ff.hasMoreElements()) { | 613 | while(ff.hasMoreElements()) { |
626 | var f = ff.getNext(); | 614 | var f = ff.getNext(); |
627 | f.QueryInterface(Components.interfaces.nsIFile); | 615 | f.QueryInterface(Components.interfaces.nsIFile); |
628 | this.add(f.path); | 616 | this.add(f.path); |
629 | } | 617 | } |
630 | } | 618 | } |
631 | }, | 619 | }, |
632 | on_cmd_open: function(ev) { | 620 | on_cmd_open: function(ev) { |
633 | if(this.selection.currentIndex<0) return; | 621 | if(this.selection.currentIndex<0) return; |
634 | var f = this.files[this.selection.currentIndex]; | 622 | var f = this.files[this.selection.currentIndex]; |
635 | if(f.photoid) { | 623 | if(f.photoid) { |
636 | this.fireflix.openTab( | 624 | this.fireflix.openTab( |
637 | this.fireflix.flickr.make_uploader_edit_url(f.photoid) | 625 | this.fireflix.flickr.make_uploader_edit_url(f.photoid) |
638 | ); | 626 | ); |
639 | }else{ | 627 | }else{ |
640 | this.fireflix.openTab( 'file://'+f.file); | 628 | this.fireflix.openTab( 'file://'+f.file); |
641 | } | 629 | } |
642 | } | 630 | } |
643 | }, | 631 | }, |
644 | 632 | ||
645 | on_set_props: function() { | 633 | on_set_props: function() { |
646 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; | 634 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; |
647 | window.openDialog( | 635 | window.openDialog( |
648 | "chrome://fireflix/content/photoset-props.xul", | 636 | "chrome://fireflix/content/photoset-props.xul", |
649 | null, "dependent,modal,dialog,chrome", this, | 637 | null, "dependent,modal,dialog,chrome", this, |
650 | pset ); | 638 | pset ); |
651 | if(pset.dirty) { | 639 | if(pset.dirty) { |
652 | var _this = this; | 640 | var _this = this; |
653 | this.flickr.api_call( | 641 | this.flickr.api_call( |
654 | { | 642 | { |
655 | method: 'flickr.photosets.editMeta', | 643 | method: 'flickr.photosets.editMeta', |
656 | auth_token: 'default', | 644 | auth_token: 'default', |
657 | photoset_id: pset.id, | 645 | photoset_id: pset.id, |
658 | title: pset.title, | 646 | title: pset.title, |
659 | description: pset.description | 647 | description: pset.description |
660 | }, function(xr) { | 648 | }, function(xr) { |
661 | pset.dirty = false; | 649 | pset.dirty = false; |
662 | _this.flickr.api_call( | 650 | _this.flickr.api_call( |
663 | { | 651 | { |
664 | method: 'flickr.photosets.getPhotos', | 652 | method: 'flickr.photosets.getPhotos', |
665 | auth_token: 'default', | 653 | auth_token: 'default', |
666 | photoset_id: pset.id | 654 | photoset_id: pset.id |
667 | }, function(xr) { | 655 | }, function(xr) { |
668 | var x = xr.responseXML; | 656 | var x = xr.responseXML; |
669 | var xp = x.evaluate( | 657 | var xp = x.evaluate( |
670 | '/rsp/photoset/photo', x, null, | 658 | '/rsp/photoset/photo', x, null, |
671 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 659 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
672 | var phids = new Array(); | 660 | var phids = new Array(); |
673 | var priph = null; | 661 | var priph = null; |
674 | var n; while(n=xp.iterateNext()) { | 662 | var n; while(n=xp.iterateNext()) { |
675 | var pid = n.getAttribute('id'); | 663 | var pid = n.getAttribute('id'); |
676 | phids.push( pid ); | 664 | phids.push( pid ); |
677 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 665 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') |
678 | priph = pid; | 666 | priph = pid; |
679 | } | 667 | } |
680 | if(priph) { | 668 | if(priph) { |
681 | _this.flickr.api_call( | 669 | _this.flickr.api_call( |
682 | { | 670 | { |
683 | method: 'flickr.photosets.editPhotos', | 671 | method: 'flickr.photosets.editPhotos', |
684 | auth_token: 'default', | 672 | auth_token: 'default', |
685 | photoset_id: pset.id, | 673 | photoset_id: pset.id, |
686 | primary_photo_id: priph, | 674 | primary_photo_id: priph, |
687 | photo_ids: phids.join(',') | 675 | photo_ids: phids.join(',') |
688 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 676 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
689 | _this.flickr_failure(x,s,c,m); | 677 | _this.flickr_failure(x,s,c,m); |
690 | } | 678 | } |
691 | ); | 679 | ); |
692 | } | 680 | } |
693 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 681 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
694 | _this.flickr_failure(x,s,c,m); | 682 | _this.flickr_failure(x,s,c,m); |
695 | } | 683 | } |
696 | ); | 684 | ); |
697 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 685 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
698 | _this.flickr_failure(x,s,c,m); | 686 | _this.flickr_failure(x,s,c,m); |
699 | } | 687 | } |
700 | ); | 688 | ); |
701 | } | 689 | } |
702 | }, | 690 | }, |
703 | on_refresh_sets: function() { | 691 | on_refresh_sets: function() { |
704 | this.refresh_sets(); | 692 | this.refresh_sets(); |
705 | }, | 693 | }, |
706 | on_cmd_sets_html: function(csfx,ev) { | 694 | on_cmd_sets_html: function(csfx,ev) { |
707 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 695 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
708 | var rv = this.build_html(this.photoset.photos,uti,utl); | 696 | var rv = this.build_html(this.photoset.photos,uti,utl); |
709 | this.popup_content(rv); | 697 | this.popup_content(rv); |
710 | }, | 698 | }, |
711 | on_cmd_setphotos_html: function(csfx,ev) { | 699 | on_cmd_setphotos_html: function(csfx,ev) { |
712 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 700 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
713 | var rv = ''; | 701 | var rv = ''; |
714 | for(var p in this.photoset.photos) { | 702 | for(var p in this.photoset.photos) { |
715 | if(this.photoset.selection.isSelected(p)) | 703 | if(this.photoset.selection.isSelected(p)) |
716 | rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n'; | 704 | rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n'; |
717 | } | 705 | } |
718 | this.popup_content(rv); | 706 | this.popup_content(rv); |
719 | }, | 707 | }, |
720 | 708 | ||
721 | on_cmd_uploads_html: function(csfx,ev) { | 709 | on_cmd_uploads_html: function(csfx,ev) { |
722 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 710 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
723 | var pids = new Array(); | 711 | var pids = new Array(); |
724 | for(var f in this.uploads.files) { | 712 | for(var f in this.uploads.files) { |
725 | if(this.uploads.selection.isSelected(f)) | 713 | if(this.uploads.selection.isSelected(f)) |
726 | if(this.uploads.files[f].photoid) | 714 | if(this.uploads.files[f].photoid) |
727 | pids.push(this.uploads.files[f].photoid); | 715 | pids.push(this.uploads.files[f].photoid); |
728 | } | 716 | } |
729 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 717 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
730 | var _this = this; | 718 | var _this = this; |
731 | this.flickr.api_call( | 719 | this.flickr.api_call( |
732 | { | 720 | { |
733 | method: 'flickr.photos.search', | 721 | method: 'flickr.photos.search', |
734 | auth_token: 'default', | 722 | auth_token: 'default', |
735 | extras: 'original_format', | 723 | extras: 'original_format', |
736 | user_id: 'me', | 724 | user_id: 'me', |
737 | per_page: pp | 725 | per_page: pp |
738 | }, | 726 | }, |
739 | function(xr) { | 727 | function(xr) { |
740 | var x = xr.responseXML; | 728 | var x = xr.responseXML; |
741 | var rv = ''; | 729 | var rv = ''; |
742 | for(var pn in pids) { | 730 | for(var pn in pids) { |
743 | var p = pids[pn]; | 731 | var p = pids[pn]; |
744 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 732 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
745 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 733 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
746 | } | 734 | } |
747 | _this.popup_content(rv); | 735 | _this.popup_content(rv); |
748 | }, function(x,s,c,m) { | 736 | }, function(x,s,c,m) { |
749 | _this.flickr_failure(x,s,c,m); | 737 | _this.flickr_failure(x,s,c,m); |
750 | } | 738 | } |
751 | ); | 739 | ); |
752 | }, | 740 | }, |
753 | 741 | ||
754 | /* | 742 | /* |
755 | * | 743 | * |
756 | */ | 744 | */ |
757 | foundphotos: { | 745 | foundphotos: { |
758 | fireflix: null, | 746 | fireflix: null, |
759 | init: function(f) { | 747 | init: function(f) { |
760 | this.fireflix = f; | 748 | this.fireflix = f; |
761 | pull_elements(this,document,[ | 749 | pull_elements(this,document,[ |
762 | 'search_for','search_tags','search_mine', | 750 | 'search_for','search_tags','search_mine', |
763 | 'searchresult_props','search_photo', | 751 | 'searchresult_props','search_photo', |
764 | 'searchresult_title','searchresult_description', | 752 | 'searchresult_title','searchresult_description', |
765 | 'search_page','cmd_search_prev_page','cmd_search_next_page' | 753 | 'search_page','cmd_search_prev_page','cmd_search_next_page' |
766 | ]); | 754 | ]); |
767 | document.getElementById('searchresults').view = this; | 755 | document.getElementById('searchresults').view = this; |
768 | }, | 756 | }, |
769 | photos: new Array(), | 757 | photos: new Array(), |
770 | rowCount: 0, | 758 | rowCount: 0, |
771 | getCellText: function(r,c) { | 759 | getCellText: function(r,c) { |
772 | var p = this.photos[r]; | 760 | var p = this.photos[r]; |
773 | if(c.id=='sr_title') return p.title; | 761 | if(c.id=='sr_title') return p.title; |
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() { |
858 | if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { | 843 | if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { |
859 | this.search_page.value=''; this.search_page.hidden = true; | 844 | this.search_page.value=''; this.search_page.hidden = true; |
860 | this.cmd_search_prev_page.setAttribute('disabled','true'); | 845 | this.cmd_search_prev_page.setAttribute('disabled','true'); |
861 | this.cmd_search_next_page.setAttribute('disabled','true'); | 846 | this.cmd_search_next_page.setAttribute('disabled','true'); |
862 | }else{ | 847 | }else{ |
863 | this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); | 848 | this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); |
864 | this.search_page.hidden=false; | 849 | this.search_page.hidden=false; |
865 | this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); | 850 | this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); |
866 | this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); | 851 | this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); |
867 | } | 852 | } |
868 | }, | 853 | }, |
869 | render_description_frame: function(content) { | 854 | render_description_frame: function(content) { |
870 | this.searchresult_description.innerHTML = ''; | 855 | this.searchresult_description.innerHTML = ''; |
871 | if(content) { | 856 | if(content) { |
872 | var dp = new DOMParser(); | 857 | var dp = new DOMParser(); |
873 | var pd = dp.parseFromString( | 858 | var pd = dp.parseFromString( |
874 | '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); | 859 | '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); |
875 | var de = pd.documentElement; | 860 | var de = pd.documentElement; |
876 | if(de.tagName=='parsererror') | 861 | if(de.tagName=='parsererror') |
877 | this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); | 862 | this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); |
878 | else | 863 | else |
879 | this.searchresult_description.appendChild(de); | 864 | this.searchresult_description.appendChild(de); |
880 | /* of all linking elements flickr only allows a */ | 865 | /* of all linking elements flickr only allows a */ |
881 | var as = this.searchresult_description.getElementsByTagName('a'); | 866 | var as = this.searchresult_description.getElementsByTagName('a'); |
882 | for(var a=0;a<as.length;++a) | 867 | for(var a=0;a<as.length;++a) |
883 | as.item(a).setAttribute('target','_blank'); | 868 | as.item(a).setAttribute('target','_blank'); |
884 | } | 869 | } |
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 | }, |
933 | 917 | ||
934 | photo_html: function(p,i,l) { | 918 | photo_html: function(p,i,l) { |
935 | // TODO: add alt/title when possible | 919 | // TODO: add alt/title when possible |
936 | var rv = | 920 | var rv = |
937 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 921 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
938 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 922 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
939 | '</a>'; | 923 | '</a>'; |
940 | return rv; | 924 | return rv; |
941 | }, | 925 | }, |
942 | build_html: function(photos,uti,utl) { | 926 | build_html: function(photos,uti,utl) { |
943 | var rv = ''; | 927 | var rv = ''; |
944 | for(var i in photos) { | 928 | for(var i in photos) { |
945 | var p = photos[i]; | 929 | var p = photos[i]; |
946 | rv += this.photo_html(p,uti,utl)+'\n'; | 930 | rv += this.photo_html(p,uti,utl)+'\n'; |
947 | } | 931 | } |
948 | return rv; | 932 | return rv; |
949 | }, | 933 | }, |
950 | 934 | ||
951 | popup_content: function(s) { | 935 | popup_content: function(s) { |
952 | window.openDialog( | 936 | window.openDialog( |
953 | "chrome://fireflix/content/generated-content.xul", | 937 | "chrome://fireflix/content/generated-content.xul", |
954 | null, "dialog,chrome", this, s ); | 938 | null, "dialog,chrome", this, s ); |
955 | }, | 939 | }, |
956 | copy_to_clipboard: function(s) { | 940 | copy_to_clipboard: function(s) { |
957 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 941 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
958 | .getService(Components.interfaces.nsIClipboardHelper); | 942 | .getService(Components.interfaces.nsIClipboardHelper); |
959 | ch.copyString(s); | 943 | ch.copyString(s); |
960 | }, | 944 | }, |
961 | openTab: function(l) { | 945 | openTab: function(l) { |
962 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 946 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
963 | Components.interfaces.nsIWindowMediator ); | 947 | Components.interfaces.nsIWindowMediator ); |
964 | var bw = wm.getMostRecentWindow('navigator:browser'); | 948 | var bw = wm.getMostRecentWindow('navigator:browser'); |
965 | var b = bw.getBrowser(); | 949 | var b = bw.getBrowser(); |
966 | var t = b.addTab(l); | 950 | var t = b.addTab(l); |
967 | b.selectedTab = t; | 951 | b.selectedTab = t; |
968 | }, | 952 | }, |
969 | 953 | ||
970 | build_menus: function() { | 954 | build_menus: function() { |
971 | this.append_html_menu( | 955 | this.append_html_menu( |
972 | document.getElementById('sets_html_menu'), | 956 | document.getElementById('sets_html_menu'), |
973 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' | 957 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' |
974 | ); | 958 | ); |
975 | this.append_html_menu( | 959 | this.append_html_menu( |
976 | document.getElementById('setphotos_html_menu'), | 960 | document.getElementById('setphotos_html_menu'), |
977 | 'stm_','m_bop','cmdset_setphotos','cmd_setphotos_html' | 961 | 'stm_','m_bop','cmdset_setphotos','cmd_setphotos_html' |
978 | ); | 962 | ); |
979 | this.append_html_menu( | 963 | this.append_html_menu( |
980 | document.getElementById('uploads_html_menu'), | 964 | document.getElementById('uploads_html_menu'), |
981 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' | 965 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' |
982 | ); | 966 | ); |
983 | return; | 967 | return; |
984 | }, | 968 | }, |
985 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { | 969 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { |
986 | var mp = m.appendChild(document.createElement('menupopup')); | 970 | var mp = m.appendChild(document.createElement('menupopup')); |
987 | var t; | 971 | var t; |
988 | t=mp.appendChild(document.createElement('menuitem')); | 972 | t=mp.appendChild(document.createElement('menuitem')); |
989 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); | 973 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); |
990 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 974 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
991 | mp.appendChild(document.createElement('menuseparator')); | 975 | mp.appendChild(document.createElement('menuseparator')); |
992 | var cs = document.getElementById(csid); | 976 | var cs = document.getElementById(csid); |
993 | for(var iti=0;iti<imgt.length;++iti) { | 977 | for(var iti=0;iti<imgt.length;++iti) { |
994 | t = mp.appendChild(document.createElement('menu')); | 978 | t = mp.appendChild(document.createElement('menu')); |
995 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); | 979 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); |
996 | var smp = t.appendChild(document.createElement('menupopup')); | 980 | var smp = t.appendChild(document.createElement('menupopup')); |
997 | t=smp.appendChild(document.createElement('menuitem')); | 981 | t=smp.appendChild(document.createElement('menuitem')); |
998 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); | 982 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); |
999 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 983 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
1000 | smp.appendChild(document.createElement('menuseparator')); | 984 | smp.appendChild(document.createElement('menuseparator')); |
1001 | for(var lti=0;lti<lnkt.length;++lti) { | 985 | for(var lti=0;lti<lnkt.length;++lti) { |
1002 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); | 986 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); |
1003 | t=smp.appendChild(document.createElement('menuitem')); | 987 | t=smp.appendChild(document.createElement('menuitem')); |
1004 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); | 988 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); |
1005 | t.setAttribute('command',cpfx+'_'+csfx); | 989 | t.setAttribute('command',cpfx+'_'+csfx); |
1006 | t=cs.appendChild(document.createElement('command')); | 990 | t=cs.appendChild(document.createElement('command')); |
1007 | t.setAttribute('id',cpfx+'_'+csfx); | 991 | t.setAttribute('id',cpfx+'_'+csfx); |
1008 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); | 992 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); |
1009 | } | 993 | } |
1010 | } | 994 | } |
1011 | return mp; | 995 | return mp; |
1012 | }, | 996 | }, |
1013 | 997 | ||
1014 | flickr_failure: function(x,s,c,m) { | 998 | flickr_failure: function(x,s,c,m) { |
1015 | if(c==98) { // Invalid auth token | 999 | if(c==98) { // Invalid auth token |
1016 | this.flickr.reset_token(); | 1000 | this.flickr.reset_token(); |
1017 | this.set_auth_state(false,false); | 1001 | this.set_auth_state(false,false); |
1018 | return; | 1002 | return; |
1019 | } | 1003 | } |
1020 | // TODO: is that beauty? | 1004 | // TODO: is that beauty? |
1021 | alert('flickr api call failed\n'+c+' '+m); | 1005 | alert('flickr api call failed\n'+c+' '+m); |
1022 | } | 1006 | } |
1023 | 1007 | ||
1024 | }; | 1008 | }; |