Commit d4b65b34 authored by Jerome Mariette's avatar Jerome Mariette
Browse files

fix a bug + make the upload file be uniq

parent 9112b964
......@@ -211,14 +211,19 @@ class JFlowServer (object):
@cherrypy.expose
def upload(self, **kwargs):
file_param = kwargs.keys()[0]
prefix = ""
for key in kwargs.keys():
if key == "prefix":
prefix = kwargs[key]
else:
file_param = key
# the file transfer can take a long time; by default cherrypy
# limits responses to 300s; we increase it to 1h
cherrypy.response.timeout = 3600
# upload file by chunks
FH_sever_file = open(os.path.join(self.jflow_config_reader.get_tmp_directory(), kwargs[file_param].filename.encode('ascii','ignore')), "w")
FH_sever_file = open(os.path.join(self.jflow_config_reader.get_tmp_directory(), prefix+"_"+kwargs[file_param].filename.encode('ascii','ignore')), "w")
while True:
data = kwargs[file_param].file.read(8192)
if not data:
......
......@@ -147,6 +147,7 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
var WFForm = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, $.fn.wfform.defaults, options);
this.uploadfiles = {};
if (this.options.serverURL == "") { this.options.serverURL = $.fn.activewf.defaults.serverURL; }
}
......@@ -160,7 +161,7 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
}
}
var _uploadProgress = function(template) {
var _uploadProgress = function(elt) {
var allUploaded = true,
upload_file_status = new Array();
$(".fileupload").each(function(){
......@@ -172,16 +173,19 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
allUploaded = false
}
if (t2load != 0) {
upload_file_status.push({param: tid.join("_"), name: $("#"+iid).val(), loaded: tloaded, total: t2load});
// the name transmitted is timestamp_random_filename
var trealname = $("#"+iid).val().split("_"),
realname = trealname.slice(2, trealname.length).join("_");
upload_file_status.push({param: tid.join("_"), name: realname, loaded: tloaded, total: t2load});
}
if (allUploaded) {
clearInterval(timer);
}
});
if (allUploaded) {
clearInterval(timer);
elt.$element.trigger('uploaded');
}
$("#workflow_form").hide();
$("#progress").html("");
$.tmpl(template, {upload_file_status: upload_file_status}).appendTo($("#progress"));
$.tmpl(elt.options.progressTemplate, {upload_file_status: upload_file_status}).appendTo($("#progress"));
}
WFForm.prototype.run = function() {
......@@ -200,6 +204,10 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
var parts = $(this).attr("id").split("_"),
tid = parts.slice(1, parts.lenght).join("_");
$("#"+tid).removeAttr('disabled');
// change the name of the val by the file name with the prefix
if ($("#"+tid).val()) {
$("#"+tid).val($this.uploadfiles[tid]+"_"+$("#"+tid).val());
}
});
$.each ( $('#workflow_form').serializeArray(), function(_, kv) {
......@@ -208,7 +216,6 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
$("#workflow_form :checkbox").each(function(){
if (!$(this).prop('checked')) { params += $(this).attr("name") + "=false&"; }
});
$this.$element.on("uploaded", function() {
$.ajax({
url: $this.options.serverURL + '/run_workflow?' + params + 'callback=?',
......@@ -217,16 +224,13 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
$this.$element.trigger('run', running_wf);
}
});
});
});
$this.$element.trigger('uploading');
// execute _uploadProgress to init the display
_uploadProgress($this.options.progressTemplate)
_uploadProgress($this);
// then loop to follow the file upload
timer = setInterval(function() { _uploadProgress($this.options.progressTemplate) }, TIMER);
$this.$element.trigger('uploaded');
timer = setInterval(function() { _uploadProgress($this) }, TIMER);
}
}
......@@ -298,15 +302,21 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
});
// Initialize the jQuery File Upload widget:
$(".fileupload").fileupload({
url: $this.options.serverURL + "/upload",
forceIframeTransport: true,
add: function (e, data) {
$this.$element.on("uploading", function() {
data.submit();
});
}
});
$(".fileupload").each(function(){
var tid = $(this).attr("id").split("_"),
iid = tid.slice(1, tid.length).join("_");
$this.uploadfiles[iid] = +new Date + "_" + Math.floor((Math.random()*10000)+1); ;
$(this).fileupload({
url: $this.options.serverURL + "/upload",
formData: {prefix: $this.uploadfiles[iid]},
forceIframeTransport: true,
add: function (e, data) {
$this.$element.on("uploading", function() {
data.submit();
});
}
});
});
$('.date').datepicker().on('changeDate', function(ev){ $('.date').datepicker('hide');} );
......
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