-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathhelpers.js
58 lines (56 loc) · 1.7 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
57
58
var config = require('./config');
module.exports = Helper = {
getConfiguration : function(key) {
return config[key];
},
formFor : function(reference, path) {
if (!reference) throw new Error('invalid reference');
var form = '<form action="' + path + '/';
if (!reference.isNew) form += reference.id;
form += '" method="post">';
if (!reference.isNew) form += '\n' + Helper.hiddenField('_method', 'put');
return form;
},
endForm : function() {
return '</form>';
},
labelFor : function(fieldName) {
var name = fieldName.toUpperCase();
return '<label for="' + name + '"><p>' + name + ':</p>';
},
endLabel : function() {
return '</label>';
},
hiddenField: function(fieldName, fieldValue) {
var formField = '<input type="hidden" ';
formField += 'name="' + fieldName +'" ';
if (fieldValue) formField += 'value="' + fieldValue + '" ';
formField += '/>';
return formField;
},
textField : function(fieldName, fieldValue, options) {
var formField = Helper.labelFor(fieldName);
formField += '<input type="text" ';
formField += 'name="' + fieldName +'" ';
if (fieldValue) formField += 'value="' + fieldValue + '" ';
for(var option in options) {
formField += option + '="' + options[option] + '" ';
}
formField += '/>';
formField += Helper.endLabel();
return formField;
},
textArea: function(fieldName, fieldValue, options) {
var formField = Helper.labelFor(fieldName);
formField += '<textarea ';
formField += 'name="' + fieldName +'" ';
for(var option in options) {
formField += option + '="' + options[option] + '" ';
}
formField += '>';
if (fieldValue) formField += fieldValue;
formField += '</textarea>';
formField += Helper.endLabel();
return formField;
}
}