From 40db337b96c521330f5b13d873df2bfeaecfdb1e Mon Sep 17 00:00:00 2001 From: Bill Keese Date: Mon, 8 Apr 2013 08:52:29 +0900 Subject: [PATCH] Select, _FormSelectWidget, MultiSelect: remove deprecated API's, refs #4 _FormSelectWidget: - remove support by dojo.data - remove support for sortByLabel (instead, just pass sort option to store) - use dojo/Deferred not dojo/_base/Deferred Select: - desupport onFetch() callback - stop using ${nameAttrSetting} (it's only needed for IE6 and IE7) - use V2 NLS API MultiSelect: - remove nameAttrSetting variable; it was only needed for IE6/IE7 --- form/MultiSelect.js | 2 +- form/Select.js | 15 ++--- form/_FormSelectWidget.js | 125 ++----------------------------------- form/templates/Select.html | 2 +- 4 files changed, 13 insertions(+), 131 deletions(-) diff --git a/form/MultiSelect.js b/form/MultiSelect.js index 1e54c9e58..74bdd1290 100644 --- a/form/MultiSelect.js +++ b/form/MultiSelect.js @@ -23,7 +23,7 @@ define([ baseClass: "dijitMultiSelect", - templateString: "", + templateString: "", addSelected: function(/*dijit/form/MultiSelect*/ select){ // summary: diff --git a/form/Select.js b/form/Select.js index e723e7779..92a4a91f7 100644 --- a/form/Select.js +++ b/form/Select.js @@ -4,7 +4,6 @@ define([ "dojo/dom-attr", // domAttr.set "dojo/dom-class", // domClass.add domClass.remove domClass.toggle "dojo/dom-geometry", // domGeometry.setMarginBox - "dojo/i18n", // i18n.getLocalization "dojo/_base/lang", // lang.hitch "dojo/on", "dojo/sniff", // has("ie") @@ -18,8 +17,9 @@ define([ "../registry", // registry.byNode "dojo/text!./templates/Select.html", "dojo/i18n!./nls/validate" -], function(array, declare, domAttr, domClass, domGeometry, i18n, lang, on, has, - _FormSelectWidget, _HasDropDown, DropDownMenu, MenuItem, MenuSeparator, Tooltip, _KeyNavMixin, registry, template){ +], function(array, declare, domAttr, domClass, domGeometry, lang, on, has, + _FormSelectWidget, _HasDropDown, DropDownMenu, MenuItem, MenuSeparator, Tooltip, _KeyNavMixin, registry, + template, nlsValidate){ // module: // dijit/form/Select @@ -110,6 +110,8 @@ define([ // Whether or not our children have been loaded _childrenLoaded: false, + _missingMsg: nlsValidate.missingMessage, + _fillContent: function(){ // summary: // Set the value to be the first, or the selected index @@ -348,13 +350,6 @@ define([ this._refreshState(); // to update this.state }, - postMixInProperties: function(){ - // summary: - // set the missing message - this.inherited(arguments); - this._missingMsg = i18n.getLocalization("dijit.form", "validate", this.lang).missingMessage; - }, - postCreate: function(){ // summary: // stop mousemove from selecting text on IE to be consistent with other browsers diff --git a/form/_FormSelectWidget.js b/form/_FormSelectWidget.js index 9c3142a64..c10b536eb 100644 --- a/form/_FormSelectWidget.js +++ b/form/_FormSelectWidget.js @@ -1,8 +1,7 @@ define([ "dojo/_base/array", // array.filter array.forEach array.map array.some - "dojo/_base/Deferred", + "dojo/Deferred", "dojo/aspect", // aspect.after - "dojo/data/util/sorter", // util.sorter.createSortFunction "dojo/_base/declare", // declare "dojo/dom", // dom.setSelectable "dojo/dom-class", // domClass.toggle @@ -12,7 +11,7 @@ define([ "dojo/when", "dojo/store/util/QueryResults", "./_FormValueWidget" -], function(array, Deferred, aspect, sorter, declare, dom, domClass, kernel, lang, query, when, +], function(array, Deferred, aspect, declare, dom, domClass, kernel, lang, query, when, QueryResults, _FormValueWidget){ // module: @@ -68,17 +67,6 @@ define([ // dojo.data store rather than a new dojo/store. labelAttr: "", - // onFetch: Function - // A callback to do with an onFetch - but before any items are actually - // iterated over (i.e. to filter even further what you want to add) - onFetch: null, - - // sortByLabel: Boolean - // Flag to sort the options returned from a store by the label of - // the store. - sortByLabel: true, - - // loadChildrenOnOpen: Boolean // By default loadChildren is called when the items are fetched from the // store. This property allows delaying loadChildren (and the creation @@ -230,73 +218,10 @@ define([ // // - query: new value for Select.query, // - queryOptions: new value for Select.queryOptions, - // - onFetch: callback function for each item in data (Deprecated) + var oStore = this.store; fetchArgs = fetchArgs || {}; - - if(oStore !== store){ - // Our store has changed, so cancel any listeners on old store (remove for 2.0) - var h; - while((h = this._notifyConnections.pop())){ - h.remove(); - } - - // For backwards-compatibility, accept dojo.data store in addition to dojo.store.store. Remove in 2.0. - if(!store.get){ - lang.mixin(store, { - _oldAPI: true, - get: function(id){ - // summary: - // Retrieves an object by it's identity. This will trigger a fetchItemByIdentity. - // Like dojo.store.DataStore.get() except returns native item. - var deferred = new Deferred(); - this.fetchItemByIdentity({ - identity: id, - onItem: function(object){ - deferred.resolve(object); - }, - onError: function(error){ - deferred.reject(error); - } - }); - return deferred.promise; - }, - query: function(query, options){ - // summary: - // Queries the store for objects. Like dojo/store/DataStore.query() - // except returned Deferred contains array of native items. - var deferred = new Deferred(function(){ - if(fetchHandle.abort){ - fetchHandle.abort(); - } - }); - deferred.total = new Deferred(); - var fetchHandle = this.fetch(lang.mixin({ - query: query, - onBegin: function(count){ - deferred.total.resolve(count); - }, - onComplete: function(results){ - deferred.resolve(results); - }, - onError: function(error){ - deferred.reject(error); - } - }, options)); - return new QueryResults(deferred); - } - }); - - if(store.getFeatures()["dojo.data.api.Notification"]){ - this._notifyConnections = [ - aspect.after(store, "onNew", lang.hitch(this, "_onNewItem"), true), - aspect.after(store, "onDelete", lang.hitch(this, "_onDeleteItem"), true), - aspect.after(store, "onSet", lang.hitch(this, "_onSetItem"), true) - ]; - } - } - this._set("store", store); // Our store has changed, so update our notifications - } + this._set("store", store); // Remove existing options (if there are any) if(this.options && this.options.length){ @@ -323,28 +248,6 @@ define([ // Save result in this._queryRes so we can cancel the listeners we register below this._queryRes = store.query(this.query, this.queryOptions); when(this._queryRes, lang.hitch(this, function(items){ - - if(this.sortByLabel && !fetchArgs.sort && items.length){ - if(store.getValue){ - // Old dojo.data API to access items, remove for 2.0 - items.sort(sorter.createSortFunction([ - { - attribute: store.getLabelAttributes(items[0])[0] - } - ], store)); - }else{ - // TODO: remove sortByLabel completely for 2.0? It can be handled by queryOptions: {sort: ... }. - var labelAttr = this.labelAttr; - items.sort(function(a, b){ - return a[labelAttr] > b[labelAttr] ? 1 : b[labelAttr] > a[labelAttr] ? -1 : 0; - }); - } - } - - if(fetchArgs.onFetch){ - items = fetchArgs.onFetch.call(this, items, fetchArgs); - } - // TODO: Add these guys as a batch, instead of separately array.forEach(items, function(i){ this._addOptionForItem(i); @@ -550,9 +453,8 @@ define([ // of the option item will be the identity of the item, the "label" // of the option will be the label of the item. - // remove getLabel() call for 2.0 (it's to support the old dojo.data API) var store = this.store, - label = (this.labelAttr && this.labelAttr in item) ? item[this.labelAttr] : store.getLabel(item), + label = item[this.labelAttr], value = (label ? store.getIdentity(item) : null); return {value: value, label: label, item: item}; // __SelectOption }, @@ -560,16 +462,7 @@ define([ _addOptionForItem: function(/*item*/ item){ // summary: // Creates (and adds) the option for the given item - var store = this.store; - if(store.isItemLoaded && !store.isItemLoaded(item)){ - // We are not loaded - so let's load it and add later. - // Remove for 2.0 (it's the old dojo.data API) - store.loadItem({item: item, onItem: function(i){ - this._addOptionForItem(i); - }, - scope: this}); - return; - } + var newOpt = this._getOptionObjForItem(item); this.addOption(newOpt); }, @@ -587,7 +480,6 @@ define([ // Saves off our value, if we have an initial one set so we // can use it if we have a store as well (see startup()) this._oValue = (params || {}).value || null; - this._notifyConnections = []; // remove for 2.0 }, buildRendering: function(){ @@ -658,11 +550,6 @@ define([ // summary: // Clean up our connections - var h; - while((h = this._notifyConnections.pop())){ - h.remove(); - } - // Cancel listener for store updates if(this._queryRes && this._queryRes.close){ this._queryRes.close(); diff --git a/form/templates/Select.html b/form/templates/Select.html index 4901aa866..cd6f10364 100644 --- a/form/templates/Select.html +++ b/form/templates/Select.html @@ -7,7 +7,7 @@ >