author | Michael Krelin <hacker@klever.net> | 2006-11-12 22:09:39 (UTC) |
---|---|---|
committer | Michael Krelin <hacker@klever.net> | 2006-11-12 22:09:39 (UTC) |
commit | afcae0d9514f35c96484e6db1eb21e76821b5654 (patch) (unidiff) | |
tree | 09f24641d6d156e4592778813cbeda62ce03eded | |
parent | 41d39823cf8a9e08ad17b9863e5e3ed88df0ac4e (diff) | |
download | fireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.zip fireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.tar.gz fireflix-afcae0d9514f35c96484e6db1eb21e76821b5654.tar.bz2 |
display human readable picture upload time
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@215 fe716a7a-6dde-0310-88d9-d003556173a8
-rw-r--r-- | content/fireflix.js | 8 |
1 files changed, 7 insertions, 1 deletions
diff --git a/content/fireflix.js b/content/fireflix.js index 85b4d39..a4f13b6 100644 --- a/content/fireflix.js +++ b/content/fireflix.js | |||
@@ -1,232 +1,238 @@ | |||
1 | function splitascii(s) { | 1 | function splitascii(s) { |
2 | var rv=''; | 2 | var rv=''; |
3 | for(var i=0;i<s.length;++i) { | 3 | for(var i=0;i<s.length;++i) { |
4 | var w = s.charCodeAt(i); | 4 | var w = s.charCodeAt(i); |
5 | rv += String.fromCharCode( | 5 | rv += String.fromCharCode( |
6 | w&0xff, (w>>8)&0xff ); | 6 | w&0xff, (w>>8)&0xff ); |
7 | } | 7 | } |
8 | return rv; | 8 | return rv; |
9 | } | 9 | } |
10 | 10 | ||
11 | 11 | ||
12 | var fireflix = { | 12 | var fireflix = { |
13 | flickr: new Flickr(), | 13 | flickr: new Flickr(), |
14 | init: function() { | 14 | init: function() { |
15 | pull_elements(this,document,[ | 15 | pull_elements(this,document,[ |
16 | 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', | 16 | 'cmd_auth_auth','cmd_auth_done','cmd_auth_unauth', |
17 | 'menu_auth_done','b_auth','b_auth_done','auth_info', | 17 | 'menu_auth_done','b_auth','b_auth_done','auth_info', |
18 | 'loc_strings','cmd_set_props' | 18 | 'loc_strings','cmd_set_props' |
19 | ]); | 19 | ]); |
20 | this.build_menus(); | 20 | this.build_menus(); |
21 | this.foundphotos.init(this); | 21 | this.foundphotos.init(this); |
22 | this.photosets.init(this); | 22 | this.photosets.init(this); |
23 | this.photoset.init(this); | 23 | this.photoset.init(this); |
24 | this.uploads.init(this); | 24 | this.uploads.init(this); |
25 | this.uploadObserver.init(this); | 25 | this.uploadObserver.init(this); |
26 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; | 26 | this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; |
27 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; | 27 | this.flickr.api_shs = '9c33c9e2f0f0cfd5'; |
28 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; | 28 | this.flickr.prefs_root = 'net.klever.kin.fireflix'; |
29 | this.flickr.load_token(); | 29 | this.flickr.load_token(); |
30 | this.no_auth_info_label = this.auth_info.value; | 30 | this.no_auth_info_label = this.auth_info.value; |
31 | this.set_auth_state(this.flickr.token,false); | 31 | this.set_auth_state(this.flickr.token,false); |
32 | if(this.flickr.token) { | 32 | if(this.flickr.token) { |
33 | this.refresh_stuff(); | 33 | this.refresh_stuff(); |
34 | }else{ | 34 | }else{ |
35 | this.on_cmd_auth(); | 35 | this.on_cmd_auth(); |
36 | } | 36 | } |
37 | }, | 37 | }, |
38 | set_auth_state: function(au,inp) { /* authorized, in progress */ | 38 | set_auth_state: function(au,inp) { /* authorized, in progress */ |
39 | this.cmd_auth_unauth.disabled = !au; | 39 | this.cmd_auth_unauth.disabled = !au; |
40 | this.b_auth.hidden = au || inp; | 40 | this.b_auth.hidden = au || inp; |
41 | this.b_auth_done.hidden = !inp; | 41 | this.b_auth_done.hidden = !inp; |
42 | this.menu_auth_done.hidden = !inp; | 42 | this.menu_auth_done.hidden = !inp; |
43 | this.cmd_auth_done.setAttribute('disabled',!inp); | 43 | this.cmd_auth_done.setAttribute('disabled',!inp); |
44 | this.auth_info.disabled = !au; | 44 | this.auth_info.disabled = !au; |
45 | if(au) { | 45 | if(au) { |
46 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ | 46 | this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */ |
47 | }else{ | 47 | }else{ |
48 | this.auth_info.value = this.no_auth_info_label; | 48 | this.auth_info.value = this.no_auth_info_label; |
49 | } | 49 | } |
50 | }, | 50 | }, |
51 | on_cmd_auth: function() { | 51 | on_cmd_auth: function() { |
52 | var _this = this; | 52 | var _this = this; |
53 | this.flickr.authorize_0( | 53 | this.flickr.authorize_0( |
54 | 'delete', | 54 | 'delete', |
55 | function(x,f,u) { | 55 | function(x,f,u) { |
56 | _this.openTab(u); | 56 | _this.openTab(u); |
57 | _this.set_auth_state(_this.flickr.token,true); | 57 | _this.set_auth_state(_this.flickr.token,true); |
58 | }, function(x,s,c,m) { | 58 | }, function(x,s,c,m) { |
59 | _this.flickr_failure(x,s,c,m); | 59 | _this.flickr_failure(x,s,c,m); |
60 | } | 60 | } |
61 | ); | 61 | ); |
62 | }, | 62 | }, |
63 | on_cmd_auth_done: function() { | 63 | on_cmd_auth_done: function() { |
64 | this.set_auth_state(this.flickr.token,false); | 64 | this.set_auth_state(this.flickr.token,false); |
65 | var _this = this; | 65 | var _this = this; |
66 | this.flickr.authorize_1( | 66 | this.flickr.authorize_1( |
67 | function() { | 67 | function() { |
68 | _this.flickr.save_token(); | 68 | _this.flickr.save_token(); |
69 | _this.refresh_stuff(); | 69 | _this.refresh_stuff(); |
70 | _this.set_auth_state(_this.flickr.token,false); | 70 | _this.set_auth_state(_this.flickr.token,false); |
71 | _this.auth_info.value = | 71 | _this.auth_info.value = |
72 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; | 72 | _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; |
73 | }, function(x,s,c,m) { | 73 | }, function(x,s,c,m) { |
74 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ | 74 | _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */ |
75 | _this.flickr_failure(x,s,c,m); | 75 | _this.flickr_failure(x,s,c,m); |
76 | } | 76 | } |
77 | ); | 77 | ); |
78 | }, | 78 | }, |
79 | on_cmd_auth_unauth: function() { | 79 | on_cmd_auth_unauth: function() { |
80 | this.flickr.reset_token(); | 80 | this.flickr.reset_token(); |
81 | this.set_auth_state(false,false); | 81 | this.set_auth_state(false,false); |
82 | }, | 82 | }, |
83 | 83 | ||
84 | refresh_sets: function() { this.photosets.refresh_sets(); }, | 84 | refresh_sets: function() { this.photosets.refresh_sets(); }, |
85 | refresh_stuff: function() { | 85 | refresh_stuff: function() { |
86 | this.refresh_sets(); | 86 | this.refresh_sets(); |
87 | this.refresh_user_tags(); | 87 | this.refresh_user_tags(); |
88 | }, | 88 | }, |
89 | 89 | ||
90 | /* photoset treeview */ | 90 | /* photoset treeview */ |
91 | photoset: { | 91 | photoset: { |
92 | photos: new Array(), | 92 | photos: new Array(), |
93 | fireflix: null, | 93 | fireflix: null, |
94 | init: function(f) { | 94 | init: function(f) { |
95 | this.fireflix = f; | 95 | this.fireflix = f; |
96 | pull_elements(this,document,[ 'set_photo' ]); | 96 | pull_elements(this,document,[ 'set_photo' ]); |
97 | document.getElementById('setphotos').view = this; | 97 | document.getElementById('setphotos').view = this; |
98 | }, | 98 | }, |
99 | rowCount: 0, | 99 | rowCount: 0, |
100 | getCellText: function(r,c) { | 100 | getCellText: function(r,c) { |
101 | var p = this.photos[r]; | 101 | var p = this.photos[r]; |
102 | if(c.id=='sp_title') return p.title; | 102 | if(c.id=='sp_title') return p.title; |
103 | if(c.id=='sp_taken') return p.datetaken; | 103 | if(c.id=='sp_taken') return p.datetaken; |
104 | if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ | 104 | if(c.id=='sp_upload') { |
105 | var du = new Date(p.dateupload*1000); | ||
106 | var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate() | ||
107 | +' '+ | ||
108 | du.getHours()+':'+du.getMinutes()+':'+du.getSeconds(); | ||
109 | return rv.replace(/(\D)(\d)(\D)/,'$10$2$3'); | ||
110 | } | ||
105 | return c.id; | 111 | return c.id; |
106 | }, | 112 | }, |
107 | setTree: function(t) { this.tree = t }, | 113 | setTree: function(t) { this.tree = t }, |
108 | isContainer: function(r) { return false; }, | 114 | isContainer: function(r) { return false; }, |
109 | isSeparator: function(r) { return false; }, | 115 | isSeparator: function(r) { return false; }, |
110 | isSorted: function(r) { return false; }, | 116 | isSorted: function(r) { return false; }, |
111 | getLevel: function(r) { return 0; }, | 117 | getLevel: function(r) { return 0; }, |
112 | getImageSrc: function(r,c) { return null }, | 118 | getImageSrc: function(r,c) { return null }, |
113 | getRowProperties: function(r,p) {}, | 119 | getRowProperties: function(r,p) {}, |
114 | getCellProperties: function(cid,cel,p) {}, | 120 | getCellProperties: function(cid,cel,p) {}, |
115 | getColumnProperties: function(cid,cel,p) { }, | 121 | getColumnProperties: function(cid,cel,p) { }, |
116 | cycleHeader: function(cid,e) { }, | 122 | cycleHeader: function(cid,e) { }, |
117 | getParentIndex: function(r) { return -1; }, | 123 | getParentIndex: function(r) { return -1; }, |
118 | drop: function(r,o) { }, | 124 | drop: function(r,o) { }, |
119 | canDropBeforeAfter: function(r,b) { return false }, | 125 | canDropBeforeAfter: function(r,b) { return false }, |
120 | 126 | ||
121 | importXPR: function(xp) { | 127 | importXPR: function(xp) { |
122 | this.tree.beginUpdateBatch(); | 128 | this.tree.beginUpdateBatch(); |
123 | this.photos = new Array(); | 129 | this.photos = new Array(); |
124 | var n; while(n=xp.iterateNext()) { | 130 | var n; while(n=xp.iterateNext()) { |
125 | this.photos.push(new Photo(n)); | 131 | this.photos.push(new Photo(n)); |
126 | } | 132 | } |
127 | this.rowCount = this.photos.length; | 133 | this.rowCount = this.photos.length; |
128 | this.tree.endUpdateBatch(); | 134 | this.tree.endUpdateBatch(); |
129 | }, | 135 | }, |
130 | load_photos: function(psid) { | 136 | load_photos: function(psid) { |
131 | var _this = this; | 137 | var _this = this; |
132 | this.fireflix.flickr.api_call( | 138 | this.fireflix.flickr.api_call( |
133 | { | 139 | { |
134 | method: 'flickr.photosets.getPhotos', | 140 | method: 'flickr.photosets.getPhotos', |
135 | auth_token: 'default', | 141 | auth_token: 'default', |
136 | photoset_id: psid, | 142 | photoset_id: psid, |
137 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' | 143 | extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update' |
138 | }, function(xr) { | 144 | }, function(xr) { |
139 | var x = xr.responseXML; | 145 | var x = xr.responseXML; |
140 | var xp = x.evaluate( | 146 | var xp = x.evaluate( |
141 | '/rsp/photoset/photo', x, null, | 147 | '/rsp/photoset/photo', x, null, |
142 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 148 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
143 | _this.importXPR(xp); | 149 | _this.importXPR(xp); |
144 | }, function(x,s,c,m) { | 150 | }, function(x,s,c,m) { |
145 | _this.fireflix.flickr_failure(x,s,c,m); | 151 | _this.fireflix.flickr_failure(x,s,c,m); |
146 | } | 152 | } |
147 | ); | 153 | ); |
148 | }, | 154 | }, |
149 | on_select: function() { | 155 | on_select: function() { |
150 | if(this.selection.count==1) { | 156 | if(this.selection.count==1) { |
151 | var p = this.photos[this.selection.currentIndex]; | 157 | var p = this.photos[this.selection.currentIndex]; |
152 | this.set_photo.src = | 158 | this.set_photo.src = |
153 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); | 159 | this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t'); |
154 | this.set_photo.hidden = false; | 160 | this.set_photo.hidden = false; |
155 | }else{ | 161 | }else{ |
156 | this.set_photo.hidden = true; | 162 | this.set_photo.hidden = true; |
157 | } | 163 | } |
158 | } | 164 | } |
159 | }, | 165 | }, |
160 | 166 | ||
161 | /* photosets treeview */ | 167 | /* photosets treeview */ |
162 | photosets: { | 168 | photosets: { |
163 | sets: new Array(), | 169 | sets: new Array(), |
164 | fireflix: null, | 170 | fireflix: null, |
165 | init: function(f) { | 171 | init: function(f) { |
166 | this.fireflix = f; | 172 | this.fireflix = f; |
167 | document.getElementById('setslist').view = this; | 173 | document.getElementById('setslist').view = this; |
168 | }, | 174 | }, |
169 | rowCount: 0, | 175 | rowCount: 0, |
170 | getCellText: function(r,c) { | 176 | getCellText: function(r,c) { |
171 | var s = this.sets[r]; | 177 | var s = this.sets[r]; |
172 | if(c.id=='sl_name') return s.title; | 178 | if(c.id=='sl_name') return s.title; |
173 | if(c.id=='sl_photos') return s.photos; | 179 | if(c.id=='sl_photos') return s.photos; |
174 | return c.id; | 180 | return c.id; |
175 | }, | 181 | }, |
176 | setTree: function(t) { this.tree = t }, | 182 | setTree: function(t) { this.tree = t }, |
177 | isContainer: function(r) { return false; }, | 183 | isContainer: function(r) { return false; }, |
178 | isSeparator: function(r) { return false; }, | 184 | isSeparator: function(r) { return false; }, |
179 | isSorted: function() { return false; }, | 185 | isSorted: function() { return false; }, |
180 | getLevel: function(r) { return 0; }, | 186 | getLevel: function(r) { return 0; }, |
181 | getImageSrc: function(r,c) { return null }, | 187 | getImageSrc: function(r,c) { return null }, |
182 | getRowProperties: function(r,p) {}, | 188 | getRowProperties: function(r,p) {}, |
183 | getCellProperties: function(cid,cel,p) { }, | 189 | getCellProperties: function(cid,cel,p) { }, |
184 | getColumnProperties: function(cid,cel,p) { }, | 190 | getColumnProperties: function(cid,cel,p) { }, |
185 | cycleHeader: function(cid,e) { }, | 191 | cycleHeader: function(cid,e) { }, |
186 | getParentIndex: function(r) { return -1; }, | 192 | getParentIndex: function(r) { return -1; }, |
187 | drop: function(r,o) { }, | 193 | drop: function(r,o) { }, |
188 | canDropBeforeAfter: function(r,b) { return false }, | 194 | canDropBeforeAfter: function(r,b) { return false }, |
189 | 195 | ||
190 | importXPR: function(xp) { | 196 | importXPR: function(xp) { |
191 | this.tree.beginUpdateBatch(); | 197 | this.tree.beginUpdateBatch(); |
192 | this.sets = new Array(); | 198 | this.sets = new Array(); |
193 | var n; while(n=xp.iterateNext()) { | 199 | var n; while(n=xp.iterateNext()) { |
194 | this.sets.push(new Photoset(n)); | 200 | this.sets.push(new Photoset(n)); |
195 | } | 201 | } |
196 | this.rowCount = this.sets.length; | 202 | this.rowCount = this.sets.length; |
197 | this.tree.endUpdateBatch(); | 203 | this.tree.endUpdateBatch(); |
198 | }, | 204 | }, |
199 | refresh_sets: function() { | 205 | refresh_sets: function() { |
200 | var _this = this; | 206 | var _this = this; |
201 | this.fireflix.flickr.api_call( | 207 | this.fireflix.flickr.api_call( |
202 | { | 208 | { |
203 | method: 'flickr.photosets.getList', | 209 | method: 'flickr.photosets.getList', |
204 | auth_token: 'default' | 210 | auth_token: 'default' |
205 | }, function(xr) { | 211 | }, function(xr) { |
206 | var x = xr.responseXML; | 212 | var x = xr.responseXML; |
207 | var xp = x.evaluate( | 213 | var xp = x.evaluate( |
208 | '/rsp/photosets/photoset', x, null, | 214 | '/rsp/photosets/photoset', x, null, |
209 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); | 215 | XPathResult.ORDERED_NODE_ITERATOR_TYPE, null ); |
210 | _this.importXPR(xp); | 216 | _this.importXPR(xp); |
211 | }, function(x,s,c,m) { | 217 | }, function(x,s,c,m) { |
212 | _this.fireflix.flickr_failure(x,s,c,m); | 218 | _this.fireflix.flickr_failure(x,s,c,m); |
213 | } | 219 | } |
214 | ); | 220 | ); |
215 | }, | 221 | }, |
216 | on_select: function() { | 222 | on_select: function() { |
217 | if(this.selection.count==1) { | 223 | if(this.selection.count==1) { |
218 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); | 224 | this.fireflix.cmd_set_props.setAttribute('disabled','false'); |
219 | var s = this.sets[this.selection.currentIndex]; | 225 | var s = this.sets[this.selection.currentIndex]; |
220 | this.fireflix.photoset.load_photos(s.id); | 226 | this.fireflix.photoset.load_photos(s.id); |
221 | }else{ | 227 | }else{ |
222 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); | 228 | this.fireflix.cmd_set_props.setAttribute('disabled','true'); |
223 | } | 229 | } |
224 | } | 230 | } |
225 | }, | 231 | }, |
226 | 232 | ||
227 | refresh_user_tags: function() { | 233 | refresh_user_tags: function() { |
228 | var lb = document.getElementById('tagslist'); | 234 | var lb = document.getElementById('tagslist'); |
229 | var _this = this; | 235 | var _this = this; |
230 | this.flickr.api_call( | 236 | this.flickr.api_call( |
231 | { | 237 | { |
232 | method: 'flickr.tags.getListUser', | 238 | method: 'flickr.tags.getListUser', |