Commit 0b12716d authored by Jerome Mariette's avatar Jerome Mariette
Browse files

ok for a nice upload view

parent 66749024
This diff is collapsed.
......@@ -292,7 +292,8 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
!function ($) {
"use strict"; // jshint ;_;
var timer,
var timeriframe,
timerclassic,
SIZE_LIMIT_SPLITER = "__sl";
/* WFForm CLASS DEFINITION
......@@ -302,6 +303,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
this.$element = $(element)
this.options = $.extend({}, $.fn.wfform.defaults, options);
this.uploadfiles = {};
this.nbfileuploaded = 0;
this.handsontable_errors = {};
if (this.options.serverURL == "") { this.options.serverURL = $.fn.wfform.defaults.serverURL; }
}
......@@ -316,7 +318,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
}
}
var _uploadProgress = function(elt, justinit) {
var _uploadProgressIframe = function(elt, justinit) {
var allUploaded = true,
upload_file_status = new Array();
$(".fileupload").each(function(){
......@@ -328,18 +330,27 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
allUploaded = false
}
if (t2load != 0) {
upload_file_status.push({param: iid.split("_").join(" "), loaded: tloaded, total: t2load});
upload_file_status.push({param: iid.split("_").join(" "), param_id: iid, loaded: tloaded, total: t2load});
}
});
if (allUploaded && !justinit) {
clearInterval(timer);
clearInterval(timeriframe);
elt.$element.trigger('uploaded.wfform');
}
$("#workflow_form").hide();
$("#progress").html("");
$.tmpl(elt.options.progressTemplate, {upload_file_status: upload_file_status}).appendTo($("#progress"));
if (justinit) {
$("#workflow_form").hide();
$("#progress").html("");
$.tmpl(elt.options.progressTemplate, {upload_file_status: upload_file_status}).appendTo($("#progress"));
}
}
var _uploadProgressClassic = function(elt, nb2upload) {
if (nb2upload == elt.nbfileuploaded) {
clearInterval(timerclassic);
elt.$element.trigger('uploaded.wfform');
}
}
var _validateAndSubmitForm = function($this) {
// check if the form is valid
if ($("#workflow_form").valid()) {
......@@ -480,10 +491,24 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
});
if (nbdata2submit > 0) {
// execute _uploadProgress to init the display
_uploadProgress($this, true);
// then loop to follow the file upload
timer = setInterval(function() { _uploadProgress($this, false) }, $this.options.timer);
if ($this.options.forceIframeTransport) {
// execute _uploadProgressIframe to init the display
_uploadProgressIframe($this, true);
// then loop to follow the file upload
timeriframe = setInterval(function() { _uploadProgressIframe($this, false) }, $this.options.timer);
} else {
var upload_file_status = new Array();
$(".fileupload").each(function(){
var tid = $(this).attr("id").split("_"),
iid = tid.slice(1, tid.length).join("_");
upload_file_status.push({param: iid.split("_").join(" "), param_id: iid, loaded: 0, total: 100});
});
$("#workflow_form").hide();
$("#progress").html("");
$.tmpl($this.options.progressTemplate, {upload_file_status: upload_file_status}).appendTo($("#progress"));
// loop to follow the file upload
timerclassic = setInterval(function() { _uploadProgressClassic($this, nbdata2submit) }, $this.options.timer);
}
} else {
$this.$element.trigger('uploaded.wfform');
}
......@@ -660,7 +685,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
$(this).fileupload({
url: $this.options.serverURL + "/upload",
formData: {'uniq_directory': $this.uploadfiles[iid]},
forceIframeTransport: true,
forceIframeTransport: $this.options.forceIframeTransport,
add: function (e, data) {
// update the display
if (data.files.length == 1) {
......@@ -676,6 +701,16 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
$("#"+iid).data("data2upload", data);
// so the validation of the form is done
$("#"+iid).focusout();
},
progressall: function (e, data) {
var progress = parseInt(data.loaded / data.total * 100, 10);
$('#' + iid + '_pbar').css(
'width',
progress + '%'
);
if (progress == 100) {
$this.nbfileuploaded += 1;
}
}
});
});
......@@ -1377,7 +1412,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
'<dt>${file.param}</dt>',
'<dd>',
'<div class="progress">',
'<div class="progress-bar progress-bar-success" role="progressbar" style="width: ${parseInt((file.loaded/file.total)*100)}%;"></div>',
'<div id="${file.param_id}_pbar" class="progress-bar progress-bar-success" role="progressbar" style="width: ${parseInt((file.loaded/file.total)*100)}%;"></div>',
'</div>',
'</dd>',
'{{/each}}',
......@@ -1387,7 +1422,8 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
displayResetButton: true,
workflow: null,
parameters: {},
timer: 2000
timer: 2000,
forceIframeTransport: false
}
$.fn.wfform.Constructor = WFForm
......
This diff is collapsed.
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment