commit/galaxy-central: guerler: ToolForm: Fix select2 value selection
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/a1fff5e41925/ Changeset: a1fff5e41925 User: guerler Date: 2014-12-01 05:21:40+00:00 Summary: ToolForm: Fix select2 value selection Affected #: 9 files diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 client/galaxy/scripts/mvc/ui/ui-drilldown.js --- a/client/galaxy/scripts/mvc/ui/ui-drilldown.js +++ b/client/galaxy/scripts/mvc/ui/ui-drilldown.js @@ -23,7 +23,7 @@ /** Template to create options tree */ - _templateOptions: function(data, current) { + _templateOptions: function(options) { // link this var self = this; @@ -48,10 +48,10 @@ } // recursive function which iterates through options - function iterate ($tmpl, data) { - for (i in data) { + function iterate ($tmpl, options) { + for (i in options) { // current option level in hierarchy - var level = data[i]; + var level = options[i]; // check for options var has_options = level.options.length > 0; @@ -84,7 +84,7 @@ // iterate through options and create dom var $tmpl = $('<div/>'); - iterate($tmpl, data); + iterate($tmpl, options); return $tmpl; }, diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 client/galaxy/scripts/mvc/ui/ui-options.js --- a/client/galaxy/scripts/mvc/ui/ui-options.js +++ b/client/galaxy/scripts/mvc/ui/ui-options.js @@ -7,7 +7,6 @@ initialize: function(options) { // options this.optionsDefault = { - value : [], visible : true, data : [], id : Utils.uuid(), @@ -38,7 +37,7 @@ this.update(this.options.data); // set initial value - if (this.options.value) { + if (this.options.value !== undefined) { this.value(this.options.value); } @@ -88,13 +87,13 @@ /** Return/Set current value */ value: function (new_value) { - // check if its an array - if (typeof new_value === 'string') { - new_value = [new_value]; - } - - // set new value + // set new value if provided if (new_value !== undefined) { + // check if its an array + if (!(new_value instanceof Array)) { + new_value = [new_value]; + } + // reset selection this.$el.find('input').prop('checked', false); @@ -111,12 +110,14 @@ /** Check if selected value exists (or any if multiple) */ exists: function(value) { - if (typeof value === 'string') { - value = [value]; - } - for (var i in value) { - if (this.$el.find('input[value="' + value[i] + '"]').length > 0) { - return true; + if (value !== undefined) { + if (!(value instanceof Array)) { + value = [value]; + } + for (var i in value) { + if (this.$el.find('input[value="' + value[i] + '"]').length > 0) { + return true; + } } } return false; diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 client/galaxy/scripts/mvc/ui/ui-select-default.js --- a/client/galaxy/scripts/mvc/ui/ui-select-default.js +++ b/client/galaxy/scripts/mvc/ui/ui-select-default.js @@ -75,6 +75,9 @@ value : function (new_value) { if (new_value !== undefined) { this.$select.val(new_value); + if (this.$select.select2) { + this.$select.select2('val', new_value); + } } return this.$select.val(); }, diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/mvc/ui/ui-drilldown.js --- a/static/scripts/mvc/ui/ui-drilldown.js +++ b/static/scripts/mvc/ui/ui-drilldown.js @@ -23,7 +23,7 @@ /** Template to create options tree */ - _templateOptions: function(data, current) { + _templateOptions: function(options) { // link this var self = this; @@ -48,10 +48,10 @@ } // recursive function which iterates through options - function iterate ($tmpl, data) { - for (i in data) { + function iterate ($tmpl, options) { + for (i in options) { // current option level in hierarchy - var level = data[i]; + var level = options[i]; // check for options var has_options = level.options.length > 0; @@ -84,7 +84,7 @@ // iterate through options and create dom var $tmpl = $('<div/>'); - iterate($tmpl, data); + iterate($tmpl, options); return $tmpl; }, diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/mvc/ui/ui-options.js --- a/static/scripts/mvc/ui/ui-options.js +++ b/static/scripts/mvc/ui/ui-options.js @@ -7,7 +7,6 @@ initialize: function(options) { // options this.optionsDefault = { - value : [], visible : true, data : [], id : Utils.uuid(), @@ -38,7 +37,7 @@ this.update(this.options.data); // set initial value - if (this.options.value) { + if (this.options.value !== undefined) { this.value(this.options.value); } @@ -88,13 +87,13 @@ /** Return/Set current value */ value: function (new_value) { - // check if its an array - if (typeof new_value === 'string') { - new_value = [new_value]; - } - - // set new value + // set new value if provided if (new_value !== undefined) { + // check if its an array + if (!(new_value instanceof Array)) { + new_value = [new_value]; + } + // reset selection this.$el.find('input').prop('checked', false); @@ -111,12 +110,14 @@ /** Check if selected value exists (or any if multiple) */ exists: function(value) { - if (typeof value === 'string') { - value = [value]; - } - for (var i in value) { - if (this.$el.find('input[value="' + value[i] + '"]').length > 0) { - return true; + if (value !== undefined) { + if (!(value instanceof Array)) { + value = [value]; + } + for (var i in value) { + if (this.$el.find('input[value="' + value[i] + '"]').length > 0) { + return true; + } } } return false; diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/mvc/ui/ui-select-default.js --- a/static/scripts/mvc/ui/ui-select-default.js +++ b/static/scripts/mvc/ui/ui-select-default.js @@ -75,6 +75,9 @@ value : function (new_value) { if (new_value !== undefined) { this.$select.val(new_value); + if (this.$select.select2) { + this.$select.select2('val', new_value); + } } return this.$select.val(); }, diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/packed/mvc/ui/ui-drilldown.js --- a/static/scripts/packed/mvc/ui/ui-drilldown.js +++ b/static/scripts/packed/mvc/ui/ui-drilldown.js @@ -1,1 +1,1 @@ -define(["utils/utils","mvc/ui/ui-options"],function(b,a){var c=a.Base.extend({initialize:function(d){this.display=d.display||"checkbox";d.multiple=(this.display=="checkbox");a.Base.prototype.initialize.call(this,d)},_templateOption:function(d,f,e){return'<div><input name="'+this.options.id+'" class="ui-option" type="'+this.display+'" value="'+f+'">'+b.sanitize(d)+"<div/>"},_templateOptions:function(g,h){var e=this;function f(l,m){function k(n){if(n){m.fadeIn("fast");l.removeClass("toggle-expand");l.addClass("toggle");l.is_expanded=true}else{m.hide();l.removeClass("toggle");l.addClass("toggle-expand");l.is_expanded=false}}l.on("click",function(){k(!l.is_expanded)})}function d(q,o){for(i in o){var r=o[i];var m=r.options.length>0;var l=$("<div/>");if(m){var n=$('<span class="ui-drilldown-button form-toggle icon-button toggle-expand" style="position: relative; top: 2px;"/>');var k=$("<div/>");k.append(n);k.append(e._templateOption(r.name,r.value));l.append(k);var p=$('<div style="display: none; margin-left: 25px;"/>');d(p,r.options);l.append(p);f(n,p)}else{l.append(e._templateOption(r.name,r.value))}q.append(l)}}var j=$("<div/>");d(j,g);return j},_template:function(d){return'<div class="ui-options drilldown-container" id="'+d.id+'"/>'}});return{View:c}}); \ No newline at end of file +define(["utils/utils","mvc/ui/ui-options"],function(b,a){var c=a.Base.extend({initialize:function(d){this.display=d.display||"checkbox";d.multiple=(this.display=="checkbox");a.Base.prototype.initialize.call(this,d)},_templateOption:function(d,f,e){return'<div><input name="'+this.options.id+'" class="ui-option" type="'+this.display+'" value="'+f+'">'+b.sanitize(d)+"<div/>"},_templateOptions:function(f){var e=this;function g(k,l){function j(m){if(m){l.fadeIn("fast");k.removeClass("toggle-expand");k.addClass("toggle");k.is_expanded=true}else{l.hide();k.removeClass("toggle");k.addClass("toggle-expand");k.is_expanded=false}}k.on("click",function(){j(!k.is_expanded)})}function d(p,k){for(i in k){var q=k[i];var m=q.options.length>0;var l=$("<div/>");if(m){var n=$('<span class="ui-drilldown-button form-toggle icon-button toggle-expand" style="position: relative; top: 2px;"/>');var j=$("<div/>");j.append(n);j.append(e._templateOption(q.name,q.value));l.append(j);var o=$('<div style="display: none; margin-left: 25px;"/>');d(o,q.options);l.append(o);g(n,o)}else{l.append(e._templateOption(q.name,q.value))}p.append(l)}}var h=$("<div/>");d(h,f);return h},_template:function(d){return'<div class="ui-options drilldown-container" id="'+d.id+'"/>'}});return{View:c}}); \ No newline at end of file diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/packed/mvc/ui/ui-options.js --- a/static/scripts/packed/mvc/ui/ui-options.js +++ b/static/scripts/packed/mvc/ui/ui-options.js @@ -1,1 +1,1 @@ -define(["utils/utils"],function(b){var a=Backbone.View.extend({initialize:function(g){this.optionsDefault={value:[],visible:true,data:[],id:b.uuid(),errorText:"No data available.",waitText:"Please wait..."};this.options=b.merge(g,this.optionsDefault);this.setElement("<div/>");this.$message=$("<div/>");this.$options=$(this._template(g));this.$el.append(this.$message);this.$el.append(this.$options);if(!this.options.visible){this.$el.hide()}this.update(this.options.data);if(this.options.value){this.value(this.options.value)}var f=this;this.on("change",function(){f._change()})},update:function(g){var j=this._getValue();this.$options.empty();if(this._templateOptions){this.$options.append(this._templateOptions(g))}else{for(var h in g){var i=$(this._templateOption(g[h]));i.addClass("ui-option");this.$options.append(i)}}var f=this;this.$el.find("input").on("change",function(){f.value(f._getValue());f._change()});this._refresh();this.value(j)},value:function(g){if(typeof g==="string"){g=[g]}if(g!==undefined){this.$el.find("input").prop("checked",false);for(var f in g){this.$el.find('input[value="'+g[f]+'"]').first().prop("checked",true)}}return this._getValue()},exists:function(g){if(typeof g==="string"){g=[g]}for(var f in g){if(this.$el.find('input[value="'+g[f]+'"]').length>0){return true}}return false},first:function(){var f=this.$el.find("input");if(f.length>0){return f.val()}else{return undefined}},validate:function(){var g=this.value();if(!(g instanceof Array)){g=[g]}for(var f in g){if([null,"null",undefined].indexOf(g[f])>-1){return false}}return true},wait:function(){if(this._size()==0){this._messageShow(this.options.waitText,"info");this.$options.hide()}},unwait:function(){this._messageHide();this._refresh()},_change:function(){if(this.options.onchange){this.options.onchange(this._getValue())}},_refresh:function(){if(this._size()==0){this._messageShow(this.options.errorText,"danger");this.$options.hide()}else{this._messageHide();this.$options.css("display","inline-block")}},_getValue:function(){var g=this.$el.find(":checked");if(g.length==0){return"null"}if(this.options.multiple){var f=[];g.each(function(){f.push($(this).val())});return f}else{return g.val()}},_size:function(){return this.$el.find(".ui-option").length},_messageShow:function(g,f){this.$message.show();this.$message.removeClass();this.$message.addClass("ui-message alert alert-"+f);this.$message.html(g)},_messageHide:function(){this.$message.hide()},_template:function(){return'<div class="ui-options"/>'}});var d={};d.View=a.extend({initialize:function(f){a.prototype.initialize.call(this,f)},_templateOption:function(f){return'<div><input type="radio" name="'+this.options.id+'" value="'+f.value+'"/>'+f.label+"<br></div>"}});var c={};c.View=a.extend({initialize:function(f){f.multiple=true;a.prototype.initialize.call(this,f)},_templateOption:function(f){return'<div><input type="checkbox" name="'+this.options.id+'" value="'+f.value+'"/>'+f.label+"<br></div>"}});var e={};e.View=a.extend({initialize:function(f){a.prototype.initialize.call(this,f)},value:function(f){if(f!==undefined){this.$el.find("input").prop("checked",false);this.$el.find("label").removeClass("active");this.$el.find('[value="'+f+'"]').prop("checked",true).closest("label").addClass("active")}return this._getValue()},_templateOption:function(g){var f='<label class="btn btn-default">';if(g.icon){f+='<i class="fa '+g.icon+'"/>'}f+='<input type="radio" name="'+this.options.id+'" value="'+g.value+'">'+g.label+"</label>";return f},_template:function(){return'<div class="btn-group ui-radiobutton" data-toggle="buttons"/>'}});return{Base:a,Radio:d,RadioButton:e,Checkbox:c}}); \ No newline at end of file +define(["utils/utils"],function(b){var a=Backbone.View.extend({initialize:function(g){this.optionsDefault={visible:true,data:[],id:b.uuid(),errorText:"No data available.",waitText:"Please wait..."};this.options=b.merge(g,this.optionsDefault);this.setElement("<div/>");this.$message=$("<div/>");this.$options=$(this._template(g));this.$el.append(this.$message);this.$el.append(this.$options);if(!this.options.visible){this.$el.hide()}this.update(this.options.data);if(this.options.value!==undefined){this.value(this.options.value)}var f=this;this.on("change",function(){f._change()})},update:function(g){var j=this._getValue();this.$options.empty();if(this._templateOptions){this.$options.append(this._templateOptions(g))}else{for(var h in g){var i=$(this._templateOption(g[h]));i.addClass("ui-option");this.$options.append(i)}}var f=this;this.$el.find("input").on("change",function(){f.value(f._getValue());f._change()});this._refresh();this.value(j)},value:function(g){if(g!==undefined){if(!(g instanceof Array)){g=[g]}this.$el.find("input").prop("checked",false);for(var f in g){this.$el.find('input[value="'+g[f]+'"]').first().prop("checked",true)}}return this._getValue()},exists:function(g){if(g!==undefined){if(!(g instanceof Array)){g=[g]}for(var f in g){if(this.$el.find('input[value="'+g[f]+'"]').length>0){return true}}}return false},first:function(){var f=this.$el.find("input");if(f.length>0){return f.val()}else{return undefined}},validate:function(){var g=this.value();if(!(g instanceof Array)){g=[g]}for(var f in g){if([null,"null",undefined].indexOf(g[f])>-1){return false}}return true},wait:function(){if(this._size()==0){this._messageShow(this.options.waitText,"info");this.$options.hide()}},unwait:function(){this._messageHide();this._refresh()},_change:function(){if(this.options.onchange){this.options.onchange(this._getValue())}},_refresh:function(){if(this._size()==0){this._messageShow(this.options.errorText,"danger");this.$options.hide()}else{this._messageHide();this.$options.css("display","inline-block")}},_getValue:function(){var g=this.$el.find(":checked");if(g.length==0){return"null"}if(this.options.multiple){var f=[];g.each(function(){f.push($(this).val())});return f}else{return g.val()}},_size:function(){return this.$el.find(".ui-option").length},_messageShow:function(g,f){this.$message.show();this.$message.removeClass();this.$message.addClass("ui-message alert alert-"+f);this.$message.html(g)},_messageHide:function(){this.$message.hide()},_template:function(){return'<div class="ui-options"/>'}});var d={};d.View=a.extend({initialize:function(f){a.prototype.initialize.call(this,f)},_templateOption:function(f){return'<div><input type="radio" name="'+this.options.id+'" value="'+f.value+'"/>'+f.label+"<br></div>"}});var c={};c.View=a.extend({initialize:function(f){f.multiple=true;a.prototype.initialize.call(this,f)},_templateOption:function(f){return'<div><input type="checkbox" name="'+this.options.id+'" value="'+f.value+'"/>'+f.label+"<br></div>"}});var e={};e.View=a.extend({initialize:function(f){a.prototype.initialize.call(this,f)},value:function(f){if(f!==undefined){this.$el.find("input").prop("checked",false);this.$el.find("label").removeClass("active");this.$el.find('[value="'+f+'"]').prop("checked",true).closest("label").addClass("active")}return this._getValue()},_templateOption:function(g){var f='<label class="btn btn-default">';if(g.icon){f+='<i class="fa '+g.icon+'"/>'}f+='<input type="radio" name="'+this.options.id+'" value="'+g.value+'">'+g.label+"</label>";return f},_template:function(){return'<div class="btn-group ui-radiobutton" data-toggle="buttons"/>'}});return{Base:a,Radio:d,RadioButton:e,Checkbox:c}}); \ No newline at end of file diff -r 3ecc2541d8fc5170d9337f06b206ec09557f3afd -r a1fff5e41925f99d95def300a162e12db0f4b8c7 static/scripts/packed/mvc/ui/ui-select-default.js --- a/static/scripts/packed/mvc/ui/ui-select-default.js +++ b/static/scripts/packed/mvc/ui/ui-select-default.js @@ -1,1 +1,1 @@ -define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{id:"",cls:"",empty:"No data available",visible:true,wait:false,multiple:false,searchable:false},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));this.$select=this.$el.find(".select");this.$icon=this.$el.find(".icon");this.$button=this.$el.find(".button");if(this.options.multiple){this.$select.prop("multiple",true);this.$select.addClass("ui-select-multiple");this.$icon.remove()}else{this.$el.addClass("ui-select")}this.update(this.options.data);if(this.options.value!==undefined){this.value(this.options.value)}if(!this.options.visible){this.hide()}if(this.options.wait){this.wait()}else{this.show()}var c=this;this.$select.on("change",function(){c._change()});this.on("change",function(){c._change()})},value:function(c){if(c!==undefined){this.$select.val(c)}return this.$select.val()},first:function(){var c=this.$select.find("option");if(c.length>0){return c.val()}else{return undefined}},validate:function(){var d=this.value();if(!(d instanceof Array)){d=[d]}for(var c in d){if([null,"null",undefined].indexOf(d[c])>-1){return false}}return true},text:function(){return this.$select.find("option:selected").text()},show:function(){this.unwait();this.$select.show();this.$el.show()},hide:function(){this.$el.hide()},wait:function(){this.$icon.removeClass();this.$icon.addClass("fa fa-spinner fa-spin")},unwait:function(){this.$icon.removeClass();this.$icon.addClass("fa fa-caret-down")},disabled:function(){return this.$select.is(":disabled")},enable:function(){this.$select.prop("disabled",false)},disable:function(){this.$select.prop("disabled",true)},add:function(c){this.$select.append(this._templateOption(c));this._refresh()},del:function(c){this.$select.find("option[value="+c+"]").remove();this.$select.trigger("change");this._refresh()},update:function(c){var e=this.$select.val();this.$select.find("option").remove();for(var d in c){this.$select.append(this._templateOption(c[d]))}this._refresh();this.$select.val(e);if(!this.$select.val()){this.$select.val(this.first())}if(this.options.searchable){this.$button.hide();this.$select.select2("destroy");this.$select.select2()}},setOnChange:function(c){this.options.onchange=c},exists:function(c){return this.$select.find('option[value="'+c+'"]').length>0},_change:function(){if(this.options.onchange){this.options.onchange(this.$select.val())}},_refresh:function(){this.$select.find("option[value=null]").remove();var c=this.$select.find("option").length;if(c==0){this.disable();this.$select.append(this._templateOption({value:"null",label:this.options.empty}))}else{this.enable()}},_templateOption:function(c){return'<option value="'+c.value+'">'+c.label+"</option>"},_template:function(c){return'<div id="'+c.id+'"><select id="select" class="select '+c.cls+" "+c.id+'"></select><div class="button"><i class="icon"/></div></div>'}});return{View:b}}); \ No newline at end of file +define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{id:"",cls:"",empty:"No data available",visible:true,wait:false,multiple:false,searchable:false},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));this.$select=this.$el.find(".select");this.$icon=this.$el.find(".icon");this.$button=this.$el.find(".button");if(this.options.multiple){this.$select.prop("multiple",true);this.$select.addClass("ui-select-multiple");this.$icon.remove()}else{this.$el.addClass("ui-select")}this.update(this.options.data);if(this.options.value!==undefined){this.value(this.options.value)}if(!this.options.visible){this.hide()}if(this.options.wait){this.wait()}else{this.show()}var c=this;this.$select.on("change",function(){c._change()});this.on("change",function(){c._change()})},value:function(c){if(c!==undefined){this.$select.val(c);if(this.$select.select2){this.$select.select2("val",c)}}return this.$select.val()},first:function(){var c=this.$select.find("option");if(c.length>0){return c.val()}else{return undefined}},validate:function(){var d=this.value();if(!(d instanceof Array)){d=[d]}for(var c in d){if([null,"null",undefined].indexOf(d[c])>-1){return false}}return true},text:function(){return this.$select.find("option:selected").text()},show:function(){this.unwait();this.$select.show();this.$el.show()},hide:function(){this.$el.hide()},wait:function(){this.$icon.removeClass();this.$icon.addClass("fa fa-spinner fa-spin")},unwait:function(){this.$icon.removeClass();this.$icon.addClass("fa fa-caret-down")},disabled:function(){return this.$select.is(":disabled")},enable:function(){this.$select.prop("disabled",false)},disable:function(){this.$select.prop("disabled",true)},add:function(c){this.$select.append(this._templateOption(c));this._refresh()},del:function(c){this.$select.find("option[value="+c+"]").remove();this.$select.trigger("change");this._refresh()},update:function(c){var e=this.$select.val();this.$select.find("option").remove();for(var d in c){this.$select.append(this._templateOption(c[d]))}this._refresh();this.$select.val(e);if(!this.$select.val()){this.$select.val(this.first())}if(this.options.searchable){this.$button.hide();this.$select.select2("destroy");this.$select.select2()}},setOnChange:function(c){this.options.onchange=c},exists:function(c){return this.$select.find('option[value="'+c+'"]').length>0},_change:function(){if(this.options.onchange){this.options.onchange(this.$select.val())}},_refresh:function(){this.$select.find("option[value=null]").remove();var c=this.$select.find("option").length;if(c==0){this.disable();this.$select.append(this._templateOption({value:"null",label:this.options.empty}))}else{this.enable()}},_templateOption:function(c){return'<option value="'+c.value+'">'+c.label+"</option>"},_template:function(c){return'<div id="'+c.id+'"><select id="select" class="select '+c.cls+" "+c.id+'"></select><div class="button"><i class="icon"/></div></div>'}});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.
participants (1)
-
commits-noreply@bitbucket.org