This repository was archived by the owner on May 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathhandlebarsSetup.js
More file actions
94 lines (93 loc) · 3.34 KB
/
handlebarsSetup.js
File metadata and controls
94 lines (93 loc) · 3.34 KB
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
exports.nonRequestHelper = {
jsonStringify: function (value) {
return JSON.stringify(value)
}, uriencode: function (item) {
return encodeURIComponent(item)
}, lastElement: function (array) {
return array.reverse()[0]
}, withLastElement: function (array, opts) {
if (array)
return opts.fn(array.reverse()[0])
else
return opts.inverse(this)
}, inArrayId: function (array, id, opts) {
var lookup = {}
if (array) {
for (var i = 0; i < array.length; i++) {
lookup[array[i]._id] = array[i]
}
}
if (lookup[id])
return opts.fn(this)
else
return opts.inverse(this)
}, formatWorker: function (worker) {
if (worker) {
if (worker.firstname && worker.lastname) {
return worker.firstname + '\u00A0' + worker.lastname
} else {
return worker
}
}
}, withValue: function (data, opts) {
if (data.value) {
return opts.fn(data.value)
} else {
return opts.fn(data)
}
}, isAuthentication: function (data, opts) {
if (process.env.AUTHENTICATIONMODE === data) {
return opts.fn(true)
} else {
return opts.fn(false)
}
}
}
exports.requestHelpers = function (hbs) {
return function (req, res, next) {
hbs.helpers.isAdmin = function (opts) {
if (req.session['isAdmin'])
return opts.fn(this)
else
return opts.inverse(this)
}
hbs.helpers.loggedonuser = function () {
return req.session['username']
}
hbs.helpers.currentusername = function () {
if (req.session['fullname'])
return req.session['fullname']
return req.session['username']
}
hbs.helpers.localize = function (key) {
return req.localize(key)
}
hbs.helpers.workerIsNotAssigneeOption = function (worker, assignee, opts) {
var res = '<option value="' + worker._id + '">' + worker.firstname + ' ' + worker.lastname + (worker.department ? ' (' + req.localize(worker.department) + ')' : '') + '</option>'
if (assignee) {
if (!(worker != assignee && worker._id != assignee._id)) {
res = ''
}
}
return new hbs.handlebars.SafeString(res)
}
hbs.helpers.commentList = function (input) {
var res = '<ul class="list-unstyled">'
for (item in input) {
res +=
'<li><blockquote>' + input[item].commentvalue +
'<footer>' + hbs.helpers.formatWorker(input[item].creator) + ' — ' + hbs.handlebars.helpers.formatDate(input[item].created, '%d.%m.%y %H:%M') + '</footer></blockquote></li>'
}
res += '</ul>'
return new hbs.handlebars.SafeString(res)
}
hbs.helpers.currentUserIsAssignee = function (assignee, opts) {
if (assignee && (assignee == req.session['username'] || assignee._id && assignee._id == req.session['username'])) {
return opts.inverse(this)
} else {
return opts.fn(this)
}
}
next()
}
}