Transports.js
2.91 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
105
106
107
108
Ext.define('MyMA.controller.Transports', {
extend: 'Ext.app.Controller',
stores: ['Transports'],
views: ['Transports'],
refs: [{
selector: 'transports > grid',
ref: 'transportsList'
}],
init: function() {
this.control({
'transports > grid > toolbar > #addrecord': {
click: this.addRecord
},
'transports > grid > toolbar > #search': {
click: this.onSearch
},
'transports actioncolumn': {
click: this.onActionColumn
},
'transports > grid': {
edit: this.onEditAction,
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-delete')) {
var record = scope.store.getAt(rowIndex);
Ext.Msg.confirm('Info', 'Press Yes to confirm remove action', function(button) {
if (button === 'yes') {
if(!this.record.get('id')) {
this.store.remove(this.record);
}
else {
this.record.destroy({
scope: this,
success: function() {
this.store.remove(this.record)
}
});
}
}
}, {
store: scope.store,
record: record
});
}
},
/**
* Add record to the store and start editing
*/
addRecord: function(Button) {
this.getTransportsList().getStore().insert(0, this.getTransportsList().getStore().model.create({
id: 0,
domain: null,
transport: 'virtual'
}));
},
/**
* Search action
*/
onSearch: function(Button) {
var store = this.getTransportsList().getStore();
store.getProxy().extraParams = Ext.apply({}, Button.up('toolbar').getValues());
store.reload();
},
/**
* Fires when edit complete and record was updated
* @param {object}, Ext.grid.plugin.Editing
* @param {object}, An edit event
*/
onEditAction: function(editor, e) {
e.record.save({
scope: e,
success: function(record) {
this.store.reload();
}
});
},
/**
* Fires when widget is shown
*/
onGridRender: function(grid) {
grid.getStore().reload();
}
});