author | Michael Krelin <hacker@klever.net> | 2006-09-28 19:40:39 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-09-28 19:40:39 (UTC) |
commit | 438c60c606a15792893c38415d0f405ae21e433d (patch) (unidiff) | |
tree | d8a56268d5ebedf8669587af7469fedbe1527154 /content/fireflix.js | |
parent | b62171950ffbbdae7826b1b8cdd4cfd0bde8cc93 (diff) | |
download | fireflix-438c60c606a15792893c38415d0f405ae21e433d.zip fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.gz fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.bz2 |
Better tracking of auth state, added possibility to sign off and reauth
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@164 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix.js | 52 |
1 files changed, 35 insertions, 17 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 9518480..82c7b0c 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -1,878 +1,896 @@ | |||
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 | this.cmd_auth_auth = document.getElementById('cmd_auth_auth'); | ||
16 | this.cmd_auth_done = document.getElementById('cmd_auth_done'); | ||
17 | this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth'); | ||
18 | this.menu_auth_done = document.getElementById('menu_auth_done'); | ||
19 | this.b_auth = document.getElementById('b_auth'); | ||
20 | this.b_auth_done = document.getElementById('b_auth_done'); | ||
21 | this.auth_info = document.getElementById('auth_info'); | ||
15 | this.loc_strings = document.getElementById('loc_strings'); | 22 | this.loc_strings = document.getElementById('loc_strings'); |
16 | this.build_menus(); | 23 | this.build_menus(); |
17 | this.cmd_set_props = document.getElementById('cmd_set_props'); | 24 | this.cmd_set_props = document.getElementById('cmd_set_props'); |
18 | this.foundphotos.init(this); | 25 | this.foundphotos.init(this); |
19 | this.photosets.init(this); | 26 | this.photosets.init(this); |
20 | this.photoset.init(this); | 27 | this.photoset.init(this); |
21 | this.uploads.init(this); | 28 | this.uploads.init(this); |
22 | this.uploadObserver.init(this); | 29 | this.uploadObserver.init(this); |
23 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; | 30 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; |
24 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; | 31 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; |
25 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; | 32 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; |
26 | this.flickr.load_token(); | 33 | this.flickr.load_token(); |
27 | document.getElementById('setslist').view = this.photosets; | 34 | document.getElementById('setslist').view = this.photosets; |
28 | document.getElementById('setphotos').view = this.photoset; | 35 | document.getElementById('setphotos').view = this.photoset; |
29 | document.getElementById('uploadlist').view = this.uploads; | 36 | document.getElementById('uploadlist').view = this.uploads; |
30 | this.flickr.no_auth_info_label = document.getElementById('auth_info').value; | 37 | this.no_auth_info_label = this.auth_info.value; |
38 | this.set_auth_state(this.flickr.token,false); | ||
31 | if(this.flickr.token) { | 39 | if(this.flickr.token) { |
32 | this.refresh_stuff(); | 40 | this.refresh_stuff(); |
33 | document.getElementById('auth_info').value = | ||
34 | this.flickr.user.fullname+' ['+this.flickr.user.username+']'; | ||
35 | document.getElementById('auth_info').disabled = false; | ||
36 | document.getElementById('b_auth').hidden = true; | ||
37 | } | 41 | } |
38 | }, | 42 | }, |
39 | on_auth: function() { | 43 | set_auth_state: function(au,inp) { /* authorized, in progress */ |
44 | this.cmd_auth_unauth.disabled = !au; | ||
45 | this.b_auth.hidden = au || inp; | ||
46 | this.b_auth_done.hidden = !inp; | ||
47 | this.menu_auth_done.hidden = !inp; | ||
48 | this.cmd_auth_done.setAttribute('disabled',!inp); | ||
49 | this.auth_info.disabled = !au; | ||
50 | if(au) { | ||
51 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ | ||
52 | }else{ | ||
53 | this.auth_info.value = this.no_auth_info_label; | ||
54 | } | ||
55 | }, | ||
56 | on_cmd_auth: function() { | ||
40 | var _this = this; | 57 | var _this = this; |
41 | this.flickr.authorize_0( | 58 | this.flickr.authorize_0( |
42 | function() { | 59 | function() { |
43 | document.getElementById('b_auth').hidden = true; | 60 | _this.set_auth_state(_this.flickr.token,true); |
44 | document.getElementById('b_auth_done').hidden = false; | ||
45 | }, function(x,s,c,m) { | 61 | }, function(x,s,c,m) { |
46 | _this.flickr_failure(x,s,c,m); | 62 | _this.flickr_failure(x,s,c,m); |
47 | } | 63 | } |
48 | ); | 64 | ); |
49 | }, | 65 | }, |
50 | on_auth_done: function() { | 66 | on_cmd_auth_done: function() { |
51 | document.getElementById('b_auth_done').hidden = true; | 67 | this.set_auth_state(this.flickr.token,false); |
52 | var _this = this; | 68 | var _this = this; |
53 | this.flickr.authorize_1( | 69 | this.flickr.authorize_1( |
54 | function() { | 70 | function() { |
55 | _this.flickr.save_token(); | 71 | _this.flickr.save_token(); |
56 | _this.refresh_stuff(); | 72 | _this.refresh_stuff(); |
57 | document.getElementById('auth_info').value = | 73 | _this.set_auth_state(_this.flickr.token,false); |
74 | _this.auth_info.value = | ||
58 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 75 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
59 | document.getElementById('auth_info').disabled = false; | ||
60 | }, function(x,s,c,m) { | 76 | }, function(x,s,c,m) { |
61 | document.getElementById('b_auth').hidden = false; | 77 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ |
62 | _this.flickr_failure(x,s,c,m); | 78 | _this.flickr_failure(x,s,c,m); |
63 | } | 79 | } |
64 | ); | 80 | ); |
65 | }, | 81 | }, |
82 | on_cmd_auth_unauth: function() { | ||
83 | this.flickr.reset_token(); | ||
84 | this.set_auth_state(false,false); | ||
85 | }, | ||
66 | 86 | ||
67 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 87 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
68 | refresh_stuff: function() { | 88 | refresh_stuff: function() { |
69 | this.refresh_sets(); | 89 | this.refresh_sets(); |
70 | this.refresh_user_tags(); | 90 | this.refresh_user_tags(); |
71 | }, | 91 | }, |
72 | 92 | ||
73 | /* photoset treeview */ | 93 | /* photoset treeview */ |
74 | photoset: { | 94 | photoset: { |
75 | photos: new Array(), | 95 | photos: new Array(), |
76 | fireflix: null, | 96 | fireflix: null, |
77 | init: function(f) { | 97 | init: function(f) { |
78 | this.fireflix = f; | 98 | this.fireflix = f; |
79 | }, | 99 | }, |
80 | rowCount: 0, | 100 | rowCount: 0, |
81 | getCellText: function(r,c) { | 101 | getCellText: function(r,c) { |
82 | var p = this.photos[r]; | 102 | var p = this.photos[r]; |
83 | if(c.id=='sp_title') return p.title; | 103 | if(c.id=='sp_title') return p.title; |
84 | if(c.id=='sp_taken') return p.datetaken; | 104 | if(c.id=='sp_taken') return p.datetaken; |
85 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ | 105 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ |
86 | return c.id; | 106 | return c.id; |
87 | }, | 107 | }, |
88 | setTree: function(t) { this.tree = t }, | 108 | setTree: function(t) { this.tree = t }, |
89 | isContainer: function(r) { return false; }, | 109 | isContainer: function(r) { return false; }, |
90 | isSeparator: function(r) { return false; }, | 110 | isSeparator: function(r) { return false; }, |
91 | isSorted: function(r) { return false; }, | 111 | isSorted: function(r) { return false; }, |
92 | getLevel: function(r) { return 0; }, | 112 | getLevel: function(r) { return 0; }, |
93 | getImageSrc: function(r,c) { return null }, | 113 | getImageSrc: function(r,c) { return null }, |
94 | getRowProperties: function(r,p) {}, | 114 | getRowProperties: function(r,p) {}, |
95 | getCellProperties: function(cid,cel,p) {}, | 115 | getCellProperties: function(cid,cel,p) {}, |
96 | getColumnProperties: function(cid,cel,p) { }, | 116 | getColumnProperties: function(cid,cel,p) { }, |
97 | cycleHeader: function(cid,e) { }, | 117 | cycleHeader: function(cid,e) { }, |
98 | getParentIndex: function(r) { return -1; }, | 118 | getParentIndex: function(r) { return -1; }, |
99 | drop: function(r,o) { }, | 119 | drop: function(r,o) { }, |
100 | canDropBeforeAfter: function(r,b) { return false }, | 120 | canDropBeforeAfter: function(r,b) { return false }, |
101 | 121 | ||
102 | importXPR: function(xp) { | 122 | importXPR: function(xp) { |
103 | this.tree.beginUpdateBatch(); | 123 | this.tree.beginUpdateBatch(); |
104 | this.photos = new Array(); | 124 | this.photos = new Array(); |
105 | var n; while(n=xp.iterateNext()) { | 125 | var n; while(n=xp.iterateNext()) { |
106 | this.photos.push(new Photo(n)); | 126 | this.photos.push(new Photo(n)); |
107 | } | 127 | } |
108 | this.rowCount = this.photos.length; | 128 | this.rowCount = this.photos.length; |
109 | this.tree.endUpdateBatch(); | 129 | this.tree.endUpdateBatch(); |
110 | }, | 130 | }, |
111 | load_photos: function(psid) { | 131 | load_photos: function(psid) { |
112 | var _this = this; | 132 | var _this = this; |
113 | this.fireflix.flickr.api_call( | 133 | this.fireflix.flickr.api_call( |
114 | { | 134 | { |
115 | method: 'flickr.photosets.getPhotos', | 135 | method: 'flickr.photosets.getPhotos', |
116 | auth_token: 'default', | 136 | auth_token: 'default', |
117 | photoset_id: psid, | 137 | photoset_id: psid, |
118 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 138 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
119 | }, function(xr) { | 139 | }, function(xr) { |
120 | var x = xr.responseXML; | 140 | var x = xr.responseXML; |
121 | var xp = x.evaluate( | 141 | var xp = x.evaluate( |
122 | '/rsp/photoset/photo', x, null, | 142 | '/rsp/photoset/photo', x, null, |
123 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 143 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
124 | _this.importXPR(xp); | 144 | _this.importXPR(xp); |
125 | }, function(x,s,c,m) { | 145 | }, function(x,s,c,m) { |
126 | _this.fireflix.flickr_failure(x,s,c,m); | 146 | _this.fireflix.flickr_failure(x,s,c,m); |
127 | } | 147 | } |
128 | ); | 148 | ); |
129 | }, | 149 | }, |
130 | on_select: function() { | 150 | on_select: function() { |
131 | if(this.selection.count==1) { | 151 | if(this.selection.count==1) { |
132 | var p = this.photos[this.selection.currentIndex]; | 152 | var p = this.photos[this.selection.currentIndex]; |
133 | document.getElementById('set_photo').src = | 153 | document.getElementById('set_photo').src = |
134 | 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'); |
135 | document.getElementById('set_photo').hidden = false; | 155 | document.getElementById('set_photo').hidden = false; |
136 | }else{ | 156 | }else{ |
137 | document.getElementById('set_photo').hidden = true; | 157 | document.getElementById('set_photo').hidden = true; |
138 | } | 158 | } |
139 | } | 159 | } |
140 | }, | 160 | }, |
141 | 161 | ||
142 | /* photosets treeview */ | 162 | /* photosets treeview */ |
143 | photosets: { | 163 | photosets: { |
144 | sets: new Array(), | 164 | sets: new Array(), |
145 | fireflix: null, | 165 | fireflix: null, |
146 | init: function(f) { | 166 | init: function(f) { |
147 | this.fireflix = f; | 167 | this.fireflix = f; |
148 | }, | 168 | }, |
149 | rowCount: 0, | 169 | rowCount: 0, |
150 | getCellText: function(r,c) { | 170 | getCellText: function(r,c) { |
151 | var s = this.sets[r]; | 171 | var s = this.sets[r]; |
152 | if(c.id=='sl_name') return s.title; | 172 | if(c.id=='sl_name') return s.title; |
153 | if(c.id=='sl_photos') return s.photos; | 173 | if(c.id=='sl_photos') return s.photos; |
154 | return c.id; | 174 | return c.id; |
155 | }, | 175 | }, |
156 | setTree: function(t) { this.tree = t }, | 176 | setTree: function(t) { this.tree = t }, |
157 | isContainer: function(r) { return false; }, | 177 | isContainer: function(r) { return false; }, |
158 | isSeparator: function(r) { return false; }, | 178 | isSeparator: function(r) { return false; }, |
159 | isSorted: function() { return false; }, | 179 | isSorted: function() { return false; }, |
160 | getLevel: function(r) { return 0; }, | 180 | getLevel: function(r) { return 0; }, |
161 | getImageSrc: function(r,c) { return null }, | 181 | getImageSrc: function(r,c) { return null }, |
162 | getRowProperties: function(r,p) {}, | 182 | getRowProperties: function(r,p) {}, |
163 | getCellProperties: function(cid,cel,p) { }, | 183 | getCellProperties: function(cid,cel,p) { }, |
164 | getColumnProperties: function(cid,cel,p) { }, | 184 | getColumnProperties: function(cid,cel,p) { }, |
165 | cycleHeader: function(cid,e) { }, | 185 | cycleHeader: function(cid,e) { }, |
166 | getParentIndex: function(r) { return -1; }, | 186 | getParentIndex: function(r) { return -1; }, |
167 | drop: function(r,o) { }, | 187 | drop: function(r,o) { }, |
168 | canDropBeforeAfter: function(r,b) { return false }, | 188 | canDropBeforeAfter: function(r,b) { return false }, |
169 | 189 | ||
170 | importXPR: function(xp) { | 190 | importXPR: function(xp) { |
171 | this.tree.beginUpdateBatch(); | 191 | this.tree.beginUpdateBatch(); |
172 | this.sets = new Array(); | 192 | this.sets = new Array(); |
173 | var n; while(n=xp.iterateNext()) { | 193 | var n; while(n=xp.iterateNext()) { |
174 | this.sets.push(new Photoset(n)); | 194 | this.sets.push(new Photoset(n)); |
175 | } | 195 | } |
176 | this.rowCount = this.sets.length; | 196 | this.rowCount = this.sets.length; |
177 | this.tree.endUpdateBatch(); | 197 | this.tree.endUpdateBatch(); |
178 | }, | 198 | }, |
179 | refresh_sets: function() { | 199 | refresh_sets: function() { |
180 | var _this = this; | 200 | var _this = this; |
181 | this.fireflix.flickr.api_call( | 201 | this.fireflix.flickr.api_call( |
182 | { | 202 | { |
183 | method: 'flickr.photosets.getList', | 203 | method: 'flickr.photosets.getList', |
184 | auth_token: 'default' | 204 | auth_token: 'default' |
185 | }, function(xr) { | 205 | }, function(xr) { |
186 | var x = xr.responseXML; | 206 | var x = xr.responseXML; |
187 | var xp = x.evaluate( | 207 | var xp = x.evaluate( |
188 | '/rsp/photosets/photoset', x, null, | 208 | '/rsp/photosets/photoset', x, null, |
189 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 209 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
190 | _this.importXPR(xp); | 210 | _this.importXPR(xp); |
191 | }, function(x,s,c,m) { | 211 | }, function(x,s,c,m) { |
192 | _this.fireflix.flickr_failure(x,s,c,m); | 212 | _this.fireflix.flickr_failure(x,s,c,m); |
193 | } | 213 | } |
194 | ); | 214 | ); |
195 | }, | 215 | }, |
196 | on_select: function() { | 216 | on_select: function() { |
197 | if(this.selection.count==1) { | 217 | if(this.selection.count==1) { |
198 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 218 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
199 | var s = this.sets[this.selection.currentIndex]; | 219 | var s = this.sets[this.selection.currentIndex]; |
200 | this.fireflix.photoset.load_photos(s.id); | 220 | this.fireflix.photoset.load_photos(s.id); |
201 | }else{ | 221 | }else{ |
202 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 222 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
203 | } | 223 | } |
204 | } | 224 | } |
205 | }, | 225 | }, |
206 | 226 | ||
207 | refresh_user_tags: function() { | 227 | refresh_user_tags: function() { |
208 | var lb = document.getElementById('tagslist'); | 228 | var lb = document.getElementById('tagslist'); |
209 | var _this = this; | 229 | var _this = this; |
210 | this.flickr.api_call( | 230 | this.flickr.api_call( |
211 | { | 231 | { |
212 | method: 'flickr.tags.getListUser', | 232 | method: 'flickr.tags.getListUser', |
213 | auth_token: 'default', | 233 | auth_token: 'default', |
214 | }, function(xr) { | 234 | }, function(xr) { |
215 | var x = xr.responseXML; | 235 | var x = xr.responseXML; |
216 | var xp = x.evaluate( | 236 | var xp = x.evaluate( |
217 | '/rsp/who/tags/tag', x, null, | 237 | '/rsp/who/tags/tag', x, null, |
218 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 238 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
219 | // TODO: clear list | 239 | // TODO: clear list |
220 | var n; while(n=xp.iterateNext()) { | 240 | var n; while(n=xp.iterateNext()) { |
221 | lb.appendItem(n.firstChild.nodeValue); | 241 | lb.appendItem(n.firstChild.nodeValue); |
222 | } | 242 | } |
223 | }, function(x,s,c,m) { | 243 | }, function(x,s,c,m) { |
224 | _this.flickr_failure(x,s,c,m); | 244 | _this.flickr_failure(x,s,c,m); |
225 | } | 245 | } |
226 | ); | 246 | ); |
227 | }, | 247 | }, |
228 | 248 | ||
229 | uploadObserver: { | 249 | uploadObserver: { |
230 | fireflix: null, | 250 | fireflix: null, |
231 | init: function(f) { | 251 | init: function(f) { |
232 | this.fireflix = f; | 252 | this.fireflix = f; |
233 | }, | 253 | }, |
234 | getSupportedFlavours: function() { | 254 | getSupportedFlavours: function() { |
235 | var rv = new FlavourSet(); | 255 | var rv = new FlavourSet(); |
236 | rv.appendFlavour('application/x-moz-file','nsIFile'); | 256 | rv.appendFlavour('application/x-moz-file','nsIFile'); |
237 | rv.appendFlavour('application/x-moz-url'); | 257 | rv.appendFlavour('application/x-moz-url'); |
238 | rv.appendFlavour('text/uri-list'); | 258 | rv.appendFlavour('text/uri-list'); |
239 | rv.appendFlavour('text/unicode'); | 259 | rv.appendFlavour('text/unicode'); |
240 | return rv; | 260 | return rv; |
241 | }, | 261 | }, |
242 | canHandleMultipleItems: true, | 262 | canHandleMultipleItems: true, |
243 | onDragOver: function(ev,fl,sess) { | 263 | onDragOver: function(ev,fl,sess) { |
244 | return true; | 264 | return true; |
245 | }, | 265 | }, |
246 | onDrop: function(ev,dd,s) { | 266 | onDrop: function(ev,dd,s) { |
247 | var ldf = null; | 267 | var ldf = null; |
248 | for(var i in dd.dataList) { | 268 | for(var i in dd.dataList) { |
249 | var di = dd.dataList[i]; | 269 | var di = dd.dataList[i]; |
250 | var dif = di.first; | 270 | var dif = di.first; |
251 | if( | 271 | if( |
252 | ldf==null | 272 | ldf==null |
253 | || ldf.flavour.contentType!=dif.flavour.contentType | 273 | || ldf.flavour.contentType!=dif.flavour.contentType |
254 | || ldf.contentLength!=dif.contentLength | 274 | || ldf.contentLength!=dif.contentLength |
255 | || ldf.data!=dif.data ) | 275 | || ldf.data!=dif.data ) |
256 | this.drop_item(ev,di,s); | 276 | this.drop_item(ev,di,s); |
257 | ldf = dif; | 277 | ldf = dif; |
258 | } | 278 | } |
259 | }, | 279 | }, |
260 | drop_item: function(ev,di,s) { | 280 | drop_item: function(ev,di,s) { |
261 | var d = di.first; | 281 | var d = di.first; |
262 | switch(d.flavour.contentType) { | 282 | switch(d.flavour.contentType) { |
263 | case 'text/unicode': | 283 | case 'text/unicode': |
264 | this.drop_urilist(ev,d.data,s); | 284 | this.drop_urilist(ev,d.data,s); |
265 | break; | 285 | break; |
266 | case 'application/x-moz-file': | 286 | case 'application/x-moz-file': |
267 | this.fireflix.uploads.add(d.data.path); | 287 | this.fireflix.uploads.add(d.data.path); |
268 | document.getElementById('fireflix_tabs').selectedTab | 288 | document.getElementById('fireflix_tabs').selectedTab |
269 | = document.getElementById('tab_upload'); | 289 | = document.getElementById('tab_upload'); |
270 | break; | 290 | break; |
271 | case 'text/uri-list': | 291 | case 'text/uri-list': |
272 | // is it ascii or could it be utf8? | 292 | // is it ascii or could it be utf8? |
273 | this.drop_urilist(ev,splitascii(d.data),s); | 293 | this.drop_urilist(ev,splitascii(d.data),s); |
274 | break; | 294 | break; |
275 | default: alert(d.flavour.contentType+':'+d.data); break; | 295 | default: alert(d.flavour.contentType+':'+d.data); break; |
276 | }; | 296 | }; |
277 | }, | 297 | }, |
278 | drop_urilist: function(ev,ul,s) { | 298 | drop_urilist: function(ev,ul,s) { |
279 | // TODO: check for being a file? | 299 | // TODO: check for being a file? |
280 | var us = decodeURIComponent(ul).split(/[\r\n]/); | 300 | var us = decodeURIComponent(ul).split(/[\r\n]/); |
281 | for(var ui in us) | 301 | for(var ui in us) |
282 | if(/\S/.test(us[ui])) | 302 | if(/\S/.test(us[ui])) |
283 | this.fireflix.uploads.add(us[ui]); | 303 | this.fireflix.uploads.add(us[ui]); |
284 | document.getElementById('fireflix_tabs').selectedTab | 304 | document.getElementById('fireflix_tabs').selectedTab |
285 | = document.getElementById('tab_upload'); | 305 | = document.getElementById('tab_upload'); |
286 | } | 306 | } |
287 | }, | 307 | }, |
288 | 308 | ||
289 | uploads: { | 309 | uploads: { |
290 | fireflix: null, | 310 | fireflix: null, |
291 | init: function(f) { | 311 | init: function(f) { |
292 | this.fireflix=f; | 312 | this.fireflix=f; |
293 | this.upload_filename = document.getElementById('upload_filename'); | 313 | this.upload_filename = document.getElementById('upload_filename'); |
294 | this.upload_title = document.getElementById('upload_title'); | 314 | this.upload_title = document.getElementById('upload_title'); |
295 | this.upload_file_preview = document.getElementById('upload_file_preview'); | 315 | this.upload_file_preview = document.getElementById('upload_file_preview'); |
296 | this.upload_file_props = document.getElementById('upload_file_props'); | 316 | this.upload_file_props = document.getElementById('upload_file_props'); |
297 | this.upload_progress = document.getElementById('upload_progress'); | 317 | this.upload_progress = document.getElementById('upload_progress'); |
298 | this.upload_tags = document.getElementById('upload_tags'); | 318 | this.upload_tags = document.getElementById('upload_tags'); |
299 | }, | 319 | }, |
300 | files: new Array(), | 320 | files: new Array(), |
301 | rowCount: 0, | 321 | rowCount: 0, |
302 | getCellText: function(r,c) { | 322 | getCellText: function(r,c) { |
303 | var f = this.files[r]; | 323 | var f = this.files[r]; |
304 | if(c.id=='up_file') return f.file; | 324 | if(c.id=='up_file') return f.file; |
305 | if(c.id=='up_title') return f.title; | 325 | if(c.id=='up_title') return f.title; |
306 | if(c.id=='up_status') return f.state; | 326 | if(c.id=='up_status') return f.state; |
307 | return c.id; | 327 | return c.id; |
308 | }, | 328 | }, |
309 | setTree: function(t) { this.tree = t }, | 329 | setTree: function(t) { this.tree = t }, |
310 | isContainer: function(r) { return false; }, | 330 | isContainer: function(r) { return false; }, |
311 | isSeparator: function(r) { return false; }, | 331 | isSeparator: function(r) { return false; }, |
312 | isSorted: function(r) { return false; }, | 332 | isSorted: function(r) { return false; }, |
313 | getLevel: function(r) { return 0; }, | 333 | getLevel: function(r) { return 0; }, |
314 | getImageSrc: function(r,c) { return null }, | 334 | getImageSrc: function(r,c) { return null }, |
315 | getRowProperties: function(r,p) { | 335 | getRowProperties: function(r,p) { |
316 | try { | 336 | try { |
317 | if(!Components) return; | 337 | if(!Components) return; |
318 | }catch(e) { return } | 338 | }catch(e) { return } |
319 | var f = this.files[r]; | 339 | var f = this.files[r]; |
320 | var as = Components.classes['@mozilla.org/atom-service;1']. | 340 | var as = Components.classes['@mozilla.org/atom-service;1']. |
321 | getService(Components.interfaces.nsIAtomService); | 341 | getService(Components.interfaces.nsIAtomService); |
322 | p.AppendElement(as.getAtom(f.state)); | 342 | p.AppendElement(as.getAtom(f.state)); |
323 | }, | 343 | }, |
324 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, | 344 | getCellProperties: function(r,c,p) { this.getRowProperties(r,p); }, |
325 | getColumnProperties: function(c,p) { }, | 345 | getColumnProperties: function(c,p) { }, |
326 | cycleHeader: function(cid,e) { }, | 346 | cycleHeader: function(cid,e) { }, |
327 | getParentIndex: function(r) { return -1; }, | 347 | getParentIndex: function(r) { return -1; }, |
328 | drop: function(r,o) { }, | 348 | drop: function(r,o) { }, |
329 | canDropBeforeAfter: function(r,b) { return false }, | 349 | canDropBeforeAfter: function(r,b) { return false }, |
330 | 350 | ||
331 | add: function(f) { | 351 | add: function(f) { |
332 | if(f.indexOf('file:/')==0) { | 352 | if(f.indexOf('file:/')==0) { |
333 | f = f.substr(5); | 353 | f = f.substr(5); |
334 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) | 354 | while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-) |
335 | f = f.substr(1); | 355 | f = f.substr(1); |
336 | } | 356 | } |
337 | } | 357 | } |
338 | var t = f; | 358 | var t = f; |
339 | var ls = t.lastIndexOf('/'); | 359 | var ls = t.lastIndexOf('/'); |
340 | if(ls>0) t = t.substr(ls+1); | 360 | if(ls>0) t = t.substr(ls+1); |
341 | ls = t.lastIndexOf('\\'); | 361 | ls = t.lastIndexOf('\\'); |
342 | if(ls>0) t = t.substr(ls+1); | 362 | if(ls>0) t = t.substr(ls+1); |
343 | var ld = t.lastIndexOf('.'); | 363 | var ld = t.lastIndexOf('.'); |
344 | if(ld>0) t = t.substr(0,ld); | 364 | if(ld>0) t = t.substr(0,ld); |
345 | this.files.push( { | 365 | this.files.push( { |
346 | file: f, | 366 | file: f, |
347 | title: t, | 367 | title: t, |
348 | tags: '', | 368 | tags: '', |
349 | state: 'pending' | 369 | state: 'pending' |
350 | } ); | 370 | } ); |
351 | this.rowCount = this.files.length; | 371 | this.rowCount = this.files.length; |
352 | this.tree.rowCountChanged(this.rowCount-1,1); | 372 | this.tree.rowCountChanged(this.rowCount-1,1); |
353 | }, | 373 | }, |
354 | 374 | ||
355 | upload_worker: function() { | 375 | upload_worker: function() { |
356 | for(var f in this.files) { | 376 | for(var f in this.files) { |
357 | if(this.files[f].state=='pending') { | 377 | if(this.files[f].state=='pending') { |
358 | var ff = this.files[f]; | 378 | var ff = this.files[f]; |
359 | dump('upload '+ff.file+'\n'); | 379 | dump('upload '+ff.file+'\n'); |
360 | this.on_file_upload(ff); | 380 | this.on_file_upload(ff); |
361 | ff.state='uploading'; | 381 | ff.state='uploading'; |
362 | this.tree.invalidate(); | 382 | this.tree.invalidate(); |
363 | var _this = this; | 383 | var _this = this; |
364 | this.fireflix.flickr.upload_file( | 384 | this.fireflix.flickr.upload_file( |
365 | ff.file, { title: ff.title, tags: ff.tags }, | 385 | ff.file, { title: ff.title, tags: ff.tags }, |
366 | function(x,p) { | 386 | function(x,p) { |
367 | ff.photoid = p; | 387 | ff.photoid = p; |
368 | _this.batch_ids.push(p); | 388 | _this.batch_ids.push(p); |
369 | ff.state='completed'; | 389 | ff.state='completed'; |
370 | _this.tree.invalidate(); | 390 | _this.tree.invalidate(); |
371 | window.setTimeout(_this.upload_to,0,_this); | 391 | window.setTimeout(_this.upload_to,0,_this); |
372 | }, function(x,s,c,m) { | 392 | }, function(x,s,c,m) { |
373 | ff.state='failed'; | 393 | ff.state='failed'; |
374 | ff.flickr_errcode = c; | 394 | ff.flickr_errcode = c; |
375 | ff.flickr_errmsg = m; | 395 | ff.flickr_errmsg = m; |
376 | _this.tree.invalidate(); | 396 | _this.tree.invalidate(); |
377 | window.setTimeout(_this.upload_to,0,_this); | 397 | window.setTimeout(_this.upload_to,0,_this); |
378 | } | 398 | } |
379 | ); | 399 | ); |
380 | return; | 400 | return; |
381 | } | 401 | } |
382 | } | 402 | } |
383 | dump('uploading done\n'); | 403 | dump('uploading done\n'); |
384 | this.on_finish_upload(); | 404 | this.on_finish_upload(); |
385 | }, | 405 | }, |
386 | upload_to: function(_this) { _this.upload_worker(); }, | 406 | upload_to: function(_this) { _this.upload_worker(); }, |
387 | on_file_upload: function(f) { | 407 | on_file_upload: function(f) { |
388 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); | 408 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','true'); |
389 | for(var fi in this.files) { | 409 | for(var fi in this.files) { |
390 | if(this.files[fi].file==f.file) { | 410 | if(this.files[fi].file==f.file) { |
391 | this.tree.ensureRowIsVisible(fi); | 411 | this.tree.ensureRowIsVisible(fi); |
392 | this.selection.rangedSelect(fi,fi,false); | 412 | this.selection.rangedSelect(fi,fi,false); |
393 | this.selection.currentIndex = fi; | 413 | this.selection.currentIndex = fi; |
394 | this.selToProps(); | 414 | this.selToProps(); |
395 | break; | 415 | break; |
396 | } | 416 | } |
397 | } | 417 | } |
398 | }, | 418 | }, |
399 | on_finish_upload: function() { | 419 | on_finish_upload: function() { |
400 | if(this.batch_ids.length) { | 420 | if(this.batch_ids.length) { |
401 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); | 421 | var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset')); |
402 | if(psn!=null) { | 422 | if(psn!=null) { |
403 | var pids = this.batch_ids.join(','); | 423 | var pids = this.batch_ids.join(','); |
404 | var ppid = this.batch_ids[0]; | 424 | var ppid = this.batch_ids[0]; |
405 | var _this = this; | 425 | var _this = this; |
406 | this.fireflix.flickr.api_call( | 426 | this.fireflix.flickr.api_call( |
407 | { | 427 | { |
408 | method: 'flickr.photosets.create', | 428 | method: 'flickr.photosets.create', |
409 | auth_token: 'default', | 429 | auth_token: 'default', |
410 | title: psn, | 430 | title: psn, |
411 | primary_photo_id: ppid | 431 | primary_photo_id: ppid |
412 | }, function(x) { | 432 | }, function(x) { |
413 | var npid = | 433 | var npid = |
414 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); | 434 | x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id'); |
415 | _this.fireflix.flickr.api_call( | 435 | _this.fireflix.flickr.api_call( |
416 | { | 436 | { |
417 | method: 'flickr.photosets.editPhotos', | 437 | method: 'flickr.photosets.editPhotos', |
418 | auth_token: 'default', | 438 | auth_token: 'default', |
419 | photoset_id: npid, | 439 | photoset_id: npid, |
420 | primary_photo_id: ppid, | 440 | primary_photo_id: ppid, |
421 | photo_ids: pids | 441 | photo_ids: pids |
422 | }, function(x) { | 442 | }, function(x) { |
423 | _this.fireflix.refresh_sets(); | 443 | _this.fireflix.refresh_sets(); |
424 | }, function(x,s,c,m) { | 444 | }, function(x,s,c,m) { |
425 | _this.fireflix.flickr_failure(x,s,c,m); | 445 | _this.fireflix.flickr_failure(x,s,c,m); |
426 | } | 446 | } |
427 | ); | 447 | ); |
428 | }, function(x,s,c,m) { | 448 | }, function(x,s,c,m) { |
429 | _this.fireflix.flickr_failure(x,s,c,m); | 449 | _this.fireflix.flickr_failure(x,s,c,m); |
430 | } | 450 | } |
431 | ); | 451 | ); |
432 | } | 452 | } |
433 | } | 453 | } |
434 | this.selection.clearSelection(); | 454 | this.selection.clearSelection(); |
435 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); | 455 | document.getElementById('cmd_uploads_upload').setAttribute('disabled','false'); |
436 | this.upload_progress.setAttribute('hidden','true'); | 456 | this.upload_progress.setAttribute('hidden','true'); |
437 | }, | 457 | }, |
438 | 458 | ||
439 | clear_list: function() { | 459 | clear_list: function() { |
440 | this.tree.beginUpdateBatch(); | 460 | this.tree.beginUpdateBatch(); |
441 | this.rowCount = 0; | 461 | this.rowCount = 0; |
442 | this.files = new Array(); | 462 | this.files = new Array(); |
443 | this.tree.endUpdateBatch(); | 463 | this.tree.endUpdateBatch(); |
444 | this.selToProps(); | 464 | this.selToProps(); |
445 | }, | 465 | }, |
446 | selectionChanged: function() { | 466 | selectionChanged: function() { |
447 | this.selToProps(); | 467 | this.selToProps(); |
448 | }, | 468 | }, |
449 | disableProps: function() { | 469 | disableProps: function() { |
450 | this.upload_filename.value=''; | 470 | this.upload_filename.value=''; |
451 | this.upload_filename.disabled = true; | 471 | this.upload_filename.disabled = true; |
452 | this.upload_title.value=''; | 472 | this.upload_title.value=''; |
453 | this.upload_title.disabled = true; | 473 | this.upload_title.disabled = true; |
454 | this.upload_file_preview.src = null; | 474 | this.upload_file_preview.src = null; |
455 | this.upload_file_props.hidden = true; | 475 | this.upload_file_props.hidden = true; |
456 | this.upload_tags.value=''; | 476 | this.upload_tags.value=''; |
457 | this.upload_tags.disabled = true; | 477 | this.upload_tags.disabled = true; |
458 | }, | 478 | }, |
459 | selToProps: function() { | 479 | selToProps: function() { |
460 | if(!this.selection.count) { | 480 | if(!this.selection.count) { |
461 | this.disableProps(); | 481 | this.disableProps(); |
462 | }else if(this.selection.count==1) { | 482 | }else if(this.selection.count==1) { |
463 | var f=this.files[this.selection.currentIndex]; | 483 | var f=this.files[this.selection.currentIndex]; |
464 | if(f==null || f.state!='pending') { | 484 | if(f==null || f.state!='pending') { |
465 | this.disableProps(); | 485 | this.disableProps(); |
466 | }else{ | 486 | }else{ |
467 | this.upload_filename.value = f.file; | 487 | this.upload_filename.value = f.file; |
468 | this.upload_filename.disabled = false; | 488 | this.upload_filename.disabled = false; |
469 | this.upload_title.value = f.title; | 489 | this.upload_title.value = f.title; |
470 | this.upload_title.disabled = false; | 490 | this.upload_title.disabled = false; |
471 | this.upload_file_preview.src = 'file:///'+f.file; | 491 | this.upload_file_preview.src = 'file:///'+f.file; |
472 | this.upload_file_props.hidden = false; | 492 | this.upload_file_props.hidden = false; |
473 | this.upload_tags.value = f.tags; | 493 | this.upload_tags.value = f.tags; |
474 | this.upload_tags.disabled = false; | 494 | this.upload_tags.disabled = false; |
475 | } | 495 | } |
476 | }else{ | 496 | }else{ |
477 | var ftitle = null; var onetitle = true; | 497 | var ftitle = null; var onetitle = true; |
478 | var ftags = null; var onetag = true; | 498 | var ftags = null; var onetag = true; |
479 | var fs = 0; | 499 | var fs = 0; |
480 | for(var ff in this.files) { | 500 | for(var ff in this.files) { |
481 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { | 501 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) { |
482 | ++fs; | 502 | ++fs; |
483 | if(ftitle==null) { | 503 | if(ftitle==null) { |
484 | ftitle = this.files[ff].title; | 504 | ftitle = this.files[ff].title; |
485 | }else if(ftitle!=this.files[ff].title) { | 505 | }else if(ftitle!=this.files[ff].title) { |
486 | onetitle = false; | 506 | onetitle = false; |
487 | } | 507 | } |
488 | if(ftags==null) { | 508 | if(ftags==null) { |
489 | ftags = this.files[ff].tags; | 509 | ftags = this.files[ff].tags; |
490 | }else if(ftags!=this.files[ff].tags) { | 510 | }else if(ftags!=this.files[ff].tags) { |
491 | onetag = false; | 511 | onetag = false; |
492 | } | 512 | } |
493 | } | 513 | } |
494 | } | 514 | } |
495 | if(fs) { | 515 | if(fs) { |
496 | this.upload_filename.value=''; | 516 | this.upload_filename.value=''; |
497 | this.upload_filename.disabled = true; | 517 | this.upload_filename.disabled = true; |
498 | if(onetitle) | 518 | if(onetitle) |
499 | this.upload_title.value = ftitle; | 519 | this.upload_title.value = ftitle; |
500 | this.upload_title.disabled = false; | 520 | this.upload_title.disabled = false; |
501 | if(onetag) | 521 | if(onetag) |
502 | this.upload_tags.value = ftags; | 522 | this.upload_tags.value = ftags; |
503 | this.upload_tags.disabled = false; | 523 | this.upload_tags.disabled = false; |
504 | this.upload_file_preview.src = null; | 524 | this.upload_file_preview.src = null; |
505 | this.upload_file_props.hidden = false; | 525 | this.upload_file_props.hidden = false; |
506 | }else | 526 | }else |
507 | this.disableProps(); | 527 | this.disableProps(); |
508 | } | 528 | } |
509 | }, | 529 | }, |
510 | propsToSel: function(prop) { | 530 | propsToSel: function(prop) { |
511 | if(this.selection.count<=0) return; | 531 | if(this.selection.count<=0) return; |
512 | for(var ff in this.files) { | 532 | for(var ff in this.files) { |
513 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { | 533 | if(this.selection.isSelected(ff) && this.files[ff].state=='pending') { |
514 | if(prop=='filename') | 534 | if(prop=='filename') |
515 | this.files[ff].file = this.upload_filename.value; | 535 | this.files[ff].file = this.upload_filename.value; |
516 | if(prop=='title') | 536 | if(prop=='title') |
517 | this.files[ff].title = this.upload_title.value; | 537 | this.files[ff].title = this.upload_title.value; |
518 | if(prop=='tags') | 538 | if(prop=='tags') |
519 | this.files[ff].tags = this.upload_tags.value; | 539 | this.files[ff].tags = this.upload_tags.value; |
520 | this.tree.invalidateRow(ff); | 540 | this.tree.invalidateRow(ff); |
521 | } | 541 | } |
522 | } | 542 | } |
523 | }, | 543 | }, |
524 | 544 | ||
525 | on_upload: function() { | 545 | on_upload: function() { |
526 | this.selToProps(); | 546 | this.selToProps(); |
527 | this.batch_ids = new Array(); | 547 | this.batch_ids = new Array(); |
528 | this.upload_progress.value=0; | 548 | this.upload_progress.value=0; |
529 | this.upload_progress.setAttribute('hidden','false'); | 549 | this.upload_progress.setAttribute('hidden','false'); |
530 | this.upload_worker(); | 550 | this.upload_worker(); |
531 | }, | 551 | }, |
532 | on_clear: function() { | 552 | on_clear: function() { |
533 | this.clear_list(); | 553 | this.clear_list(); |
534 | }, | 554 | }, |
535 | on_remove: function() { | 555 | on_remove: function() { |
536 | if(this.selection.count) { | 556 | if(this.selection.count) { |
537 | this.tree.beginUpdateBatch(); | 557 | this.tree.beginUpdateBatch(); |
538 | for(var i=this.files.length-1;i>=0;--i) { | 558 | for(var i=this.files.length-1;i>=0;--i) { |
539 | if(this.selection.isSelected(i)) { | 559 | if(this.selection.isSelected(i)) { |
540 | this.files.splice(i,1); | 560 | this.files.splice(i,1); |
541 | this.rowCount--; | 561 | this.rowCount--; |
542 | } | 562 | } |
543 | } | 563 | } |
544 | this.tree.endUpdateBatch(); | 564 | this.tree.endUpdateBatch(); |
545 | this.selection.clearSelection(); | 565 | this.selection.clearSelection(); |
546 | } | 566 | } |
547 | }, | 567 | }, |
548 | on_add: function() { | 568 | on_add: function() { |
549 | var ifp = Components.interfaces.nsIFilePicker; | 569 | var ifp = Components.interfaces.nsIFilePicker; |
550 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); | 570 | var fp = Components.classes["@mozilla.org/filepicker;1"].createInstance(ifp); |
551 | fp.init(window, "Select a File", ifp.modeOpenMultiple); | 571 | fp.init(window, "Select a File", ifp.modeOpenMultiple); |
552 | fp.appendFilters(ifp.filterImages); | 572 | fp.appendFilters(ifp.filterImages); |
553 | var rv = fp.show(); | 573 | var rv = fp.show(); |
554 | if(rv==ifp.returnOK) { | 574 | if(rv==ifp.returnOK) { |
555 | var ff = fp.files; | 575 | var ff = fp.files; |
556 | while(ff.hasMoreElements()) { | 576 | while(ff.hasMoreElements()) { |
557 | var f = ff.getNext(); | 577 | var f = ff.getNext(); |
558 | f.QueryInterface(Components.interfaces.nsIFile); | 578 | f.QueryInterface(Components.interfaces.nsIFile); |
559 | this.add(f.path); | 579 | this.add(f.path); |
560 | } | 580 | } |
561 | } | 581 | } |
562 | } | 582 | } |
563 | }, | 583 | }, |
564 | 584 | ||
565 | on_set_props: function() { | 585 | on_set_props: function() { |
566 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; | 586 | var pset = this.photosets.sets[this.photosets.selection.currentIndex]; |
567 | window.openDialog( | 587 | window.openDialog( |
568 | "chrome://fireflix/content/photoset-props.xul", | 588 | "chrome://fireflix/content/photoset-props.xul", |
569 | null, "dependent,modal,dialog,chrome", this, | 589 | null, "dependent,modal,dialog,chrome", this, |
570 | pset ); | 590 | pset ); |
571 | if(pset.dirty) { | 591 | if(pset.dirty) { |
572 | var _this = this; | 592 | var _this = this; |
573 | this.flickr.api_call( | 593 | this.flickr.api_call( |
574 | { | 594 | { |
575 | method: 'flickr.photosets.editMeta', | 595 | method: 'flickr.photosets.editMeta', |
576 | auth_token: 'default', | 596 | auth_token: 'default', |
577 | photoset_id: pset.id, | 597 | photoset_id: pset.id, |
578 | title: pset.title, | 598 | title: pset.title, |
579 | description: pset.description | 599 | description: pset.description |
580 | }, function(xr) { | 600 | }, function(xr) { |
581 | pset.dirty = false; | 601 | pset.dirty = false; |
582 | _this.flickr.api_call( | 602 | _this.flickr.api_call( |
583 | { | 603 | { |
584 | method: 'flickr.photosets.getPhotos', | 604 | method: 'flickr.photosets.getPhotos', |
585 | auth_token: 'default', | 605 | auth_token: 'default', |
586 | photoset_id: pset.id | 606 | photoset_id: pset.id |
587 | }, function(xr) { | 607 | }, function(xr) { |
588 | var x = xr.responseXML; | 608 | var x = xr.responseXML; |
589 | var xp = x.evaluate( | 609 | var xp = x.evaluate( |
590 | '/rsp/photoset/photo', x, null, | 610 | '/rsp/photoset/photo', x, null, |
591 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 611 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
592 | var phids = new Array(); | 612 | var phids = new Array(); |
593 | var priph = null; | 613 | var priph = null; |
594 | var n; while(n=xp.iterateNext()) { | 614 | var n; while(n=xp.iterateNext()) { |
595 | var pid = n.getAttribute('id'); | 615 | var pid = n.getAttribute('id'); |
596 | phids.push( pid ); | 616 | phids.push( pid ); |
597 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') | 617 | if(pid==pset.primary && n.getAttribute('isprimary')!='1') |
598 | priph = pid; | 618 | priph = pid; |
599 | } | 619 | } |
600 | if(priph) { | 620 | if(priph) { |
601 | _this.flickr.api_call( | 621 | _this.flickr.api_call( |
602 | { | 622 | { |
603 | method: 'flickr.photosets.editPhotos', | 623 | method: 'flickr.photosets.editPhotos', |
604 | auth_token: 'default', | 624 | auth_token: 'default', |
605 | photoset_id: pset.id, | 625 | photoset_id: pset.id, |
606 | primary_photo_id: priph, | 626 | primary_photo_id: priph, |
607 | photo_ids: phids.join(',') | 627 | photo_ids: phids.join(',') |
608 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ | 628 | }, function() { }, function(x,s,c,m) { /* flickr.photosets.editPhotos */ |
609 | _this.flickr_failure(x,s,c,m); | 629 | _this.flickr_failure(x,s,c,m); |
610 | } | 630 | } |
611 | ); | 631 | ); |
612 | } | 632 | } |
613 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ | 633 | }, function(x,s,c,m) { /* flickr.photosets.getPhotos */ |
614 | _this.flickr_failure(x,s,c,m); | 634 | _this.flickr_failure(x,s,c,m); |
615 | } | 635 | } |
616 | ); | 636 | ); |
617 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ | 637 | }, function(x,s,c,m) { /* flickr.photosets.editMeta */ |
618 | _this.flickr_failure(x,s,c,m); | 638 | _this.flickr_failure(x,s,c,m); |
619 | } | 639 | } |
620 | ); | 640 | ); |
621 | } | 641 | } |
622 | }, | 642 | }, |
623 | on_refresh_sets: function() { | 643 | on_refresh_sets: function() { |
624 | this.refresh_sets(); | 644 | this.refresh_sets(); |
625 | }, | 645 | }, |
626 | on_cmd_sets_html: function(csfx,ev) { | 646 | on_cmd_sets_html: function(csfx,ev) { |
627 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 647 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
628 | var rv = this.build_html(this.photoset.photos,uti,utl); | 648 | var rv = this.build_html(this.photoset.photos,uti,utl); |
629 | this.popup_content(rv); | 649 | this.popup_content(rv); |
630 | }, | 650 | }, |
631 | 651 | ||
632 | on_cmd_uploads_html: function(csfx,ev) { | 652 | on_cmd_uploads_html: function(csfx,ev) { |
633 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); | 653 | var uti = csfx.charAt(0); var utl = csfx.charAt(1); |
634 | var pids = new Array(); | 654 | var pids = new Array(); |
635 | for(var f in this.uploads.files) { | 655 | for(var f in this.uploads.files) { |
636 | if(this.uploads.selection.isSelected(f)) | 656 | if(this.uploads.selection.isSelected(f)) |
637 | if(this.uploads.files[f].photoid) | 657 | if(this.uploads.files[f].photoid) |
638 | pids.push(this.uploads.files[f].photoid); | 658 | pids.push(this.uploads.files[f].photoid); |
639 | } | 659 | } |
640 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; | 660 | var pp = this.uploads.rowCount*2; if(pp>500) pp = 500; |
641 | var _this = this; | 661 | var _this = this; |
642 | this.flickr.api_call( | 662 | this.flickr.api_call( |
643 | { | 663 | { |
644 | method: 'flickr.photos.search', | 664 | method: 'flickr.photos.search', |
645 | auth_token: 'default', | 665 | auth_token: 'default', |
646 | extras: 'original_format', | 666 | extras: 'original_format', |
647 | user_id: 'me', | 667 | user_id: 'me', |
648 | per_page: pp | 668 | per_page: pp |
649 | }, | 669 | }, |
650 | function(xr) { | 670 | function(xr) { |
651 | var x = xr.responseXML; | 671 | var x = xr.responseXML; |
652 | var rv = ''; | 672 | var rv = ''; |
653 | for(var pn in pids) { | 673 | for(var pn in pids) { |
654 | var p = pids[pn]; | 674 | var p = pids[pn]; |
655 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); | 675 | var pp = new Photo(xp_node('/rsp/photos/photo[@id='+p+']',x)); |
656 | rv += _this.photo_html(pp,uti,utl)+'\n'; | 676 | rv += _this.photo_html(pp,uti,utl)+'\n'; |
657 | } | 677 | } |
658 | _this.popup_content(rv); | 678 | _this.popup_content(rv); |
659 | }, function(x,s,c,m) { | 679 | }, function(x,s,c,m) { |
660 | _this.flickr_failure(x,s,c,m); | 680 | _this.flickr_failure(x,s,c,m); |
661 | } | 681 | } |
662 | ); | 682 | ); |
663 | }, | 683 | }, |
664 | 684 | ||
665 | /* | 685 | /* |
666 | * | 686 | * |
667 | */ | 687 | */ |
668 | foundphotos: { | 688 | foundphotos: { |
669 | fireflix: null, | 689 | fireflix: null, |
670 | init: function(f) { | 690 | init: function(f) { |
671 | this.fireflix = f; | 691 | this.fireflix = f; |
672 | this.search_for = document.getElementById('search_for'); | 692 | this.search_for = document.getElementById('search_for'); |
673 | this.search_tags= document.getElementById('search_tags'); | 693 | this.search_tags= document.getElementById('search_tags'); |
674 | this.search_mine = document.getElementById('search_mine'); | 694 | this.search_mine = document.getElementById('search_mine'); |
675 | document.getElementById('searchresults').view = this; | 695 | document.getElementById('searchresults').view = this; |
676 | this.searchresult_props = document.getElementById('searchresult_props'); | 696 | this.searchresult_props = document.getElementById('searchresult_props'); |
677 | this.search_photo = document.getElementById('search_photo'); | 697 | this.search_photo = document.getElementById('search_photo'); |
678 | this.searchresult_title = document.getElementById('searchresult_title'); | 698 | this.searchresult_title = document.getElementById('searchresult_title'); |
679 | this.searchresult_description = document.getElementById('searchresult_description'); | 699 | this.searchresult_description = document.getElementById('searchresult_description'); |
680 | }, | 700 | }, |
681 | photos: new Array(), | 701 | photos: new Array(), |
682 | rowCount: 0, | 702 | rowCount: 0, |
683 | getCellText: function(r,c) { | 703 | getCellText: function(r,c) { |
684 | var p = this.photos[r]; | 704 | var p = this.photos[r]; |
685 | if(c.id=='sr_title') return p.title; | 705 | if(c.id=='sr_title') return p.title; |
686 | return c.id; | 706 | return c.id; |
687 | }, | 707 | }, |
688 | setTree: function(t) { this.tree = t }, | 708 | setTree: function(t) { this.tree = t }, |
689 | isContainer: function(r) { return false }, | 709 | isContainer: function(r) { return false }, |
690 | isSeparator: function(r) { return false }, | 710 | isSeparator: function(r) { return false }, |
691 | isSorted: function(r) { return false }, | 711 | isSorted: function(r) { return false }, |
692 | getLevel: function(r) { return 0 }, | 712 | getLevel: function(r) { return 0 }, |
693 | getImageSrc: function(r,c) { return null }, | 713 | getImageSrc: function(r,c) { return null }, |
694 | getRowProperties: function(r,p) { }, | 714 | getRowProperties: function(r,p) { }, |
695 | getCellProperties: function(cid,cel,p) { }, | 715 | getCellProperties: function(cid,cel,p) { }, |
696 | getColumnProperties: function(cid,cel,p) { }, | 716 | getColumnProperties: function(cid,cel,p) { }, |
697 | cycleHeader: function(cid,e) { }, | 717 | cycleHeader: function(cid,e) { }, |
698 | getParentIndex: function(r) { return -1 }, | 718 | getParentIndex: function(r) { return -1 }, |
699 | drop: function(r,o) { }, | 719 | drop: function(r,o) { }, |
700 | canDropBeforeAfter: function(r,b) { return false }, | 720 | canDropBeforeAfter: function(r,b) { return false }, |
701 | 721 | ||
702 | importXPR: function(xp) { | 722 | importXPR: function(xp) { |
703 | this.selection.clearSelection(); | 723 | this.selection.clearSelection(); |
704 | this.selection.currentIndex = -1; | 724 | this.selection.currentIndex = -1; |
705 | this.searchresult_props.hidden = true; | 725 | this.searchresult_props.hidden = true; |
706 | this.tree.beginUpdateBatch(); | 726 | this.tree.beginUpdateBatch(); |
707 | this.photos = new Array(); | 727 | this.photos = new Array(); |
708 | var n; while(n=xp.iterateNext()) { | 728 | var n; while(n=xp.iterateNext()) { |
709 | this.photos.push(new Photo(n)); | 729 | this.photos.push(new Photo(n)); |
710 | } | 730 | } |
711 | this.rowCount = this.photos.length; | 731 | this.rowCount = this.photos.length; |
712 | this.tree.endUpdateBatch(); | 732 | this.tree.endUpdateBatch(); |
713 | }, | 733 | }, |
714 | search_photos: function() { | 734 | search_photos: function() { |
715 | var pars = { | 735 | var pars = { |
716 | method: 'flickr.photos.search', | 736 | method: 'flickr.photos.search', |
717 | auth_token: 'default', | 737 | auth_token: 'default', |
718 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' | 738 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo' |
719 | }; | 739 | }; |
720 | if(this.search_mine.checked) | 740 | if(this.search_mine.checked) |
721 | pars.user_id='me'; | 741 | pars.user_id='me'; |
722 | if(this.search_tags.checked) { | 742 | if(this.search_tags.checked) { |
723 | pars.tags=this.search_for.value.split(/ +/).join(','); | 743 | pars.tags=this.search_for.value.split(/ +/).join(','); |
724 | }else{ | 744 | }else{ |
725 | pars.text=this.search_for.value; | 745 | pars.text=this.search_for.value; |
726 | } | 746 | } |
727 | var _this = this; | 747 | var _this = this; |
728 | this.fireflix.flickr.api_call( pars, | 748 | this.fireflix.flickr.api_call( pars, |
729 | function(xr) { | 749 | function(xr) { |
730 | var x = xr.responseXML; | 750 | var x = xr.responseXML; |
731 | var xp = x.evaluate( | 751 | var xp = x.evaluate( |
732 | '/rsp/photos/photo', x, null, | 752 | '/rsp/photos/photo', x, null, |
733 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 753 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
734 | _this.importXPR(xp); | 754 | _this.importXPR(xp); |
735 | _this.on_select(); | 755 | _this.on_select(); |
736 | }, function(x,s,c,m) { | 756 | }, function(x,s,c,m) { |
737 | _this.fireflix.flickr_failure(x,s,c,m); | 757 | _this.fireflix.flickr_failure(x,s,c,m); |
738 | } | 758 | } |
739 | ); | 759 | ); |
740 | }, | 760 | }, |
741 | on_select: function() { | 761 | on_select: function() { |
742 | if(this.selection.currentIndex<0) { | 762 | if(this.selection.currentIndex<0) { |
743 | this.searchresult_props.hidden = true; | 763 | this.searchresult_props.hidden = true; |
744 | }else{ | 764 | }else{ |
745 | var p = this.photos[this.selection.currentIndex]; | 765 | var p = this.photos[this.selection.currentIndex]; |
746 | if(!p) { | 766 | if(!p) { |
747 | this.searchresult_props.hidden = true; | 767 | this.searchresult_props.hidden = true; |
748 | }else{ | 768 | }else{ |
749 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); | 769 | this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t'); |
750 | this.searchresult_title.value = p.title; | 770 | this.searchresult_title.value = p.title; |
751 | this.searchresult_description.value = null; | 771 | this.searchresult_description.value = null; |
752 | if(p.description==null && p.description==undefined) { | 772 | if(p.description==null && p.description==undefined) { |
753 | var pid = p.id; | 773 | var pid = p.id; |
754 | var ci = this.selection.currentIndex; | 774 | var ci = this.selection.currentIndex; |
755 | var _this = this; | 775 | var _this = this; |
756 | this.fireflix.flickr.api_call( | 776 | this.fireflix.flickr.api_call( |
757 | { | 777 | { |
758 | method: 'flickr.photos.getInfo', | 778 | method: 'flickr.photos.getInfo', |
759 | auth_token: 'default', | 779 | auth_token: 'default', |
760 | photo_id: p.id, | 780 | photo_id: p.id, |
761 | secret: p.secret | 781 | secret: p.secret |
762 | }, function(xr) { | 782 | }, function(xr) { |
763 | var pp = _this.photos[ci]; | 783 | var pp = _this.photos[ci]; |
764 | if(ci==_this.selection.currentIndex && pp.id==pid) { | 784 | if(ci==_this.selection.currentIndex && pp.id==pid) { |
765 | var n = xp_node('/rsp/photo',xr.responseXML); | 785 | var n = xp_node('/rsp/photo',xr.responseXML); |
766 | pp.fromNode_(n); | 786 | pp.fromNode_(n); |
767 | _this.searchresult_description.value=pp.description?pp.description:null; | 787 | _this.searchresult_description.value=pp.description?pp.description:null; |
768 | } | 788 | } |
769 | }, function(x,s,c,m) { | 789 | }, function(x,s,c,m) { |
770 | _this.fireflix.flickr_failure(x,s,c,m); | 790 | _this.fireflix.flickr_failure(x,s,c,m); |
771 | } | 791 | } |
772 | ); | 792 | ); |
773 | this.searchresult_props.hidden = false; | 793 | this.searchresult_props.hidden = false; |
774 | }else{ | 794 | }else{ |
775 | this.searchresult_description.value=p.description?p.description:null; | 795 | this.searchresult_description.value=p.description?p.description:null; |
776 | } | 796 | } |
777 | } | 797 | } |
778 | } | 798 | } |
779 | }, | 799 | }, |
780 | on_cmd_open: function(ev) { | 800 | on_cmd_open: function(ev) { |
781 | if(this.selection.currentIndex<0) | 801 | if(this.selection.currentIndex<0) |
782 | return; | 802 | return; |
783 | var p = this.photos[this.selection.currentIndex]; | 803 | var p = this.photos[this.selection.currentIndex]; |
784 | if(!p.id) | 804 | if(!p.id) |
785 | return; | 805 | return; |
786 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); | 806 | this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p')); |
787 | } | 807 | } |
788 | }, | 808 | }, |
789 | 809 | ||
790 | photo_html: function(p,i,l) { | 810 | photo_html: function(p,i,l) { |
791 | // TODO: add alt/title when possible | 811 | // TODO: add alt/title when possible |
792 | var rv = | 812 | var rv = |
793 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + | 813 | '<a href="'+this.flickr.make_photo_url(p,l)+'">' + |
794 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ | 814 | '<img src="'+this.flickr.make_photo_url(p,i)+'" />'+ |
795 | '</a>'; | 815 | '</a>'; |
796 | return rv; | 816 | return rv; |
797 | }, | 817 | }, |
798 | build_html: function(photos,uti,utl) { | 818 | build_html: function(photos,uti,utl) { |
799 | var rv = ''; | 819 | var rv = ''; |
800 | for(var i in photos) { | 820 | for(var i in photos) { |
801 | var p = photos[i]; | 821 | var p = photos[i]; |
802 | rv += this.photo_html(p,utl,uti)+'\n'; | 822 | rv += this.photo_html(p,utl,uti)+'\n'; |
803 | } | 823 | } |
804 | return rv; | 824 | return rv; |
805 | }, | 825 | }, |
806 | 826 | ||
807 | popup_content: function(s) { | 827 | popup_content: function(s) { |
808 | window.openDialog( | 828 | window.openDialog( |
809 | "chrome://fireflix/content/generated-content.xul", | 829 | "chrome://fireflix/content/generated-content.xul", |
810 | null, "dialog,chrome", this, s ); | 830 | null, "dialog,chrome", this, s ); |
811 | }, | 831 | }, |
812 | copy_to_clipboard: function(s) { | 832 | copy_to_clipboard: function(s) { |
813 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] | 833 | var ch = Components.classes["@mozilla.org/widget/clipboardhelper;1"] |
814 | .getService(Components.interfaces.nsIClipboardHelper); | 834 | .getService(Components.interfaces.nsIClipboardHelper); |
815 | ch.copyString(s); | 835 | ch.copyString(s); |
816 | }, | 836 | }, |
817 | openTab: function(l) { | 837 | openTab: function(l) { |
818 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( | 838 | var wm = Components.classes['@mozilla.org/appshell/window-mediator;1'].getService( |
819 | Components.interfaces.nsIWindowMediator ); | 839 | Components.interfaces.nsIWindowMediator ); |
820 | var bw = wm.getMostRecentWindow('navigator:browser'); | 840 | var bw = wm.getMostRecentWindow('navigator:browser'); |
821 | var b = bw.getBrowser(); | 841 | var b = bw.getBrowser(); |
822 | var t = b.addTab(l); | 842 | var t = b.addTab(l); |
823 | b.selectedTab = t; | 843 | b.selectedTab = t; |
824 | }, | 844 | }, |
825 | 845 | ||
826 | build_menus: function() { | 846 | build_menus: function() { |
827 | this.append_html_menu( | 847 | this.append_html_menu( |
828 | document.getElementById('sets_html_menu'), | 848 | document.getElementById('sets_html_menu'), |
829 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' | 849 | 'stm_','m_bop','cmdset_sets','cmd_sets_html' |
830 | ); | 850 | ); |
831 | this.append_html_menu( | 851 | this.append_html_menu( |
832 | document.getElementById('uploads_html_menu'), | 852 | document.getElementById('uploads_html_menu'), |
833 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' | 853 | 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' |
834 | ); | 854 | ); |
835 | return; | 855 | return; |
836 | }, | 856 | }, |
837 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { | 857 | append_html_menu: function(m,imgt,lnkt,csid,cpfx) { |
838 | var mp = m.appendChild(document.createElement('menupopup')); | 858 | var mp = m.appendChild(document.createElement('menupopup')); |
839 | var t; | 859 | var t; |
840 | t=mp.appendChild(document.createElement('menuitem')); | 860 | t=mp.appendChild(document.createElement('menuitem')); |
841 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); | 861 | t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); |
842 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 862 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
843 | mp.appendChild(document.createElement('menuseparator')); | 863 | mp.appendChild(document.createElement('menuseparator')); |
844 | var cs = document.getElementById(csid); | 864 | var cs = document.getElementById(csid); |
845 | for(var iti=0;iti<imgt.length;++iti) { | 865 | for(var iti=0;iti<imgt.length;++iti) { |
846 | t = mp.appendChild(document.createElement('menu')); | 866 | t = mp.appendChild(document.createElement('menu')); |
847 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); | 867 | t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); |
848 | var smp = t.appendChild(document.createElement('menupopup')); | 868 | var smp = t.appendChild(document.createElement('menupopup')); |
849 | t=smp.appendChild(document.createElement('menuitem')); | 869 | t=smp.appendChild(document.createElement('menuitem')); |
850 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); | 870 | t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); |
851 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); | 871 | t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); |
852 | smp.appendChild(document.createElement('menuseparator')); | 872 | smp.appendChild(document.createElement('menuseparator')); |
853 | for(var lti=0;lti<lnkt.length;++lti) { | 873 | for(var lti=0;lti<lnkt.length;++lti) { |
854 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); | 874 | var csfx = imgt.charAt(iti)+lnkt.charAt(lti); |
855 | t=smp.appendChild(document.createElement('menuitem')); | 875 | t=smp.appendChild(document.createElement('menuitem')); |
856 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); | 876 | t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); |
857 | t.setAttribute('command',cpfx+'_'+csfx); | 877 | t.setAttribute('command',cpfx+'_'+csfx); |
858 | t=cs.appendChild(document.createElement('command')); | 878 | t=cs.appendChild(document.createElement('command')); |
859 | t.setAttribute('id',cpfx+'_'+csfx); | 879 | t.setAttribute('id',cpfx+'_'+csfx); |
860 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); | 880 | t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); |
861 | } | 881 | } |
862 | } | 882 | } |
863 | return mp; | 883 | return mp; |
864 | }, | 884 | }, |
865 | 885 | ||
866 | flickr_failure: function(x,s,c,m) { | 886 | flickr_failure: function(x,s,c,m) { |
867 | if(c==98) { // Invalid auth token | 887 | if(c==98) { // Invalid auth token |
868 | this.flickr.reset_token(); | 888 | this.flickr.reset_token(); |
869 | document.getElementById('auth_info').value = this.no_auth_info_label; | 889 | this.set_auth_state(false,false); |
870 | document.getElementById('auth_info').disabled = true; | ||
871 | document.getElementById('b_auth').hidden = false; | ||
872 | return; | 890 | return; |
873 | } | 891 | } |
874 | // TODO: is that beauty | 892 | // TODO: is that beauty? |
875 | alert('flickr api call failed\n'+c+' '+m); | 893 | alert('flickr api call failed\n'+c+' '+m); |
876 | } | 894 | } |
877 | 895 | ||
878 | }; | 896 | }; |