summaryrefslogtreecommitdiffabout
path: root/content/fireflix.js
authorMichael Krelin <hacker@klever.net>2011-08-28 12:17:34 (UTC)
committer Michael Krelin <hacker@klever.net>2011-08-28 12:17:34 (UTC)
commitaa13caca14bac3ed268ac6fb62f0270e40b24e48 (patch) (side-by-side diff)
treeedcfd094407b87cf9c49e9275c6d4b847fc82f29 /content/fireflix.js
parent4152a504609522fab4a269dc88d13a1078a09452 (diff)
downloadfireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.zip
fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.gz
fireflix-aa13caca14bac3ed268ac6fb62f0270e40b24e48.tar.bz2
made api calls mostly json-based
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (limited to 'content/fireflix.js') (more/less context) (show whitespace changes)
-rw-r--r--content/fireflix.js90
1 files changed, 37 insertions, 53 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 225e21c..283e930 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -103,74 +103,68 @@ var fireflix = {
if(c.id=='sp_taken') return p.datetaken;
if(c.id=='sp_upload') {
var du = new Date(p.dateupload*1000);
var rv = du.getFullYear()+'-'+(du.getMonth()+1)+'-'+du.getDate()
+' '+
du.getHours()+':'+du.getMinutes()+':'+du.getSeconds();
return rv.replace(/(\D)(\d)(\D)/,'$10$2$3');
}
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false; },
isSeparator: function(r) { return false; },
isSorted: function(r) { return false; },
getLevel: function(r) { return 0; },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) {},
getCellProperties: function(cid,cel,p) {},
getColumnProperties: function(cid,cel,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1; },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
- importXPR: function(xp) {
+ import_json: function(jp) {
this.tree.beginUpdateBatch();
this.photos = new Array();
- var n; while(n=xp.iterateNext()) {
- this.photos.push(new Photo(n));
- }
+ for(var i in jp) this.photos.push(new Photo(jp[i]));
this.rowCount = this.photos.length;
this.tree.endUpdateBatch();
this.selection.clearSelection();
},
load_photos: function(psid) {
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
method: 'flickr.photosets.getPhotos',
auth_token: 'default',
photoset_id: psid,
extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update'
- }, function(xr) {
- var x = xr.responseXML;
- var xp = x.evaluate(
- '/rsp/photoset/photo', x, null,
- XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
- _this.importXPR(xp);
+ }, function(x,j) {
+ that.import_json(j.photoset.photo);
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
},
on_select: function() {
if(this.selection.count==1) {
var p = this.photos[this.selection.currentIndex];
this.set_photo.src =
this.fireflix.flickr.get_photo_url(p.server,p.id,p.secret,'t');
this.set_photo_props.hidden = false;
}else{
this.set_photo_props.hidden = true;
}
},
on_cmd_open: function(ev) {
if(this.selection.currentIndex<0) return;
var p = this.photos[this.selection.currentIndex];
if(!p.id) return;
this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
}
},
/* photosets treeview */
photosets: {
sets: new Array(),
@@ -179,71 +173,65 @@ var fireflix = {
this.fireflix = f;
document.getElementById('setslist').view = this;
},
rowCount: 0,
getCellText: function(r,c) {
var s = this.sets[r];
if(c.id=='sl_name') return s.title;
if(c.id=='sl_photos') return s.photos;
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false; },
isSeparator: function(r) { return false; },
isSorted: function() { return false; },
getLevel: function(r) { return 0; },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) {},
getCellProperties: function(cid,cel,p) { },
getColumnProperties: function(cid,cel,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1; },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
- importXPR: function(xp) {
+ import_json: function(j) {
this.tree.beginUpdateBatch();
this.sets = new Array();
- var n; while(n=xp.iterateNext()) {
- this.sets.push(new Photoset(n));
- }
+ for(var i in j) this.sets.push(new Photoset(j[i]));
this.rowCount = this.sets.length;
this.tree.endUpdateBatch();
},
refresh_sets: function() {
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
method: 'flickr.photosets.getList',
auth_token: 'default'
- }, function(xr) {
- var x = xr.responseXML;
- var xp = x.evaluate(
- '/rsp/photosets/photoset', x, null,
- XPathResult.ORDERED_NODE_ITERATOR_TYPE, null );
- _this.importXPR(xp);
+ }, function(x,j) {
+ that.import_json(j.photosets.photoset);
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
},
on_select: function() {
if(this.selection.count==1) {
this.fireflix.cmd_set_props.setAttribute('disabled','false');
var s = this.sets[this.selection.currentIndex];
this.fireflix.photoset.load_photos(s.id);
}else{
this.fireflix.cmd_set_props.setAttribute('disabled','true');
}
},
on_cmd_open_in_flickr: function(ev) {
if(this.selection.currentIndex<0) return;
var p = this.sets[this.selection.currentIndex];
if(!p.id) return;
this.fireflix.openTab(this.fireflix.flickr.make_photoset_url(p));
}
},
refresh_user_tags: function() {
var lb = document.getElementById('tagslist');
var _this = this;
this.flickr.api_call(
@@ -766,100 +754,97 @@ var fireflix = {
]);
document.getElementById('searchresults').view = this;
},
photos: new Array(),
rowCount: 0,
getCellText: function(r,c) {
var p = this.photos[r];
if(c.id=='sr_title') return p.title;
return c.id;
},
setTree: function(t) { this.tree = t },
isContainer: function(r) { return false },
isSeparator: function(r) { return false },
isSorted: function(r) { return false },
getLevel: function(r) { return 0 },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) { },
getCellProperties: function(cid,cel,p) { },
getColumnProperties: function(cid,cel,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1 },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
- importXPR: function(xp) {
+ import_json: function(jp) {
this.selection.clearSelection();
this.selection.currentIndex = -1;
this.searchresult_props.hidden = true;
this.tree.beginUpdateBatch();
this.photos = new Array();
- var n; while(n=xp.iterateNext()) {
- this.photos.push(new Photo(n));
+ for(var i in jp) {
+ this.photos.push(new Photo(jp[i]));
}
this.rowCount = this.photos.length;
this.tree.endUpdateBatch();
},
paging: {
pars: null,
page: null, pages: null, perpage: null, total: null
},
search_photos: function() {
var pars = {
method: 'flickr.photos.search',
auth_token: 'default',
extras: 'license,date_upload,date_taken,owner_name,icon_server,original_format,last_update,geo'
};
if(this.search_mine.checked)
pars.user_id='me';
if(this.search_tags.checked) {
pars.tags=this.search_for.value.split(/ +/).join(',');
}else{
pars.text=this.search_for.value;
}
this.paging.pars = new Object();
this.paging.page = null; this.paging.pages = null;
this.paging.perpage = null; this.paging.total = null;
for(var p in pars) this.paging.pars[p] = pars[p];
this.perform_search(pars);
},
perform_search: function(p) {
- var _this = this;
- this.fireflix.flickr.api_call( p,
- function(xr) {
- var x = xr.responseXML;
- var xp = xp_nodes('/rsp/photos/photo',x);
- _this.importXPR(xp);
- _this.tree.ensureRowIsVisible(0);
- xp = xp_node('/rsp/photos',x);
- _this.paging.page = parseInt(xp.getAttribute('page'));
- _this.paging.pages = parseInt(xp.getAttribute('pages'));
- _this.paging.perpage = parseInt(xp.getAttribute('perpage'));
- _this.paging.total = parseInt(xp.getAttribute('total'));
- _this.update_paging();
- _this.on_select();
+ var that = this;
+ this.fireflix.flickr.api_call_json( p,
+ function(x,j) {
+ that.import_json(j.photos.photo);
+ that.tree.ensureRowIsVisible(0);
+ var pp=j.photos;
+ that.paging.page = pp.page; that.paging.pages = pp.pages;
+ that.paging.perpage = pp.perpage;
+ that.paging.total = pp.total;
+ that.update_paging();
+ that.on_select();
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
},
on_cmd_prev: function(ev) {
var pars = new Object();
for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
pars.page=this.paging.page-1; pars.per_page=this.paging.perpage;
this.perform_search(pars);
},
on_cmd_next: function(ev) {
var pars = new Object();
for(var p in this.paging.pars) pars[p] = this.paging.pars[p];
pars.page=this.paging.page+1; pars.per_page=this.paging.perpage;
this.perform_search(pars);
},
update_paging: function() {
if(! (this.paging.pars && this.paging.page && this.paging.pages) ) {
this.search_page.value=''; this.search_page.hidden = true;
this.cmd_search_prev_page.setAttribute('disabled','true');
this.cmd_search_next_page.setAttribute('disabled','true');
}else{
this.search_page.value=this.fireflix.loc_strings.getFormattedString('search_page',[this.paging.page,this.paging.pages]);
this.search_page.hidden=false;
this.cmd_search_prev_page.setAttribute('disabled',(this.paging.page>1)?'false':'true');
@@ -877,64 +862,63 @@ var fireflix = {
this.searchresult_description.innerHTML=this.fireflix.loc_strings.getString('broken_description');
else
this.searchresult_description.appendChild(de);
/* of all linking elements flickr only allows a */
var as = this.searchresult_description.getElementsByTagName('a');
for(var a=0;a<as.length;++a)
as.item(a).setAttribute('target','_blank');
}
},
on_select: function() {
if(this.selection.currentIndex<0) {
this.searchresult_props.hidden = true;
}else{
var p = this.photos[this.selection.currentIndex];
if(!p) {
this.searchresult_props.hidden = true;
}else{
this.search_photo.src = this.fireflix.flickr.make_photo_url(p,'t');
this.searchresult_title.value = p.title;
this.searchresult_title.tooltipText = p.title;
this.render_description_frame(null);
if(p.description==null && p.description==undefined) {
var pid = p.id;
var ci = this.selection.currentIndex;
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
method: 'flickr.photos.getInfo',
auth_token: 'default',
photo_id: p.id,
secret: p.secret
- }, function(xr) {
- var pp = _this.photos[ci];
- if(ci==_this.selection.currentIndex && pp.id==pid) {
- var n = xp_node('/rsp/photo',xr.responseXML);
- pp.fromNode_(n);
- _this.render_description_frame(pp.description);
+ }, function(x,j) {
+ var pp = that.photos[ci];
+ if(ci==that.selection.currentIndex && pp.id==pid) {
+ pp.fromJSON_(j.photo);
+ that.render_description_frame(pp.description);
}
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
this.searchresult_props.hidden = false;
}else{
this.render_description_frame(p.description);
}
}
}
},
on_cmd_open: function(ev) {
if(this.selection.currentIndex<0) return;
var p = this.photos[this.selection.currentIndex];
if(!p.id) return;
this.fireflix.openTab(this.fireflix.flickr.make_photo_url(p,'p'));
}
},
photo_html: function(p,i,l) {
// TODO: add alt/title when possible
var rv =
'<a href="'+this.flickr.make_photo_url(p,l)+'">' +
'<img src="'+this.flickr.make_photo_url(p,i)+'" />'+
'</a>';
return rv;