forked from MaZderMind/django-vs-extjs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Polls.js
61 lines (50 loc) · 1.42 KB
/
Polls.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
Ext.define('MyApp.controller.Polls', {
extend: 'Ext.app.Controller',
views: ['Polls'],
stores:['Polls'],
refs: [
{ 'ref': 'grid', selector: 'grid' },
],
init: function() {
// save the scope
var
pollsController = this,
loginController = MyApp.getApplication().getController('Login'),
navigationController = MyApp.getApplication().getController('Navigation');
this.control({
'#tbDelete': {
click: this.onRemoveRow
},
'#tbAdd': {
click: this.onAddRow
},
'grid': {
canceledit: this.onCancelEdit
}
});
loginController.on('ready', function() {
pollsController.view = pollsController.getView('Polls').create();
// register polls-view in the navigation
if(loginController.hasPermission('add_poll'))
navigationController.registerNavigationItem('polls', 'poll-management', pollsController.view);
}, {single: true});
},
onAddRow: function() {
// we have not defined an explicit model on the store but used an anonymous model
// by specifying the fields-property
// the store then
var phantomRow = this.getStore('Polls').insertPhantom(0);
var rowEditor = this.getGrid().findPlugin('rowediting');
rowEditor.cancelEdit();
rowEditor.startEdit(0, 0);
},
onRemoveRow: function() {
Ext.each(this.getGrid().getSelection(), function(row) {
row.drop();
});
},
onCancelEdit: function(editor, context) {
if (context.record.phantom)
context.record.drop();
}
});