summaryrefslogtreecommitdiffabout
authorMichael Krelin <hacker@klever.net>2011-08-28 16:22:04 (UTC)
committer Michael Krelin <hacker@klever.net>2011-08-28 16:22:04 (UTC)
commite58247a43552504e34ae31a5262a8a9dd338243c (patch) (side-by-side diff)
tree010174a32497fa0e085de0902799197f703e678a
parentaa13caca14bac3ed268ac6fb62f0270e40b24e48 (diff)
downloadfireflix-e58247a43552504e34ae31a5262a8a9dd338243c.zip
fireflix-e58247a43552504e34ae31a5262a8a9dd338243c.tar.gz
fireflix-e58247a43552504e34ae31a5262a8a9dd338243c.tar.bz2
more json calls
Signed-off-by: Michael Krelin <hacker@klever.net>
Diffstat (more/less context) (show whitespace changes)
-rw-r--r--content/fireflix.js19
1 files changed, 9 insertions, 10 deletions
diff --git a/content/fireflix.js b/content/fireflix.js
index 283e930..d70ab4d 100644
--- a/content/fireflix.js
+++ b/content/fireflix.js
@@ -352,217 +352,216 @@ var fireflix = {
isSorted: function(r) { return false; },
getLevel: function(r) { return 0; },
getImageSrc: function(r,c) { return null },
getRowProperties: function(r,p) {
try {
if(!Components) return;
}catch(e) { return }
var f = this.files[r];
var as = Components.classes['@mozilla.org/atom-service;1'].
getService(Components.interfaces.nsIAtomService);
p.AppendElement(as.getAtom(f.state));
},
getCellProperties: function(r,c,p) { this.getRowProperties(r,p); },
getColumnProperties: function(c,p) { },
cycleHeader: function(cid,e) { },
getParentIndex: function(r) { return -1; },
drop: function(r,o) { },
canDropBeforeAfter: function(r,b) { return false },
add: function(f) {
if(f.indexOf('file:/')==0) {
f = f.substr(5);
while(f.substr(0,2)=='//') { // XXX: not very performant, is it? ;-)
f = f.substr(1);
}
}
var t = f;
var ls = t.lastIndexOf('/');
if(ls>0) t = t.substr(ls+1);
ls = t.lastIndexOf('\\');
if(ls>0) t = t.substr(ls+1);
var ld = t.lastIndexOf('.');
if(ld>0) t = t.substr(0,ld);
this.files.push( {
file: f,
title: t,
tags: '',
is_public: true, is_friend: false, is_family: false,
state: 'pending'
} );
this.rowCount = this.files.length;
this.tree.rowCountChanged(this.rowCount-1,1);
},
upload_worker: function() {
for(var f in this.files) {
if(this.files[f].state=='pending') {
var ff = this.files[f];
this.on_file_upload(ff);
ff.state='uploading';
this.tree.invalidate();
var _this = this;
this.fireflix.flickr.upload_file(
ff.file, {
title: ff.title, tags: ff.tags,
is_public: ff.is_public?'1':'0',
is_friend: ff.is_friend?'1':'0',
is_family: ff.is_family?'1':'0'
}, function(x,p) {
ff.photoid = p;
_this.batch_ids.push(p);
ff.state='completed';
_this.tree.invalidate();
window.setTimeout(_this.upload_to,0,_this);
}, function(x,s,c,m) {
ff.state='failed';
ff.flickr_errcode = c;
ff.flickr_errmsg = m;
_this.tree.invalidate();
window.setTimeout(_this.upload_to,0,_this);
}
);
return;
}
}
this.on_finish_upload();
},
upload_to: function(_this) { _this.upload_worker(); },
on_file_upload: function(f) {
this.cmd_uploads_upload.setAttribute('disabled','true');
for(var fi in this.files) {
if(this.files[fi].file==f.file) {
this.tree.ensureRowIsVisible(fi);
this.selection.rangedSelect(fi,fi,false);
this.selection.currentIndex = fi;
this.selToProps();
break;
}
}
},
on_finish_upload: function() {
if(this.batch_ids.length) {
var psn = prompt(this.fireflix.loc_strings.getString('postUploadPhotoset'));
if(psn!=null) {
var pids = this.batch_ids.join(',');
var ppid = this.batch_ids[0];
- var _this = this;
- this.fireflix.flickr.api_call(
+ var that = this;
+ this.fireflix.flickr.api_call_json(
{
method: 'flickr.photosets.create',
auth_token: 'default',
title: psn,
primary_photo_id: ppid
- }, function(x) {
- var npid =
- x.responseXML.getElementsByTagName('photoset').item(0).getAttribute('id');
- _this.fireflix.flickr.api_call(
+ }, function(x,j) {
+ var npid = j.photoset.id;
+ that.fireflix.flickr.api_call_json(
{
method: 'flickr.photosets.editPhotos',
auth_token: 'default',
photoset_id: npid,
primary_photo_id: ppid,
photo_ids: pids
- }, function(x) {
- _this.fireflix.refresh_sets();
+ }, function(x,j) {
+ that.fireflix.refresh_sets();
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
}, function(x,s,c,m) {
- _this.fireflix.flickr_failure(x,s,c,m);
+ that.fireflix.flickr_failure(x,s,c,m);
}
);
}
}
this.selection.clearSelection();
this.cmd_uploads_upload.setAttribute('disabled','false');
this.upload_progress.setAttribute('hidden','true');
},
clear_list: function() {
this.tree.beginUpdateBatch();
this.rowCount = 0;
this.files = new Array();
this.tree.endUpdateBatch();
this.selToProps();
},
selectionChanged: function() {
this.selToProps();
},
disableProps: function() {
this.upload_filename.value='';
this.upload_filename.disabled = true;
this.upload_title.value='';
this.upload_title.disabled = true;
this.upload_file_preview.src = null;
this.upload_tags.value='';
this.upload_tags.disabled = true;
this.upload_is_public.disabled = true;
this.upload_is_friends.disabled = true;
this.upload_is_family.disabled = true;
/* this.upload_file_props.hidden = true; */
},
selToProps: function() {
if(!this.selection.count) {
this.disableProps();
this.upload_file_props.hidden = true;
}else if(this.selection.count==1) {
var f=this.files[this.selection.currentIndex];
if(f==null) {
this.disableProps();
this.upload_file_props.hidden = true;
}else{
var inactives = f.state!='pending';
this.upload_filename.value = f.file; this.upload_filename.disabled = inactives;
this.upload_title.value = f.title; this.upload_title.disabled = inactives;
this.upload_file_preview.src = 'file:///'+f.file;
this.upload_tags.value = f.tags; this.upload_tags.disabled = inactives;
this.upload_is_public.checked = f.is_public; this.upload_is_public.disabled = inactives;
this.upload_is_friends.checked = f.is_friend; this.upload_is_friends.disabled = inactives;
this.upload_is_family.checked = f.is_family; this.upload_is_family.disabled = inactives;
if(f.state=='failed') {
this.upload_failure.textContent=((f.flickr_errcode<0)?'':f.flickr_errcode+': ')+f.flickr_errmsg;
this.upload_failure.hidden = false;
}else{
this.upload_failure.hidden = true;
}
this.upload_file_props.hidden = false;
}
}else{
var ftitle = null; var onetitle = true;
var ftags = null; var onetag = true;
var fs = 0;
for(var ff in this.files) {
if(this.selection.isSelected(ff) && this.files[ff].state=='pending' ) {
++fs;
if(ftitle==null) {
ftitle = this.files[ff].title;
}else if(ftitle!=this.files[ff].title) {
onetitle = false;
}
if(ftags==null) {
ftags = this.files[ff].tags;
}else if(ftags!=this.files[ff].tags) {
onetag = false;
}
}
}
if(fs) {
this.upload_filename.value='';
this.upload_filename.disabled = true;
if(onetitle)
this.upload_title.value = ftitle;
this.upload_title.disabled = false;
if(onetag)
this.upload_tags.value = ftags;
this.upload_tags.disabled = false;
this.upload_file_preview.src = null;
this.upload_failure.hidden = true;
this.upload_file_props.hidden = false;
}else
this.disableProps();
this.upload_file_props.hidden = true;
}
},
propsToSel: function(prop) {
if(this.selection.count<=0) return;