-
Notifications
You must be signed in to change notification settings - Fork 0
/
helpers.js
56 lines (52 loc) · 1.42 KB
/
helpers.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
exports.helpers = {
nameAndVersion: function(name, version) {
return name + ' v' + version;
},
appName: 'node-chat',
version: '0.1'
};
// flash message class
function FlashMessage(type, msgs) {
this.type = type;
this.messages = typeof msgs === String ? [msgs] : msgs;
}
FlashMessage.prototype = {
getIcon: function() {
switch (this.type) {
case 'info':
return 'ui-icon-info';
case 'error':
return 'ui-icon-error';
}
},
getStateClass: function() {
switch (this.type) {
case 'info':
return 'ui-state-highlight';
case 'error':
return 'ui-state-error';
}
},
toHtml: function() {
return '<div class="ui-widget flash">' +
'<div style="padding: 0pt 0.7em;" class="' + this.getStateClass() + ' ui-corner-all">' +
'<p><span style="float: left; margin-right: 0.3em;" class="ui-icon ' + this.getIcon() + '"></span>' +
this.messages.join('<br />') + '</p>' +
'</div></div>';
}
};
exports.dynamicHelpers = {
flashMessages: function(req, res) {
var html = '';
[ 'info', 'error' ].forEach(function(type) {
var messages = req.flash(type);
if (messages.length > 0) {
html += new FlashMessage(type, messages).toHtml();
}
});
return html;
},
isLoggedIn: function(req, res){
return (req.session.user_id);
}
};