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