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