Users.js
2.75 KB
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
Ext.define('MyMA.controller.Users', {
extend: 'Ext.app.Controller',
stores: ['Users', 'Choice'],
views: ['Users', 'User'],
refs: [{
selector: 'users > grid',
ref: 'usersList'
}, {
selector: 'users',
ref: 'usersWindow'
}],
init: function() {
this.control({
'users > grid > toolbar > #addrecord': {
click: this.showForm
},
'users > grid > toolbar > #search': {
click: this.onSearch
},
'users actioncolumn': {
click: this.onActionColumn
},
'users > grid': {
afterrender: this.onGridRender
}
});
},
/**
* Handles action columns click
* @param {Object} grid view
* @param {HTMLElement} Element
* @param {Integer} row index
* @param {Integer} column index
* @param {Object} Event object
* @param {Object} Scope object
* @param {Object}
*/
onActionColumn: function(gridview, el, rowIndex, colIndex, e, scope, rowEl) {
if(e.getTarget('.x-ibtn-edit')) {
var record = scope.store.getAt(rowIndex);
var widget = this.getController('Taskpanel').addProgram({
name: 'user'
});
widget.setTitle('User: ' + record.get('name'));
widget.down('form').getForm().loadRecord(record);
widget.down('form').down('combo[name=domid]').getStore().reload();
}
if(e.getTarget('.x-ibtn-delete')) {
var record = scope.store.getAt(rowIndex);
Ext.Msg.confirm('Info', 'Press Yes to conform remove action', function(button) {
if (button === 'yes') {
this.record.destroy({
scope: this,
success: function() {
this.store.remove(this.record)
}
});
}
}, {
store: scope.store,
record: record
});
}
},
/**
* Show form to add new record or edit existing data
* @param {Object} Button
*/
showForm: function(Button) {
var widget = this.getController('Taskpanel').addProgram({
name: 'user',
title: 'New User'
});
widget.down('form').down('combo[name=domid]').getStore().reload();
},
/**
* Search action
*/
onSearch: function(Button) {
var store = this.getUsersList().getStore();
store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload({
params: { }
});
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
}
});