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