forked from exsurgo/ProjectTemplates
-
Notifications
You must be signed in to change notification settings - Fork 10
/
Tasks.js
133 lines (111 loc) · 3.46 KB
/
Tasks.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
126
127
128
129
130
131
132
133
/*
* File: app/controller/Tasks.js
*
* This file was generated by Sencha Architect version 3.0.0.
* http://www.sencha.com/products/architect/
*
* This file requires use of the Sencha Touch 2.3.x library, under independent license.
* License of Sencha Architect does not include license for Sencha Touch 2.3.x. For more
* details see http://www.sencha.com/license or contact license@sencha.com.
*
* This file will be auto-generated each and everytime you save your project.
*
* Do NOT hand edit this file.
*/
Ext.define('TasksList.controller.Tasks', {
extend: 'Ext.app.Controller',
config: {
refs: {
mainView: 'mainview',
addButton: 'mainview #addButton',
taskFormField: 'formpanel #taskFormField',
deleteButton: 'formpanel #deleteButton'
},
control: {
"mainview #addButton": {
tap: 'add'
},
"list": {
itemtouchend: 'edit'
},
"formpanel #saveButton": {
tap: 'save'
},
"tasklist": {
show: 'onTaskListShow'
},
"formpanel #deleteButton": {
tap: 'remove'
}
}
},
add: function(button, e, eOpts) {
// Navigate to form
this.getMainView().push({
xtype: 'formpanel',
title: 'Add task'
});
this.getAddButton().hide();
this.getDeleteButton().hide();
},
edit: function(dataview, index, target, record, e, eOpts) {
var mainView = this.getMainView();
// Navigate to form
mainView.push({
xtype: 'formpanel',
title: 'Edit Task'
});
this.getAddButton().hide();
this.getDeleteButton().show();
var taskFormField = this.getTaskFormField(),
fields = taskFormField.getFieldsAsArray();
Ext.each(fields, function(field) {
var key = field.getName(),
value = record.get(key);
field.setValue(value);
});
mainView.setRecord(record);
this.holdSelect = true;
},
save: function(button, e, eOpts) {
// Build up the model's data
var fields = this.getTaskFormField().getFieldsAsArray(),
data = {};
Ext.each(fields, function(field) {
var key = field.getName(),
value = field.getValue();
data[key] = value;
});
// Save the model's data
var mainView = this.getMainView(),
record = mainView.getRecord(),
store = Ext.getStore('Tasks');
if (record) {
record.set(data);
mainView.setRecord(null);
} else {
store.add(data);
}
store.sort();
// Navigate back to list
this.getMainView().pop();
},
onTaskListShow: function(component, eOpts) {
this.getAddButton().show();
},
remove: function(button, e, eOpts) {
var me = this,
title = 'Delete',
message = 'Are you sure you want to delete this task?';
Ext.Msg.confirm(title, message, function(response) {
if (response == 'yes') {
var mainView = me.getMainView(),
tasks = Ext.getStore('Tasks'),
task = mainView.getRecord();
tasks.remove(task);
// Navigate back to list
mainView.pop();
}
});
}
});