1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/8d307a592c72/ Changeset: 8d307a592c72 User: guerler Date: 2014-08-28 20:03:35 Summary: ToolForm: Enables hierarchical references and conversion of the tool form into a json/xml tree structure Affected #: 12 files diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/tools/tools-form.js --- a/static/scripts/mvc/tools/tools-form.js +++ b/static/scripts/mvc/tools/tools-form.js @@ -1,8 +1,8 @@ define(['mvc/ui/ui-portlet', 'mvc/ui/ui-misc', 'mvc/citation/citation-model', 'mvc/citation/citation-view', - 'mvc/tools', 'mvc/tools/tools-template', 'mvc/tools/tools-datasets', 'mvc/tools/tools-section'], + 'mvc/tools', 'mvc/tools/tools-template', 'mvc/tools/tools-datasets', 'mvc/tools/tools-section', 'mvc/tools/tools-tree'], function(Portlet, Ui, CitationModel, CitationView, - Tools, ToolTemplate, ToolDatasets, ToolSection) { + Tools, ToolTemplate, ToolDatasets, ToolSection, ToolTree) { // create tool model var Model = Backbone.Model.extend({ @@ -29,6 +29,18 @@ id : options.id }); + // creates a tree/json structure from the input form + this.tree = new ToolTree(this); + + // reset field list + this.field_list = {}; + + // reset sequential input definition list + this.inputs_sequential = {}; + + // create data model + this.data = new Backbone.Model(); + // initialize datasets this.datasets = new ToolDatasets({ success: function() { @@ -39,13 +51,6 @@ // initialize tool form _initializeToolForm: function() { - - // reset field list - this.field_list = {}; - - // reset sequential input definition list - this.inputs_sequential = {}; - // fetch model and render form var self = this; this.model.fetch({ @@ -67,6 +72,7 @@ title : 'Execute', floating : 'clear', onclick : function() { + console.log(self.tree.create(self)); } }) } @@ -107,8 +113,25 @@ // append tool section self.portlet.append(self.section.$el); + + // trigger refresh + self.refresh(); } }); + }, + + // refresh + refresh: function() { + // recreate tree structure + this.tree.refresh(); + + // trigger change + for (var id in this.field_list) { + this.field_list[id].trigger('change'); + } + + // log + console.debug('tools-form::refresh() - Recreated tree structure. Refresh.'); } }); diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/tools/tools-section.js --- a/static/scripts/mvc/tools/tools-section.js +++ b/static/scripts/mvc/tools/tools-section.js @@ -1,4 +1,5 @@ -define(['mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs'], function(Table, Ui, Tabs) { +define(['utils/utils', 'mvc/ui/ui-table', 'mvc/ui/ui-misc', 'mvc/ui/ui-tabs'], + function(Utils, Table, Ui, Tabs) { // create form view var View = Backbone.View.extend({ @@ -13,6 +14,13 @@ // link datasets this.datasets = app.datasets; + // link data model + this.data = app.data; + + // add table class for tr tag + // this assist in transforming the form into a json structure + options.cls_tr = 'form-row'; + // create table this.table = new Table.View(options); @@ -28,98 +36,115 @@ // reset table this.table.delAll(); - // model - var data = new Backbone.Model(); - // load settings elements into table - for (var id in this.inputs) { - this._add(this.inputs[id], data); - } - - // trigger change - for (var id in this.app.field_list) { - this.app.field_list[id].trigger('change'); + for (var i in this.inputs) { + this._add(this.inputs[i], this.data); } }, // add table row - _add: function(inputs_def, data) { + _add: function(input, data) { // link this var self = this; + // clone definition + var input_def = jQuery.extend(true, {}, input); + + // create unique id + input_def.id = Utils.uuid(); + + // add to sequential list of inputs + this.app.inputs_sequential[input_def.id] = input_def; + // identify field type - var type = inputs_def.type; + var type = input_def.type; switch(type) { // conditional field case 'conditional': // add label to input definition root - inputs_def.label = inputs_def.test_param.label; + input_def.label = input_def.test_param.label; - // add id to input definition root - inputs_def.name = inputs_def.test_param.name; + // add value to input definition root + input_def.value = input_def.test_param.value; // build options field - this._addRow('conditional', inputs_def, data); + this._addRow('conditional', input_def, data); // add fields - for (var i in inputs_def.cases) { + for (var i in input_def.cases) { + // create id tag + var sub_section_id = input_def.id + '-section-' + i; + // create sub section var sub_section = new View(this.app, { - inputs : inputs_def.cases[i].inputs, + inputs : input_def.cases[i].inputs, cls : 'ui-table-plain' }); // append sub section this.table.add(''); this.table.add(sub_section.$el); - this.table.append(inputs_def.name + '_formsection_' + i); + this.table.append(sub_section_id); } break; // repeat block case 'repeat': // create tab field var tabs = new Tabs.View({ - title_new : 'Add Group', + title_new : 'Add ' + input_def.title, onnew : function() { + // create id tag + var sub_section_id = input_def.id + '-section-' + Utils.uuid(); + // create sub section var sub_section = new View(self.app, { - inputs : inputs_def.inputs, + inputs : input_def.inputs, cls : 'ui-table-plain' }); - // create id tag - var sub_section_id = inputs_def.name + '_formsection_' + tabs.size(); - // add new tab tabs.add({ id : sub_section_id, - title : 'Repeat', + title : input_def.title, $el : sub_section.$el, ondel : function() { + // delete tab tabs.del(sub_section_id); + + // retitle tabs + tabs.retitle(input_def.title); + + // trigger refresh + self.app.refresh(); } }); + // retitle tabs + tabs.retitle(input_def.title); + // show tab tabs.show(sub_section_id); + + // trigger refresh + self.app.refresh(); } }); // append sub section - this.table.add(inputs_def.title); + this.table.add(''); this.table.add(tabs.$el); - this.table.append(inputs_def.name); + this.table.append(input_def.id); break; // default single element row default: - this._addRow(type, inputs_def, data); + this._addRow(type, input_def, data); } }, // add table row - _addRow: function(field_type, inputs_def, data) { + _addRow: function(field_type, input_def, data) { // get id - var id = inputs_def.name; + var id = input_def.id; // field wrapper var field = null; @@ -128,37 +153,42 @@ switch(field_type) { // text input field case 'text' : - field = this._field_text(inputs_def, data); + field = this._field_text(input_def, data); break; // select field case 'select' : - field = this._field_select(inputs_def, data); + field = this._field_select(input_def, data); break; // radiobox field case 'radiobutton' : - field = this._field_radio(inputs_def, data); + field = this._field_radio(input_def, data); break; // dataset case 'data': - field = this._field_data(inputs_def, data); + field = this._field_data(input_def, data); break; // dataset column case 'data_column': - field = this._field_column(inputs_def, data); + field = this._field_column(input_def, data); break; // text area field case 'textarea' : - field = this._field_textarea(inputs_def, data); + field = this._field_textarea(input_def, data); break; // conditional select field case 'conditional': - field = this._field_conditional(inputs_def, data); + field = this._field_conditional(input_def, data); + break; + + // hidden field + case 'hidden': + field = this._field_hidden(input_def, data); break; } @@ -170,68 +200,37 @@ // set value if (!data.get(id)) { - data.set(id, inputs_def.value); + data.set(id, input_def.value); } field.value(data.get(id)); // add to field list this.app.field_list[id] = field; - // add to input definition into sequential list - this.app.inputs_sequential[id] = inputs_def; - // combine field and info var $input = $('<div/>'); $input.append(field.$el); - if (inputs_def.help) { - $input.append('<div class="ui-table-form-info">' + inputs_def.help + '</div>'); + if (input_def.help) { + $input.append('<div class="ui-table-form-info">' + input_def.help + '</div>'); } - // add row to table - this.table.add('<span class="ui-table-form-title">' + inputs_def.label + '</span>', '25%'); + // create table row + this.table.add('<span class="ui-table-form-title">' + input_def.label + '</span>', '25%'); this.table.add($input); - // add to table + // append to table this.table.append(id); - - // show/hide - if (inputs_def.hide) { - this.table.get(id).hide(); - } - }, - - // text input field - _field_text : function(inputs_def, data) { - var id = inputs_def.name; - return new Ui.Input({ - id : 'field-' + id, - value : data.get(id), - onchange : function(value) { - data.set(id, value); - } - }); - }, - - // text area - _field_textarea : function(inputs_def, data) { - var id = inputs_def.name; - return new Ui.Textarea({ - id : 'field-' + id, - onchange : function() { - data.set(id, field.value()); - } - }); }, // conditional input field - _field_conditional : function(inputs_def, data) { + _field_conditional : function(input_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]; + for (var i in input_def.test_param.options) { + var option = input_def.test_param.options[i]; options.push({ label: option[0], value: option[1] @@ -239,7 +238,7 @@ } // select field - var id = inputs_def.name; + var id = input_def.id; return new Ui.Select.View({ id : 'field-' + id, data : options, @@ -249,19 +248,29 @@ data.set(id, value); // check value in order to hide/show options - for (var i in inputs_def.cases) { + for (var i in input_def.cases) { // get case - var case_def = inputs_def.cases[i]; + var case_def = input_def.cases[i]; // identify subsection name - var section_id = inputs_def.name + '_formsection_' + i; - + var section_id = input_def.id + '-section-' + i; + // identify row var section_row = self.table.get(section_id); - // check - if (case_def.value == value) { - section_row.show(); + // check if non-hidden elements exist + var nonhidden = false; + for (var j in case_def.inputs) { + var type = case_def.inputs[j].type; + if (type && type !== 'hidden') { + nonhidden = true; + break; + } + } + + // show/hide sub form + if (case_def.value == value && nonhidden) { + section_row.fadeIn('fast'); } else { section_row.hide(); } @@ -271,12 +280,12 @@ }, // data input field - _field_data : function(inputs_def, data) { + _field_data : function(input_def, data) { // link this var self = this; // get element id - var id = inputs_def.name; + var id = input_def.id; // get datasets var datasets = this.datasets.filterType(); @@ -299,11 +308,8 @@ // update value data.set(id, value); - // find referenced columns - var column_list = _.where(self.app.inputs_sequential, { - data_ref : id, - type : 'data_column' - }); + // get referenced columns + var column_list = self.app.tree.findReferences(id); // find selected dataset var dataset = self.datasets.filter(value); @@ -333,7 +339,7 @@ // update referenced columns for (var i in column_list) { - var column_field = self.app.field_list[column_list[i].name] + var column_field = self.app.field_list[column_list[i]] if (column_field) { column_field.update(columns); column_field.value(column_field.first()); @@ -348,8 +354,8 @@ }, // column selection field - _field_column : function (inputs_def, data) { - var id = inputs_def.name; + _field_column : function (input_def, data) { + var id = input_def.id; return new Ui.Select.View({ id : 'field-' + id, value : data.get(id), @@ -360,11 +366,11 @@ }, // select field - _field_select : function (inputs_def, data) { + _field_select : function (input_def, data) { // configure options fields var options = []; - for (var i in inputs_def.options) { - var option = inputs_def.options[i]; + for (var i in input_def.options) { + var option = input_def.options[i]; options.push({ label: option[0], value: option[1] @@ -373,12 +379,12 @@ // identify display type var SelectClass = Ui.Select; - if (inputs_def.display == 'checkboxes') { + if (input_def.display == 'checkboxes') { SelectClass = Ui.Checkbox; } // select field - var id = inputs_def.name; + var id = input_def.id; return new SelectClass.View({ id : 'field-' + id, data : options, @@ -389,17 +395,49 @@ }); }, - // radio field - _field_radio : function(inputs_def, data) { - var id = inputs_def.name; - return new Ui.RadioButton({ + // text input field + _field_text : function(input_def, data) { + var id = input_def.id; + return new Ui.Input({ id : 'field-' + id, - data : inputs_def.data, value : data.get(id), onchange : function(value) { data.set(id, value); } }); + }, + + // text area + _field_textarea : function(input_def, data) { + var id = input_def.id; + return new Ui.Textarea({ + id : 'field-' + id, + onchange : function() { + data.set(id, field.value()); + } + }); + }, + + // radio field + _field_radio : function(input_def, data) { + var id = input_def.id; + return new Ui.RadioButton({ + id : 'field-' + id, + data : input_def.data, + value : data.get(id), + onchange : function(value) { + data.set(id, value); + } + }); + }, + + // hidden field + _field_hidden : function(input_def, data) { + var id = input_def.id; + return new Ui.Hidden({ + id : 'field-' + id, + value : data.get(id) + }); } }); diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/tools/tools-tree.js --- /dev/null +++ b/static/scripts/mvc/tools/tools-tree.js @@ -0,0 +1,135 @@ +// dependencies +define([], function() { + +// tool form tree +return Backbone.Model.extend({ + // initialize + initialize: function(app) { + // link app + this.app = app; + }, + + // creates tree structure + refresh: function() { + // check if section is available + if (!this.app.section) { + return {}; + } + + // create dictionary + this.dict = {}; + + // create xml object + this.xml = $('<div/>'); + + // fill dictionary + this._iterate(this.app.section.$el, this.dict, this.xml); + }, + + // iterate + _iterate: function(parent, dict, xml) { + // get child nodes + var self = this; + var children = $(parent).children(); + children.each(function() { + // get child element + var child = this; + + // get id + var id = $(child).attr('id'); + + // create new branch + if ($(child).hasClass('form-row') || $(child).hasClass('tab-pane')) { + // create sub dictionary + dict[id] = {}; + + // add input element if it exists + var input = self.app.inputs_sequential[id]; + if (input) { + dict[id] = { + input : input + } + } + + // create xml element + var $el = $('<div id="' + id + '"/>'); + + // append xml + xml.append($el); + + // fill sub dictionary + self._iterate(child, dict[id], $el); + } else { + self._iterate(child, dict, xml); + } + }); + }, + + // find referenced elements + findReferences: function(identifier) { + // referenced elements + var referenced = []; + + // link this + var self = this; + + // iterate + function search (name, parent) { + // get child nodes + var children = $(parent).children(); + + // create sublist + var list = []; + + // verify that hierachy level is referenced to identifier + children.each(function() { + // get child element + var child = this; + + // get id + var id = $(child).attr('id'); + + // skip + if (id !== identifier) { + // get input element + var input = self.app.inputs_sequential[id]; + if (input) { + // check for new reference definition + if (input.name == name) { + // stop iteration + return; + } + + // check for referenced element + if (input.data_ref == name) { + list.push(id); + } + } + } + }); + + // merge temporary list with result + referenced = referenced.concat(list); + + // continue iteration + children.each(function() { + search(identifier, this); + }); + } + + // get initial node + var node = this.xml.find('#' + identifier); + if (node.length > 0) { + // get parent input element + var input = self.app.inputs_sequential[identifier]; + if (input) { + search(input.name, node.parent()); + } + } + + // return + return referenced; + } +}); + +}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/ui/ui-misc.js --- a/static/scripts/mvc/ui/ui-misc.js +++ b/static/scripts/mvc/ui/ui-misc.js @@ -409,6 +409,35 @@ } }); +// plugin +var Hidden = Backbone.View.extend({ + // options + optionsDefault: { + value : '' + }, + + // initialize + initialize : function(options) { + // configure options + this.options = Utils.merge(options, this.optionsDefault); + + // create new element + this.setElement(this._template(this.options)); + }, + + // value + value : function (new_val) { + if (new_val !== undefined) { + this.$el.val(new_val); + } + return this.$el.val(); + }, + + // element + _template: function(options) { + return '<hidden id="' + options.id + '" value="' + options.value + '"/>'; + } +}); // return return { @@ -426,6 +455,7 @@ Checkbox : Checkbox, Searchbox : Searchbox, Select : Select, - Textarea : Textarea + Textarea : Textarea, + Hidden : Hidden } }); diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/ui/ui-table.js --- a/static/scripts/mvc/ui/ui-table.js +++ b/static/scripts/mvc/ui/ui-table.js @@ -17,7 +17,8 @@ onchange : null, ondblclick : null, onconfirm : null, - cls : 'ui-table' + cls : 'ui-table', + cls_tr : '' }, // events @@ -43,7 +44,7 @@ this.setElement($el); // initialize row - this.row = $('<tr></tr>'); + this.row = this._row(); }, // add header cell @@ -156,13 +157,18 @@ } // row - this.row = $('<tr></tr>'); + this.row = this._row(); // row count this.row_count++; this._refresh(); }, + // create new row + _row: function() { + return $('<tr class="' + this.options.cls_tr + '"></tr>'); + }, + // onclick _onclick: function(e) { // get values diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/mvc/ui/ui-tabs.js --- a/static/scripts/mvc/ui/ui-tabs.js +++ b/static/scripts/mvc/ui/ui-tabs.js @@ -132,7 +132,7 @@ del: function(id) { // delete tab from dom this.$el.find('#tab-' + id).remove(); - this.$el.find('#tab-content-' + id).remove(); + this.$el.find('#' + id).remove(); // check if first tab has been deleted if (this.first_tab == id) { @@ -143,14 +143,17 @@ if (this.first_tab != null) { this.show(this.first_tab); } + + // delete from list + if (this.list[id]) { + delete this.list[id]; + } }, // delete tab delRemovable: function() { for (var id in this.list) { - if (this.list[id]) { - this.del(id); - } + this.del(id); } }, @@ -165,7 +168,7 @@ this.$el.find('.tab-element').removeClass('active'); this.$el.find('.tab-pane').removeClass('active'); this.$el.find('#tab-' + id).addClass('active'); - this.$el.find('#tab-content-' + id).addClass('active'); + this.$el.find('#' + id).addClass('active'); } }, @@ -201,6 +204,14 @@ return $el.html(); }, + // retitle + retitle: function(new_title) { + var index = 0; + for (var id in this.list) { + this.title(id, ++index + ': ' + new_title); + } + }, + // fill template _template: function(options) { return '<div class="ui-tabs tabbable tabs-left">' + @@ -224,8 +235,8 @@ // fill template tab _template_tab: function(options) { var tmpl = '<li id="tab-' + options.id + '" class="tab-element">' + - '<a id="tab-title-link-' + options.id + '" title="" href="#tab-content-' + options.id + '" data-original-title="">' + - '<span id="tab-title-text-' + options.id + '">' + options.title + '</span>'; + '<a id="tab-title-link-' + options.id + '" title="" href="#' + options.id + '" data-original-title="">' + + '<span id="tab-title-text-' + options.id + '" class="tab-title-text">' + options.title + '</span>'; if (options.ondel) { tmpl += '<i id="delete" class="ui-tabs-delete fa fa-minus-circle"/>'; @@ -239,7 +250,7 @@ // fill template tab content _template_tab_content: function(options) { - return '<div id="tab-content-' + options.id + '" class="tab-pane"/>'; + return '<div id="' + options.id + '" class="tab-pane"/>'; } }); diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 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-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets","mvc/tools/tools-section"],function(f,j,h,a,e,c,g,i){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(){this.field_list={};this.inputs_sequential={};var k=this;this.model.fetch({error:function(l){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},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.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.section=new i.View(k,{inputs:k.model.get("inputs")});k.portlet.append(k.section.$el)}})}});return{View:b}}); \ No newline at end of file +define(["mvc/ui/ui-portlet","mvc/ui/ui-misc","mvc/citation/citation-model","mvc/citation/citation-view","mvc/tools","mvc/tools/tools-template","mvc/tools/tools-datasets","mvc/tools/tools-section","mvc/tools/tools-tree"],function(g,k,i,a,f,d,h,j,c){var e=Backbone.Model.extend({initialize:function(l){this.url=galaxy_config.root+"api/tools/"+l.id+"?io_details=true"}});var b=Backbone.View.extend({main_el:"body",initialize:function(m){var l=this;this.options=m;this.model=new e({id:m.id});this.tree=new c(this);this.field_list={};this.inputs_sequential={};this.data=new Backbone.Model();this.datasets=new h({success:function(){l._initializeToolForm()}})},_initializeToolForm:function(){var l=this;this.model.fetch({error:function(m){console.debug("tools-form::_initializeToolForm() : Attempt to fetch tool model failed.")},success:function(){l.inputs=l.model.get("inputs");l.portlet=new g.View({icon:"fa-wrench",title:"<b>"+l.model.get("name")+"</b> "+l.model.get("description"),buttons:{execute:new k.ButtonIcon({icon:"fa-check",tooltip:"Execute the tool",title:"Execute",floating:"clear",onclick:function(){console.log(l.tree.create(l))}})}});l.message=new k.Message();l.portlet.append(l.message.$el);$(l.main_el).append(l.portlet.$el);if(l.options.help!=""){$(l.main_el).append(d.help(l.options.help))}if(l.options.citations){$(l.main_el).append(d.citations());var m=new i.ToolCitationCollection();m.tool_id=l.options.id;var n=new a.CitationListView({collection:m});n.render();m.fetch()}l.setElement(l.portlet.content());l.section=new j.View(l,{inputs:l.model.get("inputs")});l.portlet.append(l.section.$el);l.refresh()}})},refresh:function(){this.tree.refresh();for(var l in this.field_list){this.field_list[l].trigger("change")}console.debug("tools-form::refresh() - Recreated tree structure. Refresh.")}});return{View:b}}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 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(["mvc/ui/ui-table","mvc/ui/ui-misc","mvc/ui/ui-tabs"],function(b,d,a){var c=Backbone.View.extend({initialize:function(f,e){this.app=f;this.inputs=e.inputs;this.datasets=f.datasets;this.table=new b.View(e);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();var e=new Backbone.Model();for(var f in this.inputs){this._add(this.inputs[f],e)}for(var f in this.app.field_list){this.app.field_list[f].trigger("change")}},_add:function(f,k){var e=this;var j=f.type;switch(j){case"conditional":f.label=f.test_param.label;f.name=f.test_param.name;this._addRow("conditional",f,k);for(var h in f.cases){var l=new c(this.app,{inputs:f.cases[h].inputs,cls:"ui-table-plain"});this.table.add("");this.table.add(l.$el);this.table.append(f.name+"_formsection_"+h)}break;case"repeat":var g=new a.View({title_new:"Add Group",onnew:function(){var m=new c(e.app,{inputs:f.inputs,cls:"ui-table-plain"});var i=f.name+"_formsection_"+g.size();g.add({id:i,title:"Repeat",$el:m.$el,ondel:function(){g.del(i)}});g.show(i)}});this.table.add(f.title);this.table.add(g.$el);this.table.append(f.name);break;default:this._addRow(j,f,k)}},_addRow:function(h,e,f){var j=e.name;var g=null;switch(h){case"text":g=this._field_text(e,f);break;case"select":g=this._field_select(e,f);break;case"radiobutton":g=this._field_radio(e,f);break;case"data":g=this._field_data(e,f);break;case"data_column":g=this._field_column(e,f);break;case"textarea":g=this._field_textarea(e,f);break;case"conditional":g=this._field_conditional(e,f);break}if(!g){console.debug("tools-form::_addRow() : Unmatched field type ("+h+").");return}if(!f.get(j)){f.set(j,e.value)}g.value(f.get(j));this.app.field_list[j]=g;this.app.inputs_sequential[j]=e;var i=$("<div/>");i.append(g.$el);if(e.help){i.append('<div class="ui-table-form-info">'+e.help+"</div>")}this.table.add('<span class="ui-table-form-title">'+e.label+"</span>","25%");this.table.add(i);this.table.append(j);if(e.hide){this.table.get(j).hide()}},_field_text:function(e,f){var g=e.name;return new d.Input({id:"field-"+g,value:f.get(g),onchange:function(h){f.set(g,h)}})},_field_textarea:function(e,f){var g=e.name;return new d.Textarea({id:"field-"+g,onchange:function(){f.set(g,field.value())}})},_field_conditional:function(g,k){var e=this;var f=[];for(var h in g.test_param.options){var j=g.test_param.options[h];f.push({label:j[0],value:j[1]})}var l=g.name;return new d.Select.View({id:"field-"+l,data:f,value:k.get(l),onchange:function(q){k.set(l,q);for(var p in g.cases){var n=g.cases[p];var o=g.name+"_formsection_"+p;var m=e.table.get(o);if(n.value==q){m.show()}else{m.hide()}}}})},_field_data:function(g,k){var e=this;var l=g.name;var j=this.datasets.filterType();var f=[];for(var h in j){f.push({label:j[h].get("name"),value:j[h].get("id")})}return new d.Select.View({id:"field-"+l,data:f,value:f[0].value,onchange:function(r){k.set(l,r);var n=_.where(e.app.inputs_sequential,{data_ref:l,type:"data_column"});var t=e.datasets.filter(r);if(t&&n.length>0){console.debug("tool-form::field_data() - Selected dataset "+r+".");var s=t.get("metadata_column_types");if(!s){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+r+".")}var q=[];for(var p in s){q.push({label:"Column: "+(parseInt(p)+1)+" ["+s[p]+"]",value:p})}for(var o in n){var m=e.app.field_list[n[o].name];if(m){m.update(q);m.value(m.first())}}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+r+".")}}})},_field_column:function(e,f){var g=e.name;return new d.Select.View({id:"field-"+g,value:f.get(g),onchange:function(h){f.set(g,h)}})},_field_select:function(f,k){var e=[];for(var g in f.options){var h=f.options[g];e.push({label:h[0],value:h[1]})}var j=d.Select;if(f.display=="checkboxes"){j=d.Checkbox}var l=f.name;return new j.View({id:"field-"+l,data:e,value:k.get(l),onchange:function(i){k.set(l,i)}})},_field_radio:function(e,f){var g=e.name;return new d.RadioButton({id:"field-"+g,data:e.data,value:f.get(g),onchange:function(h){f.set(g,h)}})}});return{View:c}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-table","mvc/ui/ui-misc","mvc/ui/ui-tabs"],function(c,b,e,a){var d=Backbone.View.extend({initialize:function(g,f){this.app=g;this.inputs=f.inputs;this.datasets=g.datasets;this.data=g.data;f.cls_tr="form-row";this.table=new b.View(f);this.setElement(this.table.$el);this.render()},render:function(){this.table.delAll();for(var f in this.inputs){this._add(this.inputs[f],this.data)}},_add:function(n,h){var o=this;var k=jQuery.extend(true,{},n);k.id=c.uuid();this.app.inputs_sequential[k.id]=k;var l=k.type;switch(l){case"conditional":k.label=k.test_param.label;k.value=k.test_param.value;this._addRow("conditional",k,h);for(var j in k.cases){var g=k.id+"-section-"+j;var f=new d(this.app,{inputs:k.cases[j].inputs,cls:"ui-table-plain"});this.table.add("");this.table.add(f.$el);this.table.append(g)}break;case"repeat":var m=new a.View({title_new:"Add "+k.title,onnew:function(){var i=k.id+"-section-"+c.uuid();var p=new d(o.app,{inputs:k.inputs,cls:"ui-table-plain"});m.add({id:i,title:k.title,$el:p.$el,ondel:function(){m.del(i);m.retitle(k.title);o.app.refresh()}});m.retitle(k.title);m.show(i);o.app.refresh()}});this.table.add("");this.table.add(m.$el);this.table.append(k.id);break;default:this._addRow(l,k,h)}},_addRow:function(i,f,g){var k=f.id;var h=null;switch(i){case"text":h=this._field_text(f,g);break;case"select":h=this._field_select(f,g);break;case"radiobutton":h=this._field_radio(f,g);break;case"data":h=this._field_data(f,g);break;case"data_column":h=this._field_column(f,g);break;case"textarea":h=this._field_textarea(f,g);break;case"conditional":h=this._field_conditional(f,g);break;case"hidden":h=this._field_hidden(f,g);break}if(!h){console.debug("tools-form::_addRow() : Unmatched field type ("+i+").");return}if(!g.get(k)){g.set(k,f.value)}h.value(g.get(k));this.app.field_list[k]=h;var j=$("<div/>");j.append(h.$el);if(f.help){j.append('<div class="ui-table-form-info">'+f.help+"</div>")}this.table.add('<span class="ui-table-form-title">'+f.label+"</span>","25%");this.table.add(j);this.table.append(k)},_field_conditional:function(f,l){var g=this;var h=[];for(var j in f.test_param.options){var k=f.test_param.options[j];h.push({label:k[0],value:k[1]})}var m=f.id;return new e.Select.View({id:"field-"+m,data:h,value:l.get(m),onchange:function(u){l.set(m,u);for(var s in f.cases){var o=f.cases[s];var r=f.id+"-section-"+s;var n=g.table.get(r);var q=false;for(var p in o.inputs){var t=o.inputs[p].type;if(t&&t!=="hidden"){q=true;break}}if(o.value==u&&q){n.fadeIn("fast")}else{n.hide()}}}})},_field_data:function(f,l){var g=this;var m=f.id;var k=this.datasets.filterType();var h=[];for(var j in k){h.push({label:k[j].get("name"),value:k[j].get("id")})}return new e.Select.View({id:"field-"+m,data:h,value:h[0].value,onchange:function(s){l.set(m,s);var o=g.app.tree.findReferences(m);var u=g.datasets.filter(s);if(u&&o.length>0){console.debug("tool-form::field_data() - Selected dataset "+s+".");var t=u.get("metadata_column_types");if(!t){console.debug("tool-form::field_data() - FAILED: Could not find metadata for dataset "+s+".")}var r=[];for(var q in t){r.push({label:"Column: "+(parseInt(q)+1)+" ["+t[q]+"]",value:q})}for(var p in o){var n=g.app.field_list[o[p]];if(n){n.update(r);n.value(n.first())}}}else{console.debug("tool-form::field_data() - FAILED: Could not find dataset "+s+".")}}})},_field_column:function(f,g){var h=f.id;return new e.Select.View({id:"field-"+h,value:g.get(h),onchange:function(i){g.set(h,i)}})},_field_select:function(f,l){var g=[];for(var h in f.options){var j=f.options[h];g.push({label:j[0],value:j[1]})}var k=e.Select;if(f.display=="checkboxes"){k=e.Checkbox}var m=f.id;return new k.View({id:"field-"+m,data:g,value:l.get(m),onchange:function(i){l.set(m,i)}})},_field_text:function(f,g){var h=f.id;return new e.Input({id:"field-"+h,value:g.get(h),onchange:function(i){g.set(h,i)}})},_field_textarea:function(f,g){var h=f.id;return new e.Textarea({id:"field-"+h,onchange:function(){g.set(h,field.value())}})},_field_radio:function(f,g){var h=f.id;return new e.RadioButton({id:"field-"+h,data:f.data,value:g.get(h),onchange:function(i){g.set(h,i)}})},_field_hidden:function(f,g){var h=f.id;return new e.Hidden({id:"field-"+h,value:g.get(h)})}});return{View:d}}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/packed/mvc/tools/tools-tree.js --- /dev/null +++ b/static/scripts/packed/mvc/tools/tools-tree.js @@ -0,0 +1,1 @@ +define([],function(){return Backbone.Model.extend({initialize:function(a){this.app=a},refresh:function(){if(!this.app.section){return{}}this.dict={};this.xml=$("<div/>");this._iterate(this.app.section.$el,this.dict,this.xml)},_iterate:function(d,e,b){var a=this;var c=$(d).children();c.each(function(){var i=this;var h=$(i).attr("id");if($(i).hasClass("form-row")||$(i).hasClass("tab-pane")){e[h]={};var f=a.app.inputs_sequential[h];if(f){e[h]={input:f}}var g=$('<div id="'+h+'"/>');b.append(g);a._iterate(i,e[h],g)}else{a._iterate(i,e,b)}})},findReferences:function(c){var f=[];var b=this;function d(g,i){var h=$(i).children();var j=[];h.each(function(){var m=this;var l=$(m).attr("id");if(l!==c){var k=b.app.inputs_sequential[l];if(k){if(k.name==g){return}if(k.data_ref==g){j.push(l)}}}});f=f.concat(j);h.each(function(){d(c,this)})}var e=this.xml.find("#"+c);if(e.length>0){var a=b.app.inputs_sequential[c];if(a){d(a.name,e.parent())}}return f}})}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/packed/mvc/ui/ui-misc.js --- a/static/scripts/packed/mvc/ui/ui-misc.js +++ b/static/scripts/packed/mvc/ui/ui-misc.js @@ -1,1 +1,1 @@ -define(["utils/utils","mvc/ui/ui-select-default","mvc/ui/ui-checkbox","mvc/ui/ui-radiobutton","mvc/ui/ui-button-menu","mvc/ui/ui-modal"],function(l,b,e,m,p,n){var d=Backbone.View.extend({optionsDefault:{url:"",cls:""},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options))},_template:function(q){return'<img class="ui-image '+q.cls+'" src="'+q.url+'"/>'}});var k=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options))},title:function(q){this.$el.html(q)},_template:function(q){return'<label class="ui-label '+q.cls+'">'+q.title+"</label>"},value:function(){return options.title}});var c=Backbone.View.extend({optionsDefault:{floating:"right",icon:"",tooltip:"",placement:"bottom",title:"",cls:""},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).tooltip({title:q.tooltip,placement:"bottom"})},_template:function(q){return'<div><span class="fa '+q.icon+'" class="ui-icon"/> '+q.title+"</div>"}});var g=Backbone.View.extend({optionsDefault:{id:null,title:"",floating:"right",cls:"btn btn-default",icon:""},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",q.onclick);$(this.el).tooltip({title:q.tooltip,placement:"bottom"})},_template:function(q){var r='<button id="'+q.id+'" type="submit" style="float: '+q.floating+';" type="button" class="ui-button '+q.cls+'">';if(q.icon){r+='<i class="icon fa '+q.icon+'"></i> '}r+=q.title+"</button>";return r}});var h=Backbone.View.extend({optionsDefault:{id:null,title:"",floating:"right",cls:"icon-btn",icon:"",tooltip:"",onclick:null},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",q.onclick);$(this.el).tooltip({title:q.tooltip,placement:"bottom"})},_template:function(q){var r="";if(q.title){r="width: auto;"}var s='<div id="'+q.id+'" style="float: '+q.floating+"; "+r+'" class="ui-button-icon '+q.cls+'">';if(q.title){s+='<div class="button"><i class="icon fa '+q.icon+'"/> <span class="title">'+q.title+"</span></div>"}else{s+='<i class="icon fa '+q.icon+'"/>'}s+="</div>";return s}});var f=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",q.onclick)},_template:function(q){return'<div><a href="javascript:void(0)" class="ui-anchor '+q.cls+'">'+q.title+"</a></div>"}});var o=Backbone.View.extend({optionsDefault:{message:"",status:"info",persistent:false},initialize:function(q){this.options=l.merge(q,this.optionsDefault);this.setElement("<div></div>")},update:function(r){this.options=l.merge(r,this.optionsDefault);if(r.message!=""){this.$el.html(this._template(this.options));this.$el.find(".alert").append(r.message);this.$el.fadeIn();if(!r.persistent){var q=this;window.setTimeout(function(){if(q.$el.is(":visible")){q.$el.fadeOut()}else{q.$el.hide()}},3000)}}else{this.$el.fadeOut()}},_template:function(q){return'<div class="ui-message alert alert-'+q.status+'"/>'}});var a=Backbone.View.extend({optionsDefault:{onclick:null,searchword:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));var q=this;if(this.options.onclick){this.$el.on("submit",function(t){var s=q.$el.find("#search");q.options.onclick(s.val())})}},_template:function(q){return'<div class="ui-search"><form onsubmit="return false;"><input id="search" class="form-control input-sm" type="text" name="search" placeholder="Search..." value="'+q.searchword+'"><button type="submit" class="btn search-btn"><i class="fa fa-search"></i></button></form></div>'}});var j=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:false,visible:true,cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));if(this.options.disabled){this.$el.prop("disabled",true)}if(!this.options.visible){this.$el.hide()}var q=this;this.$el.on("input",function(){if(q.options.onchange){q.options.onchange(q.$el.val())}})},value:function(q){if(q!==undefined){this.$el.val(q)}return this.$el.val()},_template:function(q){return'<input id="'+q.id+'" type="'+q.type+'" value="'+q.value+'" placeholder="'+q.placeholder+'" class="ui-input '+q.cls+'">'}});var i=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:false,visible:true,cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));if(this.options.disabled){this.$el.prop("disabled",true)}if(!this.options.visible){this.$el.hide()}var q=this;this.$el.on("input",function(){if(q.options.onchange){q.options.onchange(q.$el.val())}})},value:function(q){if(q!==undefined){this.$el.val(q)}return this.$el.val()},_template:function(q){return'<textarea id="'+q.id+'" class="ui-textarea '+q.cls+'" rows="5"></textarea>'}});return{Anchor:f,Button:g,ButtonIcon:h,ButtonMenu:p,Icon:c,Image:d,Input:j,Label:k,Message:o,Modal:n,RadioButton:m,Checkbox:e,Searchbox:a,Select:b,Textarea:i}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-select-default","mvc/ui/ui-checkbox","mvc/ui/ui-radiobutton","mvc/ui/ui-button-menu","mvc/ui/ui-modal"],function(l,b,e,m,q,n){var d=Backbone.View.extend({optionsDefault:{url:"",cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options))},_template:function(r){return'<img class="ui-image '+r.cls+'" src="'+r.url+'"/>'}});var k=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options))},title:function(r){this.$el.html(r)},_template:function(r){return'<label class="ui-label '+r.cls+'">'+r.title+"</label>"},value:function(){return options.title}});var c=Backbone.View.extend({optionsDefault:{floating:"right",icon:"",tooltip:"",placement:"bottom",title:"",cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).tooltip({title:r.tooltip,placement:"bottom"})},_template:function(r){return'<div><span class="fa '+r.icon+'" class="ui-icon"/> '+r.title+"</div>"}});var g=Backbone.View.extend({optionsDefault:{id:null,title:"",floating:"right",cls:"btn btn-default",icon:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",r.onclick);$(this.el).tooltip({title:r.tooltip,placement:"bottom"})},_template:function(r){var s='<button id="'+r.id+'" type="submit" style="float: '+r.floating+';" type="button" class="ui-button '+r.cls+'">';if(r.icon){s+='<i class="icon fa '+r.icon+'"></i> '}s+=r.title+"</button>";return s}});var h=Backbone.View.extend({optionsDefault:{id:null,title:"",floating:"right",cls:"icon-btn",icon:"",tooltip:"",onclick:null},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",r.onclick);$(this.el).tooltip({title:r.tooltip,placement:"bottom"})},_template:function(r){var s="";if(r.title){s="width: auto;"}var t='<div id="'+r.id+'" style="float: '+r.floating+"; "+s+'" class="ui-button-icon '+r.cls+'">';if(r.title){t+='<div class="button"><i class="icon fa '+r.icon+'"/> <span class="title">'+r.title+"</span></div>"}else{t+='<i class="icon fa '+r.icon+'"/>'}t+="</div>";return t}});var f=Backbone.View.extend({optionsDefault:{title:"",cls:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options));$(this.el).on("click",r.onclick)},_template:function(r){return'<div><a href="javascript:void(0)" class="ui-anchor '+r.cls+'">'+r.title+"</a></div>"}});var o=Backbone.View.extend({optionsDefault:{message:"",status:"info",persistent:false},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement("<div></div>")},update:function(s){this.options=l.merge(s,this.optionsDefault);if(s.message!=""){this.$el.html(this._template(this.options));this.$el.find(".alert").append(s.message);this.$el.fadeIn();if(!s.persistent){var r=this;window.setTimeout(function(){if(r.$el.is(":visible")){r.$el.fadeOut()}else{r.$el.hide()}},3000)}}else{this.$el.fadeOut()}},_template:function(r){return'<div class="ui-message alert alert-'+r.status+'"/>'}});var a=Backbone.View.extend({optionsDefault:{onclick:null,searchword:""},initialize:function(s){this.options=l.merge(s,this.optionsDefault);this.setElement(this._template(this.options));var r=this;if(this.options.onclick){this.$el.on("submit",function(u){var t=r.$el.find("#search");r.options.onclick(t.val())})}},_template:function(r){return'<div class="ui-search"><form onsubmit="return false;"><input id="search" class="form-control input-sm" type="text" name="search" placeholder="Search..." value="'+r.searchword+'"><button type="submit" class="btn search-btn"><i class="fa fa-search"></i></button></form></div>'}});var j=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:false,visible:true,cls:""},initialize:function(s){this.options=l.merge(s,this.optionsDefault);this.setElement(this._template(this.options));if(this.options.disabled){this.$el.prop("disabled",true)}if(!this.options.visible){this.$el.hide()}var r=this;this.$el.on("input",function(){if(r.options.onchange){r.options.onchange(r.$el.val())}})},value:function(r){if(r!==undefined){this.$el.val(r)}return this.$el.val()},_template:function(r){return'<input id="'+r.id+'" type="'+r.type+'" value="'+r.value+'" placeholder="'+r.placeholder+'" class="ui-input '+r.cls+'">'}});var i=Backbone.View.extend({optionsDefault:{value:"",type:"text",placeholder:"",disabled:false,visible:true,cls:""},initialize:function(s){this.options=l.merge(s,this.optionsDefault);this.setElement(this._template(this.options));if(this.options.disabled){this.$el.prop("disabled",true)}if(!this.options.visible){this.$el.hide()}var r=this;this.$el.on("input",function(){if(r.options.onchange){r.options.onchange(r.$el.val())}})},value:function(r){if(r!==undefined){this.$el.val(r)}return this.$el.val()},_template:function(r){return'<textarea id="'+r.id+'" class="ui-textarea '+r.cls+'" rows="5"></textarea>'}});var p=Backbone.View.extend({optionsDefault:{value:""},initialize:function(r){this.options=l.merge(r,this.optionsDefault);this.setElement(this._template(this.options))},value:function(r){if(r!==undefined){this.$el.val(r)}return this.$el.val()},_template:function(r){return'<hidden id="'+r.id+'" value="'+r.value+'"/>'}});return{Anchor:f,Button:g,ButtonIcon:h,ButtonMenu:q,Icon:c,Image:d,Input:j,Label:k,Message:o,Modal:n,RadioButton:m,Checkbox:e,Searchbox:a,Select:b,Textarea:i,Hidden:p}}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/packed/mvc/ui/ui-table.js --- a/static/scripts/packed/mvc/ui/ui-table.js +++ b/static/scripts/packed/mvc/ui/ui-table.js @@ -1,1 +1,1 @@ -define(["utils/utils"],function(a){var b=Backbone.View.extend({row:null,row_count:0,optionsDefault:{content:"No content available.",onchange:null,ondblclick:null,onconfirm:null,cls:"ui-table"},events:{click:"_onclick",dblclick:"_ondblclick"},initialize:function(c){this.options=a.merge(c,this.optionsDefault);var d=$(this._template(this.options));this.$thead=d.find("thead");this.$tbody=d.find("tbody");this.$tmessage=d.find("tmessage");this.setElement(d);this.row=$("<tr></tr>")},addHeader:function(c){var d=$("<th></th>");d.append(c);this.row.append(d)},appendHeader:function(){this.$thead.append(this.row);this.row=$("<tr></tr>")},add:function(c,d,f){var e=$("<td></td>");if(d){e.css("width",d)}if(f){e.css("text-align",f)}e.append(c);this.row.append(e)},append:function(c){this._commit(c)},prepend:function(c){this._commit(c,true)},get:function(c){return this.$el.find("#"+c)},del:function(d){var c=this.$tbody.find("#"+d);if(c.length>0){c.remove();this.row_count--;this._refresh()}},delAll:function(){this.$tbody.empty();this.row_count=0;this._refresh()},value:function(c){this.before=this.$tbody.find(".current").attr("id");if(c!==undefined){this.$tbody.find("tr").removeClass("current");if(c){this.$tbody.find("#"+c).addClass("current")}}var d=this.$tbody.find(".current").attr("id");if(d===undefined){return null}else{if(d!=this.before&&this.options.onchange){this.options.onchange(c)}return d}},size:function(){return this.$tbody.find("tr").length},_commit:function(d,c){this.del(d);this.row.attr("id",d);if(c){this.$tbody.prepend(this.row)}else{this.$tbody.append(this.row)}this.row=$("<tr></tr>");this.row_count++;this._refresh()},_onclick:function(f){var c=this.value();var d=$(f.target).closest("tr").attr("id");if(d!=""){if(d&&c!=d){if(this.options.onconfirm){this.options.onconfirm(d)}else{this.value(d)}}}},_ondblclick:function(d){var c=this.value();if(c&&this.options.ondblclick){this.options.ondblclick(c)}},_refresh:function(){if(this.row_count==0){this.$tmessage.show()}else{this.$tmessage.hide()}},_template:function(c){return'<div><table class="'+c.cls+'"><thead></thead><tbody></tbody></table><tmessage>'+c.content+"</tmessage><div>"}});return{View:b}}); \ No newline at end of file +define(["utils/utils"],function(a){var b=Backbone.View.extend({row:null,row_count:0,optionsDefault:{content:"No content available.",onchange:null,ondblclick:null,onconfirm:null,cls:"ui-table",cls_tr:""},events:{click:"_onclick",dblclick:"_ondblclick"},initialize:function(c){this.options=a.merge(c,this.optionsDefault);var d=$(this._template(this.options));this.$thead=d.find("thead");this.$tbody=d.find("tbody");this.$tmessage=d.find("tmessage");this.setElement(d);this.row=this._row()},addHeader:function(c){var d=$("<th></th>");d.append(c);this.row.append(d)},appendHeader:function(){this.$thead.append(this.row);this.row=$("<tr></tr>")},add:function(c,d,f){var e=$("<td></td>");if(d){e.css("width",d)}if(f){e.css("text-align",f)}e.append(c);this.row.append(e)},append:function(c){this._commit(c)},prepend:function(c){this._commit(c,true)},get:function(c){return this.$el.find("#"+c)},del:function(d){var c=this.$tbody.find("#"+d);if(c.length>0){c.remove();this.row_count--;this._refresh()}},delAll:function(){this.$tbody.empty();this.row_count=0;this._refresh()},value:function(c){this.before=this.$tbody.find(".current").attr("id");if(c!==undefined){this.$tbody.find("tr").removeClass("current");if(c){this.$tbody.find("#"+c).addClass("current")}}var d=this.$tbody.find(".current").attr("id");if(d===undefined){return null}else{if(d!=this.before&&this.options.onchange){this.options.onchange(c)}return d}},size:function(){return this.$tbody.find("tr").length},_commit:function(d,c){this.del(d);this.row.attr("id",d);if(c){this.$tbody.prepend(this.row)}else{this.$tbody.append(this.row)}this.row=this._row();this.row_count++;this._refresh()},_row:function(){return $('<tr class="'+this.options.cls_tr+'"></tr>')},_onclick:function(f){var c=this.value();var d=$(f.target).closest("tr").attr("id");if(d!=""){if(d&&c!=d){if(this.options.onconfirm){this.options.onconfirm(d)}else{this.value(d)}}}},_ondblclick:function(d){var c=this.value();if(c&&this.options.ondblclick){this.options.ondblclick(c)}},_refresh:function(){if(this.row_count==0){this.$tmessage.show()}else{this.$tmessage.hide()}},_template:function(c){return'<div><table class="'+c.cls+'"><thead></thead><tbody></tbody></table><tmessage>'+c.content+"</tmessage><div>"}});return{View:b}}); \ No newline at end of file diff -r 419ca68e073e942fe96b450ad6628949948f306b -r 8d307a592c729ffe5e20aed1f33a56ec6aca0ee9 static/scripts/packed/mvc/ui/ui-tabs.js --- a/static/scripts/packed/mvc/ui/ui-tabs.js +++ b/static/scripts/packed/mvc/ui/ui-tabs.js @@ -1,1 +1,1 @@ -define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{title_new:"",operations:null,onnew:null},initialize:function(e){this.visible=false;this.$nav=null;this.$content=null;this.first_tab=null;this.options=a.merge(e,this.optionsDefault);var c=$(this._template(this.options));this.$nav=c.find(".tab-navigation");this.$content=c.find(".tab-content");this.setElement(c);this.list={};var d=this;if(this.options.operations){$.each(this.options.operations,function(g,h){h.$el.prop("id",g);d.$nav.find(".operations").append(h.$el)})}if(this.options.onnew){var f=$(this._template_tab_new(this.options));this.$nav.append(f);f.tooltip({title:"Add a new tab",placement:"bottom",container:d.$el});f.on("click",function(g){f.tooltip("hide");d.options.onnew()})}},size:function(){return _.size(this.list)},add:function(f){var e=this;var h=f.id;var g=$(this._template_tab(f));var d=$(this._template_tab_content(f));this.list[h]=f.ondel?true:false;if(this.options.onnew){this.$nav.find("#new-tab").before(g)}else{this.$nav.append(g)}d.append(f.$el);this.$content.append(d);if(_.size(this.list)==1){g.addClass("active");d.addClass("active");this.first_tab=h}if(f.ondel){var c=g.find("#delete");c.tooltip({title:"Delete this tab",placement:"bottom",container:e.$el});c.on("click",function(){c.tooltip("destroy");e.$el.find(".tooltip").remove();f.ondel();return false})}g.on("click",function(i){i.preventDefault();if(f.onclick){f.onclick()}else{e.show(h)}})},del:function(c){this.$el.find("#tab-"+c).remove();this.$el.find("#tab-content-"+c).remove();if(this.first_tab==c){this.first_tab=null}if(this.first_tab!=null){this.show(this.first_tab)}},delRemovable:function(){for(var c in this.list){if(this.list[c]){this.del(c)}}},show:function(c){this.$el.fadeIn("fast");this.visible=true;if(c){this.$el.find(".tab-element").removeClass("active");this.$el.find(".tab-pane").removeClass("active");this.$el.find("#tab-"+c).addClass("active");this.$el.find("#tab-content-"+c).addClass("active")}},hide:function(){this.$el.fadeOut("fast");this.visible=false},hideOperation:function(c){this.$nav.find("#"+c).hide()},showOperation:function(c){this.$nav.find("#"+c).show()},setOperation:function(e,d){var c=this.$nav.find("#"+e);c.off("click");c.on("click",d)},title:function(e,d){var c=this.$el.find("#tab-title-text-"+e);if(d){c.html(d)}return c.html()},_template:function(c){return'<div class="ui-tabs tabbable tabs-left"><ul id="tab-navigation" class="tab-navigation nav nav-tabs"><div class="operations" style="float: right; margin-bottom: 4px;"></div></ul><div id="tab-content" class="tab-content"/></div>'},_template_tab_new:function(c){return'<li id="new-tab"><a href="javascript:void(0);"><i class="ui-tabs-add fa fa-plus-circle"/>'+c.title_new+"</a></li>"},_template_tab:function(d){var c='<li id="tab-'+d.id+'" class="tab-element"><a id="tab-title-link-'+d.id+'" title="" href="#tab-content-'+d.id+'" data-original-title=""><span id="tab-title-text-'+d.id+'">'+d.title+"</span>";if(d.ondel){c+='<i id="delete" class="ui-tabs-delete fa fa-minus-circle"/>'}c+="</a></li>";return c},_template_tab_content:function(c){return'<div id="tab-content-'+c.id+'" class="tab-pane"/>'}});return{View:b}}); \ No newline at end of file +define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{title_new:"",operations:null,onnew:null},initialize:function(e){this.visible=false;this.$nav=null;this.$content=null;this.first_tab=null;this.options=a.merge(e,this.optionsDefault);var c=$(this._template(this.options));this.$nav=c.find(".tab-navigation");this.$content=c.find(".tab-content");this.setElement(c);this.list={};var d=this;if(this.options.operations){$.each(this.options.operations,function(g,h){h.$el.prop("id",g);d.$nav.find(".operations").append(h.$el)})}if(this.options.onnew){var f=$(this._template_tab_new(this.options));this.$nav.append(f);f.tooltip({title:"Add a new tab",placement:"bottom",container:d.$el});f.on("click",function(g){f.tooltip("hide");d.options.onnew()})}},size:function(){return _.size(this.list)},add:function(f){var e=this;var h=f.id;var g=$(this._template_tab(f));var d=$(this._template_tab_content(f));this.list[h]=f.ondel?true:false;if(this.options.onnew){this.$nav.find("#new-tab").before(g)}else{this.$nav.append(g)}d.append(f.$el);this.$content.append(d);if(_.size(this.list)==1){g.addClass("active");d.addClass("active");this.first_tab=h}if(f.ondel){var c=g.find("#delete");c.tooltip({title:"Delete this tab",placement:"bottom",container:e.$el});c.on("click",function(){c.tooltip("destroy");e.$el.find(".tooltip").remove();f.ondel();return false})}g.on("click",function(i){i.preventDefault();if(f.onclick){f.onclick()}else{e.show(h)}})},del:function(c){this.$el.find("#tab-"+c).remove();this.$el.find("#"+c).remove();if(this.first_tab==c){this.first_tab=null}if(this.first_tab!=null){this.show(this.first_tab)}if(this.list[c]){delete this.list[c]}},delRemovable:function(){for(var c in this.list){this.del(c)}},show:function(c){this.$el.fadeIn("fast");this.visible=true;if(c){this.$el.find(".tab-element").removeClass("active");this.$el.find(".tab-pane").removeClass("active");this.$el.find("#tab-"+c).addClass("active");this.$el.find("#"+c).addClass("active")}},hide:function(){this.$el.fadeOut("fast");this.visible=false},hideOperation:function(c){this.$nav.find("#"+c).hide()},showOperation:function(c){this.$nav.find("#"+c).show()},setOperation:function(e,d){var c=this.$nav.find("#"+e);c.off("click");c.on("click",d)},title:function(e,d){var c=this.$el.find("#tab-title-text-"+e);if(d){c.html(d)}return c.html()},retitle:function(d){var c=0;for(var e in this.list){this.title(e,++c+": "+d)}},_template:function(c){return'<div class="ui-tabs tabbable tabs-left"><ul id="tab-navigation" class="tab-navigation nav nav-tabs"><div class="operations" style="float: right; margin-bottom: 4px;"></div></ul><div id="tab-content" class="tab-content"/></div>'},_template_tab_new:function(c){return'<li id="new-tab"><a href="javascript:void(0);"><i class="ui-tabs-add fa fa-plus-circle"/>'+c.title_new+"</a></li>"},_template_tab:function(d){var c='<li id="tab-'+d.id+'" class="tab-element"><a id="tab-title-link-'+d.id+'" title="" href="#'+d.id+'" data-original-title=""><span id="tab-title-text-'+d.id+'" class="tab-title-text">'+d.title+"</span>";if(d.ondel){c+='<i id="delete" class="ui-tabs-delete fa fa-minus-circle"/>'}c+="</a></li>";return c},_template_tab_content:function(c){return'<div id="'+c.id+'" class="tab-pane"/>'}});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.