/
list-help-messages-widget.js
55 lines (52 loc) · 1.72 KB
/
list-help-messages-widget.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
import { Template } from 'meteor/templating';
import { ReactiveVar } from 'meteor/reactive-var';
import { _ } from 'meteor/erasaur:meteor-lodash';
import { HelpMessages } from '../../../api/help/HelpMessageCollection';
import { removeItMethod } from '../../../api/base/BaseCollection.methods';
import * as FormUtils from '../form-fields/form-field-utilities.js';
Template.List_Help_Messages_Widget.onCreated(function listHelpMessagesOnCreated() {
this.itemCount = new ReactiveVar(25);
this.itemIndex = new ReactiveVar(0);
});
Template.List_Help_Messages_Widget.helpers({
helpMessages() {
const items = HelpMessages.find({}, { sort: { routeName: 1 } }).fetch();
const startIndex = Template.instance().itemIndex.get();
const endIndex = startIndex + Template.instance().itemCount.get();
return _.slice(items, startIndex, endIndex);
},
count() {
return HelpMessages.count();
},
deleteDisabled() {
return '';
},
descriptionPairs(helpMessage) {
return [
{ label: 'Route Name', value: helpMessage.routeName },
{ label: 'Title', value: helpMessage.title },
{ label: 'Text', value: helpMessage.text },
];
},
getItemCount() {
return Template.instance().itemCount;
},
getItemIndex() {
return Template.instance().itemIndex;
},
getCollection() {
return HelpMessages;
},
});
Template.List_Help_Messages_Widget.events({
'click .jsUpdate': FormUtils.processUpdateButtonClick,
'click .jsDelete': function (event, instance) {
event.preventDefault();
const id = event.target.value;
removeItMethod.call({ collectionName: 'HelpMessageCollection', instance: id }, (error) => {
if (error) {
FormUtils.indicateError(instance, error);
}
});
},
});