📄 selectitem.js
字号:
//< // ------------ // Allow customization of the hilite color-scheme applied to the pickList. // If specified, overrides styling applied via the selected state of pickListBaseStyle. //>@attr SelectItem.pickListHiliteColor (string : null : IRWA) // If specified this property determines the backgroundColor to show highlighted items in the // pickList. By default we don't specify this property, and pick up the styling based on // the <code>selected</code> state of the <code>pickListBaseStyle</code>. //< //pickListHiliteColor:"#316AC5", //>@attr SelectItem.pickListHiliteTextColor (string : null : IRWA) // If specified this property determines the text color to show highlighted items in the // pickList. By default we don't specify this property, and pick up the styling based on // the <code>selected</code> state of the <code>pickListBaseStyle</code>. //< //pickListHiliteTextColor:"white", //> @attr SelectItem.showOver (boolean : true : IRWA) // When the user rolls over the select item, should the pickButton display it's // <code>Over</code> state? // @visibility external //< showOver:true, // Non-exposed property governing whether the pickList should be shown with a clickMask, // and take focus when shown. modalPickList:true, //>@attr SelectItem.changeOnValueChange (boolean : true : IRW) // If true the change handler for this item will fire when the item has focus and // modifies the selection for the item. // If false, the change handler will only fire when the user leaves a modified selectItem //< changeOnValueChange:true, //>@attr SelectItem.changeOnKeyboardNavigation (boolean : true : IRW) // If this.changeOnValueChange is true, and the user is navigating through values via // keypresses such as up and down arrows, while the pick-list is not visible, should we // fire change? // Has no effect if this.changeOnValueChange is false. // @visibility internal //< changeOnKeyboardNavigation:true, // Don't allow native text selection of the content of the SelectItem canSelectText : false, //> @attr selectItem.allowEmptyValue (boolean : false : IRW) // If set to true, always show an empty option in this item's pickList, allowing the user // to clear the value (even if there is no empty entry in the valueMap for the item). // <P> // The empty value will be displayed with the // +link{formItem.emptyDisplayValue,emptyDisplayValue}. // <P> // With a +link{optionDataSource,databound selectItem}, enabling // <code>allowEmptyValue</code> disables data paging - all data matching the // +link{pickList.pickListCriteria,current criteria} will be requested. // // @visibility external //< allowEmptyValue : false, //> @attr selectItem.autoFetchData (boolean : true : [IRA]) // If this select item retrieves its options from a <code>dataSource</code>, should options // be fetched from the server when the item is first written out, or should this fetch be // delayed until the user opens the pickList. // @visibility external // @see PickList.optionDataSource //< autoFetchData:true});isc.SelectItem.addMethods({ // At init time, pick up any deprecated properties applied to this select item. init : function () { //>!BackCompat 2006.3.9 if (this.hiliteOnFocus != null) { this._warnDeprecated("hiliteOnFocus", "showFocused"); this.showFocused = this.hiliteOnFocus; } if (this.pickButtonWidth != null) { this._warnDeprecated("pickButtonWidth", "pickerIconWidth"); this.pickerIconWidth = this.pickButtonWidth; } if (this.pickButtonHeight != null) { this._warnDeprecated("pickButtonHeight", "pickerIconHeight"); this.pickerIconHeight = this.pickButtonHeight; } if (this.pickButtonSrc != null) { this._warnDeprecated("pickButtonSrc", "pickerIconSrc"); this.pickerIconSrc = this.pickButtonSrc; } //<!BackCompat return this.Super("init", arguments); }, // Override drawn() - if this is a databound pickList we want to perform a filter before // the pickList itself ever gets shown. drawn : function (a,b,c,d) { this.invokeSuper(isc.SelectItem, "drawn", a,b,c,d); if (this.autoFetchData && this._getOptionsFromDataSource()) { this.fetchData(null, null, true); } }, _getIconVMargin : function () { return 0; }, // Override iconFocus() - if focus goes to the picker icon, shift it to the textbox instead _iconFocus : function (id, element) { var icon = this._getIcon(id); if (icon == this.getPickerIcon()) { element.blur(); this.focusInItem(); return; } return this.Super("_iconFocus", arguments); }, // --------------------------------------------------------------------------------------- // EVENTS // --------------------------------------------------------------------------------------- // Update the pick button appearance when the user rolls over the control table handleMouseMove : function () { if (this.showOver && !this.isDisabled()) { if (this._overControlTable()) this._setIconImgState(this.getPickerIcon(), true); else this._setIconImgState(this.getPickerIcon(), false); } return this.Super("handleMouseMove", arguments); }, handleMouseOut : function () { if (this.showOver && !this.isDisabled()) { this._setIconImgState(this.getPickerIcon(), false); } return this.Super("handleMouseOut", arguments); }, // on iconMouseOut - if the user rolled off the picker icon, but is still over the // control table - don't clear the picker icon hilight _iconMouseOut : function (id, a,b,c,d) { if (this._getIcon(id) == this.getPickerIcon() && this._overControlTable()) return; return this.invokeSuper("SelectItem", "_iconMouseOut", id, a,b,c,d); }, // Override click to show the pick list handleClick : function () { // Give this item explicit focus before we show the pickList this.focusInItem(); if (!this.isDisabled()) { this.showPickList(); } // call to Super fires any developer specified click handlers return this.Super("handleClick", arguments); }, // Override handleKeyPress to allow navigation via typing the first letters of valid // options handleKeyPress : function (event, eventInfo) { var returnVal = this.Super("handleKeyPress", arguments); if (returnVal == false) return false; var keyName = event.keyName; // On Enter keyPress resolve "other..." (or separator) selection to a meaningful value. if (keyName == "Enter" && this.isSelectOther) { if (this._selectOtherValue != null) this.updateValue(); // Navigate where appropriate } else if (keyName == "Arrow_Down") { if (isc.EH.altKeyDown()) this.showPickList(); else this.moveToNextValue(1); // Don't allow scrolling, etc returnVal = false; } else if (keyName == "Arrow_Up") { if (isc.EH.altKeyDown()) this.showPickList(); else this.moveToNextValue(-1); // Don't allow scrolling, etc returnVal = false; } else if (keyName == "Home") { this.moveToFirstValue(); // Don't allow scrolling, etc returnVal = false; } else if (keyName == "End") { this.moveToLastValue(); // Don't allow scrolling, etc returnVal = false; } else { // If the user hit the first char of one of our options, move to that option var charVal = event.characterValue; if (charVal != null) { this.moveToChar(charVal); } } return returnVal; }, // On Blur, if we were marked as dirty, fire the change handler _nativeElementBlur : function (element, itemID) { var returnVal = this.Super("_nativeElementBlur", arguments); if (this.changeOnBlur || this._itemValueIsDirty() || this._selectOtherValue) { if (isc.Browser.isMoz && this._selectOtherValue == this.otherValue) this.form.__suppressFocusHandler = true; this.updateValue(); } return returnVal; }, // Override handleEditorExit() - when fired from a blur, if the pickList is visible we // don't want to fire the editorExit method, since focus is going to the pickList handleEditorExit : function () { if (this._showingPickList) return; return this.Super("handleEditorExit", arguments); }, // When the pick list is shown, fire editorEnter - essentially interacting with the picklist // is the same as interacting with this item. _pickListShown : function () { // Note: this will no-op if we've already fired editorEnter() this.handleEditorEnter(); if (this.pickListShown) this.pickListShown(); }, // Navigation methods: // helper to get the locally loaded set of options: // Returns set of options if the pickList is not databound // For databound picklists, returns the set of all rows, if every row is cached // Otherwise we know we don't have complete client side data so returns null. getAllLocalOptions : function () { var valsArray; if (this._getOptionsFromDataSource()) { // if we're databound, allow keyboard navigation iff we've got a full cache if (!this.pickList || this.pickList.destroyed) return; var rs = this.pickList.data; if (!rs || !rs.lengthIsKnown() || !rs.allMatchingRowsCached()) return; // We're going to have to refilter (on the client) if the criteria have changed var criteria = this.getPickListFilterCriteria(); if (rs.compareCriteria(criteria, rs.criteria) != 0) { if (!rs.allRowsCached() || !rs.useClientFiltering) return; this.filterPickList(false, false); } valsArray = rs.getAllRows(); } else { valsArray = this.getClientPickListData(); } return valsArray; }, // moveToChar() - sets the value of this item to the next valid option that starts with // the specified character moveToChar : function (charVal) { var valsArray = this.getAllLocalOptions(); if (!valsArray || valsArray.length < 2) return; var character = String.fromCharCode(charVal); if (character == null) return; // Normalize to a lowercase string for comparison. character = character.toLowerCase(); var value = (this.isSelectOther && this._selectOtherValue != null) ? this._selectOtherValue : (this._itemValueIsDirty() ? this._localValue : this.getValue()), valueField = this.getValueFieldName(), currentIndex = valsArray.findIndex(valueField, value), i = (currentIndex == valsArray.length -1 ? 0 : currentIndex + 1); while (i != currentIndex) { // avoid an infinite loop if the current value is not in the valueMap if (currentIndex < 0) currentIndex = 0; var testValue = valsArray[i][this.getValueFieldName()], displayValue = this.mapValueToDisplay(testValue); if (isc.isA.String(displayValue)) { var compareChar = displayValue.charAt(0).toLowerCase(); if (compareChar == character) { var newValue = testValue; // use changeToValue() to update the value and fire the change handler this.changeToValue( newValue, (this.changeOnValueChange && this.changeOnKeyboardNavigation)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -