Commit 6827961d authored by Jerome Mariette's avatar Jerome Mariette
Browse files

append simple ok

parent a414ac89
......@@ -284,13 +284,24 @@ class JFlowServer (object):
# upload file by chunks
file_dir = os.path.join( self.jflow_config_reader.get_tmp_directory(), uniq_directory )
os.mkdir( file_dir )
FH_sever_file = open(os.path.join(file_dir, kwargs[file_param].filename.encode('ascii','ignore')), "w")
while True:
data = kwargs[file_param].file.read(8192)
if not data:
break
FH_sever_file.write(data)
FH_sever_file.close()
if isinstance(kwargs[file_param], list):
for cfile in kwargs[file_param]:
FH_sever_file = open(os.path.join(file_dir, cfile.filename.encode('ascii','ignore')), "w")
while True:
data = cfile.file.read(8192)
if not data:
break
FH_sever_file.write(data)
FH_sever_file.close()
else:
FH_sever_file = open(os.path.join(file_dir, kwargs[file_param].filename.encode('ascii','ignore')), "w")
while True:
data = kwargs[file_param].file.read(8192)
if not data:
break
FH_sever_file.write(data)
FH_sever_file.close()
@cherrypy.expose
@cherrypy.tools.noBodyProcess()
......@@ -324,10 +335,18 @@ class JFlowServer (object):
currentFile = formFields[current]
fileDir = os.path.join(self.jflow_config_reader.get_tmp_directory(), formFields.getvalue("uniq_directory"))
os.mkdir(fileDir)
os.link(
currentFile.file.name,
os.path.join(fileDir, currentFile.filename.encode('ascii','ignore'))
)
if isinstance(currentFile, list):
for cfile in currentFile:
os.link(
cfile.file.name,
os.path.join(fileDir, cfile.filename.encode('ascii','ignore'))
)
else:
os.link(
currentFile.file.name,
os.path.join(fileDir, currentFile.filename.encode('ascii','ignore'))
)
@cherrypy.expose
@jsonify
......
......@@ -105,11 +105,22 @@ jQuery.validator.addMethod("exclude_required", function(value, element, options)
jQuery.validator.addMethod("maxfilesize", function(value, element, params) {
if (params[0] != 0) {
return this.optional(element) || $(element).data("data2upload").files[0].size < params[0];
if ($(element).data("data2upload").files.length == 1) {
return this.optional(element) || $(element).data("data2upload").files[0].size < params[0];
} else {
var allok = true;
for (var i in $(element).data("data2upload").files) {
if ($(element).data("data2upload").files[i].size >= params[0]) {
allok = false;
break;
}
}
return this.optional(element) || allok;
}
} else {
return true;
}
}, jQuery.format("Selected file exceeds size limits: {1}"));
}, jQuery.format("Selected file(s) exceeds size limits: {1}"));
jQuery.validator.addMethod("multinumber", function(value, element, params) {
var values = value.split(/\n/),
......@@ -174,10 +185,7 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
allUploaded = false
}
if (t2load != 0) {
// the name transmitted is timestamp_random/filename
var filename_regexp = /\d+_\d+.(.+)/i;
var realname = $("#"+iid).val().match(filename_regexp)[1];
upload_file_status.push({param: tid.join("_"), name: realname, loaded: tloaded, total: t2load});
upload_file_status.push({param: iid.split("_").join(" "), loaded: tloaded, total: t2load});
}
});
if (allUploaded && !justinit) {
......@@ -210,10 +218,25 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
$("#"+tid).prop('readonly', false);
// change the name of the val by the file name with the uniq folder
if ($("#"+tid).val()) {
$("#"+tid).val( $this.uploadfiles[tid] + "/" + $("#"+tid).val() );
// delete prefix used for security in IE, Chrome and Opera
$("#"+tid).val( $("#"+tid).val().replace(/C:\\fakepath\\/i,'').replace(/C:\\fake_path\\/i,'') );
}
// if a multiple string, this is a textarea, split by lines
if ($("#"+tid).hasClass("list")) {
var allfiles = $("#"+tid).val().split(/\n/),
newtidval = "";
for (var j = 0; j < allfiles.length; j++) {
newtidval += $this.uploadfiles[tid] + "/" + allfiles[j];
newtidval.replace(/C:\\fakepath\\/i,'').replace(/C:\\fake_path\\/i,'');
newtidval += ",";
}
newtidval = newtidval.substring(0, newtidval.length-1);
$("#"+tid).val( newtidval );
// remove list class so it is not a problem with the serialization step
$("#"+tid).removeClass("list");
} else {
$("#"+tid).val( $this.uploadfiles[tid] + "/" + $("#"+tid).val() );
// delete prefix used for security in IE, Chrome and Opera
$("#"+tid).val( $("#"+tid).val().replace(/C:\\fakepath\\/i,'').replace(/C:\\fake_path\\/i,'') );
}
}
}
});
// when serializing, multiple data are repeated, so build a hash to gather values from the same parameter
......@@ -375,23 +398,28 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
tid = parts.slice(2, parts.lenght).join("_");
$("#browse_" + tid).click();
});
$("[id^=browse_]").change( function() {
var parts = $(this).attr("id").split("_"),
tid = parts.slice(1, parts.lenght).join("_");
$("#"+tid).val( $(this).val() );
});
// Initialize the jQuery File Upload widget:
$(".fileupload").each(function(){
var tid = $(this).attr("id").split("_"),
iid = tid.slice(1, tid.length).join("_"),
$thisfu = $(this);
$this.uploadfiles[iid] = +new Date + "_" + Math.floor((Math.random()*10000)+1); ;
$this.uploadfiles[iid] = +new Date + "_" + Math.floor((Math.random()*10000)+1);
$(this).fileupload({
url: $this.options.serverURL + "/upload",
formData: {'uniq_directory': $this.uploadfiles[iid]},
forceIframeTransport: true,
add: function (e, data) {
// update the display
if (data.files.length == 1) {
$("#"+iid).val( data.files[0].name );
} else {
var todisplay = "";
for (var i in data.files) {
todisplay += data.files[i].name + "\n";
}
$("#"+iid).val( todisplay.substring(0, todisplay.length-1) );
}
// add the data
$("#"+iid).data("data2upload", data);
// so the validation of the form is done
$("#"+iid).focusout();
......@@ -558,13 +586,19 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
' <span class="caret"></span>',
' </button>',
' <ul class="dropdown-menu" role="menu">',
' <li><a class="inputfile_${param.name}" href="#">server regexp</a></li>',
' <li><a class="inputfile_${param.name}" href="#">server file</a></li>',
' {{if param.action == "append"}}',
' <li><a class="inputfile_${param.name}" href="#">server regexp</a></li>',
' {{/if}}',
' <li><a class="inputfile_${param.name}" href="#">local file</a></li>',
' <li><a class="inputfile_${param.name}" href="#">url</a></li>',
' </ul>',
' </div>',
' {{if param.action == "append"}}',
' <textarea id="${param.name}" style="resize:none" name="${param.name}" value="${param.default}" class="list form-control ${param.group}"></textarea>',
' {{else}}',
' <input id="${param.name}" name="${param.name}" class="form-control ${param.group}" type="text" value="${param.default}">',
' {{/if}}',
' <span class="input-group-btn">',
' <button id="urlfile_btn_${param.name}" style="display: none;" class="btn btn-default" type="button"><span class="glyphicon glyphicon-folder-open"></span></button>',
' </span>',
......@@ -696,7 +730,7 @@ jQuery.validator.addMethod("mparam", function(value, element, params) {
'</div></div> <div class="col-md-8">Please wait until all files have being loaded!</div></div>',
'<br/>',
'{{each(index, file) upload_file_status}}',
'<dt>${file.name}</dt>',
'<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>',
......
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