summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
authorMichael Krelin <hacker@klever.net>2006-11-12 22:09:39 (UTC)
committer Michael Krelin <hacker@klever.net>2006-11-12 22:09:39 (UTC)
commitafcae0d9514f35c96484e6db1eb21e76821b5654 (patch) (unidiff)
tree09f24641d6d156e4592778813cbeda62ce03eded /content/fireflix.js
parent41d39823cf8a9e08ad17b9863e5e3ed88df0ac4e (diff)
downloadfireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.zip
fireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.tar.gz
fireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.tar.bz2
display human readable picture upload time
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@215 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js8
1 files changed, 7 insertions, 1 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 85b4d39..a4f13b6 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,488 +1,494 @@
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 pull_elements(this,document,[ 15 pull_elements(this,document,[
16 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', 16 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth',
17 'menu_auth_done','b_auth','b_auth_done','auth_info', 17 'menu_auth_done','b_auth','b_auth_done','auth_info',
18 'loc_strings','cmd_set_props' 18 'loc_strings','cmd_set_props'
19 ]); 19 ]);
20 this.build_menus(); 20 this.build_menus();
21 this.foundphotos.init(this); 21 this.foundphotos.init(this);
22 this.photosets.init(this); 22 this.photosets.init(this);
23 this.photoset.init(this); 23 this.photoset.init(this);
24 this.uploads.init(this); 24 this.uploads.init(this);
25 this.uploadObserver.init(this); 25 this.uploadObserver.init(this);
26 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; 26 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
27 this.flickr.api_shs = '9c33c9e2f0f0cfd5'; 27 this.flickr.api_shs = '9c33c9e2f0f0cfd5';
28 this.flickr.prefs_root = 'net.klever.kin.fireflix'; 28 this.flickr.prefs_root = 'net.klever.kin.fireflix';
29 this.flickr.load_token(); 29 this.flickr.load_token();
30 this.no_auth_info_label = this.auth_info.value; 30 this.no_auth_info_label = this.auth_info.value;
31 this.set_auth_state(this.flickr.token,false); 31 this.set_auth_state(this.flickr.token,false);
32 if(this.flickr.token) { 32 if(this.flickr.token) {
33 this.refresh_stuff(); 33 this.refresh_stuff();
34 }else{ 34 }else{
35 this.on_cmd_auth(); 35 this.on_cmd_auth();
36 } 36 }
37 }, 37 },
38 set_auth_state: function(au,inp) { /* authorized, in progress */ 38 set_auth_state: function(au,inp) { /* authorized, in progress */
39 this.cmd_auth_unauth.disabled = !au; 39 this.cmd_auth_unauth.disabled = !au;
40 this.b_auth.hidden = au || inp; 40 this.b_auth.hidden = au || inp;
41 this.b_auth_done.hidden = !inp; 41 this.b_auth_done.hidden = !inp;
42 this.menu_auth_done.hidden = !inp; 42 this.menu_auth_done.hidden = !inp;
43 this.cmd_auth_done.setAttribute('disabled',!inp); 43 this.cmd_auth_done.setAttribute('disabled',!inp);
44 this.auth_info.disabled = !au; 44 this.auth_info.disabled = !au;
45 if(au) { 45 if(au) {
46 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ 46 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */
47 }else{ 47 }else{
48 this.auth_info.value = this.no_auth_info_label; 48 this.auth_info.value = this.no_auth_info_label;
49 } 49 }
50 }, 50 },
51 on_cmd_auth: function() { 51 on_cmd_auth: function() {
52 var _this = this; 52 var _this = this;
53 this.flickr.authorize_0( 53 this.flickr.authorize_0(
54 'delete', 54 'delete',
55 function(x,f,u) { 55 function(x,f,u) {
56 _this.openTab(u); 56 _this.openTab(u);
57 _this.set_auth_state(_this.flickr.token,true); 57 _this.set_auth_state(_this.flickr.token,true);
58 }, function(x,s,c,m) { 58 }, function(x,s,c,m) {
59 _this.flickr_failure(x,s,c,m); 59 _this.flickr_failure(x,s,c,m);
60 } 60 }
61 ); 61 );
62 }, 62 },
63 on_cmd_auth_done: function() { 63 on_cmd_auth_done: function() {
64 this.set_auth_state(this.flickr.token,false); 64 this.set_auth_state(this.flickr.token,false);
65 var _this = this; 65 var _this = this;
66 this.flickr.authorize_1( 66 this.flickr.authorize_1(
67 function() { 67 function() {
68 _this.flickr.save_token(); 68 _this.flickr.save_token();
69 _this.refresh_stuff(); 69 _this.refresh_stuff();
70 _this.set_auth_state(_this.flickr.token,false); 70 _this.set_auth_state(_this.flickr.token,false);
71 _this.auth_info.value = 71 _this.auth_info.value =
72 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; 72 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
73 }, function(x,s,c,m) { 73 }, function(x,s,c,m) {
74 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ 74 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */
75 _this.flickr_failure(x,s,c,m); 75 _this.flickr_failure(x,s,c,m);
76 } 76 }
77 ); 77 );
78 }, 78 },
79 on_cmd_auth_unauth: function() { 79 on_cmd_auth_unauth: function() {
80 this.flickr.reset_token(); 80 this.flickr.reset_token();
81 this.set_auth_state(false,false); 81 this.set_auth_state(false,false);
82 }, 82 },
83 83
84 refresh_sets: function() { this.photosets.refresh_sets(); }, 84 refresh_sets: function() { this.photosets.refresh_sets(); },
85 refresh_stuff: function() { 85 refresh_stuff: function() {
86 this.refresh_sets(); 86 this.refresh_sets();
87 this.refresh_user_tags(); 87 this.refresh_user_tags();
88 }, 88 },
89 89
90 /* photoset treeview */ 90 /* photoset treeview */
91 photoset: { 91 photoset: {
92 photos: new Array(), 92 photos: new Array(),
93 fireflix: null, 93 fireflix: null,
94 init: function(f) { 94 init: function(f) {
95 this.fireflix = f; 95 this.fireflix = f;
96 pull_elements(this,document,[ 'set_photo' ]); 96 pull_elements(this,document,[ 'set_photo' ]);
97 document.getElementById('setphotos').view = this; 97 document.getElementById('setphotos').view = this;
98 }, 98 },
99 rowCount: 0, 99 rowCount: 0,
100 getCellText: function(r,c) { 100 getCellText: function(r,c) {
101 var p = this.photos[r]; 101 var p = this.photos[r];
102 if(c.id=='sp_title') return p.title; 102 if(c.id=='sp_title') return p.title;
103 if(c.id=='sp_taken') return p.datetaken; 103 if(c.id=='sp_taken') return p.datetaken;
104 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ 104 if(c.id=='sp_upload') {
105 var du = new Date(p.dateupload*1000);
106 var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate()
107 +' '+
108 du.getHours()+':'+du.getMinutes()+':'+du.getSeconds();
109 return rv.replace(/(\D)(\d)(\D)/,'$10$2$3');
110 }
105 return c.id; 111 return c.id;
106 }, 112 },
107 setTree: function(t) { this.tree = t }, 113 setTree: function(t) { this.tree = t },
108 isContainer: function(r) { return false; }, 114 isContainer: function(r) { return false; },
109 isSeparator: function(r) { return false; }, 115 isSeparator: function(r) { return false; },
110 isSorted: function(r) { return false; }, 116 isSorted: function(r) { return false; },
111 getLevel: function(r) { return 0; }, 117 getLevel: function(r) { return 0; },
112 getImageSrc: function(r,c) { return null }, 118 getImageSrc: function(r,c) { return null },
113 getRowProperties: function(r,p) {}, 119 getRowProperties: function(r,p) {},
114 getCellProperties: function(cid,cel,p) {}, 120 getCellProperties: function(cid,cel,p) {},
115 getColumnProperties: function(cid,cel,p) { }, 121 getColumnProperties: function(cid,cel,p) { },
116 cycleHeader: function(cid,e) { }, 122 cycleHeader: function(cid,e) { },
117 getParentIndex: function(r) { return -1; }, 123 getParentIndex: function(r) { return -1; },
118 drop: function(r,o) { }, 124 drop: function(r,o) { },
119 canDropBeforeAfter: function(r,b) { return false }, 125 canDropBeforeAfter: function(r,b) { return false },
120 126
121 importXPR: function(xp) { 127 importXPR: function(xp) {
122 this.tree.beginUpdateBatch(); 128 this.tree.beginUpdateBatch();
123 this.photos = new Array(); 129 this.photos = new Array();
124 var n; while(n=xp.iterateNext()) { 130 var n; while(n=xp.iterateNext()) {
125 this.photos.push(new Photo(n)); 131 this.photos.push(new Photo(n));
126 } 132 }
127 this.rowCount = this.photos.length; 133 this.rowCount = this.photos.length;
128 this.tree.endUpdateBatch(); 134 this.tree.endUpdateBatch();
129 }, 135 },
130 load_photos: function(psid) { 136 load_photos: function(psid) {
131 var _this = this; 137 var _this = this;
132 this.fireflix.flickr.api_call( 138 this.fireflix.flickr.api_call(
133 { 139 {
134 method: 'flickr.photosets.getPhotos', 140 method: 'flickr.photosets.getPhotos',
135 auth_token: 'default', 141 auth_token: 'default',
136 photoset_id: psid, 142 photoset_id: psid,
137 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' 143 extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
138 }, function(xr) { 144 }, function(xr) {
139 var x = xr.responseXML; 145 var x = xr.responseXML;
140 var xp = x.evaluate( 146 var xp = x.evaluate(
141 '/rsp/photoset/photo', x, null, 147 '/rsp/photoset/photo', x, null,
142 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 148 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
143 _this.importXPR(xp); 149 _this.importXPR(xp);
144 }, function(x,s,c,m) { 150 }, function(x,s,c,m) {
145 _this.fireflix.flickr_failure(x,s,c,m); 151 _this.fireflix.flickr_failure(x,s,c,m);
146 } 152 }
147 ); 153 );
148 }, 154 },
149 on_select: function() { 155 on_select: function() {
150 if(this.selection.count==1) { 156 if(this.selection.count==1) {
151 var p = this.photos[this.selection.currentIndex]; 157 var p = this.photos[this.selection.currentIndex];
152 this.set_photo.src = 158 this.set_photo.src =
153 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); 159 this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
154 this.set_photo.hidden = false; 160 this.set_photo.hidden = false;
155 }else{ 161 }else{
156 this.set_photo.hidden = true; 162 this.set_photo.hidden = true;
157 } 163 }
158 } 164 }
159 }, 165 },
160 166
161 /* photosets treeview */ 167 /* photosets treeview */
162 photosets: { 168 photosets: {
163 sets: new Array(), 169 sets: new Array(),
164 fireflix: null, 170 fireflix: null,
165 init: function(f) { 171 init: function(f) {
166 this.fireflix = f; 172 this.fireflix = f;
167 document.getElementById('setslist').view = this; 173 document.getElementById('setslist').view = this;
168 }, 174 },
169 rowCount: 0, 175 rowCount: 0,
170 getCellText: function(r,c) { 176 getCellText: function(r,c) {
171 var s = this.sets[r]; 177 var s = this.sets[r];
172 if(c.id=='sl_name') return s.title; 178 if(c.id=='sl_name') return s.title;
173 if(c.id=='sl_photos') return s.photos; 179 if(c.id=='sl_photos') return s.photos;
174 return c.id; 180 return c.id;
175 }, 181 },
176 setTree: function(t) { this.tree = t }, 182 setTree: function(t) { this.tree = t },
177 isContainer: function(r) { return false; }, 183 isContainer: function(r) { return false; },
178 isSeparator: function(r) { return false; }, 184 isSeparator: function(r) { return false; },
179 isSorted: function() { return false; }, 185 isSorted: function() { return false; },
180 getLevel: function(r) { return 0; }, 186 getLevel: function(r) { return 0; },
181 getImageSrc: function(r,c) { return null }, 187 getImageSrc: function(r,c) { return null },
182 getRowProperties: function(r,p) {}, 188 getRowProperties: function(r,p) {},
183 getCellProperties: function(cid,cel,p) { }, 189 getCellProperties: function(cid,cel,p) { },
184 getColumnProperties: function(cid,cel,p) { }, 190 getColumnProperties: function(cid,cel,p) { },
185 cycleHeader: function(cid,e) { }, 191 cycleHeader: function(cid,e) { },
186 getParentIndex: function(r) { return -1; }, 192 getParentIndex: function(r) { return -1; },
187 drop: function(r,o) { }, 193 drop: function(r,o) { },
188 canDropBeforeAfter: function(r,b) { return false }, 194 canDropBeforeAfter: function(r,b) { return false },
189 195
190 importXPR: function(xp) { 196 importXPR: function(xp) {
191 this.tree.beginUpdateBatch(); 197 this.tree.beginUpdateBatch();
192 this.sets = new Array(); 198 this.sets = new Array();
193 var n; while(n=xp.iterateNext()) { 199 var n; while(n=xp.iterateNext()) {
194 this.sets.push(new Photoset(n)); 200 this.sets.push(new Photoset(n));
195 } 201 }
196 this.rowCount = this.sets.length; 202 this.rowCount = this.sets.length;
197 this.tree.endUpdateBatch(); 203 this.tree.endUpdateBatch();
198 }, 204 },
199 refresh_sets: function() { 205 refresh_sets: function() {
200 var _this = this; 206 var _this = this;
201 this.fireflix.flickr.api_call( 207 this.fireflix.flickr.api_call(
202 { 208 {
203 method: 'flickr.photosets.getList', 209 method: 'flickr.photosets.getList',
204 auth_token: 'default' 210 auth_token: 'default'
205 }, function(xr) { 211 }, function(xr) {
206 var x = xr.responseXML; 212 var x = xr.responseXML;
207 var xp = x.evaluate( 213 var xp = x.evaluate(
208 '/rsp/photosets/photoset', x, null, 214 '/rsp/photosets/photoset', x, null,
209 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 215 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
210 _this.importXPR(xp); 216 _this.importXPR(xp);
211 }, function(x,s,c,m) { 217 }, function(x,s,c,m) {
212 _this.fireflix.flickr_failure(x,s,c,m); 218 _this.fireflix.flickr_failure(x,s,c,m);
213 } 219 }
214 ); 220 );
215 }, 221 },
216 on_select: function() { 222 on_select: function() {
217 if(this.selection.count==1) { 223 if(this.selection.count==1) {
218 this.fireflix.cmd_set_props.setAttribute('disabled','false'); 224 this.fireflix.cmd_set_props.setAttribute('disabled','false');
219 var s = this.sets[this.selection.currentIndex]; 225 var s = this.sets[this.selection.currentIndex];
220 this.fireflix.photoset.load_photos(s.id); 226 this.fireflix.photoset.load_photos(s.id);
221 }else{ 227 }else{
222 this.fireflix.cmd_set_props.setAttribute('disabled','true'); 228 this.fireflix.cmd_set_props.setAttribute('disabled','true');
223 } 229 }
224 } 230 }
225 }, 231 },
226 232
227 refresh_user_tags: function() { 233 refresh_user_tags: function() {
228 var lb = document.getElementById('tagslist'); 234 var lb = document.getElementById('tagslist');
229 var _this = this; 235 var _this = this;
230 this.flickr.api_call( 236 this.flickr.api_call(
231 { 237 {
232 method: 'flickr.tags.getListUser', 238 method: 'flickr.tags.getListUser',
233 auth_token: 'default', 239 auth_token: 'default',
234 }, function(xr) { 240 }, function(xr) {
235 var x = xr.responseXML; 241 var x = xr.responseXML;
236 var xp = x.evaluate( 242 var xp = x.evaluate(
237 '/rsp/who/tags/tag', x, null, 243 '/rsp/who/tags/tag', x, null,
238 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); 244 XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
239 // TODO: clear list 245 // TODO: clear list
240 var n; while(n=xp.iterateNext()) { 246 var n; while(n=xp.iterateNext()) {
241 lb.appendItem(n.firstChild.nodeValue); 247 lb.appendItem(n.firstChild.nodeValue);
242 } 248 }
243 }, function(x,s,c,m) { 249 }, function(x,s,c,m) {
244 _this.flickr_failure(x,s,c,m); 250 _this.flickr_failure(x,s,c,m);
245 } 251 }
246 ); 252 );
247 }, 253 },
248 254
249 uploadObserver: { 255 uploadObserver: {
250 fireflix: null, 256 fireflix: null,
251 init: function(f) { 257 init: function(f) {
252 this.fireflix = f; 258 this.fireflix = f;
253 }, 259 },
254 getSupportedFlavours: function() { 260 getSupportedFlavours: function() {
255 var rv = new FlavourSet(); 261 var rv = new FlavourSet();
256 rv.appendFlavour('application/x-moz-file','nsIFile'); 262 rv.appendFlavour('application/x-moz-file','nsIFile');
257 rv.appendFlavour('application/x-moz-url'); 263 rv.appendFlavour('application/x-moz-url');
258 rv.appendFlavour('text/uri-list'); 264 rv.appendFlavour('text/uri-list');
259 rv.appendFlavour('text/unicode'); 265 rv.appendFlavour('text/unicode');
260 return rv; 266 return rv;
261 }, 267 },
262 canHandleMultipleItems: true, 268 canHandleMultipleItems: true,
263 onDragOver: function(ev,fl,sess) { 269 onDragOver: function(ev,fl,sess) {
264 return true; 270 return true;
265 }, 271 },
266 onDrop: function(ev,dd,s) { 272 onDrop: function(ev,dd,s) {
267 var ldf = null; 273 var ldf = null;
268 for(var i in dd.dataList) { 274 for(var i in dd.dataList) {
269 var di = dd.dataList[i]; 275 var di = dd.dataList[i];
270 var dif = di.first; 276 var dif = di.first;
271 if( 277 if(
272 ldf==null 278 ldf==null
273 || ldf.flavour.contentType!=dif.flavour.contentType 279 || ldf.flavour.contentType!=dif.flavour.contentType
274 || ldf.contentLength!=dif.contentLength 280 || ldf.contentLength!=dif.contentLength
275 || ldf.data!=dif.data ) 281 || ldf.data!=dif.data )
276 this.drop_item(ev,di,s); 282 this.drop_item(ev,di,s);
277 ldf = dif; 283 ldf = dif;
278 } 284 }
279 }, 285 },
280 drop_item: function(ev,di,s) { 286 drop_item: function(ev,di,s) {
281 var d = di.first; 287 var d = di.first;
282 switch(d.flavour.contentType) { 288 switch(d.flavour.contentType) {
283 case 'text/unicode': 289 case 'text/unicode':
284 this.drop_urilist(ev,d.data,s); 290 this.drop_urilist(ev,d.data,s);
285 break; 291 break;
286 case 'application/x-moz-file': 292 case 'application/x-moz-file':
287 this.fireflix.uploads.add(d.data.path); 293 this.fireflix.uploads.add(d.data.path);
288 document.getElementById('fireflix_tabs').selectedTab 294 document.getElementById('fireflix_tabs').selectedTab
289 = document.getElementById('tab_upload'); 295 = document.getElementById('tab_upload');
290 break; 296 break;
291 case 'text/uri-list': 297 case 'text/uri-list':
292 // is it ascii or could it be utf8? 298 // is it ascii or could it be utf8?
293 this.drop_urilist(ev,splitascii(d.data),s); 299 this.drop_urilist(ev,splitascii(d.data),s);
294 break; 300 break;
295 default: alert(d.flavour.contentType+':'+d.data); break; 301 default: alert(d.flavour.contentType+':'+d.data); break;
296 }; 302 };
297 }, 303 },
298 drop_urilist: function(ev,ul,s) { 304 drop_urilist: function(ev,ul,s) {
299 // TODO: check for being a file? 305 // TODO: check for being a file?
300 var us = decodeURIComponent(ul).split(/[\r\n]/); 306 var us = decodeURIComponent(ul).split(/[\r\n]/);
301 for(var ui in us) 307 for(var ui in us)
302 if(/\S/.test(us[ui])) 308 if(/\S/.test(us[ui]))
303 this.fireflix.uploads.add(us[ui]); 309 this.fireflix.uploads.add(us[ui]);
304 document.getElementById('fireflix_tabs').selectedTab 310 document.getElementById('fireflix_tabs').selectedTab
305 = document.getElementById('tab_upload'); 311 = document.getElementById('tab_upload');
306 } 312 }
307 }, 313 },
308 314
309 uploads: { 315 uploads: {
310 fireflix: null, 316 fireflix: null,
311 init: function(f) { 317 init: function(f) {
312 this.fireflix=f; 318 this.fireflix=f;
313 pull_elements(this,document,[ 319 pull_elements(this,document,[
314 'upload_filename','upload_title','upload_file_preview', 320 'upload_filename','upload_title','upload_file_preview',
315 'upload_file_props','upload_progress','upload_tags', 321 'upload_file_props','upload_progress','upload_tags',
316 'cmd_uploads_upload' 322 'cmd_uploads_upload'
317 ]); 323 ]);
318 document.getElementById('uploadlist').view = this; 324 document.getElementById('uploadlist').view = this;
319 }, 325 },
320 files: new Array(), 326 files: new Array(),
321 rowCount: 0, 327 rowCount: 0,
322 getCellText: function(r,c) { 328 getCellText: function(r,c) {
323 var f = this.files[r]; 329 var f = this.files[r];
324 if(c.id=='up_file') return f.file; 330 if(c.id=='up_file') return f.file;
325 if(c.id=='up_title') return f.title; 331 if(c.id=='up_title') return f.title;
326 if(c.id=='up_status') return f.state; 332 if(c.id=='up_status') return f.state;
327 return c.id; 333 return c.id;
328 }, 334 },
329 setTree: function(t) { this.tree = t }, 335 setTree: function(t) { this.tree = t },
330 isContainer: function(r) { return false; }, 336 isContainer: function(r) { return false; },
331 isSeparator: function(r) { return false; }, 337 isSeparator: function(r) { return false; },
332 isSorted: function(r) { return false; }, 338 isSorted: function(r) { return false; },
333 getLevel: function(r) { return 0; }, 339 getLevel: function(r) { return 0; },
334 getImageSrc: function(r,c) { return null }, 340 getImageSrc: function(r,c) { return null },
335 getRowProperties: function(r,p) { 341 getRowProperties: function(r,p) {
336 try { 342 try {
337 if(!Components) return; 343 if(!Components) return;
338 }catch(e) { return } 344 }catch(e) { return }
339 var f = this.files[r]; 345 var f = this.files[r];
340 var as = Components.classes['@mozilla.org/atom-service;1']. 346 var as = Components.classes['@mozilla.org/atom-service;1'].
341 getService(Components.interfaces.nsIAtomService); 347 getService(Components.interfaces.nsIAtomService);
342 p.AppendElement(as.getAtom(f.state)); 348 p.AppendElement(as.getAtom(f.state));
343 }, 349 },
344 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, 350 getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
345 getColumnProperties: function(c,p) { }, 351 getColumnProperties: function(c,p) { },
346 cycleHeader: function(cid,e) { }, 352 cycleHeader: function(cid,e) { },
347 getParentIndex: function(r) { return -1; }, 353 getParentIndex: function(r) { return -1; },
348 drop: function(r,o) { }, 354 drop: function(r,o) { },
349 canDropBeforeAfter: function(r,b) { return false }, 355 canDropBeforeAfter: function(r,b) { return false },
350 356
351 add: function(f) { 357 add: function(f) {
352 if(f.indexOf('file:/')==0) { 358 if(f.indexOf('file:/')==0) {
353 f = f.substr(5); 359 f = f.substr(5);
354 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) 360 while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
355 f = f.substr(1); 361 f = f.substr(1);
356 } 362 }
357 } 363 }
358 var t = f; 364 var t = f;
359 var ls = t.lastIndexOf('/'); 365 var ls = t.lastIndexOf('/');
360 if(ls>0) t = t.substr(ls+1); 366 if(ls>0) t = t.substr(ls+1);
361 ls = t.lastIndexOf('\\'); 367 ls = t.lastIndexOf('\\');
362 if(ls>0) t = t.substr(ls+1); 368 if(ls>0) t = t.substr(ls+1);
363 var ld = t.lastIndexOf('.'); 369 var ld = t.lastIndexOf('.');
364 if(ld>0) t = t.substr(0,ld); 370 if(ld>0) t = t.substr(0,ld);
365 this.files.push( { 371 this.files.push( {
366 file: f, 372 file: f,
367 title: t, 373 title: t,
368 tags: '', 374 tags: '',
369 state: 'pending' 375 state: 'pending'
370 } ); 376 } );
371 this.rowCount = this.files.length; 377 this.rowCount = this.files.length;
372 this.tree.rowCountChanged(this.rowCount-1,1); 378 this.tree.rowCountChanged(this.rowCount-1,1);
373 }, 379 },
374 380
375 upload_worker: function() { 381 upload_worker: function() {
376 for(var f in this.files) { 382 for(var f in this.files) {
377 if(this.files[f].state=='pending') { 383 if(this.files[f].state=='pending') {
378 var ff = this.files[f]; 384 var ff = this.files[f];
379 dump('upload '+ff.file+'\n'); 385 dump('upload '+ff.file+'\n');
380 this.on_file_upload(ff); 386 this.on_file_upload(ff);
381 ff.state='uploading'; 387 ff.state='uploading';
382 this.tree.invalidate(); 388 this.tree.invalidate();
383 var _this = this; 389 var _this = this;
384 this.fireflix.flickr.upload_file( 390 this.fireflix.flickr.upload_file(
385 ff.file, { title: ff.title, tags: ff.tags }, 391 ff.file, { title: ff.title, tags: ff.tags },
386 function(x,p) { 392 function(x,p) {
387 ff.photoid = p; 393 ff.photoid = p;
388 _this.batch_ids.push(p); 394 _this.batch_ids.push(p);
389 ff.state='completed'; 395 ff.state='completed';
390 _this.tree.invalidate(); 396 _this.tree.invalidate();
391 window.setTimeout(_this.upload_to,0,_this); 397 window.setTimeout(_this.upload_to,0,_this);
392 }, function(x,s,c,m) { 398 }, function(x,s,c,m) {
393 ff.state='failed'; 399 ff.state='failed';
394 ff.flickr_errcode = c; 400 ff.flickr_errcode = c;
395 ff.flickr_errmsg = m; 401 ff.flickr_errmsg = m;
396 _this.tree.invalidate(); 402 _this.tree.invalidate();
397 window.setTimeout(_this.upload_to,0,_this); 403 window.setTimeout(_this.upload_to,0,_this);
398 } 404 }
399 ); 405 );
400 return; 406 return;
401 } 407 }
402 } 408 }
403 dump('uploading done\n'); 409 dump('uploading done\n');
404 this.on_finish_upload(); 410 this.on_finish_upload();
405 }, 411 },
406 upload_to: function(_this) { _this.upload_worker(); }, 412 upload_to: function(_this) { _this.upload_worker(); },
407 on_file_upload: function(f) { 413 on_file_upload: function(f) {
408 this.cmd_uploads_upload.setAttribute('disabled','true'); 414 this.cmd_uploads_upload.setAttribute('disabled','true');
409 for(var fi in this.files) { 415 for(var fi in this.files) {
410 if(this.files[fi].file==f.file) { 416 if(this.files[fi].file==f.file) {
411 this.tree.ensureRowIsVisible(fi); 417 this.tree.ensureRowIsVisible(fi);
412 this.selection.rangedSelect(fi,fi,false); 418 this.selection.rangedSelect(fi,fi,false);
413 this.selection.currentIndex = fi; 419 this.selection.currentIndex = fi;
414 this.selToProps(); 420 this.selToProps();
415 break; 421 break;
416 } 422 }
417 } 423 }
418 }, 424 },
419 on_finish_upload: function() { 425 on_finish_upload: function() {
420 if(this.batch_ids.length) { 426 if(this.batch_ids.length) {
421 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); 427 var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
422 if(psn!=null) { 428 if(psn!=null) {
423 var pids = this.batch_ids.join(','); 429 var pids = this.batch_ids.join(',');
424 var ppid = this.batch_ids[0]; 430 var ppid = this.batch_ids[0];
425 var _this = this; 431 var _this = this;
426 this.fireflix.flickr.api_call( 432 this.fireflix.flickr.api_call(
427 { 433 {
428 method: 'flickr.photosets.create', 434 method: 'flickr.photosets.create',
429 auth_token: 'default', 435 auth_token: 'default',
430 title: psn, 436 title: psn,
431 primary_photo_id: ppid 437 primary_photo_id: ppid
432 }, function(x) { 438 }, function(x) {
433 var npid = 439 var npid =
434 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); 440 x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
435 _this.fireflix.flickr.api_call( 441 _this.fireflix.flickr.api_call(
436 { 442 {
437 method: 'flickr.photosets.editPhotos', 443 method: 'flickr.photosets.editPhotos',
438 auth_token: 'default', 444 auth_token: 'default',
439 photoset_id: npid, 445 photoset_id: npid,
440 primary_photo_id: ppid, 446 primary_photo_id: ppid,
441 photo_ids: pids 447 photo_ids: pids
442 }, function(x) { 448 }, function(x) {
443 _this.fireflix.refresh_sets(); 449 _this.fireflix.refresh_sets();
444 }, function(x,s,c,m) { 450 }, function(x,s,c,m) {
445 _this.fireflix.flickr_failure(x,s,c,m); 451 _this.fireflix.flickr_failure(x,s,c,m);
446 } 452 }
447 ); 453 );
448 }, function(x,s,c,m) { 454 }, function(x,s,c,m) {
449 _this.fireflix.flickr_failure(x,s,c,m); 455 _this.fireflix.flickr_failure(x,s,c,m);
450 } 456 }
451 ); 457 );
452 } 458 }
453 } 459 }
454 this.selection.clearSelection(); 460 this.selection.clearSelection();
455 this.cmd_uploads_upload.setAttribute('disabled','false'); 461 this.cmd_uploads_upload.setAttribute('disabled','false');
456 this.upload_progress.setAttribute('hidden','true'); 462 this.upload_progress.setAttribute('hidden','true');
457 }, 463 },
458 464
459 clear_list: function() { 465 clear_list: function() {
460 this.tree.beginUpdateBatch(); 466 this.tree.beginUpdateBatch();
461 this.rowCount = 0; 467 this.rowCount = 0;
462 this.files = new Array(); 468 this.files = new Array();
463 this.tree.endUpdateBatch(); 469 this.tree.endUpdateBatch();
464 this.selToProps(); 470 this.selToProps();
465 }, 471 },
466 selectionChanged: function() { 472 selectionChanged: function() {
467 this.selToProps(); 473 this.selToProps();
468 }, 474 },
469 disableProps: function() { 475 disableProps: function() {
470 this.upload_filename.value=''; 476 this.upload_filename.value='';
471 this.upload_filename.disabled = true; 477 this.upload_filename.disabled = true;
472 this.upload_title.value=''; 478 this.upload_title.value='';
473 this.upload_title.disabled = true; 479 this.upload_title.disabled = true;
474 this.upload_file_preview.src = null; 480 this.upload_file_preview.src = null;
475 this.upload_file_props.hidden = true; 481 this.upload_file_props.hidden = true;
476 this.upload_tags.value=''; 482 this.upload_tags.value='';
477 this.upload_tags.disabled = true; 483 this.upload_tags.disabled = true;
478 }, 484 },
479 selToProps: function() { 485 selToProps: function() {
480 if(!this.selection.count) { 486 if(!this.selection.count) {
481 this.disableProps(); 487 this.disableProps();
482 }else if(this.selection.count==1) { 488 }else if(this.selection.count==1) {
483 var f=this.files[this.selection.currentIndex]; 489 var f=this.files[this.selection.currentIndex];
484 if(f==null || f.state!='pending') { 490 if(f==null || f.state!='pending') {
485 this.disableProps(); 491 this.disableProps();
486 }else{ 492 }else{
487 this.upload_filename.value = f.file; 493 this.upload_filename.value = f.file;
488 this.upload_filename.disabled = false; 494 this.upload_filename.disabled = false;