From 22a66cb6e243a3f1c867b62e3942fd2e828019d9 Mon Sep 17 00:00:00 2001 From: Valerio Virgillito Date: Thu, 8 Mar 2012 13:56:09 -0800 Subject: integrating v0.7 montage into ninja Signed-off-by: Valerio Virgillito --- .../montage/ui/select-input.reel/select-input.js | 115 +++++++++++++++++++-- 1 file changed, 104 insertions(+), 11 deletions(-) (limited to 'node_modules/montage/ui/select-input.reel/select-input.js') diff --git a/node_modules/montage/ui/select-input.reel/select-input.js b/node_modules/montage/ui/select-input.reel/select-input.js index 09a064d4..98902cfb 100644 --- a/node_modules/montage/ui/select-input.reel/select-input.js +++ b/node_modules/montage/ui/select-input.reel/select-input.js @@ -10,19 +10,18 @@ var Montage = require("montage").Montage, NativeControl = require("ui/native-control").NativeControl, PressComposer = require("ui/composer/press-composer").PressComposer; + var SelectInput = exports.SelectInput = Montage.create(NativeControl, { _fromInput: {value: null}, + _synching: {value: null}, + //_internalSet: {value: null}, __selectedIndexes: {value: null, enumerable: false}, _selectedIndexes: { set: function(value) { this.__selectedIndexes = value; - if(!this._fromInput) { - this.needsDraw = true; - } else { - this._fromInput = false; - } + this.needsDraw = this._synching || !this._fromInput; }, get: function() { return this.__selectedIndexes; @@ -101,6 +100,85 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { } }, + _getSelectedValuesFromIndexes: { + value: function() { + var selectedObjects = this.contentController ? this.contentController.selectedObjects : null; + var arr = []; + if(selectedObjects && selectedObjects.length > 0) { + var i=0, len = selectedObjects.length, valuePath; + for(; i 0) ? this.values[0] : null); + this._synching = false; + } + } + }, + + + _values: {value: null}, + values: { + get: function() { + return this._values; + }, + set: function(valuesArray) { + var content = this.contentController ? this.contentController.content : null; + if(valuesArray && content) { + this._values = valuesArray; + + if(!this._synching) { + var selectedIndexes = []; + var i=0, len = this._values.length, index; + for(; i= 0) { + selectedIndexes.push(index); + } + } + this._synching = true; + this.contentController.selectedIndexes = selectedIndexes; + this._synching = false; + } + } + } + //dependencies: ["_selectedIndexes"] + }, + + _value: {value: null}, + value: { + get: function() { + return this._value; + }, + set: function(value) { + this._value = value; + + if(!this._synching) { + if(value == null) { + this.values = []; + } else { + this.values = [value]; + } + } + + + } + //dependencies: ["_selectedIndexes"] + }, + // ------------------- // Montage Callbacks // -------------------- @@ -134,11 +212,13 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { } this.contentController = contentController; - - if(selectedIndexes.length > 0) { - this._fromInput = true; - this.contentController.selectedIndexes = selectedIndexes; + if(selectedIndexes.length === 0 && len > 0) { + // nothing was marked as selected by default. Select the first one (gh-122) + selectedIndexes = [0]; } + this._fromInput = true; + this.contentController.selectedIndexes = selectedIndexes; + } } @@ -222,9 +302,11 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { draw: { enumerable: false, value: function() { - var elem = this.element; + this._fromInput = false; + this._synching = false; + this._removeAll(elem); this._refreshOptions(); @@ -234,6 +316,14 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { } }, + didDraw: { + value: function() { + this._synchValues(); + } + }, + + + // find the index of the object with the specified value in the _content array _indexOf: { value: function(val) { @@ -293,8 +383,11 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { if(arr.length > 0) { this._fromInput = true; + this._synching = false; this.contentController.selectedIndexes = arr; + this._synchValues(); } + } } @@ -304,7 +397,7 @@ var SelectInput = exports.SelectInput = Montage.create(NativeControl, { //http://www.w3.org/TR/html5/the-button-element.html#the-select-element SelectInput.addAttributes({ - autofocus: null, + autofocus: {dataType: 'boolean'}, disabled: {dataType: 'boolean'}, form: null, multiple: {dataType: 'boolean'}, -- cgit v1.2.3