-
Notifications
You must be signed in to change notification settings - Fork 0
/
TreeSearchToolbarController.js
125 lines (88 loc) · 3.41 KB
/
TreeSearchToolbarController.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
Ext.define('MyApp.view.base.TreeSearchToolbarController', {
extend: 'Ext.app.ViewController',
alias: 'controller.TreeSearchToolbarController',
onSearchProduct: function(){
var me = this,
view = me.getView(),
tree = view.up(),
store = tree.getStore(),
searchFieldProduct = me.lookupReference('searchFieldProduct'),
searchBtn = me.lookupReference('searchBtn');
me.lookupReference('showNext').disable();
me.lookupReference('showPre').disable();
searchBtn.disable();
searchBtn.setText('searching ...');
Ext.Ajax.request({
url: view.searchUrl,
params : {
stringToSearch: searchFieldProduct.getValue(),
productType: tree.estateMaterials,
status: 'active'
},
success: function(response, opts) {
var obj = Ext.decode(response.responseText);
var path = '';
searchBtn.enable();
searchBtn.setText('search');
if(obj.data){
me.lengthOfPathes = obj.count;
me.arrayOfPathes = obj.data;
Ext.toast(' '+me.lengthOfPathes+' Founded');
me.getViewModel().set('ofAll', me.lengthOfPathes);
me.getViewModel().set('current', 0);
me.showNext();
}
},
failure: function(response, opts) {
searchBtn.enable();
searchBtn.setText('search');
}
});
},
onKeyUpSearch: function(com, event){
var me = this,
view = me.getView();
if(event.getKeyName() == "ENTER"){
me.onSearchProduct();
}
},
showNext: function(){
var me = this;
var current = me.getViewModel().get('current');
current++;
if(me.lengthOfPathes>=current){
me.selectCurrent(current);
if(current>1){
me.lookupReference('showPre').enable();
}
if(me.lengthOfPathes==current){
me.lookupReference('showNext').disable();
}else{
me.lookupReference('showNext').enable();
}
}
},
showPre: function(){
var me = this;
var current = me.getViewModel().get('current');
current--;
if(current>0){
me.selectCurrent(current);
me.lookupReference('showNext').enable();
}
if(current == 1){
me.lookupReference('showPre').disable();
}
},
selectCurrent: function(current){
var me = this,
view = me.getView(),
tree = view.up();
me.getViewModel().set('current', current);
tree.ensureVisible(me.arrayOfPathes[(current-1)].path, {
animate: true,
highlight: true,
select: true
});
}
});