From aebdfa82b459b5933aeac80b4653c856256db593 Mon Sep 17 00:00:00 2001 From: Aysam Guerler Date: Thu, 13 Feb 2014 02:37:10 -0500 Subject: [PATCH] Upload: Add select2 selection fields, add select2 backbone wrapper --- static/scripts/mvc/ui.select.js | 188 ++++++++++++++++++ static/scripts/mvc/upload/upload-row.js | 157 +++++++-------- static/scripts/mvc/upload/upload-view.js | 45 ++--- static/scripts/packed/mvc/ui.select.js | 1 + .../scripts/packed/mvc/upload/upload-row.js | 2 +- .../scripts/packed/mvc/upload/upload-view.js | 2 +- static/style/blue/base.css | 27 +-- static/style/src/less/upload.less | 24 ++- 8 files changed, 319 insertions(+), 127 deletions(-) create mode 100644 static/scripts/mvc/ui.select.js create mode 100644 static/scripts/packed/mvc/ui.select.js diff --git a/static/scripts/mvc/ui.select.js b/static/scripts/mvc/ui.select.js new file mode 100644 index 00000000000..0c53933c853 --- /dev/null +++ b/static/scripts/mvc/ui.select.js @@ -0,0 +1,188 @@ +// dependencies +define(['utils/utils'], function(Utils) { + +// plugin +var View = Backbone.View.extend( +{ + // options + optionsDefault: { + css : '', + placeholder : 'No data available', + data : [] + }, + + // initialize + initialize : function(options) { + // configure options + this.options = Utils.merge(options, this.optionsDefault); + + // create new element + this.setElement(this._template(this.options)); + + // add to dom + this.options.container.append(this.$el); + + // link selection dictionary + this.select_data = this.options.data; + + // 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()); + }); + } + }, + + // value + value : function (new_value) { + // get current id/value + var before = this._getValue(); + + // check if new_value is defined + if (new_value !== undefined) { + this._setValue(new_value); + } + + // get current id/value + var after = this._getValue(); + if(after === undefined) { + return null; + } else { + // fire onchange + if ((after != before && this.options.onchange)) { + this.options.onchange(after); + } + + // return current value + return after; + } + }, + + // label + text : function () { + return this.$el.select2('data').text; + }, + + // disabled + disabled: function() { + return !this.$el.select2('enable'); + }, + + // enable + enable: function() { + this.$el.select2('enable', true); + }, + + // disable + disable: function() { + this.$el.select2('enable', false); + }, + + // add + add: function(options) { + // add options + this.select_data.push({ + id : options.id, + text : options.text + }); + + // refresh + this._refresh(); + }, + + // remove + remove: function(id) { + // search option + var index = this._getIndex(id); + + // check if found + if (index != -1) { + // remove options + this.select_data.splice(index, 1); + + // refresh + this._refresh(); + } + }, + + // update + update: function(options) { + // copy options + this.select_data = []; + for (var key in options.data) { + this.select_data.push(options.data[key]); + } + + // refresh + this._refresh(); + }, + + // refresh + _refresh: function() { + + // link select data + var select_data = this.select_data; + if (!select_data || select_data.length == 0) { + select_data = []; + } + + // selected + var selected = this._getValue(); + + // add select2 data + this.$el.select2({ + data : select_data, + containerCssClass : this.options.css, + placeholder : this.options.placeholder + }); + + // select + var index = this._getIndex(selected); + if (index != -1) { + this._setValue(selected); + } + }, + + // get index + _getIndex: function(value) { + // search index + for (var key in this.select_data) { + if (this.select_data[key].id == value) { + return key; + } + } + + // not found + return -1; + }, + + // get value + _getValue: function() { + return this.$el.select2('val'); + }, + + // set value + _setValue: function(new_value) { + this.$el.select2('val', new_value); + }, + + // element + _template: function(options) { + return ''; + } +}); + +return { + View : View +} + +}); diff --git a/static/scripts/mvc/upload/upload-row.js b/static/scripts/mvc/upload/upload-row.js index d9599e5b1da..62a8966db06 100644 --- a/static/scripts/mvc/upload/upload-row.js +++ b/static/scripts/mvc/upload/upload-row.js @@ -3,13 +3,15 @@ define(['utils/utils', 'mvc/upload/upload-model', 'mvc/upload/upload-extensions', 'mvc/upload/upload-settings', - 'mvc/ui.popover'], + 'mvc/ui.popover', + 'mvc/ui.select'], function( Utils, UploadModel, UploadExtensions, UploadSettings, - Popover + Popover, + Select ) { // item view @@ -31,6 +33,12 @@ return Backbone.View.extend({ // handle for settings popover settings: null, + // genome selector + select_genome : null, + + // extension selector + select_extension : null, + // render initialize: function(app, options) { // link app @@ -55,6 +63,28 @@ return Backbone.View.extend({ placement : 'bottom' }); + // select genomes + this.select_genome = new Select.View({ + css: 'genome', + onchange : function() { + self.model.set('genome', self.select_genome.value()); + }, + data: self.app.list_genomes, + container: it.find('#genome'), + value: self.model.get('genome') + }); + + // select extension + this.select_extension = new Select.View({ + css: 'extension', + onchange : function() { + self.model.set('extension', self.select_extension.value()); + }, + data: self.app.list_extensions, + container: it.find('#extension'), + value: self.model.get('extension') + }); + // // ui events // @@ -76,16 +106,6 @@ return Backbone.View.extend({ self.model.set('file_size', $(e.target).val().length); }); - // handle genome selection - it.find('#genome').on('change', function(e) { - self.model.set('genome', $(e.target).val()); - }); - - // handle extension selection - it.find('#extension').on('change', function(e) { - self.model.set('extension', $(e.target).val()); - }); - // handle space to tabs button it.find('#space_to_tabs').on('change', function(e) { self.model.set('space_to_tabs', $(e.target).prop('checked')); @@ -100,9 +120,6 @@ return Backbone.View.extend({ this.model.on('change:status', function() { self._refreshStatus(); }); - this.model.on('change:extension', function() { - self._destroyExtensionInfo(); - }); this.model.on('change:info', function() { self._refreshInfo(); }); @@ -113,11 +130,9 @@ return Backbone.View.extend({ self._refreshFileSize(); }); this.model.on('remove', function() { - self._destroyExtensionInfo(); self.remove(); }); this.app.collection.on('reset', function() { - self._destroyExtensionInfo(); self.remove(); }); }, @@ -189,7 +204,7 @@ return Backbone.View.extend({ { // update genome info on screen var genome = this.model.get('genome'); - this.$el.find('#genome').val(genome); + this.select_genome.value(genome); }, // progress @@ -231,17 +246,23 @@ return Backbone.View.extend({ // set new status class sy.addClass(status_class); - + // enable form fields if (status == 'init') { + // select fields + this.select_genome.enable(); + this.select_extension.enable(); + + // default fields it.find('#text-content').attr('disabled', false); - it.find('#genome').attr('disabled', false); - it.find('#extension').attr('disabled', false); it.find('#space_to_tabs').attr('disabled', false); } else { + // select fields + this.select_genome.disable(); + this.select_extension.disable(); + + // default fields it.find('#text-content').attr('disabled', true); - it.find('#genome').attr('disabled', true); - it.find('#extension').attr('disabled', true); it.find('#space_to_tabs').attr('disabled', true); } @@ -275,7 +296,6 @@ return Backbone.View.extend({ // only remove from queue if not in processing line if (status == 'init' || status == 'success' || status == 'error') { - // remove from collection this.app.collection.remove(this.model); } }, @@ -286,7 +306,7 @@ return Backbone.View.extend({ // initialize var $el = $(this.el).find('#extension-info'); var extension = this.model.get('extension'); - var title = $(this.el).find('#extension').find('option:selected').text(); + var title = this.select_extension.text(); // create popup if (!this.extension_popup) { @@ -323,66 +343,43 @@ return Backbone.View.extend({ } }, - // attach file info popup - _destroyExtensionInfo : function() - { - this.$el.find('#extension-info').popover('destroy'); - }, - // template _template: function(options) { - // link this - var self = this; - - // construct template - var tmpl = '' + - '' + - '
' + - '
' + - '
' + - '
' + - '
You can tell Galaxy to download data from web by entering URL in this box (one per line). You can also directly paste the contents of a file.
' + - '' + - '
' + + return '' + + '' + + '
' + + '
' + + '
' + + '
' + + '
You can tell Galaxy to download data from web by entering URL in this box (one per line). You can also directly paste the contents of a file.
' + + '' + '
' + - '' + - '' + - '
' + - ''; - - // add file type selectore - tmpl += '' + - '' + - '  ' + - ''; - - // add genome selector - tmpl += '' + - '' + - ''; - - // add next row - tmpl += '
' + - '' + - '
' + - '
' + - '
' + - '
0%
' + - '
' + + '
' + + '' + + '' + + '
' + + '' + + '' + + '
  ' + + '