forked from parasj/vocabulary
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.js
232 lines (214 loc) · 5.86 KB
/
main.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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
var App = new Ext.Application({
name: 'ractive',
useLoadMask: true,
launch: function() {
// Define Model for Flashcard
Ext.regModel('Flashcard', {
idProperty: 'id',
fields: [
{ name: 'id', type: 'int' },
{ name: 'word', type: 'string' },
{ name: 'def', type: 'string' },
{ name: 'tries', type: 'int' },
{ name: 'correct', type: 'int' }
],
validations: [
{ type: 'presence', field: 'id' },
{ type: 'presence', field: 'word', message: 'Please enter the word for this flashcard.' },
{ type: 'presence', field: 'def', message: 'Please enter the definition for this flashcard.' },
]
});
// Define HTML5 Data Store
store: new Ext.regStore('FlashcardsStore', {
model: 'Flashcard',
sorters: [{
property: 'word',
direction: 'ASC'
}],
proxy: {
type: 'localstorage',
id: 'notes-app-localstore'
},
getGroupString: function (record) {
if (record && record.data.word) {
return record.get('word')[0].toUpperCase();
} else {
return '';
}
}
});
var loadFlashcard;
// Build List
var flashcardList = new Ext.List({
id: 'flashcardList',
store: 'FlashcardsStore',
grouped: true,
indexBar: true,
itemTpl: '<div class="list-item-word">{word}</div>'+'<div class="list-item-def">{def}</div>',
onItemDisclosure: function (record) {
var selectedNote = record;
flashcardEditor.load(selectedNote);
viewport.setActiveItem('flashcardEditor', { type: 'slide', direction: 'left' });
},
listeners: {
'render': function (thisComponent) {
thisComponent.getStore().load();
}
}
});
// INIT VIEWPORTS
flashcardEditorTopToolbar = new Ext.Toolbar({
title: 'Edit Flashcard',
items: [
{
text: 'Home',
ui: 'back',
handler: function () {
viewport.setActiveItem('flashcardListContainer', {type: 'slide', direction: 'right'});
}
},
{ xtype: 'spacer' },
{
text: 'Save',
ui: 'action',
handler: function () {
var currentFlashcard = flashcardEditor.getRecord();
flashcardEditor.updateRecord(currentFlashcard);
var errors = currentFlashcard.validate();
var errors = currentFlashcard.validate();
if (!errors.isValid()) {
Ext.Msg.alert('Required Field Empty!');
return;
}
var flashcardStore = Ext.getStore('FlashcardsStore');
if (flashcardStore.findRecord('id', currentFlashcard.data.id) === null) {
flashcardStore.add(currentFlashcard);
} else {
currentFlashcard.setDirty();
}
flashcardStore.sync();
flashcardStore.sort([{ property: 'word', direction: 'ASC'}]);
flashcardList.refresh();
viewport.setActiveItem('flashcardListContainer', {type: 'slide', direction: 'right'});
}
}
]
});
flashcardEditorBottomToolbar = new Ext.Toolbar({
dock: 'bottom',
items: [
{ xtype: 'spacer' },
{
iconCls: 'trash',
ui: 'action',
iconMask: true,
//text: 'Delete',
handler: function () {
var currentFlashcard = flashcardEditor.getRecord();
var flashcardStore = Ext.getStore('FlashcardsStore');
if (flashcardStore.findRecord('id', currentFlashcard.data.id)) {
flashcardStore.remove(currentFlashcard);
}
flashcardStore.sync();
flashcardStore.sort([{ property: 'name', direction: 'ASC'}]);
flashcardList.refresh();
viewport.setActiveItem('flashcardListContainer', { type: 'slide', direction: 'right' });
}
}
]
});
flashcardEditor = new Ext.form.FormPanel({
id: 'flashcardEditor',
items: [
{
xtype: 'textfield',
name: 'word',
label: 'Word',
required: true
},
{
xtype: 'textareafield',
name: 'def',
label: 'Definition',
required: true
}
],
dockedItems: [flashcardEditorTopToolbar, flashcardEditorBottomToolbar]
});
flashcardGameTopToolbar = new Ext.Toolbar({
id: 'flashcardGameTopToolbar',
title: 'Learn Card',
items: [
{
text: 'Home',
ui: 'back',
handler: function () {
viewport.setActiveItem('flashcardListContainer', {type: 'slide', direction: 'right'});
}
},
]
});
flashcardGameBottomToolbar = new Ext.Toolbar({
id: 'flashcardGameBottomToolbar',
dock: 'bottom',
items: [
// Next/Previous Flashcard
// Block Previous if it is first, block Next if it is last
]
});
flashcardGame = new Ext.Panel({
id: 'flashcardGame',
load: function(flashcardID) {
//Ext.util.Cookies.set("lastFlashcard", this.flashcardID);
this.loadFlashcard = flashcardID;
},
items: [
{
text: 'Home',
},
],
dockedItems: [flashcardGameTopToolbar, flashcardGameBottomToolbar]
});
var cardToolbar = new Ext.Toolbar({
dock : 'top',
title: 'Radioactive',
items: [
{
id: 'launchFlashcardGame',
text: 'Learn',
ui: 'action',
handler: function () {
flashcardGame.load(1);
viewport.setActiveItem('flashcardGame', {type: 'slide', direction: 'left'});
}
},
{ xtype: 'spacer' },
{
id: 'addFlashcardButton',
iconCls: 'add',
iconMask: true,
ui: 'action',
handler: function () {
// TODO: Create a blank note and make the note editor visible.
var store = Ext.getStore('FlashcardsStore'), num = store.getCount()+1;
var flashcard = Ext.ModelMgr.create({ id: num, word: '', def: '' },'Flashcard');
flashcardEditor.load(flashcard);
viewport.setActiveItem('flashcardEditor', {type: 'slide', direction: 'left'});
}
}
]
});
var flashcardListContainer = new Ext.Panel({
id: 'flashcardListContainer',
layout : 'fit',
dockedItems: [cardToolbar],
items: [flashcardList]
});
var viewport = new Ext.Panel({
fullscreen: true,
layout: 'card',
cardAnimation: 'slide',
items: [flashcardListContainer, flashcardEditor, flashcardGame]
});
}
});