From b1a410249bab9d49ec42b4138501bf72cfe544ea Mon Sep 17 00:00:00 2001 From: =?utf8?q?Benoi=CC=82t=20Pin?= Date: Fri, 14 Jun 2013 16:36:09 +0200 Subject: [PATCH 1/1] =?utf8?q?Upload=20js.=20Impl=C3=A9mentation=20en=20co?= =?utf8?q?urs.?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- skins/fileupload.js | 40 +++++++++++++++++++++++++++++++----- skins/photo_layout_macros.pt | 3 ++- 2 files changed, 37 insertions(+), 6 deletions(-) diff --git a/skins/fileupload.js b/skins/fileupload.js index 97b5443..d1da59e 100644 --- a/skins/fileupload.js +++ b/skins/fileupload.js @@ -3,12 +3,13 @@ var DDFileUploader; (function(){ -DDFileUploader = function(dropbox) { +DDFileUploader = function(dropbox, uploadUrl) { this.dropbox = dropbox; - var thisDDFU = this; - addListener(dropbox, 'dragenter', function(evt){thisDDFU.dragenter(evt);}); - addListener(dropbox, 'dragover', function(evt){thisDDFU.dragover(evt);}); - addListener(dropbox, 'drop', function(evt){thisDDFU.drop(evt);}); + this.uploadUrl = uploadUrl; + var self = this; + addListener(dropbox, 'dragenter', function(evt){self.dragenter(evt);}); + addListener(dropbox, 'dragover', function(evt){self.dragover(evt);}); + addListener(dropbox, 'drop', function(evt){self.drop(evt);}); }; DDFileUploader.prototype.dragenter = function(evt) { @@ -39,7 +40,36 @@ DDFileUploader.prototype.handleFiles = function(files) { for (i = 0; i < files.length; i++) { file = files[i]; console.log(file.type); + this.upload(file); } }; + +DDFileUploader.prototype.upload = function(file) { + var reader = new FileReader(); + var xhr = new XMLHttpRequest(); + var percentage; + var self = this; + // this.xhr.upload.addEventListener("progress", function(e) { + // if (e.lengthComputable) { + // var percentage = Math.round((e.loaded * 100) / e.total); + // self.ctrl.update(percentage); + // } + // }, false); + + // xhr.upload.addEventListener("load", function(e){ + // self.ctrl.update(100); + // var canvas = self.ctrl.ctx.canvas; + // canvas.parentNode.removeChild(canvas); + // }, false); + console.log(file); + xhr.open("PUT", this.uploadUrl + '/' + file.name); + xhr.setRequestHeader("Content-Type", file.type); + // xhr.overrideMimeType('text/plain; charset=x-user-defined-binary'); + reader.onload = function(evt) { + xhr.sendAsBinary(evt.target.result); + }; + reader.readAsBinaryString(file); +}; + }()); diff --git a/skins/photo_layout_macros.pt b/skins/photo_layout_macros.pt index 849699e..6e1d7aa 100644 --- a/skins/photo_layout_macros.pt +++ b/skins/photo_layout_macros.pt @@ -86,8 +86,9 @@ // -- 2.20.1