From 82399397efbc139a7af43d10dd2debd60a1b20c7 Mon Sep 17 00:00:00 2001 From: Sanj Date: Sat, 18 Jun 2011 00:35:50 +0530 Subject: [PATCH] oops, forgot to add edgeUpload.js --- edgware/static/js/upload/edgeUpload.js | 130 +++++++++++++++++++++++++ 1 file changed, 130 insertions(+) create mode 100644 edgware/static/js/upload/edgeUpload.js diff --git a/edgware/static/js/upload/edgeUpload.js b/edgware/static/js/upload/edgeUpload.js new file mode 100644 index 0000000..2569d86 --- /dev/null +++ b/edgware/static/js/upload/edgeUpload.js @@ -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('
uploading
'); +} + +/* 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').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 = $('
').addClass("fileError").text(data.errors[0]).appendTo(jq); + } else { + var $formContainer = $('
').addClass("fileForm"); + var $titleInput = $('').attr("type", "text").addClass("fileTitle").appendTo($formContainer); + var $descInput = $('