1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/41f9ca7a24c5/ Changeset: 41f9ca7a24c5 User: guerler Date: 2014-08-22 20:32:07 Summary: ToolForm: Implements conditionals Affected #: 2 files diff -r 0c2fd93d22b796bb38687ca5489e7c57c3e14c21 -r 41f9ca7a24c5748f80ed19315786ba51f4cc19b5 static/scripts/mvc/tools/tools-form.js --- a/static/scripts/mvc/tools/tools-form.js +++ b/static/scripts/mvc/tools/tools-form.js @@ -103,8 +103,11 @@ // reset table this.table.delAll(); - // reset list - this.list = []; + // reset field list + this.field_list = {}; + + // reset sequential input definition list + this.inputs_sequential = {}; // model var data = new Backbone.Model(); @@ -115,65 +118,93 @@ } // trigger change - for (var id in this.list) { - this.list[id].trigger('change'); + for (var id in this.field_list) { + this.field_list[id].trigger('change'); } }, // add table row _add: function(inputs_def, data) { - // link this - var self = this; - + // identify field type + var type = inputs_def.type; + switch(type) { + // conditional field + case 'conditional': + // add label to input definition root + inputs_def.label = inputs_def.test_param.label; + + // add id to input definition root + inputs_def.name = inputs_def.test_param.name; + + // build options field + this._addRow('conditional', inputs_def, data); + + // add fields + for (var i in inputs_def.cases) { + var cases = inputs_def.cases[i]; + for (var j in cases.inputs) { + // add element to form + this._add(cases.inputs[j], data); + } + } + break; + + // default single element row + default: + this._addRow(type, inputs_def, data); + } + }, + + // add table row + _addRow: function(field_type, inputs_def, data) { // get id var id = inputs_def.name; // field wrapper var field = null; - console.log(inputs_def); - // create select field - var type = inputs_def.type; - switch(type) { + + // identify field type + switch(field_type) { // text input field case 'text' : - field = this.field_text(inputs_def, data); + field = this._field_text(inputs_def, data); break; // select field case 'select' : - field = this.field_select(inputs_def, data); + field = this._field_select(inputs_def, data); break; // radiobox field case 'radiobutton' : - field = this.field_radio(inputs_def, data); + field = this._field_radio(inputs_def, data); break; // dataset case 'data': - field = this.field_data(inputs_def, data); + field = this._field_data(inputs_def, data); break; // dataset column case 'data_column': - field = this.field_column(inputs_def, data); + field = this._field_column(inputs_def, data); break; // text area field case 'textarea' : - field = this.field_textarea(inputs_def, data); + field = this._field_textarea(inputs_def, data); break; - - // default - default: - field = new Ui.Input({ - id : 'field-' + id, - placeholder : inputs_def.placeholder, - type : inputs_def.type, - onchange : function() { - data.set(id, field.value()); - } - }); + + // conditional select field + case 'conditional': + field = this._field_conditional(inputs_def, data); + break; + } + + // check if field type was detected + if (!field) { + console.debug('tools-form::_addRow() : Unmatched field type (' + field_type + ').'); + return; } // set value @@ -182,8 +213,11 @@ } field.value(data.get(id)); - // add list - this.list[id] = field; + // add to field list + this.field_list[id] = field; + + // add to input definition into sequential list + this.inputs_sequential[id] = inputs_def; // combine field and info var $input = $('<div/>'); @@ -206,7 +240,7 @@ }, // text input field - field_text : function(inputs_def, data) { + _field_text : function(inputs_def, data) { var id = inputs_def.name; return new Ui.Input({ id : 'field-' + id, @@ -218,7 +252,7 @@ }, // text area - field_textarea : function(inputs_def, data) { + _field_textarea : function(inputs_def, data) { var id = inputs_def.name; return new Ui.Textarea({ id : 'field-' + id, @@ -228,8 +262,72 @@ }); }, + // conditional input field + _field_conditional : function(inputs_def, data) { + // link this + var self = this; + + // configure options fields + var options = []; + for (var i in inputs_def.test_param.options) { + var option = inputs_def.test_param.options[i]; + options.push({ + label: option[0], + value: option[1] + }); + } + + // select field + var id = inputs_def.name; + return new Ui.Select.View({ + id : 'field-' + id, + data : options, + value : data.get(id), + onchange : function(value) { + // update value + data.set(id, value); + + // recursively hide/show options + function _updateVisibility(root, show) { + // loop through all inputs + for (var i in root.inputs) { + // get input element + var element = root.inputs[i]; + + // identify element name + var element_id = element.name; + + // identify row + var element_row = self.table.get(element_id); + + // show/hide row + if (show) { + element_row.fadeIn(); + } else { + element_row.hide(); + } + + // check if its a nested conditional + if (element.type == 'conditional') { + // identify all cases + for (var j in element.cases) { + _updateVisibility(element.cases[j], show); + } + } + } + } + + // check value in order to hide/show options + for (var i in inputs_def.cases) { + var case_def = inputs_def.cases[i]; + _updateVisibility(case_def, case_def.value == value); + } + } + }); + }, + // data input field - field_data : function(inputs_def, data) { + _field_data : function(inputs_def, data) { // link this var self = this; @@ -248,12 +346,6 @@ }); } - // find referenced columns - var column_list = _.where(this.inputs, { - data_ref : id, - type : 'data_column' - }); - // select field return new Ui.Select.View({ id : 'field-' + id, @@ -263,6 +355,12 @@ // update value data.set(id, value); + // find referenced columns + var column_list = _.where(self.inputs_sequential, { + data_ref : id, + type : 'data_column' + }); + // find selected dataset var dataset = self.datasets.filter(value); @@ -291,7 +389,7 @@ // update referenced columns for (var i in column_list) { - var column_field = self.list[column_list[i].name] + var column_field = self.field_list[column_list[i].name] if (column_field) { column_field.update(columns); column_field.value(column_field.first()); @@ -306,7 +404,7 @@ }, // select field - field_column : function (inputs_def, data) { + _field_column : function (inputs_def, data) { // configure options fields var options = []; for (var i in inputs_def.options) { @@ -330,7 +428,7 @@ }, // select field - field_select : function (inputs_def, data) { + _field_select : function (inputs_def, data) { // configure options fields var options = []; for (var i in inputs_def.options) { @@ -360,7 +458,7 @@ }, // radio field - field_radio : function(inputs_def, data) { + _field_radio : function(inputs_def, data) { var id = inputs_def.name; return new Ui.RadioButton({ id : 'field-' + id, diff -r 0c2fd93d22b796bb38687ca5489e7c57c3e14c21 -r 41f9ca7a24c5748f80ed19315786ba51f4cc19b5 static/scripts/packed/mvc/tools/tools-form.js --- a/static/scripts/packed/mvc/tools/tools-form.js +++ b/static/scripts/packed/mvc/tools/tools-form.js @@ -1,1 +1,1 @@ -define(["mvc/ui/ui-portlet","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets"],function(f,i,j,h,a,e,c,g){var d=Backbone.Model.extend({initialize:function(k){this.url=galaxy_config.root+"api/tools/"+k.id+"?io_details=true"}});var b=Backbone.View.extend({main_el:"body",initialize:function(l){var k=this;this.options=l;this.model=new d({id:l.id});this.datasets=new g({success:function(){k._initializeToolForm()}})},_initializeToolForm:function(){var k=this;this.model.fetch({success:function(){k.inputs=k.model.get("inputs");k.portlet=new f.View({icon:"fa-wrench",title:"<b>"+k.model.get("name")+"</b> "+k.model.get("description"),buttons:{execute:new j.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){}})}});k.table=new i.View();k.message=new j.Message();k.portlet.append(k.message.$el);$(k.main_el).append(k.portlet.$el);if(k.options.help!=""){$(k.main_el).append(c.help(k.options.help))}if(k.options.citations){$(k.main_el).append(c.citations());var l=new h.ToolCitationCollection();l.tool_id=k.options.id;var m=new a.CitationListView({collection:l});m.render();l.fetch()}k.setElement(k.portlet.content());k.portlet.append(k.table.$el);k.render()}})},render:function(){this.table.delAll();this.list=[];var k=new Backbone.Model();for(var l in this.inputs){this._add(this.inputs[l],k)}for(var l in this.list){this.list[l].trigger("change")}},_add:function(l,n){var k=this;var q=l.name;var o=null;console.log(l);var m=l.type;switch(m){case"text":o=this.field_text(l,n);break;case"select":o=this.field_select(l,n);break;case"radiobutton":o=this.field_radio(l,n);break;case"data":o=this.field_data(l,n);break;case"data_column":o=this.field_column(l,n);break;case"textarea":o=this.field_textarea(l,n);break;default:o=new j.Input({id:"field-"+q,placeholder:l.placeholder,type:l.type,onchange:function(){n.set(q,o.value())}})}if(!n.get(q)){n.set(q,l.value)}o.value(n.get(q));this.list[q]=o;var p=$("<div/>");p.append(o.$el);if(l.info){p.append('<div class="ui-table-form-info">'+l.info+"</div>")}this.table.add('<span class="ui-table-form-title">'+l.label+"</span>","25%");this.table.add(p);this.table.append(q);if(l.hide){this.table.get(q).hide()}},field_text:function(k,l){var m=k.name;return new j.Input({id:"field-"+m,value:l.get(m),onchange:function(n){l.set(m,n)}})},field_textarea:function(k,l){var m=k.name;return new j.Textarea({id:"field-"+m,onchange:function(){l.set(m,field.value())}})},field_data:function(n,q){var l=this;var r=n.name;var p=this.datasets.filterType();var m=[];for(var o in p){m.push({label:p[o].get("name"),value:p[o].get("id")})}var k=_.where(this.inputs,{data_ref:r,type:"data_column"});return new j.Select.View({id:"field-"+r,data:m,value:m[0].value,onchange:function(w){q.set(r,w);var y=l.datasets.filter(w);if(y&&k.length>0){console.debug("tool-form::field_data() - Selected dataset "+w+".");var x=y.get("metadata_column_types");if(!x){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+w+".")}var v=[];for(var u in x){v.push({label:"Column: "+(parseInt(u)+1)+" ["+x[u]+"]",value:u})}for(var t in k){var s=l.list[k[t].name];if(s){s.update(v);s.value(s.first())}}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+w+".")}}})},field_column:function(l,o){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var p=l.name;return new j.Select.View({id:"field-"+p,data:k,value:o.get(p),onchange:function(q){o.set(p,q)}})},field_select:function(l,p){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var o=j.Select;if(l.display=="checkboxes"){o=j.Checkbox}var q=l.name;return new o.View({id:"field-"+q,data:k,value:p.get(q),onchange:function(r){p.set(q,r)}})},field_radio:function(k,l){var m=k.name;return new j.RadioButton({id:"field-"+m,data:k.data,value:l.get(m),onchange:function(n){l.set(m,n)}})}});return{View:b}}); \ No newline at end of file +define(["mvc/ui/ui-portlet","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets"],function(f,i,j,h,a,e,c,g){var d=Backbone.Model.extend({initialize:function(k){this.url=galaxy_config.root+"api/tools/"+k.id+"?io_details=true"}});var b=Backbone.View.extend({main_el:"body",initialize:function(l){var k=this;this.options=l;this.model=new d({id:l.id});this.datasets=new g({success:function(){k._initializeToolForm()}})},_initializeToolForm:function(){var k=this;this.model.fetch({success:function(){k.inputs=k.model.get("inputs");k.portlet=new f.View({icon:"fa-wrench",title:"<b>"+k.model.get("name")+"</b> "+k.model.get("description"),buttons:{execute:new j.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){}})}});k.table=new i.View();k.message=new j.Message();k.portlet.append(k.message.$el);$(k.main_el).append(k.portlet.$el);if(k.options.help!=""){$(k.main_el).append(c.help(k.options.help))}if(k.options.citations){$(k.main_el).append(c.citations());var l=new h.ToolCitationCollection();l.tool_id=k.options.id;var m=new a.CitationListView({collection:l});m.render();l.fetch()}k.setElement(k.portlet.content());k.portlet.append(k.table.$el);k.render()}})},render:function(){this.table.delAll();this.field_list={};this.inputs_sequential={};var k=new Backbone.Model();for(var l in this.inputs){this._add(this.inputs[l],k)}for(var l in this.field_list){this.field_list[l].trigger("change")}},_add:function(l,p){var n=l.type;switch(n){case"conditional":l.label=l.test_param.label;l.name=l.test_param.name;this._addRow("conditional",l,p);for(var m in l.cases){var o=l.cases[m];for(var k in o.inputs){this._add(o.inputs[k],p)}}break;default:this._addRow(n,l,p)}},_addRow:function(n,k,l){var p=k.name;var m=null;switch(n){case"text":m=this._field_text(k,l);break;case"select":m=this._field_select(k,l);break;case"radiobutton":m=this._field_radio(k,l);break;case"data":m=this._field_data(k,l);break;case"data_column":m=this._field_column(k,l);break;case"textarea":m=this._field_textarea(k,l);break;case"conditional":m=this._field_conditional(k,l);break}if(!m){console.debug("tools-form::_addRow() : Unmatched field type ("+n+").");return}if(!l.get(p)){l.set(p,k.value)}m.value(l.get(p));this.field_list[p]=m;this.inputs_sequential[p]=k;var o=$("<div/>");o.append(m.$el);if(k.info){o.append('<div class="ui-table-form-info">'+k.info+"</div>")}this.table.add('<span class="ui-table-form-title">'+k.label+"</span>","25%");this.table.add(o);this.table.append(p);if(k.hide){this.table.get(p).hide()}},_field_text:function(k,l){var m=k.name;return new j.Input({id:"field-"+m,value:l.get(m),onchange:function(n){l.set(m,n)}})},_field_textarea:function(k,l){var m=k.name;return new j.Textarea({id:"field-"+m,onchange:function(){l.set(m,field.value())}})},_field_conditional:function(m,p){var k=this;var l=[];for(var n in m.test_param.options){var o=m.test_param.options[n];l.push({label:o[0],value:o[1]})}var q=m.name;return new j.Select.View({id:"field-"+q,data:l,value:p.get(q),onchange:function(u){p.set(q,u);function t(x,w){for(var A in x.inputs){var z=x.inputs[A];var v=z.name;var B=k.table.get(v);if(w){B.fadeIn()}else{B.hide()}if(z.type=="conditional"){for(var y in z.cases){t(z.cases[y],w)}}}}for(var s in m.cases){var r=m.cases[s];t(r,r.value==u)}}})},_field_data:function(m,p){var k=this;var q=m.name;var o=this.datasets.filterType();var l=[];for(var n in o){l.push({label:o[n].get("name"),value:o[n].get("id")})}return new j.Select.View({id:"field-"+q,data:l,value:l[0].value,onchange:function(w){p.set(q,w);var s=_.where(k.inputs_sequential,{data_ref:q,type:"data_column"});var y=k.datasets.filter(w);if(y&&s.length>0){console.debug("tool-form::field_data() - Selected dataset "+w+".");var x=y.get("metadata_column_types");if(!x){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+w+".")}var v=[];for(var u in x){v.push({label:"Column: "+(parseInt(u)+1)+" ["+x[u]+"]",value:u})}for(var t in s){var r=k.field_list[s[t].name];if(r){r.update(v);r.value(r.first())}}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+w+".")}}})},_field_column:function(l,o){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var p=l.name;return new j.Select.View({id:"field-"+p,data:k,value:o.get(p),onchange:function(q){o.set(p,q)}})},_field_select:function(l,p){var k=[];for(var m in l.options){var n=l.options[m];k.push({label:n[0],value:n[1]})}var o=j.Select;if(l.display=="checkboxes"){o=j.Checkbox}var q=l.name;return new o.View({id:"field-"+q,data:k,value:p.get(q),onchange:function(r){p.set(q,r)}})},_field_radio:function(k,l){var m=k.name;return new j.RadioButton({id:"field-"+m,data:k.data,value:l.get(m),onchange:function(n){l.set(m,n)}})}});return{View:b}}); \ 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.