-
Notifications
You must be signed in to change notification settings - Fork 0
/
BookWindow.js
100 lines (97 loc) · 3.2 KB
/
BookWindow.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
/**
* BookWindow class definition
*/
Ext.define('BookWindow', {
extend: 'Ext.window.Window',
config: {
arrMem: [],
memStore: null,
editMode: false,
bookId: null
},
constructor: function (config) {
this.callParent(arguments);
return this;
},
autoload: true,
modal: true,
height: 200,
width: 300,
layout: 'fit',
items: {
xtype: 'form',
border: false,
margin: 5,
// The fields
defaultType: 'textfield',
items: [{
fieldLabel: 'Name',
name: 'name',
allowBlank: false
}, {
fieldLabel: 'Description',
name: 'desc',
allowBlank: false
}, {
xtype: 'combo',
fieldLabel: 'Choose Status',
store: statuses,
queryMode: 'local',
displayField: 'name',
valueField: 'name',
name: 'status',
editable: false,
allowBlank: false
}],
// Reset and Submit buttons
buttons: [{
text: 'Reset',
handler: function () {
this.up('form').getForm().reset();
},
listeners: {
beforerender: function (me) {
if (me.up('window').config.editMode) me.disable();
} }
}, {
text: 'Save',
formBind: true, //only enabled once the form is valid
disabled: true,
handler: function () {
var form = this.up('form'),
data = form.getValues(),
arrMem = this.up('window').config.arrMem,
memStore = this.up('window').config.memStore,
editMode = this.up('window').config.editMode,
curId;
if (editMode) {
curId = this.up('window').config.bookId;
arrMem[curId][3] = data.status;
} else {
curId = arrMem.length ? Ext.Array.max(arrMem, (a, b) => a[0] - b[0] < 0 ? -1 : 0)[0] + 1 : 1;
arrMem.push([curId,
data.name,
data.desc,
data.status
]);
}
memStore.reload();
localStorage.setItem('book-shelf', JSON.stringify(arrMem));
if (form.getForm().isValid()) {
var win = this.up('window').destroy();
}
}
}]
},
listeners: {
beforerender: function (me) {
if (me.config.editMode) {
me.down('form').items.items[0].setEditable(false);
me.down('form').items.items[1].setEditable(false);
me.down('form').items.items[0].setValue ( me.config.arrMem[me.config.bookId][1]);
me.down('form').items.items[1].setValue ( me.config.arrMem[me.config.bookId][2]);
me.down('form').items.items[2].setValue ( me.config.arrMem[me.config.bookId][3]);
}
}
}
});