summaryrefslogtreecommitdiffabout
path: root/content
Unidiff
Diffstat (limited to 'content') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js2
1 files changed, 2 insertions, 0 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 82c7b0c..daf4929 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,808 +1,810 @@
1function splitascii(s) { 1function 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
12var fireflix = { 12var fireflix = {
13 flickr: new Flickr(), 13 flickr: new Flickr(),
14 init: function() { 14 init: function() {
15 this.cmd_auth_auth = document.getElementById('cmd_auth_auth'); 15 this.cmd_auth_auth = document.getElementById('cmd_auth_auth');
16 this.cmd_auth_done = document.getElementById('cmd_auth_done'); 16 this.cmd_auth_done = document.getElementById('cmd_auth_done');
17 this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth'); 17 this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth');
18 this.menu_auth_done = document.getElementById('menu_auth_done'); 18 this.menu_auth_done = document.getElementById('menu_auth_done');
19 this.b_auth = document.getElementById('b_auth'); 19 this.b_auth = document.getElementById('b_auth');
20 this.b_auth_done = document.getElementById('b_auth_done'); 20 this.b_auth_done = document.getElementById('b_auth_done');
21 this.auth_info = document.getElementById('auth_info'); 21 this.auth_info = document.getElementById('auth_info');
22 this.loc_strings = document.getElementById('loc_strings'); 22 this.loc_strings = document.getElementById('loc_strings');
23 this.build_menus(); 23 this.build_menus();
24 this.cmd_set_props = document.getElementById('cmd_set_props'); 24 this.cmd_set_props = document.getElementById('cmd_set_props');
25 this.foundphotos.init(this); 25 this.foundphotos.init(this);
26 this.photosets.init(this); 26 this.photosets.init(this);
27 this.photoset.init(this); 27 this.photoset.init(this);
28 this.uploads.init(this); 28 this.uploads.init(this);
29 this.uploadObserver.init(this); 29 this.uploadObserver.init(this);
30 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; 30 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
31 this.flickr.api_shs = '9c33c9e2f0f0cfd5'; 31 this.flickr.api_shs = '9c33c9e2f0f0cfd5';
32 this.flickr.prefs_root = 'net.klever.kin.fireflix'; 32 this.flickr.prefs_root = 'net.klever.kin.fireflix';
33 this.flickr.load_token(); 33 this.flickr.load_token();
34 document.getElementById('setslist').view = this.photosets; 34 document.getElementById('setslist').view = this.photosets;
35 document.getElementById('setphotos').view = this.photoset; 35 document.getElementById('setphotos').view = this.photoset;
36 document.getElementById('uploadlist').view = this.uploads; 36 document.getElementById('uploadlist').view = this.uploads;
37 this.no_auth_info_label = this.auth_info.value; 37 this.no_auth_info_label = this.auth_info.value;
38 this.set_auth_state(this.flickr.token,false); 38 this.set_auth_state(this.flickr.token,false);
39 if(this.flickr.token) { 39 if(this.flickr.token) {
40 this.refresh_stuff(); 40 this.refresh_stuff();
41 }else{
42 this.on_cmd_auth();
41 } 43 }
42 }, 44 },
43 set_auth_state: function(au,inp) { /* authorized, in progress */ 45 set_auth_state: function(au,inp) { /* authorized, in progress */
44 this.cmd_auth_unauth.disabled = !au; 46 this.cmd_auth_unauth.disabled = !au;
45 this.b_auth.hidden = au || inp; 47 this.b_auth.hidden = au || inp;
46 this.b_auth_done.hidden = !inp; 48 this.b_auth_done.hidden = !inp;
47 this.menu_auth_done.hidden = !inp; 49 this.menu_auth_done.hidden = !inp;
48 this.cmd_auth_done.setAttribute('disabled',!inp); 50 this.cmd_auth_done.setAttribute('disabled',!inp);
49 this.auth_info.disabled = !au; 51 this.auth_info.disabled = !au;
50 if(au) { 52 if(au) {
51 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ 53 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */
52 }else{ 54 }else{
53 this.auth_info.value = this.no_auth_info_label; 55 this.auth_info.value = this.no_auth_info_label;
54 } 56 }
55 }, 57 },
56 on_cmd_auth: function() { 58 on_cmd_auth: function() {
57 var _this = this; 59 var _this = this;
58 this.flickr.authorize_0( 60 this.flickr.authorize_0(
59 function() { 61 function() {
60 _this.set_auth_state(_this.flickr.token,true); 62 _this.set_auth_state(_this.flickr.token,true);
61 }, function(x,s,c,m) { 63 }, function(x,s,c,m) {
62 _this.flickr_failure(x,s,c,m); 64 _this.flickr_failure(x,s,c,m);
63 } 65 }
64 ); 66 );
65 }, 67 },
66 on_cmd_auth_done: function() { 68 on_cmd_auth_done: function() {
67 this.set_auth_state(this.flickr.token,false); 69 this.set_auth_state(this.flickr.token,false);
68 var _this = this; 70 var _this = this;
69 this.flickr.authorize_1( 71 this.flickr.authorize_1(
70 function() { 72 function() {
71 _this.flickr.save_token(); 73 _this.flickr.save_token();
72 _this.refresh_stuff(); 74 _this.refresh_stuff();
73 _this.set_auth_state(_this.flickr.token,false); 75 _this.set_auth_state(_this.flickr.token,false);
74 _this.auth_info.value = 76 _this.auth_info.value =
75 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; 77 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
76 }, function(x,s,c,m) { 78 }, function(x,s,c,m) {
77 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ 79 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */
78 _this.flickr_failure(x,s,c,m); 80 _this.flickr_failure(x,s,c,m);
79 } 81 }
80 ); 82 );
81 }, 83 },
82 on_cmd_auth_unauth: function() { 84 on_cmd_auth_unauth: function() {
83 this.flickr.reset_token(); 85 this.flickr.reset_token();
84 this.set_auth_state(false,false); 86 this.set_auth_state(false,false);
85 }, 87 },
86 88
87 refresh_sets: function() { this.photosets.refresh_sets(); }, 89 refresh_sets: function() { this.photosets.refresh_sets(); },
88 refresh_stuff: function() { 90 refresh_stuff: function() {
89 this.refresh_sets(); 91 this.refresh_sets();
90 this.refresh_user_tags(); 92 this.refresh_user_tags();
91 }, 93 },
92 94
93 /* photoset treeview */ 95 /* photoset treeview */
94 photoset: { 96 photoset: {
95 photos: new Array(), 97 photos: new Array(),
96 fireflix: null, 98 fireflix: null,
97 init: function(f) { 99 init: function(f) {
98 this.fireflix = f; 100 this.fireflix = f;
99 }, 101 },
100 rowCount: 0, 102 rowCount: 0,
101 getCellText: function(r,c) { 103 getCellText: function(r,c) {
102 var p = this.photos[r]; 104 var p = this.photos[r];
103 if(c.id=='sp_title') return p.title; 105 if(c.id=='sp_title') return p.title;
104 if(c.id=='sp_taken') return p.datetaken; 106 if(c.id=='sp_taken') return p.datetaken;
105 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ 107 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */
106 return c.id; 108 return c.id;
107 }, 109 },
108 setTree: function(t) { this.tree = t }, 110 setTree: function(t) { this.tree = t },
109 isContainer: function(r) { return false; }, 111 isContainer: function(r) { return false; },
110 isSeparator: function(r) { return false; }, 112 isSeparator: function(r) { return false; },
111 isSorted: function(r) { return false; }, 113 isSorted: function(r) { return false; },
112 getLevel: function(r) { return 0; }, 114 getLevel: function(r) { return 0; },
113 getImageSrc: function(r,c) { return null }, 115 getImageSrc: function(r,c) { return null },
114 getRowProperties: function(r,p) {}, 116 getRowProperties: function(r,p) {},
115 getCellProperties: function(cid,cel,p) {}, 117 getCellProperties: function(cid,cel,p) {},
116 getColumnProperties: function(cid,cel,p) { }, 118 getColumnProperties: function(cid,cel,p) { },
117 cycleHeader: function(cid,e) { }, 119 cycleHeader: function(cid,e) { },
118 getParentIndex: function(r) { return -1; }, 120 getParentIndex: function(r) { return -1; },
119 drop: function(r,o) { }, 121 drop: function(r,o) { },
120 canDropBeforeAfter: function(r,b) { return false }, 122 canDropBeforeAfter: function(r,b) { return false },
121 123
122 importXPR: function(xp) { 124 importXPR: function(xp) {
123 this.tree.beginUpdateBatch(); 125 this.tree.beginUpdateBatch();
124 this.photos = new Array(); 126 this.photos = new Array();
125 var n; while(n=xp.iterateNext()) { 127 var n; while(n=xp.iterateNext()) {
126 this.photos.push(new Photo(n)); 128 this.photos.push(new Photo(n));
127 } 129 }
128 this.rowCount = this.photos.length; 130 this.rowCount = this.photos.length;
129 this.tree.endUpdateBatch(); 131 this.tree.endUpdateBatch();
130 }, 132 },
131 load_photos: function(psid) { 133 load_photos: function(psid) {
132 var _this = this; 134 var _this = this;
133 this.fireflix.flickr.api_call( 135 this.fireflix.flickr.api_call(
134 { 136 {
135 method: 'flickr.photosets.getPhotos', 137 method: 'flickr.photosets.getPhotos',
136 auth_token: 'default', 138 auth_token: 'default',
137 photoset_id: psid, 139 photoset_id: psid,
138 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' 140 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
139 }, function(xr) { 141 }, function(xr) {
140 var x = xr.responseXML; 142 var x = xr.responseXML;
141 var xp = x.evaluate( 143 var xp = x.evaluate(
142 '/rsp/photoset/photo', x, null, 144 '/rsp/photoset/photo', x, null,
143 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 145 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
144 _this.importXPR(xp); 146 _this.importXPR(xp);
145 }, function(x,s,c,m) { 147 }, function(x,s,c,m) {
146 _this.fireflix.flickr_failure(x,s,c,m); 148 _this.fireflix.flickr_failure(x,s,c,m);
147 } 149 }
148 ); 150 );
149 }, 151 },
150 on_select: function() { 152 on_select: function() {
151 if(this.selection.count==1) { 153 if(this.selection.count==1) {
152 var p = this.photos[this.selection.currentIndex]; 154 var p = this.photos[this.selection.currentIndex];
153 document.getElementById('set_photo').src = 155 document.getElementById('set_photo').src =
154 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); 156 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
155 document.getElementById('set_photo').hidden = false; 157 document.getElementById('set_photo').hidden = false;
156 }else{ 158 }else{
157 document.getElementById('set_photo').hidden = true; 159 document.getElementById('set_photo').hidden = true;
158 } 160 }
159 } 161 }
160 }, 162 },
161 163
162 /* photosets treeview */ 164 /* photosets treeview */
163 photosets: { 165 photosets: {
164 sets: new Array(), 166 sets: new Array(),
165 fireflix: null, 167 fireflix: null,
166 init: function(f) { 168 init: function(f) {
167 this.fireflix = f; 169 this.fireflix = f;
168 }, 170 },
169 rowCount: 0, 171 rowCount: 0,
170 getCellText: function(r,c) { 172 getCellText: function(r,c) {
171 var s = this.sets[r]; 173 var s = this.sets[r];
172 if(c.id=='sl_name') return s.title; 174 if(c.id=='sl_name') return s.title;
173 if(c.id=='sl_photos') return s.photos; 175 if(c.id=='sl_photos') return s.photos;
174 return c.id; 176 return c.id;
175 }, 177 },
176 setTree: function(t) { this.tree = t }, 178 setTree: function(t) { this.tree = t },
177 isContainer: function(r) { return false; }, 179 isContainer: function(r) { return false; },
178 isSeparator: function(r) { return false; }, 180 isSeparator: function(r) { return false; },
179 isSorted: function() { return false; }, 181 isSorted: function() { return false; },
180 getLevel: function(r) { return 0; }, 182 getLevel: function(r) { return 0; },
181 getImageSrc: function(r,c) { return null }, 183 getImageSrc: function(r,c) { return null },
182 getRowProperties: function(r,p) {}, 184 getRowProperties: function(r,p) {},
183 getCellProperties: function(cid,cel,p) { }, 185 getCellProperties: function(cid,cel,p) { },
184 getColumnProperties: function(cid,cel,p) { }, 186 getColumnProperties: function(cid,cel,p) { },
185 cycleHeader: function(cid,e) { }, 187 cycleHeader: function(cid,e) { },
186 getParentIndex: function(r) { return -1; }, 188 getParentIndex: function(r) { return -1; },
187 drop: function(r,o) { }, 189 drop: function(r,o) { },
188 canDropBeforeAfter: function(r,b) { return false }, 190 canDropBeforeAfter: function(r,b) { return false },
189 191
190 importXPR: function(xp) { 192 importXPR: function(xp) {
191 this.tree.beginUpdateBatch(); 193 this.tree.beginUpdateBatch();
192 this.sets = new Array(); 194 this.sets = new Array();
193 var n; while(n=xp.iterateNext()) { 195 var n; while(n=xp.iterateNext()) {
194 this.sets.push(new Photoset(n)); 196 this.sets.push(new Photoset(n));
195 } 197 }
196 this.rowCount = this.sets.length; 198 this.rowCount = this.sets.length;
197 this.tree.endUpdateBatch(); 199 this.tree.endUpdateBatch();
198 }, 200 },
199 refresh_sets: function() { 201 refresh_sets: function() {
200 var _this = this; 202 var _this = this;
201 this.fireflix.flickr.api_call( 203 this.fireflix.flickr.api_call(
202 { 204 {
203 method: 'flickr.photosets.getList', 205 method: 'flickr.photosets.getList',
204 auth_token: 'default' 206 auth_token: 'default'
205 }, function(xr) { 207 }, function(xr) {
206 var x = xr.responseXML; 208 var x = xr.responseXML;
207 var xp = x.evaluate( 209 var xp = x.evaluate(
208 '/rsp/photosets/photoset', x, null, 210 '/rsp/photosets/photoset', x, null,
209 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 211 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
210 _this.importXPR(xp); 212 _this.importXPR(xp);
211 }, function(x,s,c,m) { 213 }, function(x,s,c,m) {
212 _this.fireflix.flickr_failure(x,s,c,m); 214 _this.fireflix.flickr_failure(x,s,c,m);
213 } 215 }
214 ); 216 );
215 }, 217 },
216 on_select: function() { 218 on_select: function() {
217 if(this.selection.count==1) { 219 if(this.selection.count==1) {
218 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 220 this.fireflix.cmd_set_props.setAttribute('disabled','false');
219 var s = this.sets[this.selection.currentIndex]; 221 var s = this.sets[this.selection.currentIndex];
220 this.fireflix.photoset.load_photos(s.id); 222 this.fireflix.photoset.load_photos(s.id);
221 }else{ 223 }else{
222 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 224 this.fireflix.cmd_set_props.setAttribute('disabled','true');
223 } 225 }
224 } 226 }
225 }, 227 },
226 228
227 refresh_user_tags: function() { 229 refresh_user_tags: function() {
228 var lb = document.getElementById('tagslist'); 230 var lb = document.getElementById('tagslist');
229 var _this = this; 231 var _this = this;
230 this.flickr.api_call( 232 this.flickr.api_call(
231 { 233 {
232 method: 'flickr.tags.getListUser', 234 method: 'flickr.tags.getListUser',
233 auth_token: 'default', 235 auth_token: 'default',
234 }, function(xr) { 236 }, function(xr) {
235 var x = xr.responseXML; 237 var x = xr.responseXML;
236 var xp = x.evaluate( 238 var xp = x.evaluate(
237 '/rsp/who/tags/tag', x, null, 239 '/rsp/who/tags/tag', x, null,
238 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 240 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
239 // TODO: clear list 241 // TODO: clear list
240 var n; while(n=xp.iterateNext()) { 242 var n; while(n=xp.iterateNext()) {
241 lb.appendItem(n.firstChild.nodeValue); 243 lb.appendItem(n.firstChild.nodeValue);
242 } 244 }
243 }, function(x,s,c,m) { 245 }, function(x,s,c,m) {
244 _this.flickr_failure(x,s,c,m); 246 _this.flickr_failure(x,s,c,m);
245 } 247 }
246 ); 248 );
247 }, 249 },
248 250
249 uploadObserver: { 251 uploadObserver: {
250 fireflix: null, 252 fireflix: null,
251 init: function(f) { 253 init: function(f) {
252 this.fireflix = f; 254 this.fireflix = f;
253 }, 255 },
254 getSupportedFlavours: function() { 256 getSupportedFlavours: function() {
255 var rv = new FlavourSet(); 257 var rv = new FlavourSet();
256 rv.appendFlavour('application/x-moz-file','nsIFile'); 258 rv.appendFlavour('application/x-moz-file','nsIFile');
257 rv.appendFlavour('application/x-moz-url'); 259 rv.appendFlavour('application/x-moz-url');
258 rv.appendFlavour('text/uri-list'); 260 rv.appendFlavour('text/uri-list');
259 rv.appendFlavour('text/unicode'); 261 rv.appendFlavour('text/unicode');
260 return rv; 262 return rv;
261 }, 263 },
262 canHandleMultipleItems: true, 264 canHandleMultipleItems: true,
263 onDragOver: function(ev,fl,sess) { 265 onDragOver: function(ev,fl,sess) {
264 return true; 266 return true;
265 }, 267 },
266 onDrop: function(ev,dd,s) { 268 onDrop: function(ev,dd,s) {
267 var ldf = null; 269 var ldf = null;
268 for(var i in dd.dataList) { 270 for(var i in dd.dataList) {
269 var di = dd.dataList[i]; 271 var di = dd.dataList[i];
270 var dif = di.first; 272 var dif = di.first;
271 if( 273 if(
272 ldf==null 274 ldf==null
273 || ldf.flavour.contentType!=dif.flavour.contentType 275 || ldf.flavour.contentType!=dif.flavour.contentType
274 || ldf.contentLength!=dif.contentLength 276 || ldf.contentLength!=dif.contentLength
275 || ldf.data!=dif.data ) 277 || ldf.data!=dif.data )
276 this.drop_item(ev,di,s); 278 this.drop_item(ev,di,s);
277 ldf = dif; 279 ldf = dif;
278 } 280 }
279 }, 281 },
280 drop_item: function(ev,di,s) { 282 drop_item: function(ev,di,s) {
281 var d = di.first; 283 var d = di.first;
282 switch(d.flavour.contentType) { 284 switch(d.flavour.contentType) {
283 case 'text/unicode': 285 case 'text/unicode':
284 this.drop_urilist(ev,d.data,s); 286 this.drop_urilist(ev,d.data,s);
285 break; 287 break;
286 case 'application/x-moz-file': 288 case 'application/x-moz-file':
287 this.fireflix.uploads.add(d.data.path); 289 this.fireflix.uploads.add(d.data.path);
288 document.getElementById('fireflix_tabs').selectedTab 290 document.getElementById('fireflix_tabs').selectedTab
289 = document.getElementById('tab_upload'); 291 = document.getElementById('tab_upload');
290 break; 292 break;
291 case 'text/uri-list': 293 case 'text/uri-list':
292 // is it ascii or could it be utf8? 294 // is it ascii or could it be utf8?
293 this.drop_urilist(ev,splitascii(d.data),s); 295 this.drop_urilist(ev,splitascii(d.data),s);
294 break; 296 break;
295 default: alert(d.flavour.contentType+':'+d.data); break; 297 default: alert(d.flavour.contentType+':'+d.data); break;
296 }; 298 };
297 }, 299 },
298 drop_urilist: function(ev,ul,s) { 300 drop_urilist: function(ev,ul,s) {
299 // TODO: check for being a file? 301 // TODO: check for being a file?
300 var us = decodeURIComponent(ul).split(/[\r\n]/); 302 var us = decodeURIComponent(ul).split(/[\r\n]/);
301 for(var ui in us) 303 for(var ui in us)
302 if(/\S/.test(us[ui])) 304 if(/\S/.test(us[ui]))
303 this.fireflix.uploads.add(us[ui]); 305 this.fireflix.uploads.add(us[ui]);
304 document.getElementById('fireflix_tabs').selectedTab 306 document.getElementById('fireflix_tabs').selectedTab
305 = document.getElementById('tab_upload'); 307 = document.getElementById('tab_upload');
306 } 308 }
307 }, 309 },
308 310
309 uploads: { 311 uploads: {
310 fireflix: null, 312 fireflix: null,
311 init: function(f) { 313 init: function(f) {
312 this.fireflix=f; 314 this.fireflix=f;
313 this.upload_filename = document.getElementById('upload_filename'); 315 this.upload_filename = document.getElementById('upload_filename');
314 this.upload_title = document.getElementById('upload_title'); 316 this.upload_title = document.getElementById('upload_title');
315 this.upload_file_preview = document.getElementById('upload_file_preview'); 317 this.upload_file_preview = document.getElementById('upload_file_preview');
316 this.upload_file_props = document.getElementById('upload_file_props'); 318 this.upload_file_props = document.getElementById('upload_file_props');
317 this.upload_progress = document.getElementById('upload_progress'); 319 this.upload_progress = document.getElementById('upload_progress');
318 this.upload_tags = document.getElementById('upload_tags'); 320 this.upload_tags = document.getElementById('upload_tags');
319 }, 321 },
320 files: new Array(), 322 files: new Array(),
321 rowCount: 0, 323 rowCount: 0,
322 getCellText: function(r,c) { 324 getCellText: function(r,c) {
323 var f = this.files[r]; 325 var f = this.files[r];
324 if(c.id=='up_file') return f.file; 326 if(c.id=='up_file') return f.file;
325 if(c.id=='up_title') return f.title; 327 if(c.id=='up_title') return f.title;
326 if(c.id=='up_status') return f.state; 328 if(c.id=='up_status') return f.state;
327 return c.id; 329 return c.id;
328 }, 330 },
329 setTree: function(t) { this.tree = t }, 331 setTree: function(t) { this.tree = t },
330 isContainer: function(r) { return false; }, 332 isContainer: function(r) { return false; },
331 isSeparator: function(r) { return false; }, 333 isSeparator: function(r) { return false; },
332 isSorted: function(r) { return false; }, 334 isSorted: function(r) { return false; },
333 getLevel: function(r) { return 0; }, 335 getLevel: function(r) { return 0; },
334 getImageSrc: function(r,c) { return null }, 336 getImageSrc: function(r,c) { return null },
335 getRowProperties: function(r,p) { 337 getRowProperties: function(r,p) {
336 try { 338 try {
337 if(!Components) return; 339 if(!Components) return;
338 }catch(e) { return } 340 }catch(e) { return }
339 var f = this.files[r]; 341 var f = this.files[r];
340 var as = Components.classes['@mozilla.org/atom-service;1']. 342 var as = Components.classes['@mozilla.org/atom-service;1'].
341 getService(Components.interfaces.nsIAtomService); 343 getService(Components.interfaces.nsIAtomService);
342 p.AppendElement(as.getAtom(f.state)); 344 p.AppendElement(as.getAtom(f.state));
343 }, 345 },
344 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 346 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
345 getColumnProperties: function(c,p) { }, 347 getColumnProperties: function(c,p) { },
346 cycleHeader: function(cid,e) { }, 348 cycleHeader: function(cid,e) { },
347 getParentIndex: function(r) { return -1; }, 349 getParentIndex: function(r) { return -1; },
348 drop: function(r,o) { }, 350 drop: function(r,o) { },
349 canDropBeforeAfter: function(r,b) { return false }, 351 canDropBeforeAfter: function(r,b) { return false },
350 352
351 add: function(f) { 353 add: function(f) {
352 if(f.indexOf('file:/')==0) { 354 if(f.indexOf('file:/')==0) {
353 f = f.substr(5); 355 f = f.substr(5);
354 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 356 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
355 f = f.substr(1); 357 f = f.substr(1);
356 } 358 }
357 } 359 }
358 var t = f; 360 var t = f;
359 var ls = t.lastIndexOf('/'); 361 var ls = t.lastIndexOf('/');
360 if(ls>0) t = t.substr(ls+1); 362 if(ls>0) t = t.substr(ls+1);
361 ls = t.lastIndexOf('\\'); 363 ls = t.lastIndexOf('\\');
362 if(ls>0) t = t.substr(ls+1); 364 if(ls>0) t = t.substr(ls+1);
363 var ld = t.lastIndexOf('.'); 365 var ld = t.lastIndexOf('.');
364 if(ld>0) t = t.substr(0,ld); 366 if(ld>0) t = t.substr(0,ld);
365 this.files.push( { 367 this.files.push( {
366 file: f, 368 file: f,
367 title: t, 369 title: t,
368 tags: '', 370 tags: '',
369 state: 'pending' 371 state: 'pending'
370 } ); 372 } );
371 this.rowCount = this.files.length; 373 this.rowCount = this.files.length;
372 this.tree.rowCountChanged(this.rowCount-1,1); 374 this.tree.rowCountChanged(this.rowCount-1,1);
373 }, 375 },
374 376
375 upload_worker: function() { 377 upload_worker: function() {
376 for(var f in this.files) { 378 for(var f in this.files) {
377 if(this.files[f].state=='pending') { 379 if(this.files[f].state=='pending') {
378 var ff = this.files[f]; 380 var ff = this.files[f];
379 dump('upload '+ff.file+'\n'); 381 dump('upload '+ff.file+'\n');
380 this.on_file_upload(ff); 382 this.on_file_upload(ff);
381 ff.state='uploading'; 383 ff.state='uploading';
382 this.tree.invalidate(); 384 this.tree.invalidate();
383 var _this = this; 385 var _this = this;
384 this.fireflix.flickr.upload_file( 386 this.fireflix.flickr.upload_file(
385 ff.file, { title: ff.title, tags: ff.tags }, 387 ff.file, { title: ff.title, tags: ff.tags },
386 function(x,p) { 388 function(x,p) {
387 ff.photoid = p; 389 ff.photoid = p;
388 _this.batch_ids.push(p); 390 _this.batch_ids.push(p);
389 ff.state='completed'; 391 ff.state='completed';
390 _this.tree.invalidate(); 392 _this.tree.invalidate();
391 window.setTimeout(_this.upload_to,0,_this); 393 window.setTimeout(_this.upload_to,0,_this);
392 }, function(x,s,c,m) { 394 }, function(x,s,c,m) {
393 ff.state='failed'; 395 ff.state='failed';
394 ff.flickr_errcode = c; 396 ff.flickr_errcode = c;
395 ff.flickr_errmsg = m; 397 ff.flickr_errmsg = m;
396 _this.tree.invalidate(); 398 _this.tree.invalidate();
397 window.setTimeout(_this.upload_to,0,_this); 399 window.setTimeout(_this.upload_to,0,_this);
398 } 400 }
399 ); 401 );
400 return; 402 return;
401 } 403 }
402 } 404 }
403 dump('uploading done\n'); 405 dump('uploading done\n');
404 this.on_finish_upload(); 406 this.on_finish_upload();
405 }, 407 },
406 upload_to: function(_this) { _this.upload_worker(); }, 408 upload_to: function(_this) { _this.upload_worker(); },
407 on_file_upload: function(f) { 409 on_file_upload: function(f) {
408 document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); 410 document.getElementById('cmd_uploads_upload').setAttribute('disabled','true');
409 for(var fi in this.files) { 411 for(var fi in this.files) {
410 if(this.files[fi].file==f.file) { 412 if(this.files[fi].file==f.file) {
411 this.tree.ensureRowIsVisible(fi); 413 this.tree.ensureRowIsVisible(fi);
412 this.selection.rangedSelect(fi,fi,false); 414 this.selection.rangedSelect(fi,fi,false);
413 this.selection.currentIndex = fi; 415 this.selection.currentIndex = fi;
414 this.selToProps(); 416 this.selToProps();
415 break; 417 break;
416 } 418 }
417 } 419 }
418 }, 420 },
419 on_finish_upload: function() { 421 on_finish_upload: function() {
420 if(this.batch_ids.length) { 422 if(this.batch_ids.length) {
421 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 423 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
422 if(psn!=null) { 424 if(psn!=null) {
423 var pids = this.batch_ids.join(','); 425 var pids = this.batch_ids.join(',');
424 var ppid = this.batch_ids[0]; 426 var ppid = this.batch_ids[0];
425 var _this = this; 427 var _this = this;
426 this.fireflix.flickr.api_call( 428 this.fireflix.flickr.api_call(
427 { 429 {
428 method: 'flickr.photosets.create', 430 method: 'flickr.photosets.create',
429 auth_token: 'default', 431 auth_token: 'default',
430 title: psn, 432 title: psn,
431 primary_photo_id: ppid 433 primary_photo_id: ppid
432 }, function(x) { 434 }, function(x) {
433 var npid = 435 var npid =
434 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 436 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
435 _this.fireflix.flickr.api_call( 437 _this.fireflix.flickr.api_call(
436 { 438 {
437 method: 'flickr.photosets.editPhotos', 439 method: 'flickr.photosets.editPhotos',
438 auth_token: 'default', 440 auth_token: 'default',
439 photoset_id: npid, 441 photoset_id: npid,
440 primary_photo_id: ppid, 442 primary_photo_id: ppid,
441 photo_ids: pids 443 photo_ids: pids
442 }, function(x) { 444 }, function(x) {
443 _this.fireflix.refresh_sets(); 445 _this.fireflix.refresh_sets();
444 }, function(x,s,c,m) { 446 }, function(x,s,c,m) {
445 _this.fireflix.flickr_failure(x,s,c,m); 447 _this.fireflix.flickr_failure(x,s,c,m);
446 } 448 }
447 ); 449 );
448 }, function(x,s,c,m) { 450 }, function(x,s,c,m) {
449 _this.fireflix.flickr_failure(x,s,c,m); 451 _this.fireflix.flickr_failure(x,s,c,m);
450 } 452 }
451 ); 453 );
452 } 454 }
453 } 455 }
454 this.selection.clearSelection(); 456 this.selection.clearSelection();
455 document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); 457 document.getElementById('cmd_uploads_upload').setAttribute('disabled','false');
456 this.upload_progress.setAttribute('hidden','true'); 458 this.upload_progress.setAttribute('hidden','true');
457 }, 459 },
458 460
459 clear_list: function() { 461 clear_list: function() {
460 this.tree.beginUpdateBatch(); 462 this.tree.beginUpdateBatch();
461 this.rowCount = 0; 463 this.rowCount = 0;
462 this.files = new Array(); 464 this.files = new Array();
463 this.tree.endUpdateBatch(); 465 this.tree.endUpdateBatch();
464 this.selToProps(); 466 this.selToProps();
465 }, 467 },
466 selectionChanged: function() { 468 selectionChanged: function() {
467 this.selToProps(); 469 this.selToProps();
468 }, 470 },
469 disableProps: function() { 471 disableProps: function() {
470 this.upload_filename.value=''; 472 this.upload_filename.value='';
471 this.upload_filename.disabled = true; 473 this.upload_filename.disabled = true;
472 this.upload_title.value=''; 474 this.upload_title.value='';
473 this.upload_title.disabled = true; 475 this.upload_title.disabled = true;
474 this.upload_file_preview.src = null; 476 this.upload_file_preview.src = null;
475 this.upload_file_props.hidden = true; 477 this.upload_file_props.hidden = true;
476 this.upload_tags.value=''; 478 this.upload_tags.value='';
477 this.upload_tags.disabled = true; 479 this.upload_tags.disabled = true;
478 }, 480 },
479 selToProps: function() { 481 selToProps: function() {
480 if(!this.selection.count) { 482 if(!this.selection.count) {
481 this.disableProps(); 483 this.disableProps();
482 }else if(this.selection.count==1) { 484 }else if(this.selection.count==1) {
483 var f=this.files[this.selection.currentIndex]; 485 var f=this.files[this.selection.currentIndex];
484 if(f==null || f.state!='pending') { 486 if(f==null || f.state!='pending') {
485 this.disableProps(); 487 this.disableProps();
486 }else{ 488 }else{
487 this.upload_filename.value = f.file; 489 this.upload_filename.value = f.file;
488 this.upload_filename.disabled = false; 490 this.upload_filename.disabled = false;
489 this.upload_title.value = f.title; 491 this.upload_title.value = f.title;
490 this.upload_title.disabled = false; 492 this.upload_title.disabled = false;
491 this.upload_file_preview.src = 'file:///'+f.file; 493 this.upload_file_preview.src = 'file:///'+f.file;
492 this.upload_file_props.hidden = false; 494 this.upload_file_props.hidden = false;
493 this.upload_tags.value = f.tags; 495 this.upload_tags.value = f.tags;
494 this.upload_tags.disabled = false; 496 this.upload_tags.disabled = false;
495 } 497 }
496 }else{ 498 }else{
497 var ftitle = null; var onetitle = true; 499 var ftitle = null; var onetitle = true;
498 var ftags = null; var onetag = true; 500 var ftags = null; var onetag = true;
499 var fs = 0; 501 var fs = 0;
500 for(var ff in this.files) { 502 for(var ff in this.files) {
501 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { 503 if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
502 ++fs; 504 ++fs;
503 if(ftitle==null) { 505 if(ftitle==null) {
504 ftitle = this.files[ff].title; 506 ftitle = this.files[ff].title;
505 }else if(ftitle!=this.files[ff].title) { 507 }else if(ftitle!=this.files[ff].title) {
506 onetitle = false; 508 onetitle = false;
507 } 509 }
508 if(ftags==null) { 510 if(ftags==null) {
509 ftags = this.files[ff].tags; 511 ftags = this.files[ff].tags;
510 }else if(ftags!=this.files[ff].tags) { 512 }else if(ftags!=this.files[ff].tags) {
511 onetag = false; 513 onetag = false;
512 } 514 }
513 } 515 }
514 } 516 }
515 if(fs) { 517 if(fs) {
516 this.upload_filename.value=''; 518 this.upload_filename.value='';
517 this.upload_filename.disabled = true; 519 this.upload_filename.disabled = true;
518 if(onetitle) 520 if(onetitle)
519 this.upload_title.value = ftitle; 521 this.upload_title.value = ftitle;
520 this.upload_title.disabled = false; 522 this.upload_title.disabled = false;
521 if(onetag) 523 if(onetag)
522 this.upload_tags.value = ftags; 524 this.upload_tags.value = ftags;
523 this.upload_tags.disabled = false; 525 this.upload_tags.disabled = false;
524 this.upload_file_preview.src = null; 526 this.upload_file_preview.src = null;
525 this.upload_file_props.hidden = false; 527 this.upload_file_props.hidden = false;
526 }else 528 }else
527 this.disableProps(); 529 this.disableProps();
528 } 530 }
529 }, 531 },
530 propsToSel: function(prop) { 532 propsToSel: function(prop) {
531 if(this.selection.count<=0) return; 533 if(this.selection.count<=0) return;
532 for(var ff in this.files) { 534 for(var ff in this.files) {
533 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { 535 if(this.selection.isSelected(ff) && this.files[ff].state=='pending') {
534 if(prop=='filename') 536 if(prop=='filename')
535 this.files[ff].file = this.upload_filename.value; 537 this.files[ff].file = this.upload_filename.value;
536 if(prop=='title') 538 if(prop=='title')
537 this.files[ff].title = this.upload_title.value; 539 this.files[ff].title = this.upload_title.value;
538 if(prop=='tags') 540 if(prop=='tags')
539 this.files[ff].tags = this.upload_tags.value; 541 this.files[ff].tags = this.upload_tags.value;
540 this.tree.invalidateRow(ff); 542 this.tree.invalidateRow(ff);
541 } 543 }
542 } 544 }
543 }, 545 },
544 546
545 on_upload: function() { 547 on_upload: function() {
546 this.selToProps(); 548 this.selToProps();
547 this.batch_ids = new Array(); 549 this.batch_ids = new Array();
548 this.upload_progress.value=0; 550 this.upload_progress.value=0;
549 this.upload_progress.setAttribute('hidden','false'); 551 this.upload_progress.setAttribute('hidden','false');
550 this.upload_worker(); 552 this.upload_worker();
551 }, 553 },
552 on_clear: function() { 554 on_clear: function() {
553 this.clear_list(); 555 this.clear_list();
554 }, 556 },
555 on_remove: function() { 557 on_remove: function() {
556 if(this.selection.count) { 558 if(this.selection.count) {
557 this.tree.beginUpdateBatch(); 559 this.tree.beginUpdateBatch();
558 for(var i=this.files.length-1;i>=0;--i) { 560 for(var i=this.files.length-1;i>=0;--i) {
559 if(this.selection.isSelected(i)) { 561 if(this.selection.isSelected(i)) {
560 this.files.splice(i,1); 562 this.files.splice(i,1);
561 this.rowCount--; 563 this.rowCount--;
562 } 564 }
563 } 565 }
564 this.tree.endUpdateBatch(); 566 this.tree.endUpdateBatch();
565 this.selection.clearSelection(); 567 this.selection.clearSelection();
566 } 568 }
567 }, 569 },
568 on_add: function() { 570 on_add: function() {
569 var ifp = Components.interfaces.nsIFilePicker; 571 var ifp = Components.interfaces.nsIFilePicker;
570 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); 572 var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp);
571 fp.init(window, "Select a File", ifp.modeOpenMultiple); 573 fp.init(window, "Select a File", ifp.modeOpenMultiple);
572 fp.appendFilters(ifp.filterImages); 574 fp.appendFilters(ifp.filterImages);
573 var rv = fp.show(); 575 var rv = fp.show();
574 if(rv==ifp.returnOK) { 576 if(rv==ifp.returnOK) {
575 var ff = fp.files; 577 var ff = fp.files;
576 while(ff.hasMoreElements()) { 578 while(ff.hasMoreElements()) {
577 var f = ff.getNext(); 579 var f = ff.getNext();
578 f.QueryInterface(Components.interfaces.nsIFile); 580 f.QueryInterface(Components.interfaces.nsIFile);
579 this.add(f.path); 581 this.add(f.path);
580 } 582 }
581 } 583 }
582 } 584 }
583 }, 585 },
584 586
585 on_set_props: function() { 587 on_set_props: function() {
586 var pset = this.photosets.sets[this.photosets.selection.currentIndex]; 588 var pset = this.photosets.sets[this.photosets.selection.currentIndex];
587 window.openDialog( 589 window.openDialog(
588 "chrome://fireflix/content/photoset-props.xul", 590 "chrome://fireflix/content/photoset-props.xul",
589 null, "dependent,modal,dialog,chrome", this, 591 null, "dependent,modal,dialog,chrome", this,
590 pset ); 592 pset );
591 if(pset.dirty) { 593 if(pset.dirty) {
592 var _this = this; 594 var _this = this;
593 this.flickr.api_call( 595 this.flickr.api_call(
594 { 596 {
595 method: 'flickr.photosets.editMeta', 597 method: 'flickr.photosets.editMeta',
596 auth_token: 'default', 598 auth_token: 'default',
597 photoset_id: pset.id, 599 photoset_id: pset.id,
598 title: pset.title, 600 title: pset.title,
599 description: pset.description 601 description: pset.description
600 }, function(xr) { 602 }, function(xr) {
601 pset.dirty = false; 603 pset.dirty = false;
602 _this.flickr.api_call( 604 _this.flickr.api_call(
603 { 605 {
604 method: 'flickr.photosets.getPhotos', 606 method: 'flickr.photosets.getPhotos',
605 auth_token: 'default', 607 auth_token: 'default',
606 photoset_id: pset.id 608 photoset_id: pset.id
607 }, function(xr) { 609 }, function(xr) {
608 var x = xr.responseXML; 610 var x = xr.responseXML;
609 var xp = x.evaluate( 611 var xp = x.evaluate(
610 '/rsp/photoset/photo', x, null, 612 '/rsp/photoset/photo', x, null,
611 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 613 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
612 var phids = new Array(); 614 var phids = new Array();
613 var priph = null; 615 var priph = null;
614 var n; while(n=xp.iterateNext()) { 616 var n; while(n=xp.iterateNext()) {
615 var pid = n.getAttribute('id'); 617 var pid = n.getAttribute('id');
616 phids.push( pid ); 618 phids.push( pid );
617 if(pid==pset.primary && n.getAttribute('isprimary')!='1') 619 if(pid==pset.primary && n.getAttribute('isprimary')!='1')
618 priph = pid; 620 priph = pid;
619 } 621 }
620 if(priph) { 622 if(priph) {
621 _this.flickr.api_call( 623 _this.flickr.api_call(
622 { 624 {
623 method: 'flickr.photosets.editPhotos', 625 method: 'flickr.photosets.editPhotos',
624 auth_token: 'default', 626 auth_token: 'default',
625 photoset_id: pset.id, 627 photoset_id: pset.id,
626 primary_photo_id: priph, 628 primary_photo_id: priph,
627 photo_ids: phids.join(',') 629 photo_ids: phids.join(',')
628 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ 630 }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */
629 _this.flickr_failure(x,s,c,m); 631 _this.flickr_failure(x,s,c,m);
630 } 632 }
631 ); 633 );
632 } 634 }
633 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ 635 }, function(x,s,c,m) { /* flickr.photosets.getPhotos */
634 _this.flickr_failure(x,s,c,m); 636 _this.flickr_failure(x,s,c,m);
635 } 637 }
636 ); 638 );
637 }, function(x,s,c,m) { /* flickr.photosets.editMeta */ 639 }, function(x,s,c,m) { /* flickr.photosets.editMeta */
638 _this.flickr_failure(x,s,c,m); 640 _this.flickr_failure(x,s,c,m);
639 } 641 }
640 ); 642 );
641 } 643 }
642 }, 644 },
643 on_refresh_sets: function() { 645 on_refresh_sets: function() {
644 this.refresh_sets(); 646 this.refresh_sets();
645 }, 647 },
646 on_cmd_sets_html: function(csfx,ev) { 648 on_cmd_sets_html: function(csfx,ev) {
647 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 649 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
648 var rv = this.build_html(this.photoset.photos,uti,utl); 650 var rv = this.build_html(this.photoset.photos,uti,utl);
649 this.popup_content(rv); 651 this.popup_content(rv);
650 }, 652 },
651 653
652 on_cmd_uploads_html: function(csfx,ev) { 654 on_cmd_uploads_html: function(csfx,ev) {
653 var uti = csfx.charAt(0); var utl = csfx.charAt(1); 655 var uti = csfx.charAt(0); var utl = csfx.charAt(1);
654 var pids = new Array(); 656 var pids = new Array();
655 for(var f in this.uploads.files) { 657 for(var f in this.uploads.files) {
656 if(this.uploads.selection.isSelected(f)) 658 if(this.uploads.selection.isSelected(f))
657 if(this.uploads.files[f].photoid) 659 if(this.uploads.files[f].photoid)
658 pids.push(this.uploads.files[f].photoid); 660 pids.push(this.uploads.files[f].photoid);
659 } 661 }
660 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; 662 var pp = this.uploads.rowCount*2; if(pp>500) pp = 500;
661 var _this = this; 663 var _this = this;
662 this.flickr.api_call( 664 this.flickr.api_call(
663 { 665 {
664 method: 'flickr.photos.search', 666 method: 'flickr.photos.search',
665 auth_token: 'default', 667 auth_token: 'default',
666 extras: 'original_format', 668 extras: 'original_format',
667 user_id: 'me', 669 user_id: 'me',
668 per_page: pp 670 per_page: pp
669 }, 671 },
670 function(xr) { 672 function(xr) {
671 var x = xr.responseXML; 673 var x = xr.responseXML;
672 var rv = ''; 674 var rv = '';
673 for(var pn in pids) { 675 for(var pn in pids) {
674 var p = pids[pn]; 676 var p = pids[pn];
675 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); 677 var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x));
676 rv += _this.photo_html(pp,uti,utl)+'\n'; 678 rv += _this.photo_html(pp,uti,utl)+'\n';
677 } 679 }
678 _this.popup_content(rv); 680 _this.popup_content(rv);
679 }, function(x,s,c,m) { 681 }, function(x,s,c,m) {
680 _this.flickr_failure(x,s,c,m); 682 _this.flickr_failure(x,s,c,m);
681 } 683 }
682 ); 684 );
683 }, 685 },
684 686
685 /* 687 /*
686 * 688 *
687 */ 689 */
688 foundphotos: { 690 foundphotos: {
689 fireflix: null, 691 fireflix: null,
690 init: function(f) { 692 init: function(f) {
691 this.fireflix = f; 693 this.fireflix = f;
692 this.search_for = document.getElementById('search_for'); 694 this.search_for = document.getElementById('search_for');
693 this.search_tags= document.getElementById('search_tags'); 695 this.search_tags= document.getElementById('search_tags');
694 this.search_mine = document.getElementById('search_mine'); 696 this.search_mine = document.getElementById('search_mine');
695 document.getElementById('searchresults').view = this; 697 document.getElementById('searchresults').view = this;
696 this.searchresult_props = document.getElementById('searchresult_props'); 698 this.searchresult_props = document.getElementById('searchresult_props');
697 this.search_photo = document.getElementById('search_photo'); 699 this.search_photo = document.getElementById('search_photo');
698 this.searchresult_title = document.getElementById('searchresult_title'); 700 this.searchresult_title = document.getElementById('searchresult_title');
699 this.searchresult_description = document.getElementById('searchresult_description'); 701 this.searchresult_description = document.getElementById('searchresult_description');
700 }, 702 },
701 photos: new Array(), 703 photos: new Array(),
702 rowCount: 0, 704 rowCount: 0,
703 getCellText: function(r,c) { 705 getCellText: function(r,c) {
704 var p = this.photos[r]; 706 var p = this.photos[r];
705 if(c.id=='sr_title') return p.title; 707 if(c.id=='sr_title') return p.title;
706 return c.id; 708 return c.id;
707 }, 709 },
708 setTree: function(t) { this.tree = t }, 710 setTree: function(t) { this.tree = t },
709 isContainer: function(r) { return false }, 711 isContainer: function(r) { return false },
710 isSeparator: function(r) { return false }, 712 isSeparator: function(r) { return false },
711 isSorted: function(r) { return false }, 713 isSorted: function(r) { return false },
712 getLevel: function(r) { return 0 }, 714 getLevel: function(r) { return 0 },
713 getImageSrc: function(r,c) { return null }, 715 getImageSrc: function(r,c) { return null },
714 getRowProperties: function(r,p) { }, 716 getRowProperties: function(r,p) { },
715 getCellProperties: function(cid,cel,p) { }, 717 getCellProperties: function(cid,cel,p) { },
716 getColumnProperties: function(cid,cel,p) { }, 718 getColumnProperties: function(cid,cel,p) { },
717 cycleHeader: function(cid,e) { }, 719 cycleHeader: function(cid,e) { },
718 getParentIndex: function(r) { return -1 }, 720 getParentIndex: function(r) { return -1 },
719 drop: function(r,o) { }, 721 drop: function(r,o) { },
720 canDropBeforeAfter: function(r,b) { return false }, 722 canDropBeforeAfter: function(r,b) { return false },
721 723
722 importXPR: function(xp) { 724 importXPR: function(xp) {
723 this.selection.clearSelection(); 725 this.selection.clearSelection();
724 this.selection.currentIndex = -1; 726 this.selection.currentIndex = -1;
725 this.searchresult_props.hidden = true; 727 this.searchresult_props.hidden = true;
726 this.tree.beginUpdateBatch(); 728 this.tree.beginUpdateBatch();
727 this.photos = new Array(); 729 this.photos = new Array();
728 var n; while(n=xp.iterateNext()) { 730 var n; while(n=xp.iterateNext()) {
729 this.photos.push(new Photo(n)); 731 this.photos.push(new Photo(n));
730 } 732 }
731 this.rowCount = this.photos.length; 733 this.rowCount = this.photos.length;
732 this.tree.endUpdateBatch(); 734 this.tree.endUpdateBatch();
733 }, 735 },
734 search_photos: function() { 736 search_photos: function() {
735 var pars = { 737 var pars = {
736 method: 'flickr.photos.search', 738 method: 'flickr.photos.search',
737 auth_token: 'default', 739 auth_token: 'default',
738 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' 740 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
739 }; 741 };
740 if(this.search_mine.checked) 742 if(this.search_mine.checked)
741 pars.user_id='me'; 743 pars.user_id='me';
742 if(this.search_tags.checked) { 744 if(this.search_tags.checked) {
743 pars.tags=this.search_for.value.split(/ +/).join(','); 745 pars.tags=this.search_for.value.split(/ +/).join(',');
744 }else{ 746 }else{
745 pars.text=this.search_for.value; 747 pars.text=this.search_for.value;
746 } 748 }
747 var _this = this; 749 var _this = this;
748 this.fireflix.flickr.api_call( pars, 750 this.fireflix.flickr.api_call( pars,
749 function(xr) { 751 function(xr) {
750 var x = xr.responseXML; 752 var x = xr.responseXML;
751 var xp = x.evaluate( 753 var xp = x.evaluate(
752 '/rsp/photos/photo', x, null, 754 '/rsp/photos/photo', x, null,
753 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 755 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
754 _this.importXPR(xp); 756 _this.importXPR(xp);
755 _this.on_select(); 757 _this.on_select();
756 }, function(x,s,c,m) { 758 }, function(x,s,c,m) {
757 _this.fireflix.flickr_failure(x,s,c,m); 759 _this.fireflix.flickr_failure(x,s,c,m);
758 } 760 }
759 ); 761 );
760 }, 762 },
761 on_select: function() { 763 on_select: function() {
762 if(this.selection.currentIndex<0) { 764 if(this.selection.currentIndex<0) {
763 this.searchresult_props.hidden = true; 765 this.searchresult_props.hidden = true;
764 }else{ 766 }else{
765 var p = this.photos[this.selection.currentIndex]; 767 var p = this.photos[this.selection.currentIndex];
766 if(!p) { 768 if(!p) {
767 this.searchresult_props.hidden = true; 769 this.searchresult_props.hidden = true;
768 }else{ 770 }else{
769 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); 771 this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
770 this.searchresult_title.value = p.title; 772 this.searchresult_title.value = p.title;
771 this.searchresult_description.value = null; 773 this.searchresult_description.value = null;
772 if(p.description==null && p.description==undefined) { 774 if(p.description==null && p.description==undefined) {
773 var pid = p.id; 775 var pid = p.id;
774 var ci = this.selection.currentIndex; 776 var ci = this.selection.currentIndex;
775 var _this = this; 777 var _this = this;
776 this.fireflix.flickr.api_call( 778 this.fireflix.flickr.api_call(
777 { 779 {
778 method: 'flickr.photos.getInfo', 780 method: 'flickr.photos.getInfo',
779 auth_token: 'default', 781 auth_token: 'default',
780 photo_id: p.id, 782 photo_id: p.id,
781 secret: p.secret 783 secret: p.secret
782 }, function(xr) { 784 }, function(xr) {
783 var pp = _this.photos[ci]; 785 var pp = _this.photos[ci];
784 if(ci==_this.selection.currentIndex && pp.id==pid) { 786 if(ci==_this.selection.currentIndex && pp.id==pid) {
785 var n = xp_node('/rsp/photo',xr.responseXML); 787 var n = xp_node('/rsp/photo',xr.responseXML);
786 pp.fromNode_(n); 788 pp.fromNode_(n);
787 _this.searchresult_description.value=pp.description?pp.description:null; 789 _this.searchresult_description.value=pp.description?pp.description:null;
788 } 790 }
789 }, function(x,s,c,m) { 791 }, function(x,s,c,m) {
790 _this.fireflix.flickr_failure(x,s,c,m); 792 _this.fireflix.flickr_failure(x,s,c,m);
791 } 793 }
792 ); 794 );
793 this.searchresult_props.hidden = false; 795 this.searchresult_props.hidden = false;
794 }else{ 796 }else{
795 this.searchresult_description.value=p.description?p.description:null; 797 this.searchresult_description.value=p.description?p.description:null;
796 } 798 }
797 } 799 }
798 } 800 }
799 }, 801 },
800 on_cmd_open: function(ev) { 802 on_cmd_open: function(ev) {
801 if(this.selection.currentIndex<0) 803 if(this.selection.currentIndex<0)
802 return; 804 return;
803 var p = this.photos[this.selection.currentIndex]; 805 var p = this.photos[this.selection.currentIndex];
804 if(!p.id) 806 if(!p.id)
805 return; 807 return;
806 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); 808 this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
807 } 809 }
808 }, 810 },