Commit 8b33cf3e authored by Jerome Mariette's avatar Jerome Mariette
Browse files

handle form check before submitting, testing types

parent 0ace08ed
......@@ -118,6 +118,7 @@
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-carousel.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-typeahead.js"></script>
<script src="http://twitter.github.com/bootstrap/assets/js/bootstrap-affix.js"></script>
<script src='src/js/jquery.validate.js' type='text/javascript'></script>
<script src='src/js/jquery.tmpl.min.js' type='text/javascript'></script>
<script src='src/js/jflow-activewf.js' type='text/javascript'></script>
<script src='src/js/jflow-availablewf.js' type='text/javascript'></script>
......
......@@ -47,8 +47,7 @@ from cctools.makeflow.log import Node
def date(datestr):
try: return datetime.datetime.strptime(datestr, '%d-%m-%Y')
except: return datetime.datetime.strptime(datestr, '%d/%m/%Y')
return datetime.datetime.strptime(datestr, '%d/%m/%Y')
class Workflow(threading.Thread):
"""
......@@ -243,7 +242,7 @@ class Workflow(threading.Thread):
# if it's a date and there is no default value, use today as default value
if params[param]["type"] == "date" and not params[param].has_key("default"):
today = datetime.date.today()
default = today.strftime('%d-%m-%Y')
default = today.strftime('%d/%m/%Y')
elif params[param].has_key("action"):
if params[param]["action"] == "append": default = []
else:
......
......@@ -19,6 +19,47 @@
* This copyright notice MUST APPEAR in all copies of the script!
***************************************************************/
$.validator.setDefaults({
highlight: function (element, errorClass, validClass) {
var $element;
if ( element.type === "radio" ) {
$element = this.findByName(element.name);
} else {
$element = $(element);
}
$element.addClass(errorClass).removeClass(validClass);
// add the bootstrap error class
$element.parents("div.control-group").addClass("error");
},
unhighlight: function (element, errorClass, validClass) {
var $element;
if (element.type === 'radio') {
$element = this.findByName(element.name);
} else {
$element = $(element);
}
$element.removeClass(errorClass).addClass(validClass);
// remove the bootstrap error class
if ($element.parents("div.control-group").find("." + errorClass).length == 0) {
// Only remove the class if there are no other errors
$element.parents("div.control-group").removeClass(errorClass).addClass(validClass);
}
},
errorPlacement: function(error, element) {
if (element.parent("div.input-append").length > 0) {
error.insertAfter(element.parent("div.input-append"));
if (element.parent("div.input-append").find(".btn").length > 0) {
element.parent("div.input-append").find(".btn")
}
} else {
error.insertAfter(element);
}
},
errorElement: "span",
errorClass: "help-block error"
});
!function ($) {
"use strict"; // jshint ;_;
......@@ -37,18 +78,22 @@
}
WFForm.prototype.run = function() {
var params = "",
$this = this;
$.each ( $('#workflow_form').serializeArray(), function(_, kv) {
params += kv.name + "=" +kv.value + "&";
});
$.ajax({
url: this.options.serverURL + '/run_workflow?' + params + 'callback=?',
dataType: "json",
success: function(running_wf) {
$this.options.callback(running_wf);
}
});
// first check if the form is valid
if ($("#workflow_form").valid()) {
// then send data
var params = "",
$this = this;
$.each ( $('#workflow_form').serializeArray(), function(_, kv) {
params += kv.name + "=" +kv.value + "&";
});
$.ajax({
url: this.options.serverURL + '/run_workflow?' + params + 'callback=?',
dataType: "json",
success: function(running_wf) {
$this.options.callback(running_wf);
}
});
}
}
WFForm.prototype.load = function() {
......@@ -57,7 +102,8 @@
url: this.options.serverURL + '/get_available_workflows?callback=?',
dataType: "json",
success: function(data) {
var workflow = null;
var workflow = null,
rules = {};
for (var i in data) {
if (data[i]["class"] == $this.options.workflowClass) {
workflow = data[i];
......@@ -68,6 +114,24 @@
$.tmpl($this.options.template, {workflow: workflow, display_run_button: $this.options.displayRunButton,
display_reset_button: $this.options.displayResetButton}).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,
number: true
}
} else if (workflow.parameters[i].type == "date") {
rules[workflow.parameters[i].name] = {
required: workflow.parameters[i].required,
date: true
}
} else {
rules[workflow.parameters[i].name] = {
required: workflow.parameters[i].required
}
}
}
$("#workflow_form").validate({ rules: rules });
if ($this.options.displayRunButton) {
$("#wfform_run_btn").click(function() { $this.run(); })
}
......@@ -119,7 +183,7 @@
' </select>',
// if param is a date
' {{else param.type == "date"}}',
' <div class="input-append date" data-date="${param.default}" data-date-format="dd-mm-yyyy">',
' <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}">',
' <button class="btn" type="button"><i class="icon-calendar"></i></button>',
' </div>',
......@@ -127,7 +191,7 @@
' {{else}}',
' <input name="${param.name}" value="${param.default}" class="input-xlarge" type="text">',
' {{/if}}',
' <p class="help-block">${param.help}</p>',
' <span class="help-block">${param.help}</span>',
' </div>',
' </div>',
' {{/each}}',
......
This diff is collapsed.
......@@ -45,6 +45,7 @@ read_2.action = append
reference_genome.name = reference_genome
reference_genome.flag = --reference-genome
reference_genome.help = Which genome should the read being align on
reference_genome.required = True
#
# Bellow workflow specifc sections
......
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