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

📄 picklist.js

📁 javascript 很酷的类库
💻 JS
📖 第 1 页 / 共 5 页
字号:
        }                // We have to build a new picklist if the global one doesn't exist, or if we're         // not sharing pickLists.        if (!this.pickList) {            // The pickList is a pickListMenu - subclass of ScrollingMenu with some             // overrides specific to form item pickLists.            // The pattern we will use is to set the pickList up here, then override the            // properties to allow us to reuse the list for other                     // Determine desired properties from the various init params.            var pickListProperties = this.pickListProperties;            this.pickList = isc.PickListMenu.create(                                // no need to set up showPickList - this is done with setFields                                {headerHeight:this.pickListHeaderHeight},                                 pickListProperties                            );            // apply local fetchMode if 'filterLocally' was explicitly specified.            var data = this.pickList.dataProperties || {};            if (this.filterLocally) data.fetchMode = "local";            // allow ourselves to be notified when data arrives within the pickList            if (this.dataArrived) {                data.dataArrived = new Function ("startRow", "endRow", "item",                                          // if component is destroyed before data returns, we                                          // would JS error, so in the callback check that the                                          // component is still around before firing                                          // dataArrived on it.                                          "window."+this.getID()+"&&"+                                          this.getID() + ".dataArrived(startRow,endRow,this)");            }                           this.pickList.dataProperties = data;               // If this is a shared pickList, store it in a publically accessible place            if (reusePickList) this.storeSharedPickList();        }        // fire 'setUpPickList' to set up the specific properties relevant to this form item        this.setUpPickList(show, false, request);        //>DEBUG        if (this.logIsInfoEnabled("timing"))            this.logInfo("Time to initially create pickList:" + (isc.timeStamp() - startTime), "timing");        //<DEBUG    },    // Can this item use a cached pickList menu instance?    reusePickList : function () {            // we can reuse the pickList if the pickListProperties are null        // For databound pickLists we create a cache of pickLists to reuse based on the        // datasource ID and pickList fields        // For client-only pickLists we have a single central reusable pickList.        // "item.uniquePickList" - unexposed, but non obfuscated way to explicitly suppress pickList        // caching for some item, if desired.        return this.pickListProperties == null && !this.uniquePickList;    },    // Retrieves the cached pickList menu for an item    getSharedPickList : function () {        if (this._getOptionsFromDataSource()) {                        // Store pickList menus for databound pickLists on a per DS basis.            // cache of lists looks like this            // isc._cachedDSPickLists = {            //  dataSourceID:[            //      {_pickList:..., +fields:...}            //  ]            // }                        var ds = this.getOptionDataSource().getID(),                cachedLists = isc.PickListMenu._cachedDSPickLists[ds];                            if (cachedLists) {                for (var i = 0; i < cachedLists.length;i++) {                    if (cachedLists[i]._fields == this.pickListFields) {                        // Note when we last used the pickList so we can                        // destroy on a leastRecentlyUsed basis                        cachedLists[i]._lastAccess = isc.timeStamp();                        return cachedLists[i]._pickList;                    }                }            }            return null;            } else {            return isc.PickList._pickListInstance;        }    },         storeSharedPickList : function () {        if (this._getOptionsFromDataSource()) {                        var ds = this.getOptionDataSource().getID(),                cachedLists = isc.PickListMenu._cachedDSPickLists;            if (!cachedLists[ds]) cachedLists[ds] = [];            var newMenu = {_pickList:this.pickList, _fields:this.pickListFields,                                 _lastAccess:isc.timeStamp()}            cachedLists[ds].add(newMenu);             if (isc.PickListMenu._DSPickListCacheSize == null) {                 isc.PickListMenu._DSPickListCacheSize = 1;             } else {                 isc.PickListMenu._DSPickListCacheSize += 1;                 if (isc.PickListMenu._DSPickListCacheSize > isc.PickListMenu.pickListCacheLimit) {                     // If we've exceeded our pickListCacheLimit, destroy a pickList to make room                     // for the new one.                     // We store last access timestamps on each pickList we create so we                     // can destroy them in a least-recently-used order.                                           var oldMenu, ts = isc.timeStamp();                     for (var ds in cachedLists) {                         var dsLists = cachedLists[ds];                         for (var i = 0; i < dsLists.length; i++) {                             var entry = dsLists[i];                             if (entry._lastAccess <= ts && (entry != newMenu)) {                                 oldMenu = entry;                                 ts = entry._lastAccess;                             }                         }                     }                     if (oldMenu) {                         isc.PickListMenu._DSPickListCacheSize -= 1;                         var pickList = oldMenu._pickList;                                                  var dsLists = cachedLists[pickList.getDataSource().getID()];                         dsLists.remove(oldMenu);                                                  if (pickList._formItems != null) {                                                          for (var formItem in pickList._formItems) {                                 if (window[formItem] && window[formItem].pickList == pickList)                                      delete window[formItem].pickList                             }                         }                         // destroy on a delay so it doesn't slow this method down                         oldMenu._pickList.delayCall("destroy");                                              }                                      }             }                    } else {            isc.PickList._pickListInstance = this.pickList;        }    },        getPickListCellHeight : function () {        var cellHeight = this.pickListCellHeight;        if (this.valueicons != null || this.getValueIcon != null) {            var valueIconHeight = this.getValueIconHeight();            if (valueIconHeight > cellHeight) cellHeight = valueIconHeight;        }        return cellHeight;    },        // Set Up Pick List - apply properties to the pickList to link it to this form item.    // Called every time the pick-list is shown.    // For form items that re-use the same pickList this method must set properties connecting    // the pickList to this form item.    // Otherwise simply ensure the displayed set of data is up to date.   setUpPickList : function (show, queueFetches, request) {        var pickList = this.pickList;                       var cellHeight = this.pickListCellHeight;        pickList.setCellHeight(cellHeight);                     // These methods both no-op if the pickList is already applied to this item        // and already showing the correct set of fields        this._applyPickListToItem();        this.setUpPickListFields();        // always refilter                this.filterPickList(show, queueFetches, request);    },         _applyPickListToItem : function () {        var oldFormItem = this.pickList.formItem;            if (oldFormItem == this) return;                // Determine desired properties from the various init params.        var pickListProperties = this.pickListProperties || {};        isc.addProperties(pickListProperties, {            // Ensure there's a pointer back to the form item            formItem:this,                        baseStyle:this.pickListBaseStyle,                        hiliteColor:this.pickListHiliteColor,            hiliteTextColor:this.pickListHiliteTextColor,                        // Allow components to show the pickList as a modal list            showModal:this.modalPickList        });                this.pickList.setProperties(pickListProperties);                // Keep track of every form item for which 'this.pickList' points to this pickList        // Required for shared pickLists - allows us to clear up these pointers if the cached        // pickList gets removed to make room for more lists in the cached                if (!this.pickList._formItems) this.pickList._formItems = {};        this.pickList._formItems[this.getID()] = true;        // If we're re-using a pickList, clear it's observations on the previous form item        // it was associated with.        if (oldFormItem) {            if (this.pickList.isObserving(oldFormItem.containerWidget, "hide")) {                this.pickList.ignore(oldFormItem.containerWidget, "hide");            }            if (this.pickList.isObserving(oldFormItem.containerWidget, "clear")) {                this.pickList.ignore(oldFormItem.containerWidget, "clear");            }        }        // Clean up the pickList if the form goes away                if (!this.pickList.isObserving(this.containerWidget, "hide")) {            this.pickList.observe(this.containerWidget, "hide", "observer.hide();");        }                if (!this.pickList.isObserving(this.containerWidget, "clear")) {            this.pickList.observe(this.containerWidget, "clear",                                                     "if(observer.isDrawn())observer.clear();");        }            },        // ------------    // Data Management    // ------------        //>@method pickList.getOptionDataSource()    // Pick-lists can derive their data directly from a valueMap, or retrieve data from a     // dataSource to display as options.    //     // This method will return the dataSource used to populate the pickList, or null if     // none specified (implies this list will derive its data from the valueMap for the item).    // Default implementation  will return +link{pickList.optionDataSource} if specified,    // otherwise if this is a field with a specified <code>foreignKey</code> in a databound    // form, returns the dataSource for the <code>foreignKey</code>.    // Otherwise picks up <code>this.form.dataSource</code> if set.    //    // @return (DataSource) DataSource to use for fetching options    // @visibility external    //<            // getPickListFields()     getPickListFields : function () {        // Allow the developer to specify a set of fields         // Only really has meaning if the select item is databound, where multiple fields are        // available.  For databound lists properties such as valueMaps will be picked up from        // the dataSource.        if (this.pickListFields) return this.pickListFields;                var displayField = this.getDisplayFieldName(),            fieldObj;        if (displayField != null) {            fieldObj = {width:"*", name:displayField}            fieldObj.formatCellValue = this._formatDisplayFieldCellValue        } else {            fieldObj = {width:"*", name:this.getValueFieldName(),                         // apply the same valueMap to this field so the display values show up                        // correctly                                                valueMap:this.getValueMap()                       }            // If an empty cell value is specified, apply it to the field as well so we show            // empty options with the correct title.            if (this.emptyDisplayValue != null) fieldObj.emptyCellValue = this.emptyDisplayValue;        }        return [fieldObj]    },        // custom formatter for the display field - if the valueField is empty, show the empty    // cell value (unless there's an explicit display field value for the record in question    // in which case the "right" behavior is ambiguous)    _formatDisplayFieldCellValue : function (value,record,rowNum,colNum,grid) {        if (value != null) return value;        var item = grid.formItem,            valueField = item.getValueFieldName()        if (record[valueField] == null) return item.emptyCellValue;        return value;    },        //> @method  PickList.getPickListFilterCriteria()  (A)    // Returns a set of filter criteria to be applied to the data displayed in the pickList when    // it is shown.    // <P>    // If this is a databound item the criteria will be passed as criteria to    // +link{dataSource.fetchData()}.  Otherwise an equivalent client-side filter will be    // performed on the data returned by +link{getClientPickListData()}.    // <P>    // By default returns +link{pickList.pickListCriteria} if specified, otherwise an empty     // set of criteria so all records will be displayed.    //    // @return (Criteria) criteria to be used for databound or local filtering

⌨️ 快捷键说明

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