This repository has been archived by the owner on Dec 25, 2018. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhelpers.js
56 lines (47 loc) · 1.95 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
var util = require('util');
module.exports = function(app) {
app.locals({
errorFor : function(model, property) {
var errorTag = property ?
'<span class="error help-inline">%s</span>':
'<div class="alert alert-danger">%s</div>';
if (model && model.errors) {
if (property && model.errors[property]) {
var error = model.errors[property];
if (error.type == 'required') {
var fieldName = error.path[0].toLocaleUpperCase() + error.path.slice(1);
var message = util.format('%s is required', fieldName);
return util.format(errorTag, message);
}
return util.format(errorTag, error.type || error.message);
}
else if (!property && model.errors.length > 0) {
return util.format(errorTag, model.errors.map(function(e) { return e.message; }).join(','));
}
}
},
display : function(value) {
if (util.isDate(value)) {
return value.toLocaleDateString();
}
else if (typeof value == "boolean") {
if (value === true) return "да";
else return "не";
}
else if (value === undefined)
return "не се знае";
return value;
},
dateAsValue : function(date) {
// check if this is a date
if(util.isDate(date)){
// if so we can format it to RFC3339 specification, 'yyyy-mm-dd'
var day = date.getDate();
var month = date.getMonth() + 1; //Months are zero based
var year = date.getFullYear();
return year + '-' + (month < 10 ? '0'+month: month) + '-' + day;
}
return date;
}
});
};