summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
authorMichael Krelin <hacker@klever.net>2006-09-28 19:40:39 (UTC)
committer Michael Krelin <hacker@klever.net>2006-09-28 19:40:39 (UTC)
commit438c60c606a15792893c38415d0f405ae21e433d (patch) (unidiff)
treed8a56268d5ebedf8669587af7469fedbe1527154 /content/fireflix.js
parentb62171950ffbbdae7826b1b8cdd4cfd0bde8cc93 (diff)
downloadfireflix-438c60c606a15792893c38415d0f405ae21e433d.zip
fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.gz
fireflix-438c60c606a15792893c38415d0f405ae21e433d.tar.bz2
Better tracking of auth state, added possibility to sign off and reauth
git-svn-id: http://svn.klever.net/kin/fireflix/trunk@164 fe716a7a-6dde-0310-88d9-d003556173a8
Diffstat (limited to 'content/fireflix.js') (more/less context) (ignore whitespace changes)
-rw-r--r--content/fireflix.js52
1 files changed, 35 insertions, 17 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 9518480..82c7b0c 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -1,113 +1,133 @@
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');
16 this.cmd_auth_done = document.getElementById('cmd_auth_done');
17 this.cmd_auth_unauth = document.getElementById('cmd_auth_unauth');
18 this.menu_auth_done = document.getElementById('menu_auth_done');
19 this.b_auth = document.getElementById('b_auth');
20 this.b_auth_done = document.getElementById('b_auth_done');
21 this.auth_info = document.getElementById('auth_info');
15 this.loc_strings = document.getElementById('loc_strings'); 22 this.loc_strings = document.getElementById('loc_strings');
16 this.build_menus(); 23 this.build_menus();
17 this.cmd_set_props = document.getElementById('cmd_set_props'); 24 this.cmd_set_props = document.getElementById('cmd_set_props');
18 this.foundphotos.init(this); 25 this.foundphotos.init(this);
19 this.photosets.init(this); 26 this.photosets.init(this);
20 this.photoset.init(this); 27 this.photoset.init(this);
21 this.uploads.init(this); 28 this.uploads.init(this);
22 this.uploadObserver.init(this); 29 this.uploadObserver.init(this);
23 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3'; 30 this.flickr.api_key = '9c43cd66947a57e6f29db1a9da3f72e3';
24 this.flickr.api_shs = '9c33c9e2f0f0cfd5'; 31 this.flickr.api_shs = '9c33c9e2f0f0cfd5';
25 this.flickr.prefs_root = 'net.klever.kin.fireflix'; 32 this.flickr.prefs_root = 'net.klever.kin.fireflix';
26 this.flickr.load_token(); 33 this.flickr.load_token();
27 document.getElementById('setslist').view = this.photosets; 34 document.getElementById('setslist').view = this.photosets;
28 document.getElementById('setphotos').view = this.photoset; 35 document.getElementById('setphotos').view = this.photoset;
29 document.getElementById('uploadlist').view = this.uploads; 36 document.getElementById('uploadlist').view = this.uploads;
30 this.flickr.no_auth_info_label = document.getElementById('auth_info').value; 37 this.no_auth_info_label = this.auth_info.value;
38 this.set_auth_state(this.flickr.token,false);
31 if(this.flickr.token) { 39 if(this.flickr.token) {
32 this.refresh_stuff(); 40 this.refresh_stuff();
33 document.getElementById('auth_info').value =
34 this.flickr.user.fullname+' ['+this.flickr.user.username+']';
35 document.getElementById('auth_info').disabled = false;
36 document.getElementById('b_auth').hidden = true;
37 } 41 }
38 }, 42 },
39 on_auth: function() { 43 set_auth_state: function(au,inp) { /* authorized, in progress */
44 this.cmd_auth_unauth.disabled = !au;
45 this.b_auth.hidden = au || inp;
46 this.b_auth_done.hidden = !inp;
47 this.menu_auth_done.hidden = !inp;
48 this.cmd_auth_done.setAttribute('disabled',!inp);
49 this.auth_info.disabled = !au;
50 if(au) {
51 this.auth_info.value = this.flickr.user.fullname+' ['+this.flickr.user.username+']'; /* TODO: move to locale */
52 }else{
53 this.auth_info.value = this.no_auth_info_label;
54 }
55 },
56 on_cmd_auth: function() {
40 var _this = this; 57 var _this = this;
41 this.flickr.authorize_0( 58 this.flickr.authorize_0(
42 function() { 59 function() {
43 document.getElementById('b_auth').hidden = true; 60 _this.set_auth_state(_this.flickr.token,true);
44 document.getElementById('b_auth_done').hidden = false;
45 }, function(x,s,c,m) { 61 }, function(x,s,c,m) {
46 _this.flickr_failure(x,s,c,m); 62 _this.flickr_failure(x,s,c,m);
47 } 63 }
48 ); 64 );
49 }, 65 },
50 on_auth_done: function() { 66 on_cmd_auth_done: function() {
51 document.getElementById('b_auth_done').hidden = true; 67 this.set_auth_state(this.flickr.token,false);
52 var _this = this; 68 var _this = this;
53 this.flickr.authorize_1( 69 this.flickr.authorize_1(
54 function() { 70 function() {
55 _this.flickr.save_token(); 71 _this.flickr.save_token();
56 _this.refresh_stuff(); 72 _this.refresh_stuff();
57 document.getElementById('auth_info').value = 73 _this.set_auth_state(_this.flickr.token,false);
74 _this.auth_info.value =
58 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']'; 75 _this.flickr.user.fullname+' ['+_this.flickr.user.username+']';
59 document.getElementById('auth_info').disabled = false;
60 }, function(x,s,c,m) { 76 }, function(x,s,c,m) {
61 document.getElementById('b_auth').hidden = false; 77 _this.set_auth_state(_this.flickr.token,false); /* XXX: no reset token? */
62 _this.flickr_failure(x,s,c,m); 78 _this.flickr_failure(x,s,c,m);
63 } 79 }
64 ); 80 );
65 }, 81 },
82 on_cmd_auth_unauth: function() {
83 this.flickr.reset_token();
84 this.set_auth_state(false,false);
85 },
66 86
67 refresh_sets: function() { this.photosets.refresh_sets(); }, 87 refresh_sets: function() { this.photosets.refresh_sets(); },
68 refresh_stuff: function() { 88 refresh_stuff: function() {
69 this.refresh_sets(); 89 this.refresh_sets();
70 this.refresh_user_tags(); 90 this.refresh_user_tags();
71 }, 91 },
72 92
73 /* photoset treeview */ 93 /* photoset treeview */
74 photoset: { 94 photoset: {
75 photos: new Array(), 95 photos: new Array(),
76 fireflix: null, 96 fireflix: null,
77 init: function(f) { 97 init: function(f) {
78 this.fireflix = f; 98 this.fireflix = f;
79 }, 99 },
80 rowCount: 0, 100 rowCount: 0,
81 getCellText: function(r,c) { 101 getCellText: function(r,c) {
82 var p = this.photos[r]; 102 var p = this.photos[r];
83 if(c.id=='sp_title') return p.title; 103 if(c.id=='sp_title') return p.title;
84 if(c.id=='sp_taken') return p.datetaken; 104 if(c.id=='sp_taken') return p.datetaken;
85 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */ 105 if(c.id=='sp_upload') return p.dateupload; /* TODO: unixtime conversion */
86 return c.id; 106 return c.id;
87 }, 107 },
88 setTree: function(t) { this.tree = t }, 108 setTree: function(t) { this.tree = t },
89 isContainer: function(r) { return false; }, 109 isContainer: function(r) { return false; },
90 isSeparator: function(r) { return false; }, 110 isSeparator: function(r) { return false; },
91 isSorted: function(r) { return false; }, 111 isSorted: function(r) { return false; },
92 getLevel: function(r) { return 0; }, 112 getLevel: function(r) { return 0; },
93 getImageSrc: function(r,c) { return null }, 113 getImageSrc: function(r,c) { return null },
94 getRowProperties: function(r,p) {}, 114 getRowProperties: function(r,p) {},
95 getCellProperties: function(cid,cel,p) {}, 115 getCellProperties: function(cid,cel,p) {},
96 getColumnProperties: function(cid,cel,p) { }, 116 getColumnProperties: function(cid,cel,p) { },
97 cycleHeader: function(cid,e) { }, 117 cycleHeader: function(cid,e) { },
98 getParentIndex: function(r) { return -1; }, 118 getParentIndex: function(r) { return -1; },
99 drop: function(r,o) { }, 119 drop: function(r,o) { },
100 canDropBeforeAfter: function(r,b) { return false }, 120 canDropBeforeAfter: function(r,b) { return false },
101 121
102 importXPR: function(xp) { 122 importXPR: function(xp) {
103 this.tree.beginUpdateBatch(); 123 this.tree.beginUpdateBatch();
104 this.photos = new Array(); 124 this.photos = new Array();
105 var n; while(n=xp.iterateNext()) { 125 var n; while(n=xp.iterateNext()) {
106 this.photos.push(new Photo(n)); 126 this.photos.push(new Photo(n));
107 } 127 }
108 this.rowCount = this.photos.length; 128 this.rowCount = this.photos.length;
109 this.tree.endUpdateBatch(); 129 this.tree.endUpdateBatch();
110 }, 130 },
111 load_photos: function(psid) { 131 load_photos: function(psid) {
112 var _this = this; 132 var _this = this;
113 this.fireflix.flickr.api_call( 133 this.fireflix.flickr.api_call(
@@ -821,58 +841,56 @@ var fireflix = {
821 var b = bw.getBrowser(); 841 var b = bw.getBrowser();
822 var t = b.addTab(l); 842 var t = b.addTab(l);
823 b.selectedTab = t; 843 b.selectedTab = t;
824 }, 844 },
825 845
826 build_menus: function() { 846 build_menus: function() {
827 this.append_html_menu( 847 this.append_html_menu(
828 document.getElementById('sets_html_menu'), 848 document.getElementById('sets_html_menu'),
829 'stm_','m_bop','cmdset_sets','cmd_sets_html' 849 'stm_','m_bop','cmdset_sets','cmd_sets_html'
830 ); 850 );
831 this.append_html_menu( 851 this.append_html_menu(
832 document.getElementById('uploads_html_menu'), 852 document.getElementById('uploads_html_menu'),
833 'stm_','m_bop','cmdset_uploads','cmd_uploads_html' 853 'stm_','m_bop','cmdset_uploads','cmd_uploads_html'
834 ); 854 );
835 return; 855 return;
836 }, 856 },
837 append_html_menu: function(m,imgt,lnkt,csid,cpfx) { 857 append_html_menu: function(m,imgt,lnkt,csid,cpfx) {
838 var mp = m.appendChild(document.createElement('menupopup')); 858 var mp = m.appendChild(document.createElement('menupopup'));
839 var t; 859 var t;
840 t=mp.appendChild(document.createElement('menuitem')); 860 t=mp.appendChild(document.createElement('menuitem'));
841 t.setAttribute('label',this.loc_strings.getString('menutitle_Images')); 861 t.setAttribute('label',this.loc_strings.getString('menutitle_Images'));
842 t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); 862 t.setAttribute('class','menuhead');t.setAttribute('disabled','true');
843 mp.appendChild(document.createElement('menuseparator')); 863 mp.appendChild(document.createElement('menuseparator'));
844 var cs = document.getElementById(csid); 864 var cs = document.getElementById(csid);
845 for(var iti=0;iti<imgt.length;++iti) { 865 for(var iti=0;iti<imgt.length;++iti) {
846 t = mp.appendChild(document.createElement('menu')); 866 t = mp.appendChild(document.createElement('menu'));
847 t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti))); 867 t.setAttribute('label',this.loc_strings.getString('urltype_'+imgt.charAt(iti)));
848 var smp = t.appendChild(document.createElement('menupopup')); 868 var smp = t.appendChild(document.createElement('menupopup'));
849 t=smp.appendChild(document.createElement('menuitem')); 869 t=smp.appendChild(document.createElement('menuitem'));
850 t.setAttribute('label',this.loc_strings.getString('menutitle_Links')); 870 t.setAttribute('label',this.loc_strings.getString('menutitle_Links'));
851 t.setAttribute('class','menuhead');t.setAttribute('disabled','true'); 871 t.setAttribute('class','menuhead');t.setAttribute('disabled','true');
852 smp.appendChild(document.createElement('menuseparator')); 872 smp.appendChild(document.createElement('menuseparator'));
853 for(var lti=0;lti<lnkt.length;++lti) { 873 for(var lti=0;lti<lnkt.length;++lti) {
854 var csfx = imgt.charAt(iti)+lnkt.charAt(lti); 874 var csfx = imgt.charAt(iti)+lnkt.charAt(lti);
855 t=smp.appendChild(document.createElement('menuitem')); 875 t=smp.appendChild(document.createElement('menuitem'));
856 t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti))); 876 t.setAttribute('label',this.loc_strings.getString('urltype_'+lnkt.charAt(lti)));
857 t.setAttribute('command',cpfx+'_'+csfx); 877 t.setAttribute('command',cpfx+'_'+csfx);
858 t=cs.appendChild(document.createElement('command')); 878 t=cs.appendChild(document.createElement('command'));
859 t.setAttribute('id',cpfx+'_'+csfx); 879 t.setAttribute('id',cpfx+'_'+csfx);
860 t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)"); 880 t.setAttribute('oncommand','fireflix.on_'+cpfx+"('"+csfx+"',event)");
861 } 881 }
862 } 882 }
863 return mp; 883 return mp;
864 }, 884 },
865 885
866 flickr_failure: function(x,s,c,m) { 886 flickr_failure: function(x,s,c,m) {
867 if(c==98) { // Invalid auth token 887 if(c==98) { // Invalid auth token
868 this.flickr.reset_token(); 888 this.flickr.reset_token();
869 document.getElementById('auth_info').value = this.no_auth_info_label; 889 this.set_auth_state(false,false);
870 document.getElementById('auth_info').disabled = true;
871 document.getElementById('b_auth').hidden = false;
872 return; 890 return;
873 } 891 }
874 // TODO: is that beauty 892 // TODO: is that beauty?
875 alert('flickr api call failed\n'+c+' '+m); 893 alert('flickr api call failed\n'+c+' '+m);
876 } 894 }
877 895
878}; 896};