-
Notifications
You must be signed in to change notification settings - Fork 0
/
Ext.form.field.ComboChain.js
117 lines (107 loc) · 2.93 KB
/
Ext.form.field.ComboChain.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
/**
* @class Ext.form.field.ComboChain
* @extends Ext.form.field.ComboBox
* <p>An extension of the combo class which provides to chain and link combos in a form</p>
*
* ## Example usage:
*
* // Create the combo box, attached to the states data store, with Company as chain combo
* var comboState = {
* xtype: 'combochain',
* fieldLabel: 'Choose State',
* name: 'State',
* store: states,
* queryMode: 'local',
* displayField: 'name',
* valueField: 'abbr',
* renderTo: Ext.getBody(),
* chains: [{name:'Company'}]
* };
*
* // Create the combo box, attached to the company data store, with State as chained combo
* var comboCompany = {
* xtype: 'combochain',
* fieldLabel: 'Choose Company',
* name: 'Company',
* store: company,
* queryMode: 'local',
* displayField: 'name',
* valueField: 'abbr',
* renderTo: Ext.getBody(),
* chained:[ {name:'State',key: 'StateId',value:'',required:true}]
* });
* @docauthor Carlos Miranda <[email protected]>
*/
Ext.define('Ext.form.field.ComboChain', {
extend: 'Ext.form.field.ComboBox',
alias: 'widget.combochain',
initComponent: function() {
if(!this.checkIsReady())
this.setDisabled(true);
this.on({
afterrender: this.setChains,
select: this.comboChainSelect,
});
this.callParent(arguments);
},
clear: function()
{
this.clearValue();
this.getStore().clearData();
this.lastQuery = null;
this.setDisabled(true);
},
setChains: function(){
var me = this;
me.comboChainSelect(me);
},
checkIsReady: function()
{
me = this;
if(!me.chained)
return true;
var result = true;
var chained = me.chained;
Ext.Array.each(chained, function(chain) {
if((chain.value === '' || chain.value === undefined) && (chain.required))
result = false;
});
return result;
},
load: function()
{
var store = this.getStore();
var me = this;
me.setDisabled(false);
Ext.Array.each(me.chained, function(chained) {
store.proxy.extraParams[chained.key] = chained.value;
},me);
store.load();
},
comboChainSelect: function(combo, record, options){
if(!combo.chains)
return;
var chains = combo.chains;
var painel = combo.up('form');
var form = painel.getForm();
var uid = combo.getValue();
if(!uid)
return;
Ext.Array.each(chains, function(chain) {
var comboChained = form.findField(chain.name);
if(comboChained){
var chained = comboChained.chained;
Ext.Array.each(chained, function(chaind) {
if(combo.name==chaind.name)
chaind.value = uid;
});
if(comboChained.checkIsReady())
comboChained.load();
else
comboChained.clear();
}
},this);
},
chained: null,
chains: null,
});