Sha256: 47257e6a0f273f241e0a860baad78dacad3ef5fce0accf18553bf4f21d5a2f26
Contents?: true
Size: 1.55 KB
Versions: 4
Compression:
Stored size: 1.55 KB
Contents
pageflow.SelectInputView = Backbone.Marionette.ItemView.extend({ mixins: [pageflow.inputView], template: 'templates/inputs/select_input', events: { 'change': 'save' }, ui: { select: 'select' }, initialize: function() { if (this.options.collection) { this.options.values = _.pluck(this.options.collection, this.options.valueProperty); if (this.options.textProperty) { this.options.texts = _.pluck(this.options.collection, this.options.textProperty); } else if (this.options.translationKeyProperty) { this.options.translationKeys = _.pluck(this.options.collection, this.options.translationKeyProperty); } } if (!this.options.texts) { if (!this.options.translationKeys) { this.options.translationKeys = _.map(this.options.values, function(value) { return 'activerecord.values.' + this.model.i18nKey + '.' + this.options.propertyName + '.' + value; }, this); } this.options.texts = _.map(this.options.translationKeys, function(key) { return I18n.t(key); }); } }, onRender: function() { _.each(this.options.values, function(value, index) { var option = document.createElement('option'); option.value = value; option.text = this.options.texts[index]; this.ui.select.append(option); }, this); this.load(); }, save: function() { this.model.set(this.options.propertyName, this.ui.select.val()); }, load: function() { this.ui.select.val(this.model.get(this.options.propertyName)); } });
Version data entries
4 entries across 4 versions & 1 rubygems