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