forked from fex-team/kityminder
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcommandselectmenu.js
45 lines (39 loc) · 1.27 KB
/
commandselectmenu.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
/**
* @fileOverview
*
* 生成与指定命令绑定的下拉选框
*
* @author: techird
* @copyright: Baidu FEX, 2014
*/
KityMinder.registerUI('widget/commandselectmenu', function(minder) {
function mapValueWidget(command, valueList) {
return valueList.map(function(value) {
var text = minder.getLang([command, value].join('.')) || value;
return {
clazz: 'Button',
label: text,
text: text,
value: value,
className: [command, value].join(' ')
};
});
}
function generate(command, valueList, column) {
var $selectMenu = new FUI.SelectMenu({
widgets: typeof(valueList[0]) == 'object' ? valueList : mapValueWidget(command, valueList),
className: ['command-widget', 'command-selectmenu', command].join(' '),
column: column || 3
});
$selectMenu.bindExecution('change', function() {
minder.execCommand(command, $selectMenu.getValue());
});
$selectMenu.bindCommandState(minder, command, function(value) {
if (value !== undefined) this.selectByValue(value);
});
return $selectMenu;
}
return {
generate: generate
};
});