Commit e5c676d1 authored by Celine Noirot's avatar Celine Noirot
Browse files

handle files list and choices

parent dae949ca
......@@ -16,12 +16,8 @@
#
import re
import sys
import types
import datetime
import logging
import argparse
import os
import fnmatch
import tempfile
import urllib.parse
......@@ -373,7 +369,13 @@ class AbstractParameter(object):
# Set parameter value
if choices != None and default == None:
self.default = choices[0]
try :
if isinstance(choices, list):
self.default = choices[0]
elif isinstance(choices, dict):
self.default = choices.keys()[0]
except:
self.default = None
else:
self.default = default
......
......@@ -190,13 +190,13 @@ class Workflow(threading.Thread):
self.params_order.append(name)
self.__setattr__(name, new_param)
def add_input_file(self, name, help, file_format="any", default=None, type="inputfile",
def add_input_file(self, name, help, file_format="any", choices=None, default=None, type="inputfile",
required=False, flag=None, group="default", display_name=None, size_limit="0", add_to=None,
rules=None):
# check if the size provided is correct
try: int(get_nb_octet(size_limit))
except: size_limit="0"
new_param = InputFile(name, help, flag=flag, file_format=file_format, default=default,
new_param = InputFile(name, help, flag=flag, file_format=file_format, choices=choices, default=default,
type=type, required=required, group=group, display_name=display_name, size_limit=size_limit,
rules=rules)
new_param.linkTrace_nameid = name
......
......@@ -691,7 +691,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
// trigger an event to specify the workflow is loaded
$this.$element.trigger('loaded.wfform', $this.workflow);
$this.$element.html("");
$.tmpl(
$.tmpl(
globalTemplate, {
workflow: $this.workflow,
display_form_type: $this.options.displayFormType,
......@@ -704,6 +704,7 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
parameterTemplate: $this.options.parameterTemplate,
dateTemplate: $this.options.dateTemplate,
choiceTemplate: $this.options.choiceTemplate,
inputfileChoiceTemplate: $this.options.inputfileChoiceTemplate,
inputfileTemplate: $this.options.inputfileTemplate,
browsefileTemplate: $this.options.browsefileTemplate,
regexpfilesTemplate: $this.options.regexpfilesTemplate,
......@@ -937,6 +938,10 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
return false;
})
$('#myCollapsible').on('hidden.bs.collapse', function () {
// do something…
})
$(".to-readonly").on("focusin", function(event) {
$(this).prop('readonly', true);
});
......@@ -1289,9 +1294,11 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
* @returns {String} The template name (see getParameterDisplay).
*/
WFForm.prototype._getTplName = function(param) {
if( param.choices ) {
return "choiceTemplate" ;
} else if( param.type == "date" ){
if( param.choices && param.type.indexOf("inputfile") === 0 ) {
return "inputfileChoiceTemplate" ;
}else if( param.choices){
return "choiceTemplate" ;
}else if( param.type == "date" ){
return "dateTemplate" ;
} else if( param.type == "bool" ){
return "booleanTemplate" ;
......@@ -1463,7 +1470,109 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
' {{/each}}',
'</form>',
'<div id="progress"></div>'].join('\n');
var globalClassicTemplate = ['<form id="workflow_form" class="form-horizontal" role="form">',
' {{each(gindex, group) workflow.groups}}',
' <fieldset>',
' {{if group != "default" }}',
' <legend>${group}</legend>',
' {{/if}}',
' {{each(index, param) workflow.parameters_per_groups[group]}}',
// it the parameter has not already been settled
' {{if Object.keys(parameters).indexOf(param.name) == -1 }}',
// if this is an exclusion group, only display one label and make only one structure
' <div class="form-group param-field">',
' <label id="label_${param.group}" class="col-sm-2 control-label" for="${param.name}">${param.display_name}</label>',
' <div class="col-sm-10">',
// if it's a multiple type
' {{if param.type == "MultipleParameters"}}',
' <blockquote style="font-size:14px;">',
' {{if param.paired_columns}}',
' <button class="selectMultipleFiles" for="${param.name}" paired_columns="${param.paired_columns}"></button>',
' {{/if}}',
' {{if param.action == "MiltipleAppendAction"}}', // if it's an append and multiple type
' <div id="handsontable_${param.name}" > </div>',
' <span id="error_handsontable_${param.name}" class="help-block" for="read_2"></span>',
' <span id="help_handsontable_${param.name}" class="help-block">${param.help}</span>',
' {{else}}', // if it's a single and multiple type
' {{each(spindex, sub_param) param.sub_parameters}}',
' <div class="param-field">',
' {{if sub_param.type == "bool"}}',
' {{html getParameterDisplay(templates, getTplName(sub_param), sub_param, sub_param.display_name)}}',
' {{else}}',
' <div class="input-group">',
' <span class="input-group-addon">${sub_param.display_name}</span>',
' {{html getParameterDisplay(templates, getTplName(sub_param), sub_param)}}',
' </div>',
' {{/if}}',
' <span class="help-block">${sub_param.help}</span> <br />',
' </div>',
' {{/each}}',
' {{/if}}',
' </blockquote>',
// if it's a single type
' {{else}}',
' {{html getParameterDisplay(templates, getTplName(param), param)}}',
' <span class="help-block">${param.help}</span>',
' {{/if}}',
' </div>',
' </div>',
' {{else}}',
// if the param is already settled, hide it
' {{if param.action == "append"}}',
' <input id="${param.name}" name="${param.name}" value="${parameters[param.name].join(\"::-::\")}" type="hidden">',
' {{else}}',
' <input id="${param.name}" name="${param.name}" value="${parameters[param.name]}" type="hidden">',
' {{/if}}',
' {{/if}}',
' {{/each}}',
' </fieldset>',
' {{/each}}',
' <fieldset>',
// for all workflow add the workflowClass
' <input name="workflow_class" value="${workflow.class}" type="hidden">',
// add buttons if requested
' {{if display_reset_button || display_run_button}}',
' <div class="row"> <div class="col-md-3 col-md-offset-9">',
' <div class="btn-group launch-wf">',
' {{if display_reset_button}}',
' <button id="wfform_reset_btn" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Reset</button>',
' {{/if}}',
' {{if display_run_button}}',
' <button id="wfform_run_btn" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-cog"></span> Run</button>',
' {{/if}}',
' </div>',
' </div>',
' {{/if}}',
' </fieldset>',
'</form>',
// add a second form for the files to upload
'<form method="post" enctype="multipart/form-data" style="display:none;">',
' {{each(gindex, group) workflow.groups}}',
' {{each(index, param) workflow.parameters_per_groups[group]}}',
// if param is an inputfile or just a browsefile
' {{if param.type.indexOf("inputfile") === 0 || param.type.indexOf("browsefile") === 0}}',
' {{if param.action == "append"}}',
' <input name="browse_${param.name}" id="browse_${param.name}" class="fileupload" multiple type="file">',
' {{else}}',
' <input name="browse_${param.name}" id="browse_${param.name}" class="fileupload" type="file">',
' {{/if}}',
// if it's a multiple type
' {{else param.type == "MultipleParameters"}}',
' {{each(spindex, sub_param) param.sub_parameters}}',
' {{if sub_param.type.indexOf("inputfile") === 0 || sub_param.type.indexOf("browsefile") === 0}}',
' {{if param.action == "append"}}',
' <input name="browse_${sub_param.name}" id="browse_${sub_param.name}" multiple class="fileupload" type="file">',
' {{else}}',
' <input name="browse_${sub_param.name}" id="browse_${sub_param.name}" class="fileupload" type="file">',
' {{/if}}',
' {{/if}}',
' {{/each}}',
' {{/if}}',
' {{/each}}',
' {{/each}}',
'</form>',
'<div id="progress"></div>'].join('\n');
$.fn.wfform.defaults = {
serverURL: "",
dateTemplate: [
......@@ -1488,24 +1597,33 @@ Handsontable.cellTypes["bootdate"] = Handsontable.BootstrapDateCell;
' <select id="${param.name}" name="${param.name}" class="form-control">',
'{{/if}}',
' {{each(j, choice) param.choices}}',
' {{if choice == param.default}}',
' <option {{if $.type(param.choices) === "object"}} value=${j} {{/if}} selected>${choice}</option>', //Add value= if choices is a dict
' {{if choice==param.default || j==param.default }}',
' <option {{if $.type(param.choices) === "object"}} id="opt_${param.name}_${j}" value=${j} {{/if}} selected>${choice}</option>', //Add value= if choices is a dict
' {{else}}',
' <option {{if $.type(param.choices) === "object"}} value=${j} {{/if}} >${choice}</option>',
' <option {{if $.type(param.choices) === "object"}} id="opt_${param.name}_${j}" value=${j} {{/if}} >${choice}</option>',
' {{/if}}',
' {{/each}}',
' </select>',
'</div>'
].join('\n'),
inputfileChoiceTemplate: [
'<div>',
'{{if param.action == "append"}}', // if it's a multiple choice parameter, add a multiple select
' <select id="${param.name}" multiple name="${param.name}" class="form-control list">',
'{{else}}', // if it's a single choice parameter, add a simple select
' <select id="${param.name}" name="${param.name}" class="form-control">',
'{{/if}}',
' {{each(j, choice) param.choices}}',
' <option {{if $.type(param.choices) === "object"}} id="opt_${param.name}_${choice}" value=${j} {{/if}} >${choice}</option>',
' {{/each}}',
' </select>',
'</div>'
].join('\n'),
inputfileTemplate: [
'<div>',
' <div class="input-group">',
' <div class="input-group-btn">',
// ' {{if param.action == "append"}}',
// ' <button type="button" style="padding-top:23px; padding-bottom:22px;" class="btn btn-default dropdown-toggle" data-toggle="dropdown">',
// ' {{else}}',
' <button type="button" class="btn btn-default dropdown-toggle" data-toggle="dropdown">',
// ' {{/if}}',
' <span id="inputfile_${param.name}">server file</span>',
' <span class="caret"></span>',
' </button>',
......
This diff is collapsed.
Markdown is supported
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