source: Dev/trunk/src/client/dijit/form/ComboBoxMixin.js @ 483

Last change on this file since 483 was 483, checked in by hendrikvanantwerpen, 11 years ago

Added Dojo 1.9.3 release.

File size: 4.5 KB
Line 
1define([
2        "dojo/_base/declare", // declare
3        "dojo/Deferred",
4        "dojo/_base/kernel", // kernel.deprecated
5        "dojo/_base/lang", // lang.mixin
6        "dojo/store/util/QueryResults",
7        "./_AutoCompleterMixin",
8        "./_ComboBoxMenu",
9        "../_HasDropDown",
10        "dojo/text!./templates/DropDownBox.html"
11], function(declare, Deferred, kernel, lang, QueryResults, _AutoCompleterMixin, _ComboBoxMenu, _HasDropDown, template){
12
13
14        // module:
15        //              dijit/form/ComboBoxMixin
16
17        return declare("dijit.form.ComboBoxMixin", [_HasDropDown, _AutoCompleterMixin], {
18                // summary:
19                //              Provides main functionality of ComboBox widget
20
21                // dropDownClass: [protected extension] Function String
22                //              Dropdown widget class used to select a date/time.
23                //              Subclasses should specify this.
24                dropDownClass: _ComboBoxMenu,
25
26                // hasDownArrow: Boolean
27                //              Set this textbox to have a down arrow button, to display the drop down list.
28                //              Defaults to true.
29                hasDownArrow: true,
30
31                templateString: template,
32
33                baseClass: "dijitTextBox dijitComboBox",
34
35                /*=====
36                // store: [const] dojo/store/api/Store|dojo/data/api/Read
37                //              Reference to data provider object used by this ComboBox.
38                //
39                //              Should be dojo/store/api/Store, but dojo/data/api/Read supported
40                //              for backwards compatibility.
41                store: null,
42                =====*/
43
44                // Set classes like dijitDownArrowButtonHover depending on
45                // mouse action over button node
46                cssStateNodes: {
47                        "_buttonNode": "dijitDownArrowButton"
48                },
49
50                _setHasDownArrowAttr: function(/*Boolean*/ val){
51                        this._set("hasDownArrow", val);
52                        this._buttonNode.style.display = val ? "" : "none";
53                },
54
55                _showResultList: function(){
56                        // hide the tooltip
57                        this.displayMessage("");
58                        this.inherited(arguments);
59                },
60
61                _setStoreAttr: function(store){
62                        // For backwards-compatibility, accept dojo.data store in addition to dojo/store/api/Store.  Remove in 2.0.
63                        if(!store.get){
64                                lang.mixin(store, {
65                                        _oldAPI: true,
66                                        get: function(id){
67                                                // summary:
68                                                //              Retrieves an object by it's identity. This will trigger a fetchItemByIdentity.
69                                                //              Like dojo/store/DataStore.get() except returns native item.
70                                                var deferred = new Deferred();
71                                                this.fetchItemByIdentity({
72                                                        identity: id,
73                                                        onItem: function(object){
74                                                                deferred.resolve(object);
75                                                        },
76                                                        onError: function(error){
77                                                                deferred.reject(error);
78                                                        }
79                                                });
80                                                return deferred.promise;
81                                        },
82                                        query: function(query, options){
83                                                // summary:
84                                                //              Queries the store for objects.   Like dojo/store/DataStore.query()
85                                                //              except returned Deferred contains array of native items.
86                                                var deferred = new Deferred(function(){ fetchHandle.abort && fetchHandle.abort(); });
87                                                deferred.total = new Deferred();
88                                                var fetchHandle = this.fetch(lang.mixin({
89                                                        query: query,
90                                                        onBegin: function(count){
91                                                                deferred.total.resolve(count);
92                                                        },
93                                                        onComplete: function(results){
94                                                                deferred.resolve(results);
95                                                        },
96                                                        onError: function(error){
97                                                                deferred.reject(error);
98                                                        }
99                                                }, options));
100                                                return QueryResults(deferred);
101                                        }
102                                });
103                        }
104                        this._set("store", store);
105                },
106
107                postMixInProperties: function(){
108                        // Since _setValueAttr() depends on this.store, _setStoreAttr() needs to execute first.
109                        // Unfortunately, without special code, it ends up executing second.
110                        var store = this.params.store || this.store;
111                        if(store){
112                                this._setStoreAttr(store);
113                        }
114
115                        this.inherited(arguments);
116
117                        // User may try to access this.store.getValue() etc.  in a custom labelFunc() function.
118                        // It's not available with the new data store for handling inline <option> tags, so add it.
119                        if(!this.params.store && !this.store._oldAPI){
120                                var clazz = this.declaredClass;
121                                lang.mixin(this.store, {
122                                        getValue: function(item, attr){
123                                                kernel.deprecated(clazz + ".store.getValue(item, attr) is deprecated for builtin store.  Use item.attr directly", "", "2.0");
124                                                return item[attr];
125                                        },
126                                        getLabel: function(item){
127                                                kernel.deprecated(clazz + ".store.getLabel(item) is deprecated for builtin store.  Use item.label directly", "", "2.0");
128                                                return item.name;
129                                        },
130                                        fetch: function(args){
131                                                kernel.deprecated(clazz + ".store.fetch() is deprecated for builtin store.", "Use store.query()", "2.0");
132                                                var shim = ["dojo/data/ObjectStore"];   // indirection so it doesn't get rolled into a build
133                                                require(shim, lang.hitch(this, function(ObjectStore){
134                                                        new ObjectStore({objectStore: this}).fetch(args);
135                                                }));
136                                        }
137                                });
138                        }
139                }
140        });
141});
Note: See TracBrowser for help on using the repository browser.