commit/galaxy-central: martenson: extended ui-select module to support multiple inputs and on-demand ajax loading of paginated data
1 new commit in galaxy-central: https://bitbucket.org/galaxy/galaxy-central/commits/b027397c99c6/ Changeset: b027397c99c6 User: martenson Date: 2014-05-14 19:50:15 Summary: extended ui-select module to support multiple inputs and on-demand ajax loading of paginated data Affected #: 2 files diff -r 882f51a4d9dced2ce731c5b4afa5bed9623933c2 -r b027397c99c639d5b200b88649c6e7ca75a292f8 static/scripts/mvc/ui/ui-select.js --- a/static/scripts/mvc/ui/ui-select.js +++ b/static/scripts/mvc/ui/ui-select.js @@ -11,10 +11,13 @@ { // options optionsDefault: { - css : '', - placeholder : 'No data available', - data : [], - value : null + css : '', + placeholder : 'No data available', + data : [], + value : null, + multiple : false, + minimumInputLength : 0, + initialData : '' }, // initialize @@ -40,17 +43,19 @@ // refresh this._refresh(); - // initial value - if (this.options.value) { - this._setValue(this.options.value); - } - - // add change event - var self = this; - if (this.options.onchange) { - this.$el.on('change', function() { - self.options.onchange(self.value()); - }); + if (!this.options.multiple){ + // initial value + if (this.options.value) { + this._setValue(this.options.value); + } + + // add change event + var self = this; + if (this.options.onchange) { + this.$el.on('change', function() { + self.options.onchange(self.value()); + }); + } } }, @@ -142,18 +147,33 @@ // refresh _refresh: function() { - // selected - var selected = this._getValue(); - - // add select2 data - this.$el.select2({ - data : this.select_data, - containerCssClass : this.options.css, - placeholder : this.options.placeholder - }); - - // select previous value (if exists) - this._setValue(selected); + // add select2 data based on type of input + if (!this.options.multiple){ + var selected = this._getValue(); + var select_opt = { + data : this.select_data, + containerCssClass : this.options.css, + placeholder : this.options.placeholder, + }; + this.$el.select2(select_opt); + // select previous value (if exists) + this._setValue(selected); + } else { + var select_opt = { + multiple : this.options.multiple, + containerCssClass : this.options.css, + placeholder : this.options.placeholder, + minimumInputLength : this.options.minimumInputLength, + ajax : this.options.ajax, + dropdownCssClass : this.options.dropdownCssClass, + escapeMarkup : this.options.escapeMarkup, + formatResult : this.options.formatResult, + formatSelection : this.options.formatSelection, + initSelection : this.options.initSelection, + initialData : this.options.initialData + }; + this.$el.select2(select_opt); + } }, // get index @@ -186,8 +206,8 @@ }, // element - _template: function() { - return '<input type="hidden"/>'; + _template: function(options) { + return '<input type="hidden" value="' + this.options.initialData + '"/>'; } }); diff -r 882f51a4d9dced2ce731c5b4afa5bed9623933c2 -r b027397c99c639d5b200b88649c6e7ca75a292f8 static/scripts/packed/mvc/ui/ui-select.js --- a/static/scripts/packed/mvc/ui/ui-select.js +++ b/static/scripts/packed/mvc/ui/ui-select.js @@ -1,1 +1,1 @@ -define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{css:"",placeholder:"No data available",data:[],value:null},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));if(!this.options.container){console.log("ui-select::initialize() : container not specified.");return}this.options.container.append(this.$el);this.select_data=this.options.data;this._refresh();if(this.options.value){this._setValue(this.options.value)}var c=this;if(this.options.onchange){this.$el.on("change",function(){c.options.onchange(c.value())})}},value:function(c){var d=this._getValue();if(c!==undefined){this._setValue(c)}var e=this._getValue();if((e!=d&&this.options.onchange)){this.options.onchange(e)}return e},text:function(){return this.$el.select2("data").text},disabled:function(){return !this.$el.select2("enable")},enable:function(){this.$el.select2("enable",true)},disable:function(){this.$el.select2("enable",false)},add:function(c){this.select_data.push({id:c.id,text:c.text});this._refresh()},del:function(d){var c=this._getIndex(d);if(c!=-1){this.select_data.splice(c,1);this._refresh()}},remove:function(){this.$el.select2("destroy")},update:function(c){this.select_data=[];for(var d in c.data){this.select_data.push(c.data[d])}this._refresh()},_refresh:function(){var c=this._getValue();this.$el.select2({data:this.select_data,containerCssClass:this.options.css,placeholder:this.options.placeholder});this._setValue(c)},_getIndex:function(d){for(var c in this.select_data){if(this.select_data[c].id==d){return c}}return -1},_getValue:function(){return this.$el.select2("val")},_setValue:function(d){var c=this._getIndex(d);if(c==-1){if(this.select_data.length>0){d=this.select_data[0].id}}this.$el.select2("val",d)},_template:function(){return'<input type="hidden"/>'}});return{View:b}}); \ No newline at end of file +define(["utils/utils"],function(a){var b=Backbone.View.extend({optionsDefault:{css:"",placeholder:"No data available",data:[],value:null,multiple:false,minimumInputLength:0,initialData:""},initialize:function(d){this.options=a.merge(d,this.optionsDefault);this.setElement(this._template(this.options));if(!this.options.container){console.log("ui-select::initialize() : container not specified.");return}this.options.container.append(this.$el);this.select_data=this.options.data;this._refresh();if(!this.options.multiple){if(this.options.value){this._setValue(this.options.value)}var c=this;if(this.options.onchange){this.$el.on("change",function(){c.options.onchange(c.value())})}}},value:function(c){var d=this._getValue();if(c!==undefined){this._setValue(c)}var e=this._getValue();if((e!=d&&this.options.onchange)){this.options.onchange(e)}return e},text:function(){return this.$el.select2("data").text},disabled:function(){return !this.$el.select2("enable")},enable:function(){this.$el.select2("enable",true)},disable:function(){this.$el.select2("enable",false)},add:function(c){this.select_data.push({id:c.id,text:c.text});this._refresh()},del:function(d){var c=this._getIndex(d);if(c!=-1){this.select_data.splice(c,1);this._refresh()}},remove:function(){this.$el.select2("destroy")},update:function(c){this.select_data=[];for(var d in c.data){this.select_data.push(c.data[d])}this._refresh()},_refresh:function(){if(!this.options.multiple){var d=this._getValue();var c={data:this.select_data,containerCssClass:this.options.css,placeholder:this.options.placeholder,};this.$el.select2(c);this._setValue(d)}else{var c={multiple:this.options.multiple,containerCssClass:this.options.css,placeholder:this.options.placeholder,minimumInputLength:this.options.minimumInputLength,ajax:this.options.ajax,dropdownCssClass:this.options.dropdownCssClass,escapeMarkup:this.options.escapeMarkup,formatResult:this.options.formatResult,formatSelection:this.options.formatSelection,initSelection:this.options.initSelection,initialData:this.options.initialData};this.$el.select2(c)}},_getIndex:function(d){for(var c in this.select_data){if(this.select_data[c].id==d){return c}}return -1},_getValue:function(){return this.$el.select2("val")},_setValue:function(d){var c=this._getIndex(d);if(c==-1){if(this.select_data.length>0){d=this.select_data[0].id}}this.$el.select2("val",d)},_template:function(c){return'<input type="hidden" value="'+this.options.initialData+'"/>'}});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