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