/** This class creates a tool form input element wrapper */ define([], function() { // input field element wrapper return Backbone.View.extend({ // initialize input wrapper initialize: function(options) { // link field this.field = options.field; // set element this.setElement(this._template(options)); // link elements this.$field = this.$el.find('.ui-table-form-field'); this.$title_optional = this.$el.find('.ui-table-form-title-optional'); this.$error_text = this.$el.find('.ui-table-form-error-text'); this.$error = this.$el.find('.ui-table-form-error'); // add field element this.$field.prepend(this.field.$el); // hide optional field on initialization if (options.optional) { this.field.skip = true; } else { this.field.skip = false; } // refresh view this._refresh(); // add optional hide/show var self = this; this.$title_optional.on('click', function() { // flip flag self.field.skip = !self.field.skip; // refresh view self._refresh(); }); }, /** Set error text */ error: function(text) { this.$error_text.html(text); this.$error.fadeIn(); this.$el.addClass('ui-error'); }, /** Reset this view */ reset: function() { this.$error.hide(); this.$el.removeClass('ui-error'); }, /** Refresh element */ _refresh: function() { // show/hide field element if (!this.field.skip) { this.$field.fadeIn('fast'); this.$title_optional.html('Disable'); } else { this.$field.hide(); this.$title_optional.html('Enable'); } }, /** Main Template */ _template: function(options) { // create table element var tmp = '
' + '
' + '' + '
' + '
'; // is optional if (options.optional) { tmp += 'Optional: ' + options.label + ' []'; } else { tmp += options.label; } // finalize title tmp += '
' + '
'; // add help if (options.help) { tmp += '
' + options.help + '
'; } // finalize tmp += '
' + '
'; // return input element return tmp; } }); });