📄 selectitem.js
字号:
_valueIsValid : function (value) { if (this.addUnknownValues || this.optionDataSource) return true; // Allow null values regardless of what the valueMap looks like if (value == null) return true; // Disallow values that aren't in the valueMap. return this._valueInValueMap(value) }, _valueInValueMap : function (value) { var valueMap = this.getValueMap(), undef; if (isc.isAn.Array(valueMap)) { return valueMap.contains(value) } else if (isc.isAn.Object(valueMap)) { return (valueMap[value] !== undef); } return false; }, // Display vs internal value mapping // mapValueToDisplay() allows us to convert internal value to display value. mapValueToDisplay : function (internalValue, a, b, c) { if (this.isSelectOther) { if (internalValue == this.otherValue) return this.otherTitle; if (internalValue == this.separatorValue) return this.separatorTitle; } return this.invokeSuper(isc.SelectItem, "mapValueToDisplay", internalValue,a, b, c); }, // Map valueToDisplay needs to pick up // the mapping between displayField and valueField, if there is one. // We implement this by overriding _mapKey() to check for the value in // our pickList's dataSet, in addition to checking against any explicitly specified valueMap _mapKey : function (value, dontReturnKey, a,b,c,d) { var displayValue = this.invokeSuper(isc.SelectItem, "_mapKey", value, true ,a,b,c,d); // _translateFieldValue part of the pickList interface if (displayValue == null && this.getDisplayFieldName() != null) displayValue = this._translateValueFieldValue(value, false); if (displayValue == null && !dontReturnKey) displayValue = value; return displayValue; }, // Override checkForDisplayFieldValue() // This is the method that, if we have a displayField specified, kicks off a fetch against // our optionDataSource to load the appropriate display value from the server. // In PickList based items we use the pickList data (if present) to map data to display // values. // Catch the case where checkForDisplayFieldValue is called when we are in the process of // fetching our pickList data from the server. // In this case we want to wait for the pickList data to be returned rather than kicking off // an additional fetch as our data value will usually be present in that pickList data. // When the pickList data returns we re-check this method. If the data is present, we're // done, otherwise we need to kick off another fetch as we didn't find our data value in // the pickList data array. This can happen if the pickList data is paged, for instance. _checkForDisplayFieldValue : function (newValue, delayed) { var inValueMap = (this._mapKey(newValue, true) != null); if (inValueMap) return; if (this._fetchingPickListData) { this._checkDisplayFieldValueOnFilterComplete = true; return; } this.invokeSuper(isc.ComboBoxItem, "_checkForDisplayFieldValue", newValue); }, // INTERACTIONS WITH PICK-LIST ------------------------------------------------------------ // comes from the interface // Include useful JSDoc from pickList //> @attr SelectItem.optionDataSource (DataSource | String : null : IRA) // @include PickList.optionDataSource //< //> @attr SelectItem.pickListFields (Array : null : IRA) // @include PickList.pickListFields // @example relatedRecords //< //> @method SelectItem.fetchData() // @include PickList.fetchData() //< //> @attr SelectItem.optionFilterContext (RPCRequest Properties : null : IRA) // @include PickList.optionFilterContext //< //> @attr SelectItem.displayField (string : null : IRW) // @include PickList.displayField // @visibility external // @example relatedRecords //< //> @attr SelectItem.valueField (string : null : IRW) // @include PickList.valueField // @visibility external // @example relatedRecords //< //> @method SelectItem.getDisplayFieldName() ([A]) // @include PickList.getDisplayFieldName // @visibility external //< //> @method SelectItem.getValueFieldName() ([A]) // @include PickList.getValueFieldName // @visibility external //< //> @attr SelectItem.filterLocally // @include PickList.filterLocally // @visibility external //< //> @method SelectItem.dataArrived() // @include PickList.dataArrived() // @visibility external //< //> @method SelectItem.getSelectedRecord() // @include PickList.getSelectedRecord() // @visibility external //< //> @attr SelectItem.pickListCriteria (Criteria : null : IRWA) // @include PickList.pickListCriteria // @visibility external //< //> @attr SelectItem.showOptionsFromDataSource (boolean : null : IRWA) // @include PickList.showOptionsFromDataSource // @visibility external //< //> @attr SelectItem.pickListProperties (object : null : IRA) // @include PickList.pickListProperties // @visibility external //< // Override the method to get pickList data to add unknown values and selectOther // properties getClientPickListData : function () { if (this._clientPickListData) return this._clientPickListData; var records = isc.PickList.optionsFromValueMap(this), valueField = this.getValueFieldName(); // If allowEmptyValue is true, add an empty entry to the top of the list // Note that this is independant of addUnknownValues - we don't treat the null value // as an 'unknown' values - it's more like lack of a value. if (this.allowEmptyValue && (records.find(valueField, null) == null)) { var emptyRecord = {}; // No need for an explicit 'null' value on the value field really // emptyRecord[valueField] = null; records.addAt(emptyRecord, 0); } // The current selected value must always be present in the records for the VM. var value = this.getValue(); if (value != null && records.find(valueField, value) == null) { var newRecord = {}; newRecord[valueField] = value; records.addAt(newRecord, 0); } if (this.isSelectOther) { var separator = {}, other = {}; separator[valueField] = this.separatorValue; other[valueField] = this.otherValue; records.addListAt([separator, other], records.length); } this._clientPickListData = records; return records; }, // Use the 'formatPickListValue()' method to display the appropriate title for the // special selectOther options. formatPickListValue : function (value, fieldName, record) { if (this.isSelectOther && (fieldName == this.getValueFieldName())) { if (value == this.otherValue) return this.otherTitle; if (value == this.separatorValue) return this.separatorTitle; } return value; }, // pickValue : select the picked value. pickValue : function (value) { // selectOther behavior: // If the user selects the separator, treat this as a null selection. // If they select the "other" value, pop a prompt to get the value to use. if (this.isSelectOther) { if(this.getSelectOtherValue(value)) return; } // use changeToValue() to update the value and fire the change handler this.changeToValue(value, this.changeOnValueChange); }, //>@method SelectItem.getPickListPosition() (A) // Returns the global top and left coordinates for the pickList. // Default implementation always draws the pick-list below the Select Item - override for // any special implementation. // @return (array) 2 element array indicating left and top coordinate for the pick list. //< getPickListPosition : function () { var itemTop = this.getPageTop(), top = itemTop + this.getHeight(), left = this.getPageLeft(), height = this.getPickListHeight(), pageTop = isc.Page.getScrollTop(), pageBottom = isc.Page.getHeight() + pageTop; // If the pickList would extend beyond the end of the page, show it above the select // item if (top + height > pageBottom) { top = Math.max(pageTop, (itemTop - height)); } return [left,top]; }, // override setValue map to update the list and update the displayed value if necessary. setValueMap : function () { this.Super("setValueMap", arguments); if (this._clientPickListData) delete this._clientPickListData; if (this.hasPickList()) { if (this.pickList.isVisible()) this.pickList.hide(); // clear the 'formItem' property on the pickList - ensures it will have its data // reset when it is next shown. delete this.pickList.formItem; } // if the current value is no longer valid, update it. var currentValue = this.getValue(), value = this._getValidValue(currentValue); if (currentValue != value) { this.setValue(value); // even if the value is unchanged, it's display value is likely to be different, so // do a setElementValue. } else { this.setElementValue(this.mapValueToDisplay(value)); } }, // Returns true if this item has its picklist already set up hasPickList : function () { // note the check for this.pickList.formItem pointing back to this select is required // for the case where the pickList is reused. return (this.pickList && !this.pickList.destroyed && this.pickList.formItem == this); }, // Returns true if this item's pickList is showing. pickListVisible : function () { return (this.hasPickList() && this.pickList.isDrawn() && this.pickList.isVisible()); }, // If we get yanked out of the DOM, ensure our pickList gets hidden cleared : function () { if (this.pickListVisible()) this.pickList.hide(); return this.Super("cleared", arguments); }, // Override filterComplete to // - Add an empty entry to the top of the list if this.allowEmptyValue is true filterComplete : function () { // If we are allowing empty values we always to 'basic' filtering, which means // we can directly add the empty entry to the ResultSet's cache if (this.allowEmptyValue && this._getOptionsFromDataSource()) { var RS = this.pickList.data, localCache = RS.isLocal() ? RS.allRows : RS.localData; if (localCache && !localCache.find(this.getValueFieldName(), null)) { RS.insertCacheData({},0); } } var interfaceFilterComplete = isc.PickList.getPrototype().filterComplete; interfaceFilterComplete.apply(this, arguments); }});// Mix in the PickList interface - handles creating and showing the PickList itself.isc.ClassFactory.mixInInterface("SelectItem", "PickList");isc.SelectItem.registerStringMethods({ dataArrived:"startRow,endRow,data"});}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -