Skip to content

Commit

Permalink
Select, _FormSelectWidget, MultiSelect: remove deprecated API's, refs #4
Browse files Browse the repository at this point in the history


_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)

MultiSelect:
- remove nameAttrSetting variable; it was only needed for IE6/IE7
  • Loading branch information
wkeese committed Apr 30, 2013
1 parent bab02db commit 46a97da
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 119 deletions.
2 changes: 1 addition & 1 deletion form/MultiSelect.js
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ define([

baseClass: "dijitMultiSelect",

templateString: "<select multiple='true' ${!nameAttrSetting} data-dojo-attach-point='containerNode,focusNode' data-dojo-attach-event='onchange: _onChange'></select>",
templateString: "<select multiple='true' data-dojo-attach-point='containerNode,focusNode' data-dojo-attach-event='onchange: _onChange'></select>",

addSelected: function(/*dijit/form/MultiSelect*/ select){
// summary:
Expand Down
122 changes: 5 additions & 117 deletions form/_FormSelectWidget.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
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
Expand Down Expand Up @@ -68,17 +68,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
Expand Down Expand Up @@ -230,73 +219,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){
Expand All @@ -323,28 +249,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);
Expand Down Expand Up @@ -550,26 +454,16 @@ 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
},

_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);
},
Expand All @@ -587,7 +481,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(){
Expand Down Expand Up @@ -658,11 +551,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();
Expand Down
2 changes: 1 addition & 1 deletion form/templates/Select.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
><div class="dijitReset dijitValidationContainer"
><input class="dijitReset dijitInputField dijitValidationIcon dijitValidationInner" value="&#935; " type="text" tabIndex="-1" readonly="readonly" role="presentation"
/></div
><input type="hidden" ${!nameAttrSetting} data-dojo-attach-point="valueNode" value="${value}" aria-hidden="true"
><input type="hidden" data-dojo-attach-point="valueNode" value="${value}" aria-hidden="true"
/></td
><td class="dijitReset dijitRight dijitButtonNode dijitArrowButton dijitDownArrowButton dijitArrowButtonContainer"
data-dojo-attach-point="titleNode" role="presentation"
Expand Down

0 comments on commit 46a97da

Please sign in to comment.