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