⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 selectitem.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 4 页
字号:
                    );                    return;                }            }            i += 1;            if (i >= valsArray.length) i = 0;        }    },    // moveToNextValue() - sets the value of this item to the previous / next valid option in    // the valueMap    moveToNextValue : function (step) {        var valsArray = this.getAllLocalOptions();        if (!valsArray || valsArray.length < 2) return;        var value;        if (this.isSelectOther && this._selectOtherValue != null) value = this._selectOtherValue;        else value = (this._itemValueIsDirty() ? this._localValue : this.getValue());                var valueField = this.getValueFieldName(),            currentIndex = valsArray.findIndex(valueField, value);                currentIndex += step;        // Native selects don't allow wrapping of arrow key navigation (so we won't either)        if (currentIndex >= valsArray.length || currentIndex < 0) return;        // use changeToValue() to update the value and fire the change handler                        var val = valsArray[currentIndex][valueField];        this.changeToValue(            val,             (this.changeOnValueChange && this.changeOnKeyboardNavigation)        );    },        // moveToFirstValue() / moveToLastValue() - sets the value of this item to the first/last    // values in the valueMap for this item.    moveToFirstValue : function () {        if (this.optionDataSource) return;        var valsArray = this.getClientPickListData(),            valueField = this.getValueFieldName(),            val = valsArray[0][valueField];        this.changeToValue(            val,             (this.changeOnValueChange && this.changeOnKeyboardNavigation)        );    },    moveToLastValue : function () {        if (this.optionDataSource) return;        var valsArray = this.getClientPickListData(),            valueField = this.getValueFieldName(),            val = valsArray[valsArray.length -1][valueField]        this.changeToValue(            val,             (this.changeOnValueChange && this.changeOnKeyboardNavigation)        );    },    // ---------------------------------------------------------------------------------------    // FOCUS AND STYLING    // ---------------------------------------------------------------------------------------        _canFocus : function () {        return true;    },            _getIconMouseDownFunction: function () {        if (!this._iconMouseDownFunction) {            this._iconMouseDownFunction =                 new Function ("if(window." + this.getID() + ")window." + this.getID() +                                "._showingPickList=true;");        }        return this._iconMouseDownFunction;    },        _applyHandlersToElement : function (a,b,c,d) {        // Apply the normal handlers        this.invokeSuper(isc.SelectItem, "_applyHandlersToElement", a,b,c,d);        if (isc.Browser.isIE) {            var iconElement = this._getIconImgElement(this.getPickerIcon());            if (iconElement) {                iconElement.onmousedown = this._getIconMouseDownFunction();            }        }            },            // ----------------------------------------------------------------------------------------    // Values Management    // ----------------------------------------------------------------------------------------            makePickList : function (show) {        if (!this.filterLocally && this.allowEmptyValue && this._getOptionsFromDataSource()) {            if (this.pickListProperties == null)                 this.pickListProperties = {};            if (this.pickListProperties.dataProperties == null)                 this.pickListProperties.dataProperties = {};            // Using basic rather than local means if we do have outstanding filter criteria            // we'll fetch fewer rows from the server, while still being able to manipulate            // the cache to insert the empty row at the top.            this.pickListProperties.dataProperties.fetchMode = "basic";        }        var interfaceMakePickList = isc.PickList.getPrototype().makePickList;        return interfaceMakePickList.apply(this, arguments);    },        // changeToValue()    // Helper method to fire the change handler for this item, then update to the value     // specified.  Called when the user navigates to a new value.        changeToValue : function (newValue, saveValue) {        var value = (this._selectOtherValue || this._localValue || this.getValue());        if (value == newValue) return;                if (this.isSelectOther &&             (newValue == this.separatorValue || newValue == this.otherValue))         {            this.setElementValue(this.mapValueToDisplay(newValue));            // keep a pointer around to tell us which value the user selected.                        this._selectOtherValue = newValue;            return;        } else {            delete this._selectOtherValue;        }        // Update the displayed HTML and store the new value locally.        this.setLocalValue(newValue);        // if we're saving the value out, fire 'updateValue()'        if (saveValue) this.updateValue();    },        // setLocalValue:    // Update the displayed value without saving the value out / firing the change handler.    setLocalValue : function (value) {        if (this.isVisible() && this.containerWidget.isDrawn()) {                        if (value == null) value = null;            this.setElementValue(this.mapValueToDisplay(value), value);        }        this._localValue = value;        this._markValueAsDirty();    },        // Override setElementValue to hang onto a copy of the current display value        setElementValue : function (displayValue, dataValue, a,b,c) {        this._displayValue = displayValue;        return this.invokeSuper(isc.SelectItem, "setElementValue", displayValue, dataValue, a,b,c);    },    // Override updateValue - this method will save out the value previously applied locally.    updateValue : function () {        // Handle the case of a selectOther item where the user has selected the separator        // or the "Other..." options.        if (this.isSelectOther && this._selectOtherValue != null) {            var selectOtherValue = this.getSelectOtherValue(this._selectOtherValue);            delete this._selectOtherValue;            this.setLocalValue(selectOtherValue);        }        // if we're not dirty we don't need to update at all.        if (!this._itemValueIsDirty()) return;                var newValue = this._localValue;        this._updateValue(newValue);    },        // Disable mapDisplayToValue entirely.    // This method is called from _updateValue which is passed the displayValue in most form items    // however in SelectItems we always pass the data value directly into this method so it needs    // no further modification.    mapDisplayToValue : function (value) {        return value;    },            //>@attr    SelectOtherItem.selectOtherPrompt   (string : "Other value for <br>${item.getTitle()}?" : IR)    // Title to show in prompt for "other" value.    // Note this is a dynamic string. JavaScript content is supported within <code>\${...}</code>    // tags, with local variables for <code>item</code> (a pointer to this item), <code>value</code>    // a pointer to the currently selected item value    // @group i18nMessages    // @visibility external    //<    selectOtherPrompt:"Other value for <br>${item.getTitle()}?",        // getSelectOtherValue - only used by isSelectOther items -- if the user selected    // "Other" or the separator, return the desired value for the cell (uses the prompt if    // necessary)    getSelectOtherValue : function (value) {        if (value == this.separatorValue) return (this._localValue || this.getValue());        if (value == this.otherValue) {            // Note the prompt contents should probably be customizeable            var oldValue = this._localValue || this.getValue(),                oldTitle = (oldValue == null ? "" : this.mapValueToDisplay(oldValue)),                promptTitle = this.selectOtherPrompt.evalDynamicString(null,                                                     {item:this, value:oldValue});                                                                 isc.askForValue(promptTitle, this.getID() + ".getSelectOtherValueCallback(value)");            return true;        }    },        getSelectOtherValueCallback : function (value) {        if (value != null) {            value = this.mapDisplayToValue(value);            this.changeToValue(value, this.changeOnValueChange);        }    },    // Override setValue     // - must handle 'addUnknownValues' logic    // - must redraw the selected value text.    setValue : function (value,b,c,d) {        // Make sure this value is a valid option from our valueMap if necessary.                value = this._getValidValue(value);                        var undef,            localValue = this._localValue;        if (localValue === undef) localValue = this._value;                // Let the superclass implementation save the value out and mark as not dirty.         // Note: at this point the value passed in may be null - if so we're relying on         // the superclass implementation to get the defaultValue and set up the 'isDefaultValue'        // flag on this item.        // NOTE: we are passing a modified value.          this.invokeSuper(isc.SelectItem, "setValue", value,b,c,d);        value = this.getValue();                // Calling setLocalValue actually sets the displayed element value (may have been        // changed by the call to Super("setValue"...)        if (value != localValue) this.setLocalValue(value);                // if the pickList is showing, ensure it's showing the right set of data and has        // the correct element selected.        if (this.pickList && this.pickList.isDrawn() && this.pickListVisible()) {            this.setUpPickList(true);        }        return value;    },                saveValue : function (value, a,b,c,d) {        var oldValue = this._value;        if (this._dropCacheOnValueChange(oldValue, value)) delete this._clientPickListData;        return this.invokeSuper(isc.SelectItem, "saveValue", value, a,b,c,d);    },    _dropCacheOnValueChange : function (oldValue, newValue) {        return (this.addUnknownValues && this._clientPickListData &&                ((oldValue != null && !this._valueInValueMap(oldValue)) ||                 (newValue != null && !this._valueInValueMap(newValue))    ) );    },        // Override 'markValueAsNotDirty' to clear out the temp local value.    // note this means that callers should have already ensured that the displayed value    // matches the appropriate value. This method is strictly internal, so this is an     // acceptable assertion to make    _markValueAsNotDirty : function (a,b,c,d) {        this.invokeSuper(isc.SelectItem, "_markValueAsNotDirty", a,b,c,d);        delete this._localValue;    },        // override getDefaultValue to pick up the first option if defaultToFirstOption is true    // getDefaultValue should not be able to return a value that is not included    // in the valueMap for this select.    getDefaultValue : function () {                var dV;        if (this.defaultToFirstOption) {            dV = this.getFirstOptionValue(true, {target:this, methodName:"defaultToFirstReply"});        }                if (!dV) dV = this.Super("getDefaultValue", arguments);        return this._getValidValue(dV);    },        defaultToFirstReply : function () {        if (this.getValue() == null) this.setToDefaultValue();    },        // selectItems have a limited set of valid values (represented by the valueMap).    // this method will take a value, and ensure it is a member of the value map for the item.    // The value will be returned if valid - otherwise this method returns null.    _getValidValue : function (value) {                // Disallow values that aren't in the valueMap.        // If passed a value not in the valueMap:        // - if our current (or 'previous') value is valid, return it        // - if not, clear the value        if (!this._valueIsValid(value)) {                        var alreadyChecking = this._checkingValidValue;            this._checkingValidValue = true;            var validValue;            if (alreadyChecking) validValue = value;            else validValue = this._localValue || this.getValue();            // If the value passed in is the 'current value', or our previous value isn't            // valid, clear the value.            // [a null value is always considered valid by this mechanism].            if (value == validValue || !this._valueIsValid(validValue)) {                validValue = null;            }             value = validValue;        }               return value;    },

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -