1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/f8012e167c9d/ Changeset: f8012e167c9d User: guerler Date: 2015-02-12 16:10:14+00:00 Summary: ToolForm: Separate tool parameters from sections Affected #: 6 files diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 client/galaxy/scripts/mvc/tools/tools-parameters.js --- /dev/null +++ b/client/galaxy/scripts/mvc/tools/tools-parameters.js @@ -0,0 +1,247 @@ +/** + This class creates input elements. New input parameter types should be added to the types dictionary. +*/ +define(['utils/utils','mvc/ui/ui-misc', 'mvc/tools/tools-select-content'], + function(Utils, Ui, SelectContent) { + + // create form view + return Backbone.Model.extend({ + /** Available parameter types */ + types: { + 'text' : '_fieldText', + 'select' : '_fieldSelect', + 'data_column' : '_fieldSelect', + 'genomebuild' : '_fieldSelect', + 'data' : '_fieldData', + 'data_collection' : '_fieldData', + 'integer' : '_fieldSlider', + 'float' : '_fieldSlider', + 'boolean' : '_fieldBoolean', + 'drill_down' : '_fieldDrilldown', + 'hidden' : '_fieldHidden', + 'hidden_data' : '_fieldHidden', + 'baseurl' : '_fieldHidden' + }, + + // initialize + initialize: function(app, options) { + this.app = app; + }, + + /** Returns an input field for a given field type + */ + create: function(input_def) { + // add regular/default value if missing + if (input_def.value === undefined) { + input_def.value = null; + } + if (input_def.default_value === undefined) { + input_def.default_value = input_def.value; + } + + // field wrapper + var field = null; + + // get field class + var fieldClass = this.types[input_def.type]; + if (fieldClass && typeof(this[fieldClass]) === 'function') { + field = this[fieldClass].call(this, input_def); + } + + // identify field type + if (!field) { + // flag + this.app.incompatible = true; + + // with or without options + if (input_def.options) { + // assign select field + field = this._fieldSelect(input_def); + } else { + // assign text field + field = this._fieldText(input_def); + } + + // log + console.debug('tools-form::_addRow() : Auto matched field type (' + input_def.type + ').'); + } + + // set field value + if (input_def.value !== undefined) { + field.value(input_def.value); + } + + // return field element + return field; + }, + + /** Data input field + */ + _fieldData : function(input_def) { + if (!this.app.options.is_dynamic) { + input_def.info = 'Data input \'' + input_def.name + '\' (' + Utils.textify(input_def.extensions.toString()) + ')'; + input_def.value = null; + return this._fieldHidden(input_def); + } + var self = this; + return new SelectContent.View(this.app, { + id : 'field-' + input_def.id, + extensions : input_def.extensions, + optional : input_def.optional, + multiple : input_def.multiple, + type : input_def.type, + data : input_def.options, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Select/Checkbox/Radio options field + */ + _fieldSelect : function (input_def) { + // show text field in if dynamic fields are disabled e.g. in workflow editor + if (!this.app.options.is_dynamic && input_def.is_dynamic) { + return this._fieldText(input_def); + } + + // customize properties + if (input_def.type == 'data_column') { + input_def.error_text = 'Missing columns in referenced dataset.' + } + if (input_def.type == 'genomebuild') { + input_def.searchable = true; + } + + // configure options fields + var options = []; + for (var i in input_def.options) { + var option = input_def.options[i]; + options.push({ + label: option[0], + value: option[1] + }); + } + + // identify display type + var SelectClass = Ui.Select; + switch (input_def.display) { + case 'checkboxes': + SelectClass = Ui.Checkbox; + break; + case 'radio': + SelectClass = Ui.Radio; + break; + } + + // select field + var self = this; + return new SelectClass.View({ + id : 'field-' + input_def.id, + data : options, + error_text : input_def.error_text || 'No options available', + multiple : input_def.multiple, + searchable : input_def.searchable, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Drill down options field + */ + _fieldDrilldown : function (input_def) { + // show text field in if dynamic fields are disabled e.g. in workflow editor + if (!this.app.options.is_dynamic && input_def.is_dynamic) { + return this._fieldText(input_def); + } + + // create drill down field + var self = this; + return new Ui.Drilldown.View({ + id : 'field-' + input_def.id, + data : input_def.options, + display : input_def.display, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Text input field + */ + _fieldText : function(input_def) { + // field replaces e.g. a select field + if (input_def.options) { + // show text area if selecting multiple entries is allowed + input_def.area = input_def.multiple; + + // validate value + if (!Utils.validate(input_def.value)) { + input_def.value = ''; + } else { + if (input_def.value instanceof Array) { + input_def.value = value.toString(); + } else { + input_def.value = String(input_def.value).replace(/[\[\]'"\s]/g, ''); + if (input_def.multiple) { + input_def.value = input_def.value.replace(/,/g, '\n'); + } + } + } + } + + // create input element + var self = this; + return new Ui.Input({ + id : 'field-' + input_def.id, + area : input_def.area, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Slider field + */ + _fieldSlider: function(input_def) { + var self = this; + return new Ui.Slider.View({ + id : 'field-' + input_def.id, + precise : input_def.type == 'float', + min : input_def.min, + max : input_def.max, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Hidden field + */ + _fieldHidden : function(input_def) { + return new Ui.Hidden({ + id : 'field-' + input_def.id, + info : input_def.info + }); + }, + + /** Boolean field + */ + _fieldBoolean : function(input_def) { + var self = this; + return new Ui.RadioButton.View({ + id : 'field-' + input_def.id, + data : [ { label : 'Yes', value : 'true' }, + { label : 'No', value : 'false' }], + onchange : function() { + self.app.trigger('refresh'); + } + }); + } + }); + + return { + View: View + }; +}); diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 client/galaxy/scripts/mvc/tools/tools-section.js --- a/client/galaxy/scripts/mvc/tools/tools-section.js +++ b/client/galaxy/scripts/mvc/tools/tools-section.js @@ -1,8 +1,14 @@ /** - This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. New input elements can be plugged in by adding cases to the switch block defined in the _createField() function. + This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. */ -define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/ui/ui-portlet', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-content', 'mvc/tools/tools-input'], - function(Utils, Table, Ui, Portlet, Repeat, SelectContent, InputElement) { +define(['utils/utils', + 'mvc/ui/ui-table', + 'mvc/ui/ui-misc', + 'mvc/ui/ui-portlet', + 'mvc/tools/tools-repeat', + 'mvc/tools/tools-input', + 'mvc/tools/tools-parameters'], + function(Utils, Table, Ui, Portlet, Repeat, InputElement, Parameters) { // create form view var View = Backbone.View.extend({ @@ -23,6 +29,9 @@ // create table this.table = new Table.View(options); + + // create parameter handler + this.parameters = new Parameters(app, options); // configure portlet and form table this.setElement(this.table.$el); @@ -294,16 +303,8 @@ // get id var id = input_def.id; - // add regular/default value if missing - if (input_def.value === undefined) { - input_def.value = null; - } - if (input_def.default_value === undefined) { - input_def.default_value = input_def.value; - } - // create input field - var field = this._createField(input_def); + var field = this.parameters.create(input_def); // add to field list this.app.field_list[id] = field; @@ -333,265 +334,6 @@ // return created field return field; - }, - - /** Returns an input field for a given field type - */ - _createField: function(input_def) { - // field wrapper - var field = null; - - // identify field type - switch(input_def.type) { - // text input field - case 'text' : - field = this._fieldText(input_def); - break; - - // select field - case 'select' : - field = this._fieldSelect(input_def); - break; - - // data selector - case 'data': - field = this._fieldData(input_def); - break; - - // collection selector - case 'data_collection': - field = this._fieldData(input_def); - break; - - // data column - case 'data_column': - input_def.error_text = 'Missing columns in referenced dataset.'; - field = this._fieldSelect(input_def); - break; - - // hidden field - case 'hidden': - field = this._fieldHidden(input_def); - break; - - // hidden data field - case 'hidden_data': - field = this._fieldHidden(input_def); - break; - - // integer field - case 'integer': - field = this._fieldSlider(input_def); - break; - - // float field - case 'float': - field = this._fieldSlider(input_def); - break; - - // boolean field - case 'boolean': - field = this._fieldBoolean(input_def); - break; - - // genome field - case 'genomebuild': - input_def.searchable = true; - field = this._fieldSelect(input_def); - break; - - // drill down field - case 'drill_down': - field = this._fieldDrilldown(input_def); - break; - - // base url field - case 'baseurl': - field = this._fieldHidden(input_def); - break; - - // field not found - default: - // flag - this.app.incompatible = true; - - // with or without options - if (input_def.options) { - // assign select field - field = this._fieldSelect(input_def); - } else { - // assign text field - field = this._fieldText(input_def); - } - - // log - console.debug('tools-form::_addRow() : Auto matched field type (' + input_def.type + ').'); - } - - // set field value - if (input_def.value !== undefined) { - field.value(input_def.value); - } - - // return field element - return field; - }, - - /** Data input field - */ - _fieldData : function(input_def) { - if (!this.app.options.is_dynamic) { - input_def.info = 'Data input \'' + input_def.name + '\' (' + Utils.textify(input_def.extensions.toString()) + ')'; - input_def.value = null; - return this._fieldHidden(input_def); - } - var self = this; - return new SelectContent.View(this.app, { - id : 'field-' + input_def.id, - extensions : input_def.extensions, - optional : input_def.optional, - multiple : input_def.multiple, - type : input_def.type, - data : input_def.options, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Select/Checkbox/Radio options field - */ - _fieldSelect : function (input_def) { - // show text field in if dynamic fields are disabled e.g. in workflow editor - if (!this.app.options.is_dynamic && input_def.is_dynamic) { - return this._fieldText(input_def); - } - - // configure options fields - var options = []; - for (var i in input_def.options) { - var option = input_def.options[i]; - options.push({ - label: option[0], - value: option[1] - }); - } - - // identify display type - var SelectClass = Ui.Select; - switch (input_def.display) { - case 'checkboxes': - SelectClass = Ui.Checkbox; - break; - case 'radio': - SelectClass = Ui.Radio; - break; - } - - // select field - var self = this; - return new SelectClass.View({ - id : 'field-' + input_def.id, - data : options, - error_text : input_def.error_text || 'No options available', - multiple : input_def.multiple, - searchable : input_def.searchable, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Drill down options field - */ - _fieldDrilldown : function (input_def) { - // show text field in if dynamic fields are disabled e.g. in workflow editor - if (!this.app.options.is_dynamic && input_def.is_dynamic) { - return this._fieldText(input_def); - } - - // create drill down field - var self = this; - return new Ui.Drilldown.View({ - id : 'field-' + input_def.id, - data : input_def.options, - display : input_def.display, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Text input field - */ - _fieldText : function(input_def) { - // field replaces e.g. a select field - if (input_def.options) { - // show text area if selecting multiple entries is allowed - input_def.area = input_def.multiple; - - // validate value - if (!Utils.validate(input_def.value)) { - input_def.value = ''; - } else { - if (input_def.value instanceof Array) { - input_def.value = value.toString(); - } else { - input_def.value = String(input_def.value).replace(/[\[\]'"\s]/g, ''); - if (input_def.multiple) { - input_def.value = input_def.value.replace(/,/g, '\n'); - } - } - } - } - - // create input element - var self = this; - return new Ui.Input({ - id : 'field-' + input_def.id, - area : input_def.area, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Slider field - */ - _fieldSlider: function(input_def) { - var self = this; - return new Ui.Slider.View({ - id : 'field-' + input_def.id, - precise : input_def.type == 'float', - min : input_def.min, - max : input_def.max, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Hidden field - */ - _fieldHidden : function(input_def) { - return new Ui.Hidden({ - id : 'field-' + input_def.id, - info : input_def.info - }); - }, - - /** Boolean field - */ - _fieldBoolean : function(input_def) { - var self = this; - return new Ui.RadioButton.View({ - id : 'field-' + input_def.id, - data : [ { label : 'Yes', value : 'true' }, - { label : 'No', value : 'false' }], - onchange : function() { - self.app.trigger('refresh'); - } - }); } }); diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 static/scripts/mvc/tools/tools-parameters.js --- /dev/null +++ b/static/scripts/mvc/tools/tools-parameters.js @@ -0,0 +1,247 @@ +/** + This class creates input elements. New input parameter types should be added to the types dictionary. +*/ +define(['utils/utils','mvc/ui/ui-misc', 'mvc/tools/tools-select-content'], + function(Utils, Ui, SelectContent) { + + // create form view + return Backbone.Model.extend({ + /** Available parameter types */ + types: { + 'text' : '_fieldText', + 'select' : '_fieldSelect', + 'data_column' : '_fieldSelect', + 'genomebuild' : '_fieldSelect', + 'data' : '_fieldData', + 'data_collection' : '_fieldData', + 'integer' : '_fieldSlider', + 'float' : '_fieldSlider', + 'boolean' : '_fieldBoolean', + 'drill_down' : '_fieldDrilldown', + 'hidden' : '_fieldHidden', + 'hidden_data' : '_fieldHidden', + 'baseurl' : '_fieldHidden' + }, + + // initialize + initialize: function(app, options) { + this.app = app; + }, + + /** Returns an input field for a given field type + */ + create: function(input_def) { + // add regular/default value if missing + if (input_def.value === undefined) { + input_def.value = null; + } + if (input_def.default_value === undefined) { + input_def.default_value = input_def.value; + } + + // field wrapper + var field = null; + + // get field class + var fieldClass = this.types[input_def.type]; + if (fieldClass && typeof(this[fieldClass]) === 'function') { + field = this[fieldClass].call(this, input_def); + } + + // identify field type + if (!field) { + // flag + this.app.incompatible = true; + + // with or without options + if (input_def.options) { + // assign select field + field = this._fieldSelect(input_def); + } else { + // assign text field + field = this._fieldText(input_def); + } + + // log + console.debug('tools-form::_addRow() : Auto matched field type (' + input_def.type + ').'); + } + + // set field value + if (input_def.value !== undefined) { + field.value(input_def.value); + } + + // return field element + return field; + }, + + /** Data input field + */ + _fieldData : function(input_def) { + if (!this.app.options.is_dynamic) { + input_def.info = 'Data input \'' + input_def.name + '\' (' + Utils.textify(input_def.extensions.toString()) + ')'; + input_def.value = null; + return this._fieldHidden(input_def); + } + var self = this; + return new SelectContent.View(this.app, { + id : 'field-' + input_def.id, + extensions : input_def.extensions, + optional : input_def.optional, + multiple : input_def.multiple, + type : input_def.type, + data : input_def.options, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Select/Checkbox/Radio options field + */ + _fieldSelect : function (input_def) { + // show text field in if dynamic fields are disabled e.g. in workflow editor + if (!this.app.options.is_dynamic && input_def.is_dynamic) { + return this._fieldText(input_def); + } + + // customize properties + if (input_def.type == 'data_column') { + input_def.error_text = 'Missing columns in referenced dataset.' + } + if (input_def.type == 'genomebuild') { + input_def.searchable = true; + } + + // configure options fields + var options = []; + for (var i in input_def.options) { + var option = input_def.options[i]; + options.push({ + label: option[0], + value: option[1] + }); + } + + // identify display type + var SelectClass = Ui.Select; + switch (input_def.display) { + case 'checkboxes': + SelectClass = Ui.Checkbox; + break; + case 'radio': + SelectClass = Ui.Radio; + break; + } + + // select field + var self = this; + return new SelectClass.View({ + id : 'field-' + input_def.id, + data : options, + error_text : input_def.error_text || 'No options available', + multiple : input_def.multiple, + searchable : input_def.searchable, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Drill down options field + */ + _fieldDrilldown : function (input_def) { + // show text field in if dynamic fields are disabled e.g. in workflow editor + if (!this.app.options.is_dynamic && input_def.is_dynamic) { + return this._fieldText(input_def); + } + + // create drill down field + var self = this; + return new Ui.Drilldown.View({ + id : 'field-' + input_def.id, + data : input_def.options, + display : input_def.display, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Text input field + */ + _fieldText : function(input_def) { + // field replaces e.g. a select field + if (input_def.options) { + // show text area if selecting multiple entries is allowed + input_def.area = input_def.multiple; + + // validate value + if (!Utils.validate(input_def.value)) { + input_def.value = ''; + } else { + if (input_def.value instanceof Array) { + input_def.value = value.toString(); + } else { + input_def.value = String(input_def.value).replace(/[\[\]'"\s]/g, ''); + if (input_def.multiple) { + input_def.value = input_def.value.replace(/,/g, '\n'); + } + } + } + } + + // create input element + var self = this; + return new Ui.Input({ + id : 'field-' + input_def.id, + area : input_def.area, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Slider field + */ + _fieldSlider: function(input_def) { + var self = this; + return new Ui.Slider.View({ + id : 'field-' + input_def.id, + precise : input_def.type == 'float', + min : input_def.min, + max : input_def.max, + onchange : function() { + self.app.trigger('refresh'); + } + }); + }, + + /** Hidden field + */ + _fieldHidden : function(input_def) { + return new Ui.Hidden({ + id : 'field-' + input_def.id, + info : input_def.info + }); + }, + + /** Boolean field + */ + _fieldBoolean : function(input_def) { + var self = this; + return new Ui.RadioButton.View({ + id : 'field-' + input_def.id, + data : [ { label : 'Yes', value : 'true' }, + { label : 'No', value : 'false' }], + onchange : function() { + self.app.trigger('refresh'); + } + }); + } + }); + + return { + View: View + }; +}); diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 static/scripts/mvc/tools/tools-section.js --- a/static/scripts/mvc/tools/tools-section.js +++ b/static/scripts/mvc/tools/tools-section.js @@ -1,8 +1,14 @@ /** - This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. New input elements can be plugged in by adding cases to the switch block defined in the _createField() function. + This class creates a tool form section and populates it with input elements. It also handles repeat blocks and conditionals by recursively creating new sub sections. */ -define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/ui/ui-portlet', 'mvc/tools/tools-repeat', 'mvc/tools/tools-select-content', 'mvc/tools/tools-input'], - function(Utils, Table, Ui, Portlet, Repeat, SelectContent, InputElement) { +define(['utils/utils', + 'mvc/ui/ui-table', + 'mvc/ui/ui-misc', + 'mvc/ui/ui-portlet', + 'mvc/tools/tools-repeat', + 'mvc/tools/tools-input', + 'mvc/tools/tools-parameters'], + function(Utils, Table, Ui, Portlet, Repeat, InputElement, Parameters) { // create form view var View = Backbone.View.extend({ @@ -23,6 +29,9 @@ // create table this.table = new Table.View(options); + + // create parameter handler + this.parameters = new Parameters(app, options); // configure portlet and form table this.setElement(this.table.$el); @@ -294,16 +303,8 @@ // get id var id = input_def.id; - // add regular/default value if missing - if (input_def.value === undefined) { - input_def.value = null; - } - if (input_def.default_value === undefined) { - input_def.default_value = input_def.value; - } - // create input field - var field = this._createField(input_def); + var field = this.parameters.create(input_def); // add to field list this.app.field_list[id] = field; @@ -333,265 +334,6 @@ // return created field return field; - }, - - /** Returns an input field for a given field type - */ - _createField: function(input_def) { - // field wrapper - var field = null; - - // identify field type - switch(input_def.type) { - // text input field - case 'text' : - field = this._fieldText(input_def); - break; - - // select field - case 'select' : - field = this._fieldSelect(input_def); - break; - - // data selector - case 'data': - field = this._fieldData(input_def); - break; - - // collection selector - case 'data_collection': - field = this._fieldData(input_def); - break; - - // data column - case 'data_column': - input_def.error_text = 'Missing columns in referenced dataset.'; - field = this._fieldSelect(input_def); - break; - - // hidden field - case 'hidden': - field = this._fieldHidden(input_def); - break; - - // hidden data field - case 'hidden_data': - field = this._fieldHidden(input_def); - break; - - // integer field - case 'integer': - field = this._fieldSlider(input_def); - break; - - // float field - case 'float': - field = this._fieldSlider(input_def); - break; - - // boolean field - case 'boolean': - field = this._fieldBoolean(input_def); - break; - - // genome field - case 'genomebuild': - input_def.searchable = true; - field = this._fieldSelect(input_def); - break; - - // drill down field - case 'drill_down': - field = this._fieldDrilldown(input_def); - break; - - // base url field - case 'baseurl': - field = this._fieldHidden(input_def); - break; - - // field not found - default: - // flag - this.app.incompatible = true; - - // with or without options - if (input_def.options) { - // assign select field - field = this._fieldSelect(input_def); - } else { - // assign text field - field = this._fieldText(input_def); - } - - // log - console.debug('tools-form::_addRow() : Auto matched field type (' + input_def.type + ').'); - } - - // set field value - if (input_def.value !== undefined) { - field.value(input_def.value); - } - - // return field element - return field; - }, - - /** Data input field - */ - _fieldData : function(input_def) { - if (!this.app.options.is_dynamic) { - input_def.info = 'Data input \'' + input_def.name + '\' (' + Utils.textify(input_def.extensions.toString()) + ')'; - input_def.value = null; - return this._fieldHidden(input_def); - } - var self = this; - return new SelectContent.View(this.app, { - id : 'field-' + input_def.id, - extensions : input_def.extensions, - optional : input_def.optional, - multiple : input_def.multiple, - type : input_def.type, - data : input_def.options, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Select/Checkbox/Radio options field - */ - _fieldSelect : function (input_def) { - // show text field in if dynamic fields are disabled e.g. in workflow editor - if (!this.app.options.is_dynamic && input_def.is_dynamic) { - return this._fieldText(input_def); - } - - // configure options fields - var options = []; - for (var i in input_def.options) { - var option = input_def.options[i]; - options.push({ - label: option[0], - value: option[1] - }); - } - - // identify display type - var SelectClass = Ui.Select; - switch (input_def.display) { - case 'checkboxes': - SelectClass = Ui.Checkbox; - break; - case 'radio': - SelectClass = Ui.Radio; - break; - } - - // select field - var self = this; - return new SelectClass.View({ - id : 'field-' + input_def.id, - data : options, - error_text : input_def.error_text || 'No options available', - multiple : input_def.multiple, - searchable : input_def.searchable, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Drill down options field - */ - _fieldDrilldown : function (input_def) { - // show text field in if dynamic fields are disabled e.g. in workflow editor - if (!this.app.options.is_dynamic && input_def.is_dynamic) { - return this._fieldText(input_def); - } - - // create drill down field - var self = this; - return new Ui.Drilldown.View({ - id : 'field-' + input_def.id, - data : input_def.options, - display : input_def.display, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Text input field - */ - _fieldText : function(input_def) { - // field replaces e.g. a select field - if (input_def.options) { - // show text area if selecting multiple entries is allowed - input_def.area = input_def.multiple; - - // validate value - if (!Utils.validate(input_def.value)) { - input_def.value = ''; - } else { - if (input_def.value instanceof Array) { - input_def.value = value.toString(); - } else { - input_def.value = String(input_def.value).replace(/[\[\]'"\s]/g, ''); - if (input_def.multiple) { - input_def.value = input_def.value.replace(/,/g, '\n'); - } - } - } - } - - // create input element - var self = this; - return new Ui.Input({ - id : 'field-' + input_def.id, - area : input_def.area, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Slider field - */ - _fieldSlider: function(input_def) { - var self = this; - return new Ui.Slider.View({ - id : 'field-' + input_def.id, - precise : input_def.type == 'float', - min : input_def.min, - max : input_def.max, - onchange : function() { - self.app.trigger('refresh'); - } - }); - }, - - /** Hidden field - */ - _fieldHidden : function(input_def) { - return new Ui.Hidden({ - id : 'field-' + input_def.id, - info : input_def.info - }); - }, - - /** Boolean field - */ - _fieldBoolean : function(input_def) { - var self = this; - return new Ui.RadioButton.View({ - id : 'field-' + input_def.id, - data : [ { label : 'Yes', value : 'true' }, - { label : 'No', value : 'false' }], - onchange : function() { - self.app.trigger('refresh'); - } - }); } }); diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 static/scripts/packed/mvc/tools/tools-parameters.js --- /dev/null +++ b/static/scripts/packed/mvc/tools/tools-parameters.js @@ -0,0 +1,1 @@ +define(["utils/utils","mvc/ui/ui-misc","mvc/tools/tools-select-content"],function(b,c,a){return Backbone.Model.extend({types:{text:"_fieldText",select:"_fieldSelect",data_column:"_fieldSelect",genomebuild:"_fieldSelect",data:"_fieldData",data_collection:"_fieldData",integer:"_fieldSlider","float":"_fieldSlider","boolean":"_fieldBoolean",drill_down:"_fieldDrilldown",hidden:"_fieldHidden",hidden_data:"_fieldHidden",baseurl:"_fieldHidden"},initialize:function(e,d){this.app=e},create:function(d){if(d.value===undefined){d.value=null}if(d.default_value===undefined){d.default_value=d.value}var f=null;var e=this.types[d.type];if(e&&typeof(this[e])==="function"){f=this[e].call(this,d)}if(!f){this.app.incompatible=true;if(d.options){f=this._fieldSelect(d)}else{f=this._fieldText(d)}console.debug("tools-form::_addRow() : Auto matched field type ("+d.type+").")}if(d.value!==undefined){f.value(d.value)}return f},_fieldData:function(d){if(!this.app.options.is_dynamic){d.info="Data input '"+d.name+"' ("+b.textify(d.extensions.toString())+")";d.value=null;return this._fieldHidden(d)}var e=this;return new a.View(this.app,{id:"field-"+d.id,extensions:d.extensions,optional:d.optional,multiple:d.multiple,type:d.type,data:d.options,onchange:function(){e.app.trigger("refresh")}})},_fieldSelect:function(d){if(!this.app.options.is_dynamic&&d.is_dynamic){return this._fieldText(d)}if(d.type=="data_column"){d.error_text="Missing columns in referenced dataset."}if(d.type=="genomebuild"){d.searchable=true}var f=[];for(var g in d.options){var h=d.options[g];f.push({label:h[0],value:h[1]})}var j=c.Select;switch(d.display){case"checkboxes":j=c.Checkbox;break;case"radio":j=c.Radio;break}var e=this;return new j.View({id:"field-"+d.id,data:f,error_text:d.error_text||"No options available",multiple:d.multiple,searchable:d.searchable,onchange:function(){e.app.trigger("refresh")}})},_fieldDrilldown:function(d){if(!this.app.options.is_dynamic&&d.is_dynamic){return this._fieldText(d)}var e=this;return new c.Drilldown.View({id:"field-"+d.id,data:d.options,display:d.display,onchange:function(){e.app.trigger("refresh")}})},_fieldText:function(d){if(d.options){d.area=d.multiple;if(!b.validate(d.value)){d.value=""}else{if(d.value instanceof Array){d.value=value.toString()}else{d.value=String(d.value).replace(/[\[\]'"\s]/g,"");if(d.multiple){d.value=d.value.replace(/,/g,"\n")}}}}var e=this;return new c.Input({id:"field-"+d.id,area:d.area,onchange:function(){e.app.trigger("refresh")}})},_fieldSlider:function(d){var e=this;return new c.Slider.View({id:"field-"+d.id,precise:d.type=="float",min:d.min,max:d.max,onchange:function(){e.app.trigger("refresh")}})},_fieldHidden:function(d){return new c.Hidden({id:"field-"+d.id,info:d.info})},_fieldBoolean:function(d){var e=this;return new c.RadioButton.View({id:"field-"+d.id,data:[{label:"Yes",value:"true"},{label:"No",value:"false"}],onchange:function(){e.app.trigger("refresh")}})}});return{View:View}}); \ No newline at end of file diff -r 2c6690a2faea4882a688044ec269de5b15569f58 -r f8012e167c9d569cd06140d28e3def5135ba3ed9 static/scripts/packed/mvc/tools/tools-section.js --- a/static/scripts/packed/mvc/tools/tools-section.js +++ b/static/scripts/packed/mvc/tools/tools-section.js @@ -1,1 +1,1 @@ -define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/ui/ui-portlet","mvc/tools/tools-repeat","mvc/tools/tools-select-content","mvc/tools/tools-input"],function(e,b,h,d,c,a,f){var g=Backbone.View.extend({initialize:function(j,i){this.app=j;this.inputs=i.inputs;i.cls="ui-table-plain";i.cls_tr="section-row";this.table=new b.View(i);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();for(var j in this.inputs){this.add(this.inputs[j])}},add:function(k){var j=this;var i=jQuery.extend(true,{},k);i.id=k.id=e.uuid();this.app.input_list[i.id]=i;var l=i.type;switch(l){case"conditional":this._addConditional(i);break;case"repeat":this._addRepeat(i);break;case"section":this._addSection(i);break;default:this._addRow(i)}},_addConditional:function(j){var k=this;j.test_param.id=j.id;var n=this._addRow(j.test_param);n.options.onchange=function(w){var v=k.app.tree.matchCase(j,w);for(var u in j.cases){var q=j.cases[u];var t=j.id+"-section-"+u;var p=k.table.get(t);var s=false;for(var r in q.inputs){if(!q.inputs[r].hidden){s=true;break}}if(u==v&&s){p.fadeIn("fast")}else{p.hide()}}k.app.trigger("refresh")};for(var m in j.cases){var l=j.id+"-section-"+m;var o=new g(this.app,{inputs:j.cases[m].inputs});o.$el.addClass("ui-table-section");this.table.add(o.$el);this.table.append(l)}n.trigger("change")},_addRepeat:function(p){var s=this;var q=0;var l=new c.View({title:p.title,title_new:p.title,min:p.min,max:p.max,onnew:function(){n(p.inputs);s.app.trigger("refresh")}});function n(i){var t=p.id+"-section-"+(q++);var u=new g(s.app,{inputs:i});l.add({id:t,$el:u.$el,ondel:function(){l.del(t);s.app.trigger("refresh")}})}var j=p.min;var r=_.size(p.cache);for(var m=0;m<Math.max(r,j);m++){var o=null;if(m<r){o=p.cache[m]}else{o=p.inputs}n(o)}var k=new f(this.app,{label:p.title,help:p.help,field:l});this.table.add(k.$el);this.table.append(p.id)},_addSection:function(i){var j=this;var n=new g(j.app,{inputs:i.inputs});var m=new h.ButtonIcon({icon:"fa-eye-slash",tooltip:"Show/hide section",cls:"ui-button-icon-plain"});var l=new d.View({title:i.label,cls:"ui-portlet-section",operations:{button_visible:m}});l.append(n.$el);l.append($("<div/>").addClass("ui-table-form-info").html(i.help));var k=false;l.$content.hide();l.$header.css("cursor","pointer");l.$header.on("click",function(){if(k){k=false;l.$content.hide();m.setIcon("fa-eye-slash")}else{k=true;l.$content.fadeIn("fast");m.setIcon("fa-eye")}});if(i.expand){l.$header.trigger("click")}this.table.add(l.$el);this.table.append(i.id)},_addRow:function(i){var l=i.id;if(i.value===undefined){i.value=null}if(i.default_value===undefined){i.default_value=i.value}var j=this._createField(i);this.app.field_list[l]=j;var k=new f(this.app,{label:i.label,default_value:i.default_value,optional:i.optional,help:i.help,field:j});this.app.element_list[l]=k;this.table.add(k.$el);this.table.append(l);if(i.hidden){this.table.get(l).hide()}return j},_createField:function(i){var j=null;switch(i.type){case"text":j=this._fieldText(i);break;case"select":j=this._fieldSelect(i);break;case"data":j=this._fieldData(i);break;case"data_collection":j=this._fieldData(i);break;case"data_column":i.error_text="Missing columns in referenced dataset.";j=this._fieldSelect(i);break;case"hidden":j=this._fieldHidden(i);break;case"hidden_data":j=this._fieldHidden(i);break;case"integer":j=this._fieldSlider(i);break;case"float":j=this._fieldSlider(i);break;case"boolean":j=this._fieldBoolean(i);break;case"genomebuild":i.searchable=true;j=this._fieldSelect(i);break;case"drill_down":j=this._fieldDrilldown(i);break;case"baseurl":j=this._fieldHidden(i);break;default:this.app.incompatible=true;if(i.options){j=this._fieldSelect(i)}else{j=this._fieldText(i)}console.debug("tools-form::_addRow() : Auto matched field type ("+i.type+").")}if(i.value!==undefined){j.value(i.value)}return j},_fieldData:function(i){if(!this.app.options.is_dynamic){i.info="Data input '"+i.name+"' ("+e.textify(i.extensions.toString())+")";i.value=null;return this._fieldHidden(i)}var j=this;return new a.View(this.app,{id:"field-"+i.id,extensions:i.extensions,optional:i.optional,multiple:i.multiple,type:i.type,data:i.options,onchange:function(){j.app.trigger("refresh")}})},_fieldSelect:function(j){if(!this.app.options.is_dynamic&&j.is_dynamic){return this._fieldText(j)}var l=[];for(var m in j.options){var n=j.options[m];l.push({label:n[0],value:n[1]})}var o=h.Select;switch(j.display){case"checkboxes":o=h.Checkbox;break;case"radio":o=h.Radio;break}var k=this;return new o.View({id:"field-"+j.id,data:l,error_text:j.error_text||"No options available",multiple:j.multiple,searchable:j.searchable,onchange:function(){k.app.trigger("refresh")}})},_fieldDrilldown:function(i){if(!this.app.options.is_dynamic&&i.is_dynamic){return this._fieldText(i)}var j=this;return new h.Drilldown.View({id:"field-"+i.id,data:i.options,display:i.display,onchange:function(){j.app.trigger("refresh")}})},_fieldText:function(i){if(i.options){i.area=i.multiple;if(!e.validate(i.value)){i.value=""}else{if(i.value instanceof Array){i.value=value.toString()}else{i.value=String(i.value).replace(/[\[\]'"\s]/g,"");if(i.multiple){i.value=i.value.replace(/,/g,"\n")}}}}var j=this;return new h.Input({id:"field-"+i.id,area:i.area,onchange:function(){j.app.trigger("refresh")}})},_fieldSlider:function(i){var j=this;return new h.Slider.View({id:"field-"+i.id,precise:i.type=="float",min:i.min,max:i.max,onchange:function(){j.app.trigger("refresh")}})},_fieldHidden:function(i){return new h.Hidden({id:"field-"+i.id,info:i.info})},_fieldBoolean:function(i){var j=this;return new h.RadioButton.View({id:"field-"+i.id,data:[{label:"Yes",value:"true"},{label:"No",value:"false"}],onchange:function(){j.app.trigger("refresh")}})}});return{View:g}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/ui/ui-portlet","mvc/tools/tools-repeat","mvc/tools/tools-input","mvc/tools/tools-parameters"],function(e,a,h,d,c,f,b){var g=Backbone.View.extend({initialize:function(j,i){this.app=j;this.inputs=i.inputs;i.cls="ui-table-plain";i.cls_tr="section-row";this.table=new a.View(i);this.parameters=new b(j,i);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();for(var j in this.inputs){this.add(this.inputs[j])}},add:function(k){var j=this;var i=jQuery.extend(true,{},k);i.id=k.id=e.uuid();this.app.input_list[i.id]=i;var l=i.type;switch(l){case"conditional":this._addConditional(i);break;case"repeat":this._addRepeat(i);break;case"section":this._addSection(i);break;default:this._addRow(i)}},_addConditional:function(j){var k=this;j.test_param.id=j.id;var n=this._addRow(j.test_param);n.options.onchange=function(w){var v=k.app.tree.matchCase(j,w);for(var u in j.cases){var q=j.cases[u];var t=j.id+"-section-"+u;var p=k.table.get(t);var s=false;for(var r in q.inputs){if(!q.inputs[r].hidden){s=true;break}}if(u==v&&s){p.fadeIn("fast")}else{p.hide()}}k.app.trigger("refresh")};for(var m in j.cases){var l=j.id+"-section-"+m;var o=new g(this.app,{inputs:j.cases[m].inputs});o.$el.addClass("ui-table-section");this.table.add(o.$el);this.table.append(l)}n.trigger("change")},_addRepeat:function(p){var s=this;var q=0;var l=new c.View({title:p.title,title_new:p.title,min:p.min,max:p.max,onnew:function(){n(p.inputs);s.app.trigger("refresh")}});function n(i){var t=p.id+"-section-"+(q++);var u=new g(s.app,{inputs:i});l.add({id:t,$el:u.$el,ondel:function(){l.del(t);s.app.trigger("refresh")}})}var j=p.min;var r=_.size(p.cache);for(var m=0;m<Math.max(r,j);m++){var o=null;if(m<r){o=p.cache[m]}else{o=p.inputs}n(o)}var k=new f(this.app,{label:p.title,help:p.help,field:l});this.table.add(k.$el);this.table.append(p.id)},_addSection:function(i){var j=this;var n=new g(j.app,{inputs:i.inputs});var m=new h.ButtonIcon({icon:"fa-eye-slash",tooltip:"Show/hide section",cls:"ui-button-icon-plain"});var l=new d.View({title:i.label,cls:"ui-portlet-section",operations:{button_visible:m}});l.append(n.$el);l.append($("<div/>").addClass("ui-table-form-info").html(i.help));var k=false;l.$content.hide();l.$header.css("cursor","pointer");l.$header.on("click",function(){if(k){k=false;l.$content.hide();m.setIcon("fa-eye-slash")}else{k=true;l.$content.fadeIn("fast");m.setIcon("fa-eye")}});if(i.expand){l.$header.trigger("click")}this.table.add(l.$el);this.table.append(i.id)},_addRow:function(i){var l=i.id;var j=this.parameters.create(i);this.app.field_list[l]=j;var k=new f(this.app,{label:i.label,default_value:i.default_value,optional:i.optional,help:i.help,field:j});this.app.element_list[l]=k;this.table.add(k.$el);this.table.append(l);if(i.hidden){this.table.get(l).hide()}return j}});return{View:g}}); \ No newline at end of file Repository URL: https://bitbucket.org/galaxy/galaxy-central/ -- This is a commit notification from bitbucket.org. You are receiving this because you have the service enabled, addressing the recipient of this email.