oops, forgot to add edgeUpload.js

This commit is contained in:
Sanj 2011-06-18 00:35:50 +05:30
parent ee4b290770
commit 82399397ef

View File

@ -0,0 +1,130 @@
function doProgress(progress) {
//do something with status and progress, i.e. set progressbar width:
$('#progress').css('width', parseInt(progress*100, 10) +'%');
$('#progressstatus').html(parseInt(progress*100, 10) + '% - ' + ogg.status);
}
var UploadQueue = function() {
var that = this;
this.allFiles = [];
this.isUploading = false;
this.$list = $('#filesList');
this.$progress = $('#progressbar');
this.len = function() {
return this.allFiles.length;
};
this.getLi = function(no) {
return this.$list.children('li').eq(no);
}
this.init();
}
UploadQueue.prototype.init = function() {
// $('#progressbar').show();
$('#progressbar').width(200).height(20);
// $('#progressbar').css('background-color', '#80ADB0');
$('#progressbar').html('<div id="progress" style="height:20px;width:0%"></div><div id="progressstatus" style="">uploading</div>');
}
/* param f = file */
UploadQueue.prototype.getData = function(f) {
return {
'firefogg': 1,
'name': f.name,
'category': $('#files_category').val()
};
};
UploadQueue.prototype.uploadNext = function() {
};
UploadQueue.prototype.addFile = function(f) {
for (var i=0; i<this.len(); i++) {
if (this.allFiles[i].name == f.name) {
return false;
}
}
this.allFiles.push(f);
this.addFileToList(f);
// this.$list.triggerEvent("fileAdded");
if (!this.isUploading) {
this.upload(this.len() - 1);
}
return this;
};
UploadQueue.prototype.addFileToList = function(f) {
var that = this;
var $li = $('<li />').data("file", f).text(f.name).appendTo(that.$list);
};
UploadQueue.prototype.markDone = function(no, data) {
$('.uploading').removeClass("uploading");
var $li = this.getLi(no);
$li.addClass("uploaded");
fileUploadedCallback($li, data);
if (this.len() > (no + 1)) {
this.upload(no + 1);
} else {
this.isUploading = false;
$('#progressbar').hide();
}
};
UploadQueue.prototype.upload = function(no) {
var that = this;
var fil = this.allFiles[no];
// console.log("uploading", fil);
var data = this.getData(fil);
var $li = this.getLi(no);
this.isUploading = true;
$('#progressbar').show();
$li.addClass("uploading");
ogg = FirefoggUploader(fil, add_url, data, function(ogg) {
if (ogg.resultUrl) {
that.markDone(no, ogg);
} else {
$('#progressbar').html(ogg.status);
}
}, doProgress);
};
function fileUploadedCallback(jq, data) {
// alert("hi");
var fileId = data.fileId;
jq.data("fileId", fileId);
if (data.hasOwnProperty("errors")) {
var $error = $('<div />').addClass("fileError").text(data.errors[0]).appendTo(jq);
} else {
var $formContainer = $('<div />').addClass("fileForm");
var $titleInput = $('<input />').attr("type", "text").addClass("fileTitle").appendTo($formContainer);
var $descInput = $('<textarea />').addClass("fileDesc").appendTo($formContainer);
var $submitBtn = $('<button />').text("Submit").click(function() {
var $parent = $(this).parents('.uploaded');
var fileId = $parent.data("fileId");
var title = $parent.find(".fileTitle").val();
var description = $parent.find(".fileDesc").val();
$.post("/files/editFile", {
'id': fileId,
'title': title,
'description': description
}, function(response) {
console.log(response);
},
"json");
}).appendTo($formContainer);
$formContainer.appendTo(jq);
}
}