📄 picklist.js
字号:
/*
* Isomorphic SmartClient
* Version 6.5 (2008-04-30)
* Copyright(c) 1998-2007 Isomorphic Software, Inc. All rights reserved.
* "SmartClient" is a trademark of Isomorphic Software, Inc.
*
* licensing@smartclient.com
*
* http://smartclient.com/license
*/
// Class will not work without the ListGridif (isc.ListGrid) {//> @interface PickList// Interface to show a drop-down list of pickable options. Used by the +link{SelectItem} and// +link{ComboBoxItem} classes.// @treeLocation Client Reference/Forms/Form Items// @visibility external//<isc.ClassFactory.defineInterface("PickList");//> @class PickListMenu// Subclass of ScrollingMenu to be used by the pickList class// @treeLocation Client Reference/Forms/Form Items// @visibility internal//<isc.ClassFactory.defineClass("PickListMenu", "ScrollingMenu");isc.PickListMenu.addClassProperties({ // object to hold cached pickListMenu instances for databound pickList items _cachedDSPickLists:{}, // Don't cache more than 50 DS pickListMenus pickListCacheLimit:50});isc.PickListMenu.addProperties({ // Don't get fields from the DS. useAllDataSourceFields:false, // disallow tabbing to the pickList tabIndex:-1, // Don't allow fields to be resized, if multiple are showing canResizeFields:false });isc.PickListMenu.addMethods({ // Pick up valueIcons from this form item, if specified getValueIcon : function (field, value, record) { var formItem = this.formItem; // If this is a databound pickList, we have 2 sets of valueIcons to consider - // those specified by the formItem and those specified on the field definition itself. // - If the form item specifies any valueIcons, we typically want to show them on the // column that matches the display-value for the formItem. // - This will be the result of formItem.getDisplayField() or formItem.getValueField() // - If the developer specified explicit pickListFields for this item, this field may // not be showing. In this case we allow the developer to explicitly specify a // field to show the form item valueIcons via the property "formItem.valueIconField". // If this property is set, always respect it. // - For all other fields, and if the form item has no custom valueIcons, just fall // through to the standard ListGrid implementation, so we can pick up valueIcons // specified on the datasource fields. var hasCustomValueIcons = formItem && !formItem.suppressValueIcons && (formItem.valueIcons != null || formItem.getValueIcon !=null); if (hasCustomValueIcons) { var valueField = formItem.getValueFieldName(), valueIconField = formItem.valueIconField || formItem.getDisplayFieldName() || valueField; if (this.getFieldName(field) == valueIconField) { // The form item expects the value passed to getValueIcon to be the 'valueField' // value, not the value from whatever field is being displayed in the pickList return formItem._getValueIcon(record[valueField]); } } return this.Super("getValueIcon", arguments); }, // 'pick' the selected value on click. Matches Windows ComboBox behavior itemClick : function (record) { var formItem = this.formItem, fieldName = formItem.getValueFieldName(), value = record[fieldName]; formItem.pickValue(value); }, hide : function (a,b,c,d) { this.invokeSuper(isc.PickListMenu, "hide", a,b,c,d); // If we're being hidden as part of a formItem.destroy(), this.formItem will have been // cleared out. if (!this.formItem) return; // put focus back in the item if this was a modal pickList if (this.showModal) this.formItem.focusInItem(); // Clear out the showingPickList flag this.formItem._showingPickList = null; // fire a notification for observing / overriding the pick list being hidden this.formItem._pickListHidden(); delete this.formItem._showOnFilter; }, show : function () { // If the pickListis already showing we could arguably bail here, but this isn't // how Canvas.show() behaves (still calls 'setVisibility()')... // Instead we'll just avoid firing the _pickListShown notification function var alreadyShowing = this.isVisible() && this.isDrawn(); this.bringToFront(); this.Super("show", arguments); // fire a notification for observing / overriding the pick list being shown if (!alreadyShowing) this.formItem._pickListShown(); }, // Override showClickMask() - if this is a modal PickList, ensure that when the pickList is // hidden focus goes to the form item that spawned the pickList. showClickMask : function () { if (!this.clickMaskUp(this.getID())) { // Actually cmID will match this.getID() since that's the default ID for a CM // associated with a widget. var cmID = this.Super("showClickMask", arguments); if (this.formItem) { var form = this.formItem.form, mask = isc.EH.clickMaskRegistry.find("ID", cmID); // Suppress the default behavior of putting focus into whatever had focus before // this CM was shown. We'll explicitly put focus into the appropraite item when // hiding the pickList if (mask._maskedFocusCanvas) mask._maskedFocusCanvas = null; } } }, _$_backgroundColor:"background-color:", _$_color:"color:", getCellCSSText : function (record, rowNum, colNum) { // if it's selected apply the hilite color, if specified // Otherwise we rely on regular css class type styling. if (record == this.selection.getSelectedRecord()) { var cssText = []; if (this.hiliteColor != null) cssText[0] = this._$_backgroundColor cssText[1] = this.hiliteColor cssText[2] = isc._semi; if (this.hiliteTextColor != null) cssText[3] = this._$_color; cssText[4] = this.hiliteTextColor; cssText[5] = isc.semi; return cssText.join(isc.emptyString); } }, // override keyDown to catch tabs and hide the pickList. keyDown : function () { var keyName = isc.EH.lastEvent.keyName; if (keyName == "Tab") { this.hide(); return false; } }, // Override formatCellValue to allow custom display at the form item level formatCellValue : function (value, record, rowNum, colNum) { var fieldName = this.getFieldName(colNum); if (this.formItem.formatPickListValue) return this.formItem.formatPickListValue(value, fieldName, record); return value; }, // override keyPress to allow for navigation to different items by typing // the first letter of the option. bodyKeyPress : function (event, eventInfo) { var keyName = isc.EH.lastEvent.keyName; // Catch shift+tab in safari in keyPress rather than keydown if (isc.Browser.isSafari) { if (keyName == "Tab") { this.hide(); return false; } } var charVal = isc.EH.getKeyEventCharacterValue(); if (charVal != null) { var data = this.formItem.getAllLocalOptions(); if (isc.isAn.Array(data) && data.length > 1) { var typedChar = String.fromCharCode(charVal), // Normalize to a lowercase string for comparison. typedChar = typedChar.toLowerCase(), formItem = this.formItem, valueField = formItem.getValueFieldName(), currentIndex = data.indexOf(this.getSelectedRecord()), newIndex = currentIndex < (data.length -1) ? currentIndex + 1 : 0; if (currentIndex < 0) currentIndex = 0; while (newIndex != currentIndex) { var value = data[newIndex][valueField]; value = formItem.mapValueToDisplay(value); if (isc.isA.String(value) && value.length > 0 && value.charAt(0).toLowerCase() == typedChar) { this.scrollRecordIntoView(newIndex); this._hiliteRecord(newIndex); return; } newIndex += 1; if (newIndex >= data.length) newIndex = 0; } } } // If the "Enter" key was pressed, but no record was selected, dismiss the menu // (this is really useful for the ComboBox item when showAllRecords is true and // the user has entered a value that isn't in the c-box). if (this.getFocusRow() == null && keyName == "Enter") { this.cancel(); return false; } // The superclass implementation will handle cancelling on escape click / selecting // on enter click return this.Super("bodyKeyPress", arguments); }, // Override dataChanged -- avoid redrawing to show temp. loading rows - wait // for the rows to come back from the server instead. dataChanged : function () { var data = this.data; if (!data) return; var data = this.requestVisibleRows(); if (data && Array.isLoading(data[0])) { //this.logWarn("not redrawing since data still loading"); return; } return this.Super("dataChanged", arguments); } });isc.PickList.addInterfaceProperties({ //> @attr PickList.pickListHeight (number : 300 : IRW) // Maximum height to show the pick list before it starts to scroll. // Note that by default the pickList will be sized to the height required by its content // so it will be taller when more rows are available as selectable options // @visibility external //< pickListHeight:300, //> @attr PickList.pickListWidth (number : null : IRW) // Default width to show the pickList. // If not specified, the width of this form item's element will be used instead. // @visibility external // @example listComboBox //< //pickListWidth : null, // Styling. // Users must be able to style pickLists //> @attr PickList.pickListBaseStyle (string : "pickListCell" : IR) // Base Style for pickList cells. As with ListGrid Cells, will have 'over', 'selected' // and 'disabled' appended on changes of state for the cells. // @visibility external //< pickListBaseStyle : "pickListCell", //> @attr PickList.pickListHiliteColor (string : null : IR) // If specified this color will be applied to hilighted rows in the pickList, when the // user rolls over them. This color will be applied on top of the "over" CSS Style // specified by <code>pickListBaseStyle</code> //< //pickListHiliteColor:null, //> @attr PickList.pickListHiliteTextColor (string : null : IR)
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -