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

add reseting action

parent 155c8faa
......@@ -74,12 +74,18 @@
var WFForm = function (element, options) {
this.$element = $(element)
this.options = $.extend({}, $.fn.wfform.defaults, options)
this.options = $.extend({}, $.fn.wfform.defaults, options);
if (this.options.serverURL == "") { this.options.serverURL = $.fn.activewf.defaults.serverURL; }
}
WFForm.prototype.reset = function() {
alert("reseting")
for (var i in this.workflow.parameters) {
if (this.workflow.parameters[i].default) {
$("#"+this.workflow.parameters[i].name).val(this.workflow.parameters[i].default);
} else {
$("#"+this.workflow.parameters[i].name).val("");
}
}
}
WFForm.prototype.run = function() {
......@@ -133,34 +139,33 @@
$this.$element.html(alert_message);
},
success: function(data) {
var workflow = null,
rules = {};
var rules = {};
for (var i in data) {
if (data[i]["class"] == $this.options.workflowClass) {
workflow = data[i];
$this.workflow = data[i];
break;
}
}
// trigger an event to specify the workflow is loaded
$this.$element.trigger('loaded', workflow);
$this.$element.trigger('loaded', $this.workflow);
$this.$element.html("");
$.tmpl($this.options.template, {workflow: workflow, display_run_button: $this.options.displayRunButton,
$.tmpl($this.options.template, {workflow: $this.workflow, display_run_button: $this.options.displayRunButton,
display_reset_button: $this.options.displayResetButton, parameters: $this.options.parameters}).appendTo($this.$element);
$('.date').datepicker().on('changeDate', function(ev){ $('.date').datepicker('hide');} );
for (var i in workflow.parameters) {
if (workflow.parameters[i].type == "int") {
rules[workflow.parameters[i].name] = {
required: workflow.parameters[i].required,
for (var i in $this.workflow.parameters) {
if ($this.workflow.parameters[i].type == "int") {
rules[$this.workflow.parameters[i].name] = {
required: $this.workflow.parameters[i].required,
number: true
}
} else if (workflow.parameters[i].type == "date") {
rules[workflow.parameters[i].name] = {
required: workflow.parameters[i].required,
} else if ($this.workflow.parameters[i].type == "date") {
rules[$this.workflow.parameters[i].name] = {
required: $this.workflow.parameters[i].required,
date: true
}
} else {
rules[workflow.parameters[i].name] = {
required: workflow.parameters[i].required
rules[$this.workflow.parameters[i].name] = {
required: $this.workflow.parameters[i].required
}
}
}
......@@ -207,7 +212,7 @@
' <div class="controls">',
// if it's a multiple choice parameter, add a select
' {{if param.choices}}',
' <select name="${param.name}" class="input-xlarge">',
' <select id="${param.name}" name="${param.name}" class="input-xlarge">',
' {{each(j, choice) param.choices}}',
' {{if choice == param.default}}',
' <option selected>${choice}</option>',
......@@ -219,28 +224,28 @@
// if param is a date
' {{else param.type == "date"}}',
' <div class="input-append date" data-date="${param.default}" data-date-format="dd/mm/yyyy">',
' <input name="${param.name}" class="input-xlarge span2" type="text" value="${param.default}">',
' <input id="${param.name}" name="${param.name}" class="input-xlarge span2" type="text" value="${param.default}">',
' <button class="btn" type="button"><i class="icon-calendar"></i></button>',
' </div>',
// if param is a boolean
' {{else param.type == "bool"}}',
' <label class="checkbox">',
' {{if param.default == true}}',
' <input name="${param.name}" value="${param.default}" type="checkbox" checked>',
' <input id="${param.name}" name="${param.name}" value="${param.default}" type="checkbox" checked>',
' {{else}}',
' <input name="${param.name}" value="${param.default}" type="checkbox">',
' <input id="${param.name}" name="${param.name}" value="${param.default}" type="checkbox">',
' {{/if}}',
' </label>',
// else a simple text input
' {{else}}',
' <input name="${param.name}" value="${param.default}" class="input-xlarge" type="text">',
' <input id="${param.name}" name="${param.name}" value="${param.default}" class="input-xlarge" type="text">',
' {{/if}}',
' <span class="help-block">${param.help}</span>',
' </div>',
' </div>',
' {{else}}',
// if the param is already settled, hide it
' <input name="${param.name}" value="${parameters[param.name]}" type="hidden">',
' <input id="${param.name}" name="${param.name}" value="${parameters[param.name]}" type="hidden">',
' {{/if}}',
' {{/each}}',
// for all workflow add the workflowClass
......@@ -264,6 +269,7 @@
workflowClass: null,
displayRunButton: true,
displayResetButton: true,
workflow: null,
parameters: {}
}
......
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