summaryrefslogtreecommitdiffabout
path: root/content
authorMichael Krelin <hacker@klever.net>2006-09-28 21:04:48 (UTC)
committer Michael Krelin <hacker@klever.net>2006-09-28 21:04:48 (UTC)
commit5659bfd13d49fe56aba072b29de0bd0bb332aebd (patch) (unidiff)
tree832f120283e5cc4f950c001ead3a94175a3ccca2 /content
parent84e84c0f62208bba6012e0db7296a9808bbbb148 (diff)
downloadfireflix-5659bfd13d49fe56aba072b29de0bd0bb332aebd.zip
fireflix-5659bfd13d49fe56aba072b29de0bd0bb332aebd.tar.gz
fireflix-5659bfd13d49fe56aba072b29de0bd0bb332aebd.tar.bz2
automatically start auth process in absence of token
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@166 fe716a7a-6dde-0310-88d9-d003556173a8
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,424 +1,426 @@
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];