-
Notifications
You must be signed in to change notification settings - Fork 2
/
Ext.ux.menu.StoreMenu.js
174 lines (143 loc) · 5.22 KB
/
Ext.ux.menu.StoreMenu.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
/*
* Ext.ux.menu.StoreMenu Addon
*
* @author Marco Wienkoop (wm003/lubber)
* @copyright (c) 2009, Marco Wienkoop (marco.wienkoop@lubber.de) http://www.lubber.de
*
* @class Ext.ux.menu.StoreMenu
* @extends Ext.menu.Menu
* Donations are always welcome :)
* Any amount is greatly appreciated and will help to continue on developing ExtJS Widgets
*
* You can donate via PayPal to donate@lubber.de
*
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>
* This Addon requires the ExtJS Library, which is distributed under the terms of the GPL v3 (from V2.1)
* See http://extjs.com/license for more info
Revision History
v 0.2 [2009/03/04]
- added support for submenu ("menu" has to be delivered such as "handler")
v 0.1 [2009/03/03]
Initial release
*/
/*
Modified by Joe Kuan - kuan.joe@gmail.com
*/
Ext.namespace('Ext.ux.menu');
Ext.ux.menu.StoreMenu = function(config) {
Ext.ux.menu.StoreMenu.superclass.constructor.call(this,config);
if(!this.store){
//at least url/proxy or data need to be given in config when initiating this component
this.store = new Ext.data.JsonStore({
fields: this.fields,
root: this.root,
baseParams: this.baseParams,
idProperty: this.id,
proxy: new Ext.data.HttpProxy({
url: this.url,
method: ((!this.method) ? 'POST' : this.method),
})
/*proxy:this.proxy,
data: this.data*/
});
}
// Keep track of what menu items have been added
this.storeMenus = [];
// List of handlers for menu and submenus
this.handlerTypes = {};
if (this.itemsOffset === undefined)
this.itemsOffset = 0;
this.on('show', this.onMenuLoad, this);
this.store.on('beforeload', this.onBeforeLoad, this);
this.store.on('load', this.onLoad, this);
};
Ext.extend(Ext.ux.menu.StoreMenu, Ext.menu.Menu, {
loadingText: Ext.LoadMask.prototype.msg || 'Loading...',
loaded: false,
onMenuLoad: function(){
if(!this.loaded || this.autoReload){
// if(this.options) {
// this.store.loadData(this.options);
// }
// else {
this.store.load();
// }
}
},
updateMenuItems: function(loadedState,records) {
// var visible = this.isVisible();
// this.hide(false);
for (var i = 0; i < this.storeMenus.length; i++) {
this.remove(this.storeMenus[i]);
}
this.storeMenus = [];
//to sync the height of the shadow
this.el.sync();
if (loadedState) {
for(var i=0, len=records.length; i<len; i++){
//create a real function if a handler or menu is given as a string (because a function cannot really be encoded in JSON
if (records[i].json.handler) {
eval("records[i].json.handler = "+records[i].json.handler);
// records[i].json.handler = new Function(records[i].json.handler);
} else if (this.itemsHandler) {
records[i].json.handler = this.itemsHandler;
}
if (records[i].json.menu && records[i].json.menu.items) {
//eval("records[i].json.menu = "+records[i].json.menu);
// records[i].json.menu = new Function(records[i].json.menu);
for (var j = 0; j < records[i].json.menu.items.length; j++) {
var handlerType = records[i].json.menu.items[j].smHandler;
if (handlerType && this.handlerTypes[handlerType]) {
records[i].json.menu.items[j].handler = this.handlerTypes[handlerType];
}
}
}
this.storeMenus.push(this.insert(this.itemsOffset + i, records[i].json));
}
// this.hide();
//this.show();
}
else {
this.storeMenus.push(this.insert(this.itemsOffset + i,
'<span class="loading-indicator">' + this.loadingText + '</span>'));
}
this.loaded = loadedState;
//if(visible && loadedState) {
// this.show(this.getEl().getXY());
//this.show();
//}
},
onBeforeLoad: function(store) {
this.updateMenuItems(false);
},
onLoad: function(store, records){
this.updateMenuItems(true,records);
},
setItemsHandler: function(handler) {
this.itemsHandler = handler;
},
setSubMenuHandler: function(handler, handlerType) {
this.handlerTypes[handlerType] = handler;
},
setOffset: function(offset) {
this.itemsOffset = offset;
},
setAutoReload: function(autoReload) {
this.autoReload = autoReload;
},
setBaseParam: function(param, value) {
this.store.setBaseParam(param, value);
},
setStore: function(store) {
this.store = store;
}
});