-rw-r--r-- | content/fireflix.js | 32 |
1 files changed, 14 insertions, 18 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 34cfd3e..f30daee 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -121,881 +121,877 @@ var fireflix = { | |||
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 | import_json: function(jp) { | 127 | import_json: function(jp) { |
128 | this.tree.beginUpdateBatch(); | 128 | this.tree.beginUpdateBatch(); |
129 | this.photos = new Array(); | 129 | this.photos = new Array(); |
130 | for(var i in jp) this.photos.push(new Photo(jp[i])); | 130 | for(var i in jp) this.photos.push(new Photo(jp[i])); |
131 | this.rowCount =this.photos.length; | 131 | this.rowCount =this.photos.length; |
132 | this.tree.endUpdateBatch(); | 132 | this.tree.endUpdateBatch(); |
133 | this.selection.clearSelection(); | 133 | this.selection.clearSelection(); |
134 | }, | 134 | }, |
135 | load_photos: function(psid) { | 135 | load_photos: function(psid) { |
136 | var that = this; | 136 | var that = this; |
137 | this.fireflix.flickr.api_call_json( | 137 | this.fireflix.flickr.api_call_json( |
138 | { | 138 | { |
139 | method: 'flickr.photosets.getPhotos', | 139 | method: 'flickr.photosets.getPhotos', |
140 | auth_token: 'default', | 140 | auth_token: 'default', |
141 | photoset_id: psid, | 141 | photoset_id: psid, |
142 | 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' |
143 | }, function(x,j) { | 143 | }, function(x,j) { |
144 | that.import_json(j.photoset.photo); | 144 | that.import_json(j.photoset.photo); |
145 | }, function(x,s,c,m) { | 145 | }, function(x,s,c,m) { |
146 | that.fireflix.flickr_failure(x,s,c,m); | 146 | that.fireflix.flickr_failure(x,s,c,m); |
147 | } | 147 | } |
148 | ); | 148 | ); |
149 | }, | 149 | }, |
150 | on_select: function() { | 150 | on_select: function() { |
151 | if(this.selection.count==1) { | 151 | if(this.selection.count==1) { |
152 | var p = this.photos[this.selection.currentIndex]; | 152 | var p = this.photos[this.selection.currentIndex]; |
153 | this.set_photo.src = | 153 | this.set_photo.src = |
154 | 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'); |
155 | this.set_photo_props.hidden = false; | 155 | this.set_photo_props.hidden = false; |
156 | }else{ | 156 | }else{ |
157 | this.set_photo_props.hidden = true; | 157 | this.set_photo_props.hidden = true; |
158 | } | 158 | } |
159 | }, | 159 | }, |
160 | on_cmd_open: function(ev) { | 160 | on_cmd_open: function(ev) { |
161 | if(this.selection.currentIndex<0) return; | 161 | if(this.selection.currentIndex<0) return; |
162 | var p = this.photos[this.selection.currentIndex]; | 162 | var p = this.photos[this.selection.currentIndex]; |
163 | if(!p.id) return; | 163 | if(!p.id) return; |
164 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 164 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
165 | } | 165 | } |
166 | }, | 166 | }, |
167 | 167 | ||
168 | /* photosets treeview */ | 168 | /* photosets treeview */ |
169 | photosets: { | 169 | photosets: { |
170 | sets: new Array(), | 170 | sets: new Array(), |
171 | fireflix: null, | 171 | fireflix: null, |
172 | init: function(f) { | 172 | init: function(f) { |
173 | this.fireflix = f; | 173 | this.fireflix = f; |
174 | document.getElementById('setslist').view = this; | 174 | document.getElementById('setslist').view = this; |
175 | }, | 175 | }, |
176 | rowCount: 0, | 176 | rowCount: 0, |
177 | getCellText: function(r,c) { | 177 | getCellText: function(r,c) { |
178 | var s = this.sets[r]; | 178 | var s = this.sets[r]; |
179 | if(c.id=='sl_name') return s.title; | 179 | if(c.id=='sl_name') return s.title; |
180 | if(c.id=='sl_photos') return s.photos; | 180 | if(c.id=='sl_photos') return s.photos; |
181 | return c.id; | 181 | return c.id; |
182 | }, | 182 | }, |
183 | setTree: function(t) { this.tree = t }, | 183 | setTree: function(t) { this.tree = t }, |
184 | isContainer: function(r) { return false; }, | 184 | isContainer: function(r) { return false; }, |
185 | isSeparator: function(r) { return false; }, | 185 | isSeparator: function(r) { return false; }, |
186 | isSorted: function() { return false; }, | 186 | isSorted: function() { return false; }, |
187 | getLevel: function(r) { return 0; }, | 187 | getLevel: function(r) { return 0; }, |
188 | getImageSrc: function(r,c) { return null }, | 188 | getImageSrc: function(r,c) { return null }, |
189 | getRowProperties: function(r,p) {}, | 189 | getRowProperties: function(r,p) {}, |
190 | getCellProperties: function(cid,cel,p) { }, | 190 | getCellProperties: function(cid,cel,p) { }, |
191 | getColumnProperties: function(cid,cel,p) { }, | 191 | getColumnProperties: function(cid,cel,p) { }, |
192 | cycleHeader: function(cid,e) { }, | 192 | cycleHeader: function(cid,e) { }, |
193 | getParentIndex: function(r) { return -1; }, | 193 | getParentIndex: function(r) { return -1; }, |
194 | drop: function(r,o) { }, | 194 | drop: function(r,o) { }, |
195 | canDropBeforeAfter: function(r,b) { return false }, | 195 | canDropBeforeAfter: function(r,b) { return false }, |
196 | 196 | ||
197 | import_json: function(j) { | 197 | import_json: function(j) { |
198 | this.tree.beginUpdateBatch(); | 198 | this.tree.beginUpdateBatch(); |
199 | this.sets = new Array(); | 199 | this.sets = new Array(); |
200 | for(var i in j) this.sets.push(new Photoset(j[i])); | 200 | for(var i in j) this.sets.push(new Photoset(j[i])); |
201 | this.rowCount = this.sets.length; | 201 | this.rowCount = this.sets.length; |
202 | this.tree.endUpdateBatch(); | 202 | this.tree.endUpdateBatch(); |
203 | }, | 203 | }, |
204 | refresh_sets: function() { | 204 | refresh_sets: function() { |
205 | var that = this; | 205 | var that = this; |
206 | this.fireflix.flickr.api_call_json( | 206 | this.fireflix.flickr.api_call_json( |
207 | { | 207 | { |
208 | method: 'flickr.photosets.getList', | 208 | method: 'flickr.photosets.getList', |
209 | auth_token: 'default' | 209 | auth_token: 'default' |
210 | }, function(x,j) { | 210 | }, function(x,j) { |
211 | that.import_json(j.photosets.photoset); | 211 | that.import_json(j.photosets.photoset); |
212 | }, function(x,s,c,m) { | 212 | }, function(x,s,c,m) { |
213 | that.fireflix.flickr_failure(x,s,c,m); | 213 | that.fireflix.flickr_failure(x,s,c,m); |
214 | } | 214 | } |
215 | ); | 215 | ); |
216 | }, | 216 | }, |
217 | on_select: function() { | 217 | on_select: function() { |
218 | if(this.selection.count==1) { | 218 | if(this.selection.count==1) { |
219 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 219 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
220 | var s = this.sets[this.selection.currentIndex]; | 220 | var s = this.sets[this.selection.currentIndex]; |
221 | this.fireflix.photoset.load_photos(s.id); | 221 | this.fireflix.photoset.load_photos(s.id); |
222 | }else{ | 222 | }else{ |
223 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 223 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
224 | } | 224 | } |
225 | }, | 225 | }, |
226 | on_cmd_open_in_flickr: function(ev) { | 226 | on_cmd_open_in_flickr: function(ev) { |
227 | if(this.selection.currentIndex<0) return; | 227 | if(this.selection.currentIndex<0) return; |
228 | var p = this.sets[this.selection.currentIndex]; | 228 | var p = this.sets[this.selection.currentIndex]; |
229 | if(!p.id) return; | 229 | if(!p.id) return; |
230 | this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p)); | 230 | this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p)); |
231 | } | 231 | } |
232 | }, | 232 | }, |
233 | 233 | ||
234 | refresh_user_tags: function() { | 234 | refresh_user_tags: function() { |
235 | var lb = document.getElementById('tagslist'); | 235 | var lb = document.getElementById('tagslist'); |
236 | var that = this; | 236 | var that = this; |
237 | this.flickr.api_call_json( | 237 | this.flickr.api_call_json( |
238 | { | 238 | { |
239 | method: 'flickr.tags.getListUser', | 239 | method: 'flickr.tags.getListUser', |
240 | auth_token: 'default', | 240 | auth_token: 'default', |
241 | }, function(x,j) { | 241 | }, function(x,j) { |
242 | var tt = j.who.tags.tag; | 242 | var tt = j.who.tags.tag; |
243 | for(var i in tt) lb.appendItem(tt[i]._content); | 243 | for(var i in tt) lb.appendItem(tt[i]._content); |
244 | }, function(x,s,c,m) { | 244 | }, function(x,s,c,m) { |
245 | that.flickr_failure(x,s,c,m); | 245 | that.flickr_failure(x,s,c,m); |
246 | } | 246 | } |
247 | ); | 247 | ); |
248 | }, | 248 | }, |
249 | 249 | ||
250 | uploadObserver: { | 250 | uploadObserver: { |
251 | fireflix: null, | 251 | fireflix: null, |
252 | init: function(f) { | 252 | init: function(f) { |
253 | this.fireflix = f; | 253 | this.fireflix = f; |
254 | }, | 254 | }, |
255 | getSupportedFlavours: function() { | 255 | getSupportedFlavours: function() { |
256 | var rv = new FlavourSet(); | 256 | var rv = new FlavourSet(); |
257 | rv.appendFlavour('application/x-moz-file','nsIFile'); | 257 | rv.appendFlavour('application/x-moz-file','nsIFile'); |
258 | rv.appendFlavour('application/x-moz-url'); | 258 | rv.appendFlavour('application/x-moz-url'); |
259 | rv.appendFlavour('text/uri-list'); | 259 | rv.appendFlavour('text/uri-list'); |
260 | rv.appendFlavour('text/unicode'); | 260 | rv.appendFlavour('text/unicode'); |
261 | return rv; | 261 | return rv; |
262 | }, | 262 | }, |
263 | canHandleMultipleItems: true, | 263 | canHandleMultipleItems: true, |
264 | onDragOver: function(ev,fl,sess) { | 264 | onDragOver: function(ev,fl,sess) { |
265 | return true; | 265 | return true; |
266 | }, | 266 | }, |
267 | onDrop: function(ev,dd,s) { | 267 | onDrop: function(ev,dd,s) { |
268 | var ldf = null; | 268 | var ldf = null; |
269 | for(var i in dd.dataList) { | 269 | for(var i in dd.dataList) { |
270 | var di = dd.dataList[i]; | 270 | var di = dd.dataList[i]; |
271 | var dif = di.first; | 271 | var dif = di.first; |
272 | if( | 272 | if( |
273 | ldf==null | 273 | ldf==null |
274 | || ldf.flavour.contentType!=dif.flavour.contentType | 274 | || ldf.flavour.contentType!=dif.flavour.contentType |
275 | || ldf.contentLength!=dif.contentLength | 275 | || ldf.contentLength!=dif.contentLength |
276 | || ldf.data!=dif.data ) | 276 | || ldf.data!=dif.data ) |
277 | this.drop_item(ev,di,s); | 277 | this.drop_item(ev,di,s); |
278 | ldf = dif; | 278 | ldf = dif; |
279 | } | 279 | } |
280 | }, | 280 | }, |
281 | drop_item: function(ev,di,s) { | 281 | drop_item: function(ev,di,s) { |
282 | var d = di.first; | 282 | var d = di.first; |
283 | switch(d.flavour.contentType) { | 283 | switch(d.flavour.contentType) { |
284 | case 'text/unicode': | 284 | case 'text/unicode': |
285 | this.drop_urilist(ev,d.data,s); | 285 | this.drop_urilist(ev,d.data,s); |
286 | break; | 286 | break; |
287 | case 'application/x-moz-file': | 287 | case 'application/x-moz-file': |
288 | this.fireflix.uploads.add(d.data.path); | 288 | this.fireflix.uploads.add(d.data.path); |
289 | document.getElementById('fireflix_tabs').selectedTab | 289 | document.getElementById('fireflix_tabs').selectedTab |
290 | = document.getElementById('tab_upload'); | 290 | = document.getElementById('tab_upload'); |
291 | break; | 291 | break; |
292 | case 'text/uri-list': | 292 | case 'text/uri-list': |
293 | // is it ascii or could it be utf8? | 293 | // is it ascii or could it be utf8? |
294 | this.drop_urilist(ev,splitascii(d.data),s); | 294 | this.drop_urilist(ev,splitascii(d.data),s); |
295 | break; | 295 | break; |
296 | default: alert(d.flavour.contentType+':'+d.data); break; | 296 | default: alert(d.flavour.contentType+':'+d.data); break; |
297 | }; | 297 | }; |
298 | }, | 298 | }, |
299 | drop_urilist: function(ev,ul,s) { | 299 | drop_urilist: function(ev,ul,s) { |
300 | // TODO: check for being a file? | 300 | // TODO: check for being a file? |
301 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 301 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
302 | for(var ui in us) | 302 | for(var ui in us) |
303 | if(/\S/.test(us[ui])) | 303 | if(/\S/.test(us[ui])) |
304 | this.fireflix.uploads.add(us[ui]); | 304 | this.fireflix.uploads.add(us[ui]); |
305 | document.getElementById('fireflix_tabs').selectedTab | 305 | document.getElementById('fireflix_tabs').selectedTab |
306 | = document.getElementById('tab_upload'); | 306 | = document.getElementById('tab_upload'); |
307 | } | 307 | } |
308 | }, | 308 | }, |
309 | 309 | ||
310 | uploads: { | 310 | uploads: { |
311 | fireflix: null, | 311 | fireflix: null, |
312 | init: function(f) { | 312 | init: function(f) { |
313 | this.fireflix=f; | 313 | this.fireflix=f; |
314 | pull_elements(this,document,[ | 314 | pull_elements(this,document,[ |
315 | 'upload_filename','upload_title','upload_file_preview', | 315 | 'upload_filename','upload_title','upload_file_preview', |
316 | 'upload_file_props','upload_progress','upload_tags', | 316 | 'upload_file_props','upload_progress','upload_tags', |
317 | 'cmd_uploads_upload', 'upload_failure', 'upload_is_public', | 317 | 'cmd_uploads_upload', 'upload_failure', 'upload_is_public', |
318 | 'upload_is_friends', 'upload_is_family' | 318 | 'upload_is_friends', 'upload_is_family' |
319 | ]); | 319 | ]); |
320 | document.getElementById('uploadlist').view = this; | 320 | document.getElementById('uploadlist').view = this; |
321 | this.upload_is_public.addEventListener( | 321 | this.upload_is_public.addEventListener( |
322 | 'CheckboxStateChange', { that: this, | 322 | 'CheckboxStateChange', { that: this, |
323 | handleEvent: function(ev) { this.that.propsToSel('is_public'); } | 323 | handleEvent: function(ev) { this.that.propsToSel('is_public'); } |
324 | }, false ); | 324 | }, false ); |
325 | this.upload_is_friends.addEventListener( | 325 | this.upload_is_friends.addEventListener( |
326 | 'CheckboxStateChange', { that: this, | 326 | 'CheckboxStateChange', { that: this, |
327 | handleEvent: function(ev) { this.that.propsToSel('is_friends'); } | 327 | handleEvent: function(ev) { this.that.propsToSel('is_friends'); } |
328 | }, false ); | 328 | }, false ); |
329 | this.upload_is_family.addEventListener( | 329 | this.upload_is_family.addEventListener( |
330 | 'CheckboxStateChange', { that: this, | 330 | 'CheckboxStateChange', { that: this, |
331 | handleEvent: function(ev) { this.that.propsToSel('is_family'); } | 331 | handleEvent: function(ev) { this.that.propsToSel('is_family'); } |
332 | }, false ); | 332 | }, false ); |
333 | }, | 333 | }, |
334 | files: new Array(), | 334 | files: new Array(), |
335 | rowCount: 0, | 335 | rowCount: 0, |
336 | getCellText: function(r,c) { | 336 | getCellText: function(r,c) { |
337 | var f = this.files[r]; | 337 | var f = this.files[r]; |
338 | if(c.id=='up_file') return f.file; | 338 | if(c.id=='up_file') return f.file; |
339 | if(c.id=='up_title') return f.title; | 339 | if(c.id=='up_title') return f.title; |
340 | if(c.id=='up_status') return f.state; | 340 | if(c.id=='up_status') return f.state; |
341 | return c.id; | 341 | return c.id; |
342 | }, | 342 | }, |
343 | setTree: function(t) { this.tree = t }, | 343 | setTree: function(t) { this.tree = t }, |
344 | isContainer: function(r) { return false; }, | 344 | isContainer: function(r) { return false; }, |
345 | isSeparator: function(r) { return false; }, | 345 | isSeparator: function(r) { return false; }, |
346 | isSorted: function(r) { return false; }, | 346 | isSorted: function(r) { return false; }, |
347 | getLevel: function(r) { return 0; }, | 347 | getLevel: function(r) { return 0; }, |
348 | getImageSrc: function(r,c) { return null }, | 348 | getImageSrc: function(r,c) { return null }, |
349 | getRowProperties: function(r,p) { | 349 | getRowProperties: function(r,p) { |
350 | try { | 350 | try { |
351 | if(!Components) return; | 351 | if(!Components) return; |
352 | }catch(e) { return } | 352 | }catch(e) { return } |
353 | var f = this.files[r]; | 353 | var f = this.files[r]; |
354 | var as = Components.classes['@mozilla.org/atom-service;1']. | 354 | var as = Components.classes['@mozilla.org/atom-service;1']. |
355 | getService(Components.interfaces.nsIAtomService); | 355 | getService(Components.interfaces.nsIAtomService); |
356 | p.AppendElement(as.getAtom(f.state)); | 356 | p.AppendElement(as.getAtom(f.state)); |
357 | }, | 357 | }, |
358 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 358 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
359 | getColumnProperties: function(c,p) { }, | 359 | getColumnProperties: function(c,p) { }, |
360 | cycleHeader: function(cid,e) { }, | 360 | cycleHeader: function(cid,e) { }, |
361 | getParentIndex: function(r) { return -1; }, | 361 | getParentIndex: function(r) { return -1; }, |
362 | drop: function(r,o) { }, | 362 | drop: function(r,o) { }, |
363 | canDropBeforeAfter: function(r,b) { return false }, | 363 | canDropBeforeAfter: function(r,b) { return false }, |
364 | 364 | ||
365 | add: function(f) { | 365 | add: function(f) { |
366 | if(f.indexOf('file:/')==0) { | 366 | if(f.indexOf('file:/')==0) { |
367 | f = f.substr(5); | 367 | f = f.substr(5); |
368 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 368 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
369 | f = f.substr(1); | 369 | f = f.substr(1); |
370 | } | 370 | } |
371 | } | 371 | } |
372 | var t = f; | 372 | var t = f; |
373 | var ls = t.lastIndexOf('/'); | 373 | var ls = t.lastIndexOf('/'); |
374 | if(ls>0) t = t.substr(ls+1); | 374 | if(ls>0) t = t.substr(ls+1); |
375 | ls = t.lastIndexOf('\\'); | 375 | ls = t.lastIndexOf('\\'); |
376 | if(ls>0) t = t.substr(ls+1); | 376 | if(ls>0) t = t.substr(ls+1); |
377 | var ld = t.lastIndexOf('.'); | 377 | var ld = t.lastIndexOf('.'); |
378 | if(ld>0) t = t.substr(0,ld); | 378 | if(ld>0) t = t.substr(0,ld); |
379 | this.files.push( { | 379 | this.files.push( { |
380 | file: f, | 380 | file: f, |
381 | title: t, | 381 | title: t, |
382 | tags: '', | 382 | tags: '', |
383 | is_public: true, is_friend: false, is_family: false, | 383 | is_public: true, is_friend: false, is_family: false, |
384 | state: 'pending' | 384 | state: 'pending' |
385 | } ); | 385 | } ); |
386 | this.rowCount = this.files.length; | 386 | this.rowCount = this.files.length; |
387 | this.tree.rowCountChanged(this.rowCount-1,1); | 387 | this.tree.rowCountChanged(this.rowCount-1,1); |
388 | }, | 388 | }, |
389 | 389 | ||
390 | upload_worker: function() { | 390 | upload_worker: function() { |
391 | for(var f in this.files) { | 391 | for(var f in this.files) { |
392 | if(this.files[f].state=='pending') { | 392 | if(this.files[f].state=='pending') { |
393 | var ff = this.files[f]; | 393 | var ff = this.files[f]; |
394 | this.on_file_upload(ff); | 394 | this.on_file_upload(ff); |
395 | ff.state='uploading'; | 395 | ff.state='uploading'; |
396 | this.tree.invalidate(); | 396 | this.tree.invalidate(); |
397 | var _this = this; | 397 | var _this = this; |
398 | this.fireflix.flickr.upload_file( | 398 | this.fireflix.flickr.upload_file( |
399 | ff.file, { | 399 | ff.file, { |
400 | title: ff.title, tags: ff.tags, | 400 | title: ff.title, tags: ff.tags, |
401 | is_public: ff.is_public?'1':'0', | 401 | is_public: ff.is_public?'1':'0', |
402 | is_friend: ff.is_friend?'1':'0', | 402 | is_friend: ff.is_friend?'1':'0', |
403 | is_family: ff.is_family?'1':'0' | 403 | is_family: ff.is_family?'1':'0' |
404 | }, function(x,p) { | 404 | }, function(x,p) { |
405 | ff.photoid = p; | 405 | ff.photoid = p; |
406 | _this.batch_ids.push(p); | 406 | _this.batch_ids.push(p); |
407 | ff.state='completed'; | 407 | ff.state='completed'; |
408 | _this.tree.invalidate(); | 408 | _this.tree.invalidate(); |
409 | window.setTimeout(_this.upload_to,0,_this); | 409 | window.setTimeout(_this.upload_to,0,_this); |
410 | }, function(x,s,c,m) { | 410 | }, function(x,s,c,m) { |
411 | ff.state='failed'; | 411 | ff.state='failed'; |
412 | ff.flickr_errcode = c; | 412 | ff.flickr_errcode = c; |
413 | ff.flickr_errmsg = m; | 413 | ff.flickr_errmsg = m; |
414 | _this.tree.invalidate(); | 414 | _this.tree.invalidate(); |
415 | window.setTimeout(_this.upload_to,0,_this); | 415 | window.setTimeout(_this.upload_to,0,_this); |
416 | } | 416 | } |
417 | ); | 417 | ); |
418 | return; | 418 | return; |
419 | } | 419 | } |
420 | } | 420 | } |
421 | this.on_finish_upload(); | 421 | this.on_finish_upload(); |
422 | }, | 422 | }, |
423 | upload_to: function(_this) { _this.upload_worker(); }, | 423 | upload_to: function(_this) { _this.upload_worker(); }, |
424 | on_file_upload: function(f) { | 424 | on_file_upload: function(f) { |
425 | this.cmd_uploads_upload.setAttribute('disabled','true'); | 425 | this.cmd_uploads_upload.setAttribute('disabled','true'); |
426 | for(var fi in this.files) { | 426 | for(var fi in this.files) { |
427 | if(this.files[fi].file==f.file) { | 427 | if(this.files[fi].file==f.file) { |
428 | this.tree.ensureRowIsVisible(fi); | 428 | this.tree.ensureRowIsVisible(fi); |
429 | this.selection.rangedSelect(fi,fi,false); | 429 | this.selection.rangedSelect(fi,fi,false); |
430 | this.selection.currentIndex = fi; | 430 | this.selection.currentIndex = fi; |
431 | this.selToProps(); | 431 | this.selToProps(); |
432 | break; | 432 | break; |
433 | } | 433 | } |
434 | } | 434 | } |
435 | }, | 435 | }, |
436 | on_finish_upload: function() { | 436 | on_finish_upload: function() { |
437 | if(this.batch_ids.length) { | 437 | if(this.batch_ids.length) { |
438 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 438 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
439 | if(psn!=null) { | 439 | if(psn!=null) { |
440 | var pids = this.batch_ids.join(','); | 440 | var pids = this.batch_ids.join(','); |
441 | var ppid = this.batch_ids[0]; | 441 | var ppid = this.batch_ids[0]; |
442 | var that = this; | 442 | var that = this; |
443 | this.fireflix.flickr.api_call_json( | 443 | this.fireflix.flickr.api_call_json( |
444 | { | 444 | { |
445 | method: 'flickr.photosets.create', | 445 | method: 'flickr.photosets.create', |
446 | auth_token: 'default', | 446 | auth_token: 'default', |
447 | title: psn, | 447 | title: psn, |
448 | primary_photo_id: ppid | 448 | primary_photo_id: ppid |
449 | }, function(x,j) { | 449 | }, function(x,j) { |
450 | var npid = j.photoset.id; | 450 | var npid = j.photoset.id; |
451 | that.fireflix.flickr.api_call_json( | 451 | that.fireflix.flickr.api_call_json( |
452 | { | 452 | { |
453 | method: 'flickr.photosets.editPhotos', | 453 | method: 'flickr.photosets.editPhotos', |
454 | auth_token: 'default', | 454 | auth_token: 'default', |
455 | photoset_id: npid, | 455 | photoset_id: npid, |
456 | primary_photo_id: ppid, | 456 | primary_photo_id: ppid, |
457 | photo_ids: pids | 457 | photo_ids: pids |
458 | }, function(x,j) { | 458 | }, function(x,j) { |
459 | that.fireflix.refresh_sets(); | 459 | that.fireflix.refresh_sets(); |
460 | }, function(x,s,c,m) { | 460 | }, function(x,s,c,m) { |
461 | that.fireflix.flickr_failure(x,s,c,m); | 461 | that.fireflix.flickr_failure(x,s,c,m); |
462 | } | 462 | } |
463 | ); | 463 | ); |
464 | }, function(x,s,c,m) { | 464 | }, function(x,s,c,m) { |
465 | that.fireflix.flickr_failure(x,s,c,m); | 465 | that.fireflix.flickr_failure(x,s,c,m); |
466 | } | 466 | } |
467 | ); | 467 | ); |
468 | } | 468 | } |
469 | } | 469 | } |
470 | this.selection.clearSelection(); | 470 | this.selection.clearSelection(); |
471 | this.cmd_uploads_upload.setAttribute('disabled','false'); | 471 | this.cmd_uploads_upload.setAttribute('disabled','false'); |
472 | this.upload_progress.setAttribute('hidden','true'); | 472 | this.upload_progress.setAttribute('hidden','true'); |
473 | }, | 473 | }, |
474 | 474 | ||
475 | clear_list: function() { | 475 | clear_list: function() { |
476 | this.tree.beginUpdateBatch(); | 476 | this.tree.beginUpdateBatch(); |
477 | this.rowCount = 0; | 477 | this.rowCount = 0; |
478 | this.files = new Array(); | 478 | this.files = new Array(); |
479 | this.tree.endUpdateBatch(); | 479 | this.tree.endUpdateBatch(); |
480 | this.selToProps(); | 480 | this.selToProps(); |
481 | }, | 481 | }, |
482 | selectionChanged: function() { | 482 | selectionChanged: function() { |
483 | this.selToProps(); | 483 | this.selToProps(); |
484 | }, | 484 | }, |
485 | disableProps: function() { | 485 | disableProps: function() { |
486 | this.upload_filename.value=''; | 486 | this.upload_filename.value=''; |
487 | this.upload_filename.disabled = true; | 487 | this.upload_filename.disabled = true; |
488 | this.upload_title.value=''; | 488 | this.upload_title.value=''; |
489 | this.upload_title.disabled = true; | 489 | this.upload_title.disabled = true; |
490 | this.upload_file_preview.src = null; | 490 | this.upload_file_preview.src = null; |
491 | this.upload_tags.value=''; | 491 | this.upload_tags.value=''; |
492 | this.upload_tags.disabled = true; | 492 | this.upload_tags.disabled = true; |
493 | this.upload_is_public.disabled = true; | 493 | this.upload_is_public.disabled = true; |
494 | this.upload_is_friends.disabled = true; | 494 | this.upload_is_friends.disabled = true; |
495 | this.upload_is_family.disabled = true; | 495 | this.upload_is_family.disabled = true; |
496 | /* this.upload_file_props.hidden = true; */ | 496 | /* this.upload_file_props.hidden = true; */ |
497 | }, | 497 | }, |
498 | selToProps: function() { | 498 | selToProps: function() { |
499 | if(!this.selection.count) { | 499 | if(!this.selection.count) { |
500 | this.disableProps(); | 500 | this.disableProps(); |
501 | this.upload_file_props.hidden = true; | 501 | this.upload_file_props.hidden = true; |
502 | }else if(this.selection.count==1) { | 502 | }else if(this.selection.count==1) { |
503 | var f=this.files[this.selection.currentIndex]; | 503 | var f=this.files[this.selection.currentIndex]; |
504 | if(f==null) { | 504 | if(f==null) { |
505 | this.disableProps(); | 505 | this.disableProps(); |
506 | this.upload_file_props.hidden = true; | 506 | this.upload_file_props.hidden = true; |
507 | }else{ | 507 | }else{ |
508 | var inactives = f.state!='pending'; | 508 | var inactives = f.state!='pending'; |
509 | this.upload_filename.value = f.file; this.upload_filename.disabled = inactives; | 509 | this.upload_filename.value = f.file; this.upload_filename.disabled = inactives; |
510 | this.upload_title.value = f.title; this.upload_title.disabled = inactives; | 510 | this.upload_title.value = f.title; this.upload_title.disabled = inactives; |
511 | this.upload_file_preview.src = 'file:///'+f.file; | 511 | this.upload_file_preview.src = 'file:///'+f.file; |
512 | this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives; | 512 | this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives; |
513 | this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives; | 513 | this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives; |
514 | this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives; | 514 | this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives; |
515 | this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives; | 515 | this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives; |
516 | if(f.state=='failed') { | 516 | if(f.state=='failed') { |
517 | this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg; | 517 | this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg; |
518 | this.upload_failure.hidden = false; | 518 | this.upload_failure.hidden = false; |
519 | }else{ | 519 | }else{ |
520 | this.upload_failure.hidden = true; | 520 | this.upload_failure.hidden = true; |
521 | } | 521 | } |
522 | this.upload_file_props.hidden = false; | 522 | this.upload_file_props.hidden = false; |
523 | } | 523 | } |
524 | }else{ | 524 | }else{ |
525 | var ftitle = null; var onetitle = true; | 525 | var ftitle = null; var onetitle = true; |
526 | var ftags = null; var onetag = true; | 526 | var ftags = null; var onetag = true; |
527 | var fs = 0; | 527 | var fs = 0; |
528 | for(var ff in this.files) { | 528 | for(var ff in this.files) { |
529 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 529 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
530 | ++fs; | 530 | ++fs; |
531 | if(ftitle==null) { | 531 | if(ftitle==null) { |
532 | ftitle = this.files[ff].title; | 532 | ftitle = this.files[ff].title; |
533 | }else if(ftitle!=this.files[ff].title) { | 533 | }else if(ftitle!=this.files[ff].title) { |
534 | onetitle = false; | 534 | onetitle = false; |
535 | } | 535 | } |
536 | if(ftags==null) { | 536 | if(ftags==null) { |
537 | ftags = this.files[ff].tags; | 537 | ftags = this.files[ff].tags; |
538 | }else if(ftags!=this.files[ff].tags) { | 538 | }else if(ftags!=this.files[ff].tags) { |
539 | onetag = false; | 539 | onetag = false; |
540 | } | 540 | } |
541 | } | 541 | } |
542 | } | 542 | } |
543 | if(fs) { | 543 | if(fs) { |
544 | this.upload_filename.value=''; | 544 | this.upload_filename.value=''; |
545 | this.upload_filename.disabled = true; | 545 | this.upload_filename.disabled = true; |
546 | if(onetitle) | 546 | if(onetitle) |
547 | this.upload_title.value = ftitle; | 547 | this.upload_title.value = ftitle; |
548 | this.upload_title.disabled = false; | 548 | this.upload_title.disabled = false; |
549 | if(onetag) | 549 | if(onetag) |
550 | this.upload_tags.value = ftags; | 550 | this.upload_tags.value = ftags; |
551 | this.upload_tags.disabled = false; | 551 | this.upload_tags.disabled = false; |
552 | this.upload_file_preview.src = null; | 552 | this.upload_file_preview.src = null; |
553 | this.upload_failure.hidden = true; | 553 | this.upload_failure.hidden = true; |
554 | this.upload_file_props.hidden = false; | 554 | this.upload_file_props.hidden = false; |
555 | }else | 555 | }else |
556 | this.disableProps(); | 556 | this.disableProps(); |
557 | this.upload_file_props.hidden = true; | 557 | this.upload_file_props.hidden = true; |
558 | } | 558 | } |
559 | }, | 559 | }, |
560 | propsToSel: function(prop) { | 560 | propsToSel: function(prop) { |
561 | if(this.selection.count<=0) return; | 561 | if(this.selection.count<=0) return; |
562 | for(var ff in this.files) { | 562 | for(var ff in this.files) { |
563 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { | 563 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { |
564 | if(prop=='filename') this.files[ff].file = this.upload_filename.value; | 564 | if(prop=='filename') this.files[ff].file = this.upload_filename.value; |
565 | if(prop=='title') this.files[ff].title = this.upload_title.value; | 565 | if(prop=='title') this.files[ff].title = this.upload_title.value; |
566 | if(prop=='tags') this.files[ff].tags = this.upload_tags.value; | 566 | if(prop=='tags') this.files[ff].tags = this.upload_tags.value; |
567 | if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked; | 567 | if(prop=='is_public') this.files[ff].is_public = this.upload_is_public.checked; |
568 | if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked; | 568 | if(prop=='is_friends') this.files[ff].is_friend = this.upload_is_friends.checked; |
569 | if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked; | 569 | if(prop=='is_family') this.files[ff].is_family = this.upload_is_family.checked; |
570 | this.tree.invalidateRow(ff); | 570 | this.tree.invalidateRow(ff); |
571 | } | 571 | } |
572 | } | 572 | } |
573 | }, | 573 | }, |
574 | 574 | ||
575 | on_upload: function() { | 575 | on_upload: function() { |
576 | this.selToProps(); | 576 | this.selToProps(); |
577 | this.batch_ids = new Array(); | 577 | this.batch_ids = new Array(); |
578 | this.upload_progress.value=0; | 578 | this.upload_progress.value=0; |
579 | this.upload_progress.setAttribute('hidden','false'); | 579 | this.upload_progress.setAttribute('hidden','false'); |
580 | this.upload_worker(); | 580 | this.upload_worker(); |
581 | }, | 581 | }, |
582 | on_clear: function() { | 582 | on_clear: function() { |
583 | this.clear_list(); | 583 | this.clear_list(); |
584 | }, | 584 | }, |
585 | on_remove: function() { | 585 | on_remove: function() { |
586 | if(this.selection.count) { | 586 | if(this.selection.count) { |
587 | this.tree.beginUpdateBatch(); | 587 | this.tree.beginUpdateBatch(); |
588 | for(var i=this.files.length-1;i>=0;--i) { | 588 | for(var i=this.files.length-1;i>=0;--i) { |
589 | if(this.selection.isSelected(i)) { | 589 | if(this.selection.isSelected(i)) { |
590 | this.files.splice(i,1); | 590 | this.files.splice(i,1); |
591 | this.rowCount--; | 591 | this.rowCount--; |
592 | } | 592 | } |
593 | } | 593 | } |
594 | this.tree.endUpdateBatch(); | 594 | this.tree.endUpdateBatch(); |
595 | this.selection.clearSelection(); | 595 | this.selection.clearSelection(); |
596 | } | 596 | } |
597 | }, | 597 | }, |
598 | on_add: function() { | 598 | on_add: function() { |
599 | var ifp = Components.interfaces.nsIFilePicker; | 599 | var ifp = Components.interfaces.nsIFilePicker; |
600 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); | 600 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); |
601 | fp.init(window, "Select a File", ifp.modeOpenMultiple); | 601 | fp.init(window, "Select a File", ifp.modeOpenMultiple); |
602 | fp.appendFilters(ifp.filterImages); | 602 | fp.appendFilters(ifp.filterImages); |
603 | var rv = fp.show(); | 603 | var rv = fp.show(); |
604 | if(rv==ifp.returnOK) { | 604 | if(rv==ifp.returnOK) { |
605 | var ff = fp.files; | 605 | var ff = fp.files; |
606 | while(ff.hasMoreElements()) { | 606 | while(ff.hasMoreElements()) { |
607 | var f = ff.getNext(); | 607 | var f = ff.getNext(); |
608 | f.QueryInterface(Components.interfaces.nsIFile); | 608 | f.QueryInterface(Components.interfaces.nsIFile); |
609 | this.add(f.path); | 609 | this.add(f.path); |
610 | } | 610 | } |
611 | } | 611 | } |
612 | }, | 612 | }, |
613 | on_cmd_open: function(ev) { | 613 | on_cmd_open: function(ev) { |
614 | if(this.selection.currentIndex<0) return; | 614 | if(this.selection.currentIndex<0) return; |
615 | var f = this.files[this.selection.currentIndex]; | 615 | var f = this.files[this.selection.currentIndex]; |
616 | if(f.photoid) { | 616 | if(f.photoid) { |
617 | this.fireflix.openTab( | 617 | this.fireflix.openTab( |
618 | this.fireflix.flickr.make_uploader_edit_url(f.photoid) | 618 | this.fireflix.flickr.make_uploader_edit_url(f.photoid) |
619 | ); | 619 | ); |
620 | }else{ | 620 | }else{ |
621 | this.fireflix.openTab( 'file://'+f.file); | 621 | this.fireflix.openTab( 'file://'+f.file); |
622 | } | 622 | } |
623 | } | 623 | } |
624 | }, | 624 | }, |
625 | 625 | ||
626 | on_set_props: function() { | 626 | on_set_props: function() { |
627 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; | 627 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; |
628 | window.openDialog( | 628 | window.openDialog( |
629 | "chrome://fireflix/content/photoset-props.xul", | 629 | "chrome://fireflix/content/photoset-props.xul", |
630 | null, "dependent,modal,dialog,chrome", this, | 630 | null, "dependent,modal,dialog,chrome", this, |
631 | pset ); | 631 | pset ); |
632 | if(pset.dirty) { | 632 | if(pset.dirty) { |
633 | var _this = this; | 633 | var that = this; |
634 | this.flickr.api_call( | 634 | this.flickr.api_call_json( |
635 | { | 635 | { |
636 | method: 'flickr.photosets.editMeta', | 636 | method: 'flickr.photosets.editMeta', |
637 | auth_token: 'default', | 637 | auth_token: 'default', |
638 | photoset_id: pset.id, | 638 | photoset_id: pset.id, |
639 | title: pset.title, | 639 | title: pset.title, |
640 | description: pset.description | 640 | description: pset.description |
641 | }, function(xr) { | 641 | }, function(x,j) { |
642 | pset.dirty = false; | 642 | pset.dirty = false; |
643 | _this.flickr.api_call( | 643 | that.flickr.api_call_json( |
644 | { | 644 | { |
645 | method: 'flickr.photosets.getPhotos', | 645 | method: 'flickr.photosets.getPhotos', |
646 | auth_token: 'default', | 646 | auth_token: 'default', |
647 | photoset_id: pset.id | 647 | photoset_id: pset.id |
648 | }, function(xr) { | 648 | }, function(x,j) { |
649 | var x = xr.responseXML; | 649 | var pp = j.photoset.photo; |
650 | var xp = x.evaluate( | ||
651 | '/rsp/photoset/photo', x, null, | ||
652 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | ||
653 | var phids = new Array(); | 650 | var phids = new Array(); |
654 | var priph = null; | 651 | var priph = null; |
655 | var n; while(n=xp.iterateNext()) { | 652 | for(var i in pp) { |
656 | var pid = n.getAttribute('id'); | 653 | var pid = pp[i].id; |
657 | phids.push( pid ); | 654 | phids.push(pid); |
658 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 655 | if(pid==pset.primary && pp[i].isprimary) priph = pid; |
659 | priph = pid; | ||
660 | } | 656 | } |
661 | if(priph) { | 657 | if(priph) { |
662 | _this.flickr.api_call( | 658 | that.flickr.api_call_json( |
663 | { | 659 | { |
664 | method: 'flickr.photosets.editPhotos', | 660 | method: 'flickr.photosets.editPhotos', |
665 | auth_token: 'default', | 661 | auth_token: 'default', |
666 | photoset_id: pset.id, | 662 | photoset_id: pset.id, |
667 | primary_photo_id: priph, | 663 | primary_photo_id: priph, |
668 | photo_ids: phids.join(',') | 664 | photo_ids: phids.join(',') |
669 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 665 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
670 | _this.flickr_failure(x,s,c,m); | 666 | that.flickr_failure(x,s,c,m); |
671 | } | 667 | } |
672 | ); | 668 | ); |
673 | } | 669 | } |
674 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 670 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
675 | _this.flickr_failure(x,s,c,m); | 671 | that.flickr_failure(x,s,c,m); |
676 | } | 672 | } |
677 | ); | 673 | ); |
678 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 674 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
679 | _this.flickr_failure(x,s,c,m); | 675 | that.flickr_failure(x,s,c,m); |
680 | } | 676 | } |
681 | ); | 677 | ); |
682 | } | 678 | } |
683 | }, | 679 | }, |
684 | on_refresh_sets: function() { | 680 | on_refresh_sets: function() { |
685 | this.refresh_sets(); | 681 | this.refresh_sets(); |
686 | }, | 682 | }, |
687 | on_cmd_sets_html: function(csfx,ev) { | 683 | on_cmd_sets_html: function(csfx,ev) { |
688 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 684 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
689 | var rv = this.build_html(this.photoset.photos,uti,utl); | 685 | var rv = this.build_html(this.photoset.photos,uti,utl); |
690 | this.popup_content(rv); | 686 | this.popup_content(rv); |
691 | }, | 687 | }, |
692 | on_cmd_setphotos_html: function(csfx,ev) { | 688 | on_cmd_setphotos_html: function(csfx,ev) { |
693 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 689 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
694 | var rv = ''; | 690 | var rv = ''; |
695 | for(var p in this.photoset.photos) { | 691 | for(var p in this.photoset.photos) { |
696 | if(this.photoset.selection.isSelected(p)) | 692 | if(this.photoset.selection.isSelected(p)) |
697 | rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n'; | 693 | rv += this.photo_html(this.photoset.photos[p],uti,utl)+'\n'; |
698 | } | 694 | } |
699 | this.popup_content(rv); | 695 | this.popup_content(rv); |
700 | }, | 696 | }, |
701 | 697 | ||
702 | on_cmd_uploads_html: function(csfx,ev) { | 698 | on_cmd_uploads_html: function(csfx,ev) { |
703 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 699 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
704 | var pids = new Array(); | 700 | var pids = new Array(); |
705 | for(var f in this.uploads.files) { | 701 | for(var f in this.uploads.files) { |
706 | if(this.uploads.selection.isSelected(f)) | 702 | if(this.uploads.selection.isSelected(f)) |
707 | if(this.uploads.files[f].photoid) | 703 | if(this.uploads.files[f].photoid) |
708 | pids.push(this.uploads.files[f].photoid); | 704 | pids.push(this.uploads.files[f].photoid); |
709 | } | 705 | } |
710 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 706 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
711 | var _this = this; | 707 | var _this = this; |
712 | this.flickr.api_call( | 708 | this.flickr.api_call( |
713 | { | 709 | { |
714 | method: 'flickr.photos.search', | 710 | method: 'flickr.photos.search', |
715 | auth_token: 'default', | 711 | auth_token: 'default', |
716 | extras: 'original_format', | 712 | extras: 'original_format', |
717 | user_id: 'me', | 713 | user_id: 'me', |
718 | per_page: pp | 714 | per_page: pp |
719 | }, | 715 | }, |
720 | function(xr) { | 716 | function(xr) { |
721 | var x = xr.responseXML; | 717 | var x = xr.responseXML; |
722 | var rv = ''; | 718 | var rv = ''; |
723 | for(var pn in pids) { | 719 | for(var pn in pids) { |
724 | var p = pids[pn]; | 720 | var p = pids[pn]; |
725 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 721 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
726 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 722 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
727 | } | 723 | } |
728 | _this.popup_content(rv); | 724 | _this.popup_content(rv); |
729 | }, function(x,s,c,m) { | 725 | }, function(x,s,c,m) { |
730 | _this.flickr_failure(x,s,c,m); | 726 | _this.flickr_failure(x,s,c,m); |
731 | } | 727 | } |
732 | ); | 728 | ); |
733 | }, | 729 | }, |
734 | 730 | ||
735 | /* | 731 | /* |
736 | * | 732 | * |
737 | */ | 733 | */ |
738 | foundphotos: { | 734 | foundphotos: { |
739 | fireflix: null, | 735 | fireflix: null, |
740 | init: function(f) { | 736 | init: function(f) { |
741 | this.fireflix = f; | 737 | this.fireflix = f; |
742 | pull_elements(this,document,[ | 738 | pull_elements(this,document,[ |
743 | 'search_for','search_tags','search_mine', | 739 | 'search_for','search_tags','search_mine', |
744 | 'searchresult_props','search_photo', | 740 | 'searchresult_props','search_photo', |
745 | 'searchresult_title','searchresult_description', | 741 | 'searchresult_title','searchresult_description', |
746 | 'search_page','cmd_search_prev_page','cmd_search_next_page' | 742 | 'search_page','cmd_search_prev_page','cmd_search_next_page' |
747 | ]); | 743 | ]); |
748 | document.getElementById('searchresults').view = this; | 744 | document.getElementById('searchresults').view = this; |
749 | }, | 745 | }, |
750 | photos: new Array(), | 746 | photos: new Array(), |
751 | rowCount: 0, | 747 | rowCount: 0, |
752 | getCellText: function(r,c) { | 748 | getCellText: function(r,c) { |
753 | var p = this.photos[r]; | 749 | var p = this.photos[r]; |
754 | if(c.id=='sr_title') return p.title; | 750 | if(c.id=='sr_title') return p.title; |
755 | return c.id; | 751 | return c.id; |
756 | }, | 752 | }, |
757 | setTree: function(t) { this.tree = t }, | 753 | setTree: function(t) { this.tree = t }, |
758 | isContainer: function(r) { return false }, | 754 | isContainer: function(r) { return false }, |
759 | isSeparator: function(r) { return false }, | 755 | isSeparator: function(r) { return false }, |
760 | isSorted: function(r) { return false }, | 756 | isSorted: function(r) { return false }, |
761 | getLevel: function(r) { return 0 }, | 757 | getLevel: function(r) { return 0 }, |
762 | getImageSrc: function(r,c) { return null }, | 758 | getImageSrc: function(r,c) { return null }, |
763 | getRowProperties: function(r,p) { }, | 759 | getRowProperties: function(r,p) { }, |
764 | getCellProperties: function(cid,cel,p) { }, | 760 | getCellProperties: function(cid,cel,p) { }, |
765 | getColumnProperties: function(cid,cel,p) { }, | 761 | getColumnProperties: function(cid,cel,p) { }, |
766 | cycleHeader: function(cid,e) { }, | 762 | cycleHeader: function(cid,e) { }, |
767 | getParentIndex: function(r) { return -1 }, | 763 | getParentIndex: function(r) { return -1 }, |
768 | drop: function(r,o) { }, | 764 | drop: function(r,o) { }, |
769 | canDropBeforeAfter: function(r,b) { return false }, | 765 | canDropBeforeAfter: function(r,b) { return false }, |
770 | 766 | ||
771 | import_json: function(jp) { | 767 | import_json: function(jp) { |
772 | this.selection.clearSelection(); | 768 | this.selection.clearSelection(); |
773 | this.selection.currentIndex=-1; | 769 | this.selection.currentIndex=-1; |
774 | this.searchresult_props.hidden=true; | 770 | this.searchresult_props.hidden=true; |
775 | this.tree.beginUpdateBatch(); | 771 | this.tree.beginUpdateBatch(); |
776 | this.photos = new Array(); | 772 | this.photos = new Array(); |
777 | for(var i in jp) { | 773 | for(var i in jp) { |
778 | this.photos.push(new Photo(jp[i])); | 774 | this.photos.push(new Photo(jp[i])); |
779 | } | 775 | } |
780 | this.rowCount = this.photos.length; | 776 | this.rowCount = this.photos.length; |
781 | this.tree.endUpdateBatch(); | 777 | this.tree.endUpdateBatch(); |
782 | }, | 778 | }, |
783 | paging: { | 779 | paging: { |
784 | pars: null, | 780 | pars: null, |
785 | page: null, pages: null, perpage: null, total: null | 781 | page: null, pages: null, perpage: null, total: null |
786 | }, | 782 | }, |
787 | search_photos: function() { | 783 | search_photos: function() { |
788 | var pars = { | 784 | var pars = { |
789 | method: 'flickr.photos.search', | 785 | method: 'flickr.photos.search', |
790 | auth_token: 'default', | 786 | auth_token: 'default', |
791 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 787 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
792 | }; | 788 | }; |
793 | if(this.search_mine.checked) | 789 | if(this.search_mine.checked) |
794 | pars.user_id='me'; | 790 | pars.user_id='me'; |
795 | if(this.search_tags.checked) { | 791 | if(this.search_tags.checked) { |
796 | pars.tags=this.search_for.value.split(/ +/).join(','); | 792 | pars.tags=this.search_for.value.split(/ +/).join(','); |
797 | }else{ | 793 | }else{ |
798 | pars.text=this.search_for.value; | 794 | pars.text=this.search_for.value; |
799 | } | 795 | } |
800 | this.paging.pars = new Object(); | 796 | this.paging.pars = new Object(); |
801 | this.paging.page = null; this.paging.pages = null; | 797 | this.paging.page = null; this.paging.pages = null; |
802 | this.paging.perpage = null; this.paging.total = null; | 798 | this.paging.perpage = null; this.paging.total = null; |
803 | for(var p in pars) this.paging.pars[p] = pars[p]; | 799 | for(var p in pars) this.paging.pars[p] = pars[p]; |
804 | this.perform_search(pars); | 800 | this.perform_search(pars); |
805 | }, | 801 | }, |
806 | perform_search: function(p) { | 802 | perform_search: function(p) { |
807 | var that = this; | 803 | var that = this; |
808 | this.fireflix.flickr.api_call_json( p, | 804 | this.fireflix.flickr.api_call_json( p, |
809 | function(x,j) { | 805 | function(x,j) { |
810 | that.import_json(j.photos.photo); | 806 | that.import_json(j.photos.photo); |
811 | that.tree.ensureRowIsVisible(0); | 807 | that.tree.ensureRowIsVisible(0); |
812 | var pp=j.photos; | 808 | var pp=j.photos; |
813 | that.paging.page = pp.page; that.paging.pages = pp.pages; | 809 | that.paging.page = pp.page; that.paging.pages = pp.pages; |
814 | that.paging.perpage = pp.perpage; | 810 | that.paging.perpage = pp.perpage; |
815 | that.paging.total = pp.total; | 811 | that.paging.total = pp.total; |
816 | that.update_paging(); | 812 | that.update_paging(); |
817 | that.on_select(); | 813 | that.on_select(); |
818 | }, function(x,s,c,m) { | 814 | }, function(x,s,c,m) { |
819 | that.fireflix.flickr_failure(x,s,c,m); | 815 | that.fireflix.flickr_failure(x,s,c,m); |
820 | } | 816 | } |
821 | ); | 817 | ); |
822 | }, | 818 | }, |
823 | on_cmd_prev: function(ev) { | 819 | on_cmd_prev: function(ev) { |
824 | var pars = new Object(); | 820 | var pars = new Object(); |
825 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | 821 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; |
826 | pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; | 822 | pars.page=this.paging.page-1; pars.per_page=this.paging.perpage; |
827 | this.perform_search(pars); | 823 | this.perform_search(pars); |
828 | }, | 824 | }, |
829 | on_cmd_next: function(ev) { | 825 | on_cmd_next: function(ev) { |
830 | var pars = new Object(); | 826 | var pars = new Object(); |
831 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; | 827 | for(var p in this.paging.pars) pars[p] = this.paging.pars[p]; |
832 | pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; | 828 | pars.page=this.paging.page+1; pars.per_page=this.paging.perpage; |
833 | this.perform_search(pars); | 829 | this.perform_search(pars); |
834 | }, | 830 | }, |
835 | update_paging: function() { | 831 | update_paging: function() { |
836 | if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { | 832 | if(! (this.paging.pars && this.paging.page && this.paging.pages) ) { |
837 | this.search_page.value=''; this.search_page.hidden = true; | 833 | this.search_page.value=''; this.search_page.hidden = true; |
838 | this.cmd_search_prev_page.setAttribute('disabled','true'); | 834 | this.cmd_search_prev_page.setAttribute('disabled','true'); |
839 | this.cmd_search_next_page.setAttribute('disabled','true'); | 835 | this.cmd_search_next_page.setAttribute('disabled','true'); |
840 | }else{ | 836 | }else{ |
841 | this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); | 837 | this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]); |
842 | this.search_page.hidden=false; | 838 | this.search_page.hidden=false; |
843 | this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); | 839 | this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true'); |
844 | this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); | 840 | this.cmd_search_next_page.setAttribute('disabled',(this.paging.page<this.paging.pages)?'false':'true'); |
845 | } | 841 | } |
846 | }, | 842 | }, |
847 | render_description_frame: function(content) { | 843 | render_description_frame: function(content) { |
848 | this.searchresult_description.innerHTML = ''; | 844 | this.searchresult_description.innerHTML = ''; |
849 | if(content) { | 845 | if(content) { |
850 | var dp = new DOMParser(); | 846 | var dp = new DOMParser(); |
851 | var pd = dp.parseFromString( | 847 | var pd = dp.parseFromString( |
852 | '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); | 848 | '<div xmlns="http://www.w3.org/1999/xhtml">'+content+'</div>', 'text/xml' ); |
853 | var de = pd.documentElement; | 849 | var de = pd.documentElement; |
854 | if(de.tagName=='parsererror') | 850 | if(de.tagName=='parsererror') |
855 | this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); | 851 | this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description'); |
856 | else | 852 | else |
857 | this.searchresult_description.appendChild(de); | 853 | this.searchresult_description.appendChild(de); |
858 | /* of all linking elements flickr only allows a */ | 854 | /* of all linking elements flickr only allows a */ |
859 | var as = this.searchresult_description.getElementsByTagName('a'); | 855 | var as = this.searchresult_description.getElementsByTagName('a'); |
860 | for(var a=0;a<as.length;++a) | 856 | for(var a=0;a<as.length;++a) |
861 | as.item(a).setAttribute('target','_blank'); | 857 | as.item(a).setAttribute('target','_blank'); |
862 | } | 858 | } |
863 | }, | 859 | }, |
864 | on_select: function() { | 860 | on_select: function() { |
865 | if(this.selection.currentIndex<0) { | 861 | if(this.selection.currentIndex<0) { |
866 | this.searchresult_props.hidden = true; | 862 | this.searchresult_props.hidden = true; |
867 | }else{ | 863 | }else{ |
868 | var p = this.photos[this.selection.currentIndex]; | 864 | var p = this.photos[this.selection.currentIndex]; |
869 | if(!p) { | 865 | if(!p) { |
870 | this.searchresult_props.hidden = true; | 866 | this.searchresult_props.hidden = true; |
871 | }else{ | 867 | }else{ |
872 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 868 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
873 | this.searchresult_title.value = p.title; | 869 | this.searchresult_title.value = p.title; |
874 | this.searchresult_title.tooltipText = p.title; | 870 | this.searchresult_title.tooltipText = p.title; |
875 | this.render_description_frame(null); | 871 | this.render_description_frame(null); |
876 | if(p.description==null && p.description==undefined) { | 872 | if(p.description==null && p.description==undefined) { |
877 | var pid = p.id; | 873 | var pid = p.id; |
878 | var ci = this.selection.currentIndex; | 874 | var ci = this.selection.currentIndex; |
879 | var that = this; | 875 | var that = this; |
880 | this.fireflix.flickr.api_call_json( | 876 | this.fireflix.flickr.api_call_json( |
881 | { | 877 | { |
882 | method: 'flickr.photos.getInfo', | 878 | method: 'flickr.photos.getInfo', |
883 | auth_token: 'default', | 879 | auth_token: 'default', |
884 | photo_id: p.id, | 880 | photo_id: p.id, |
885 | secret: p.secret | 881 | secret: p.secret |
886 | }, function(x,j) { | 882 | }, function(x,j) { |
887 | var pp = that.photos[ci]; | 883 | var pp = that.photos[ci]; |
888 | if(ci==that.selection.currentIndex && pp.id==pid) { | 884 | if(ci==that.selection.currentIndex && pp.id==pid) { |
889 | pp.fromJSON_(j.photo); | 885 | pp.fromJSON_(j.photo); |
890 | that.render_description_frame(pp.description); | 886 | that.render_description_frame(pp.description); |
891 | } | 887 | } |
892 | }, function(x,s,c,m) { | 888 | }, function(x,s,c,m) { |
893 | that.fireflix.flickr_failure(x,s,c,m); | 889 | that.fireflix.flickr_failure(x,s,c,m); |
894 | } | 890 | } |
895 | ); | 891 | ); |
896 | this.searchresult_props.hidden = false; | 892 | this.searchresult_props.hidden = false; |
897 | }else{ | 893 | }else{ |
898 | this.render_description_frame(p.description); | 894 | this.render_description_frame(p.description); |
899 | } | 895 | } |
900 | } | 896 | } |
901 | } | 897 | } |
902 | }, | 898 | }, |
903 | on_cmd_open: function(ev) { | 899 | on_cmd_open: function(ev) { |
904 | if(this.selection.currentIndex<0) return; | 900 | if(this.selection.currentIndex<0) return; |
905 | var p = this.photos[this.selection.currentIndex]; | 901 | var p = this.photos[this.selection.currentIndex]; |
906 | if(!p.id) return; | 902 | if(!p.id) return; |
907 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 903 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
908 | } | 904 | } |
909 | }, | 905 | }, |
910 | 906 | ||
911 | photo_html: function(p,i,l) { | 907 | photo_html: function(p,i,l) { |
912 | // TODO: add alt/title when possible | 908 | // TODO: add alt/title when possible |
913 | var rv = | 909 | var rv = |
914 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 910 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
915 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 911 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
916 | '</a>'; | 912 | '</a>'; |
917 | return rv; | 913 | return rv; |
918 | }, | 914 | }, |
919 | build_html: function(photos,uti,utl) { | 915 | build_html: function(photos,uti,utl) { |
920 | var rv = ''; | 916 | var rv = ''; |
921 | for(var i in photos) { | 917 | for(var i in photos) { |
922 | var p = photos[i]; | 918 | var p = photos[i]; |
923 | rv += this.photo_html(p,uti,utl)+'\n'; | 919 | rv += this.photo_html(p,uti,utl)+'\n'; |
924 | } | 920 | } |
925 | return rv; | 921 | return rv; |
926 | }, | 922 | }, |
927 | 923 | ||
928 | popup_content: function(s) { | 924 | popup_content: function(s) { |
929 | window.openDialog( | 925 | window.openDialog( |
930 | "chrome://fireflix/content/generated-content.xul", | 926 | "chrome://fireflix/content/generated-content.xul", |
931 | null, "dialog,chrome", this, s ); | 927 | null, "dialog,chrome", this, s ); |
932 | }, | 928 | }, |
933 | copy_to_clipboard: function(s) { | 929 | copy_to_clipboard: function(s) { |
934 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 930 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
935 | .getService(Components.interfaces.nsIClipboardHelper); | 931 | .getService(Components.interfaces.nsIClipboardHelper); |
936 | ch.copyString(s); | 932 | ch.copyString(s); |
937 | }, | 933 | }, |
938 | openTab: function(l) { | 934 | openTab: function(l) { |
939 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 935 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
940 | Components.interfaces.nsIWindowMediator ); | 936 | Components.interfaces.nsIWindowMediator ); |
941 | var bw = wm.getMostRecentWindow('navigator:browser'); | 937 | var bw = wm.getMostRecentWindow('navigator:browser'); |
942 | var b = bw.getBrowser(); | 938 | var b = bw.getBrowser(); |
943 | var t = b.addTab(l); | 939 | var t = b.addTab(l); |
944 | b.selectedTab = t; | 940 | b.selectedTab = t; |
945 | }, | 941 | }, |
946 | 942 | ||
947 | build_menus: function() { | 943 | build_menus: function() { |
948 | this.append_html_menu( | 944 | this.append_html_menu( |
949 | document.getElementById('sets_html_menu'), | 945 | document.getElementById('sets_html_menu'), |
950 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' | 946 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' |
951 | ); | 947 | ); |
952 | this.append_html_menu( | 948 | this.append_html_menu( |
953 | document.getElementById('setphotos_html_menu'), | 949 | document.getElementById('setphotos_html_menu'), |
954 | 'stm_','m_bop','cmdset_setphotos','cmd_setphotos_html' | 950 | 'stm_','m_bop','cmdset_setphotos','cmd_setphotos_html' |
955 | ); | 951 | ); |
956 | this.append_html_menu( | 952 | this.append_html_menu( |
957 | document.getElementById('uploads_html_menu'), | 953 | document.getElementById('uploads_html_menu'), |
958 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' | 954 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' |
959 | ); | 955 | ); |
960 | return; | 956 | return; |
961 | }, | 957 | }, |
962 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { | 958 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { |
963 | var mp = m.appendChild(document.createElement('menupopup')); | 959 | var mp = m.appendChild(document.createElement('menupopup')); |
964 | var t; | 960 | var t; |
965 | t=mp.appendChild(document.createElement('menuitem')); | 961 | t=mp.appendChild(document.createElement('menuitem')); |
966 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); | 962 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); |
967 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 963 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
968 | mp.appendChild(document.createElement('menuseparator')); | 964 | mp.appendChild(document.createElement('menuseparator')); |
969 | var cs = document.getElementById(csid); | 965 | var cs = document.getElementById(csid); |
970 | for(var iti=0;iti<imgt.length;++iti) { | 966 | for(var iti=0;iti<imgt.length;++iti) { |
971 | t = mp.appendChild(document.createElement('menu')); | 967 | t = mp.appendChild(document.createElement('menu')); |
972 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); | 968 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); |
973 | var smp = t.appendChild(document.createElement('menupopup')); | 969 | var smp = t.appendChild(document.createElement('menupopup')); |
974 | t=smp.appendChild(document.createElement('menuitem')); | 970 | t=smp.appendChild(document.createElement('menuitem')); |
975 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); | 971 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); |
976 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 972 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
977 | smp.appendChild(document.createElement('menuseparator')); | 973 | smp.appendChild(document.createElement('menuseparator')); |
978 | for(var lti=0;lti<lnkt.length;++lti) { | 974 | for(var lti=0;lti<lnkt.length;++lti) { |
979 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); | 975 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); |
980 | t=smp.appendChild(document.createElement('menuitem')); | 976 | t=smp.appendChild(document.createElement('menuitem')); |
981 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); | 977 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); |
982 | t.setAttribute('command',cpfx+'_'+csfx); | 978 | t.setAttribute('command',cpfx+'_'+csfx); |
983 | t=cs.appendChild(document.createElement('command')); | 979 | t=cs.appendChild(document.createElement('command')); |
984 | t.setAttribute('id',cpfx+'_'+csfx); | 980 | t.setAttribute('id',cpfx+'_'+csfx); |
985 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); | 981 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); |
986 | } | 982 | } |
987 | } | 983 | } |
988 | return mp; | 984 | return mp; |
989 | }, | 985 | }, |
990 | 986 | ||
991 | flickr_failure: function(x,s,c,m) { | 987 | flickr_failure: function(x,s,c,m) { |
992 | if(c==98) { // Invalid auth token | 988 | if(c==98) { // Invalid auth token |
993 | this.flickr.reset_token(); | 989 | this.flickr.reset_token(); |
994 | this.set_auth_state(false,false); | 990 | this.set_auth_state(false,false); |
995 | return; | 991 | return; |
996 | } | 992 | } |
997 | // TODO: is that beauty? | 993 | // TODO: is that beauty? |
998 | alert('flickr api call failed\n'+c+' '+m); | 994 | alert('flickr api call failed\n'+c+' '+m); |
999 | } | 995 | } |
1000 | 996 | ||
1001 | }; | 997 | }; |