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