|
1
|
|
|
define([ |
|
|
|
|
|
|
2
|
|
|
'dojo/_base/declare', |
|
3
|
|
|
'dojo/_base/array', |
|
4
|
|
|
'dojo/_base/lang', |
|
5
|
|
|
'dojo/dom-construct', |
|
6
|
|
|
'dojo/dom-class', |
|
7
|
|
|
'dojo/dom-style', |
|
8
|
|
|
'dojo/json', |
|
9
|
|
|
'dojo/on', |
|
10
|
|
|
'dojo/topic', |
|
11
|
|
|
'dijit/_WidgetBase', |
|
12
|
|
|
'dijit/_TemplatedMixin', |
|
13
|
|
|
'dojo/text!./templates/NoteManager.html', |
|
14
|
|
|
'dstore/Memory', |
|
15
|
|
|
'dstore/Trackable', |
|
16
|
|
|
'dgrid/OnDemandGrid', |
|
17
|
|
|
'dgrid/extensions/DijitRegistry', |
|
18
|
|
|
'dgrid/extensions/ColumnResizer', |
|
19
|
|
|
'../../utils/DomUtils', |
|
20
|
|
|
'../dialogs/NotesDialog' |
|
21
|
|
|
], function ( |
|
22
|
|
|
declare, |
|
23
|
|
|
array, |
|
24
|
|
|
lang, |
|
25
|
|
|
domConstruct, |
|
26
|
|
|
domClass, |
|
27
|
|
|
domStyle, |
|
28
|
|
|
JSON, |
|
29
|
|
|
on, |
|
30
|
|
|
topic, |
|
31
|
|
|
_WidgetBase, |
|
32
|
|
|
_TemplatedMixin, |
|
33
|
|
|
template, |
|
34
|
|
|
Memory, |
|
35
|
|
|
Trackable, |
|
36
|
|
|
OnDemandGrid, |
|
37
|
|
|
DijitRegistry, |
|
38
|
|
|
ColumnResizer, |
|
39
|
|
|
DomUtils, |
|
40
|
|
|
NotesDialog |
|
41
|
|
|
) { |
|
42
|
|
|
return declare([_WidgetBase, _TemplatedMixin], { |
|
43
|
|
|
|
|
44
|
|
|
templateString: template, |
|
45
|
|
|
baseClass: 'note-manager', |
|
46
|
|
|
languageController: null, |
|
47
|
|
|
listController: null, |
|
48
|
|
|
concept: null, |
|
49
|
|
|
languageList: null, |
|
50
|
|
|
_noteStore: null, |
|
51
|
|
|
_noteGrid: null, |
|
52
|
|
|
_index: 0, |
|
53
|
|
|
|
|
54
|
|
|
postCreate: function () { |
|
55
|
|
|
this.inherited(arguments); |
|
56
|
|
|
console.debug('NoteManager::postCreate'); |
|
57
|
|
|
|
|
58
|
|
|
this.trackableMemory = declare([Memory, Trackable]); |
|
59
|
|
|
this._noteStore = new this.trackableMemory({ data: [] }); |
|
60
|
|
|
if (this.concept) { |
|
61
|
|
|
array.forEach(this.concept.notes, lang.hitch(this, function (item) { |
|
62
|
|
|
item.id = this._index++; |
|
63
|
|
|
this._noteStore.put(item); |
|
64
|
|
|
})); |
|
65
|
|
|
} |
|
66
|
|
|
this._createGrid({ |
|
67
|
|
|
collection: this._noteStore |
|
68
|
|
|
}, this.noteGridNode); |
|
69
|
|
|
|
|
70
|
|
|
this._notesDialog = new NotesDialog({ |
|
71
|
|
|
parentNode: this, |
|
72
|
|
|
langList: this.languageList, |
|
73
|
|
|
typeList: this.listController.getNoteTypes() |
|
74
|
|
|
}); |
|
75
|
|
|
on(this._notesDialog, 'add.note', lang.hitch(this, function(evt) { |
|
76
|
|
|
this._doAddNote(evt); |
|
77
|
|
|
})); |
|
78
|
|
|
on(this._notesDialog, 'edit.note', lang.hitch(this, function(evt) { |
|
79
|
|
|
this._doEditNote(evt); |
|
80
|
|
|
})); |
|
81
|
|
|
}, |
|
82
|
|
|
|
|
83
|
|
|
startup: function () { |
|
84
|
|
|
this.inherited(arguments); |
|
85
|
|
|
console.debug('NoteManager::startup'); |
|
86
|
|
|
this._notesDialog.startup(); |
|
87
|
|
|
this._noteGrid.startup(); |
|
88
|
|
|
this._noteGrid.resize(); |
|
89
|
|
|
}, |
|
90
|
|
|
|
|
91
|
|
|
reset: function() { |
|
92
|
|
|
if (this._notesDialog) { this._notesDialog.reset(); } |
|
93
|
|
|
var TrackableMemory = declare([Memory, Trackable]); |
|
94
|
|
|
this._noteStore = new TrackableMemory({ data: [] }); |
|
95
|
|
|
this._noteGrid.set('collection', this._noteStore); |
|
96
|
|
|
}, |
|
97
|
|
|
|
|
98
|
|
|
_createGrid: function(options, node) { |
|
99
|
|
|
var columns = { |
|
100
|
|
|
note: { |
|
101
|
|
|
label: "Note", |
|
102
|
|
|
field: "note", |
|
103
|
|
|
renderCell: function(object) { |
|
104
|
|
|
if (object) { |
|
|
|
|
|
|
105
|
|
|
var div = domConstruct.create('div', {innerHTML: object.note}); |
|
106
|
|
|
return div; |
|
107
|
|
|
} |
|
108
|
|
|
} |
|
109
|
|
|
}, |
|
110
|
|
|
language: { |
|
111
|
|
|
label: "Language", |
|
112
|
|
|
field: "language", |
|
113
|
|
|
formatter: lang.hitch(this, function (value) { |
|
114
|
|
|
var lang = array.filter(this.languageList, function (obj) { |
|
115
|
|
|
return obj.id === value; |
|
116
|
|
|
})[0]; |
|
117
|
|
|
if (lang) { |
|
118
|
|
|
return lang.name; |
|
119
|
|
|
} else { |
|
120
|
|
|
return '-'; |
|
121
|
|
|
} |
|
122
|
|
|
}) |
|
123
|
|
|
}, |
|
124
|
|
|
type: { |
|
125
|
|
|
label: "Type", |
|
126
|
|
|
field: "type", |
|
127
|
|
|
formatter: lang.hitch(this, function (value) { |
|
128
|
|
|
var lang = array.filter(this.listController.getNoteTypes(), function (obj) { |
|
129
|
|
|
return obj.value === value; |
|
130
|
|
|
})[0]; |
|
131
|
|
|
return lang.label; |
|
132
|
|
|
}) |
|
133
|
|
|
}, |
|
134
|
|
|
actions: { |
|
135
|
|
|
label: '', |
|
136
|
|
|
renderCell: lang.hitch(this, function (object) { |
|
137
|
|
|
if (object.id === undefined) { |
|
138
|
|
|
return null; |
|
139
|
|
|
} |
|
140
|
|
|
var div = domConstruct.create('div', {'class': 'dGridHyperlink'}); |
|
141
|
|
|
domConstruct.create('a', { |
|
142
|
|
|
href: '#', |
|
143
|
|
|
title: 'Edit note', |
|
144
|
|
|
className: 'fa fa-pencil', |
|
145
|
|
|
innerHTML: '', |
|
146
|
|
|
style: 'margin-right: 12px;', |
|
147
|
|
|
onclick: lang.hitch(this, function (evt) { |
|
148
|
|
|
evt.preventDefault(); |
|
149
|
|
|
this._editNote(object); |
|
150
|
|
|
}) |
|
151
|
|
|
}, div); |
|
152
|
|
|
domConstruct.create('a', { |
|
153
|
|
|
href: '#', |
|
154
|
|
|
title: 'Remove note', |
|
155
|
|
|
className: 'fa fa-trash', |
|
156
|
|
|
innerHTML: '', |
|
157
|
|
|
onclick: lang.hitch(this, function (evt) { |
|
158
|
|
|
evt.preventDefault(); |
|
159
|
|
|
this._removeRow(object.id); |
|
160
|
|
|
}) |
|
161
|
|
|
}, div); |
|
162
|
|
|
return div; |
|
163
|
|
|
}) |
|
164
|
|
|
} |
|
165
|
|
|
}; |
|
166
|
|
|
|
|
167
|
|
|
var grid = new (declare([OnDemandGrid, DijitRegistry, ColumnResizer]))({ |
|
168
|
|
|
collection: options.collection, |
|
169
|
|
|
columns: columns, |
|
170
|
|
|
showHeader: false, |
|
171
|
|
|
noDataMessage: 'No notes found', |
|
172
|
|
|
loadingMessage: 'Fetching data..' |
|
173
|
|
|
}, node); |
|
174
|
|
|
|
|
175
|
|
|
this._noteGrid = grid; |
|
176
|
|
|
|
|
177
|
|
|
grid.on('dgrid-error', function(event) { |
|
178
|
|
|
console.log(event.error.message); |
|
|
|
|
|
|
179
|
|
|
}); |
|
180
|
|
|
}, |
|
181
|
|
|
|
|
182
|
|
|
getData: function() { |
|
183
|
|
|
var notes = { |
|
184
|
|
|
notes: this._noteStore.data |
|
185
|
|
|
} |
|
186
|
|
|
return notes; |
|
187
|
|
|
}, |
|
188
|
|
|
|
|
189
|
|
|
setConcept: function(concept) { |
|
190
|
|
|
if (concept) { |
|
191
|
|
|
this.concept = concept; |
|
192
|
|
|
this._noteStore = new this.trackableMemory({ data: [] }); |
|
193
|
|
|
array.forEach(this.concept.notes, lang.hitch(this, function (item) { |
|
194
|
|
|
item.id = this._index++; |
|
195
|
|
|
this._noteStore.put(item); |
|
196
|
|
|
})); |
|
197
|
|
|
this._noteGrid.set('collection', this._noteStore); |
|
198
|
|
|
} |
|
199
|
|
|
}, |
|
200
|
|
|
|
|
201
|
|
|
updateLanguages: function(languages) { |
|
202
|
|
|
if (languages) { |
|
203
|
|
|
this.languageList = languages; |
|
204
|
|
|
this._notesDialog.updateLanguages(languages); |
|
205
|
|
|
} |
|
206
|
|
|
}, |
|
207
|
|
|
|
|
208
|
|
|
_addNote: function(evt) { |
|
209
|
|
|
evt ? evt.preventDefault() : null; |
|
210
|
|
|
this._notesDialog.show(); |
|
211
|
|
|
}, |
|
212
|
|
|
|
|
213
|
|
|
_editNote: function(note) { |
|
214
|
|
|
this._notesDialog.show(note); |
|
215
|
|
|
}, |
|
216
|
|
|
|
|
217
|
|
|
_doAddNote: function(note) { |
|
218
|
|
|
var newNote = { |
|
219
|
|
|
language: note.lang, |
|
220
|
|
|
type: note.noteType, |
|
221
|
|
|
note: note.note |
|
222
|
|
|
}; |
|
223
|
|
|
console.log(newNote); |
|
|
|
|
|
|
224
|
|
|
this._noteStore.add(newNote); |
|
225
|
|
|
}, |
|
226
|
|
|
|
|
227
|
|
|
_doEditNote: function(note) { |
|
228
|
|
|
var editNote = { |
|
229
|
|
|
language: note.lang, |
|
230
|
|
|
type: note.noteType, |
|
231
|
|
|
note: note.note, |
|
232
|
|
|
id: note.id |
|
233
|
|
|
}; |
|
234
|
|
|
console.log(editNote); |
|
|
|
|
|
|
235
|
|
|
this._noteStore.put(editNote); |
|
236
|
|
|
}, |
|
237
|
|
|
|
|
238
|
|
|
_removeRow: function(rowId) { |
|
239
|
|
|
this._noteStore.remove(rowId); |
|
240
|
|
|
} |
|
241
|
|
|
}); |
|
242
|
|
|
}); |