-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathcommon.js
91 lines (80 loc) · 2.13 KB
/
common.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
/**
* Enable any previously disabled button when any button is clicked.
*
* @param Object node
* @param String selector
*
* @returns void
*/
function enableSiblings(node, selector){
var sibling = node.previousSibling(selector);
while( sibling != null) {
sibling.setDisabled(false);
var sibling = sibling.previousSibling(selector);
}
var sibling = node.nextSibling(selector);
while( sibling != null) {
sibling.setDisabled(false);
var sibling = sibling.nextSibling(selector);
}
}
/**
* Enable all the buttons in a toolbar.
*
* @param Object toolbar - The alias of an existing toolbar
*
* @returns void
*/
function enableToolbarButtons(toolbar)
{
// Need to get all siblings of the add operator, it is only button that
// is enabled by default on page load.
var btns = Ext.ComponentQuery.query(toolbar + ' > button');
Ext.Array.each(btns, function(button) {
button.enable();
});
}
/**
* Enable or disable all elements within the received array.
*
* Elements of string can be Ext components or HTML ids
*
* @param Array items (array of strings or objects)
* @param String action (enable or disable)
*
* @returns void
*/
function toggleEnabled(items, action)
{
items.forEach( function(item) {
if( ! Ext.isObject(item) )
{
// Query by alias
var el = Ext.ComponentQuery.query(item);
if( ! Ext.isEmpty(el) )
{
toggleEnabled(el, action);
} else
{
// Query by id
var el = Ext.ComponentQuery.query('#' + item);
if( ! Ext.isEmpty(el) )
{
toggleEnabled(el, action);
} else
{
console.log('Failed to query ' + item + ' in redisableItems');
}
}
} else
{
if( action == 'enable' )
{
item.enable();
} else
{
item.disable();
}
}
});
}