Repository navigation
Expand file tree
/
Copy pathtest.js
More file actions
122 lines (105 loc) · 3.16 KB
/
Copy pathtest.js
File metadata and controls
122 lines (105 loc) · 3.16 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
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
//variable declarations
var saveHistory = [new Version("John Smith", new Date(Date.now()))];
var validators = [new Validator("Client Executive", "", 0), new Validator("Practice Manager", "", 0), new Validator("Legal", "", 0)];
window.onload = run;
//object definitions
function Validator(title, name, approved) {
this.title = title;
this.name = name;
this.approved = approved;
}
function Version(name, date) {
this.name = name;
this.date = date;
}
//calls initial functions
function run() {
$("#templates").load("http://localhost:8000/template.html", function() {
createFormGroups();
updateApprovalTable();
updateSaveHistory();
})
}
//html generation functions
function createFormGroups() {
$("#formgroups").html("");
var template1 = $('#template1').html();
$("#formgroups").append(Mustache.render(template1, {name: "Project Information"}));
var template2 = $('#template2').html();
for(var index in validators) {
$("#formgroups").append(Mustache.render(template2, {name: validators[index].name, title: validators[index].title}));
if(index == 0) {
$("#formgroups").append('<div class="add-btn-holder"><button type="button" class="btn btn-main" onclick="addValidator()">Add Validator <span class="glyphicon glyphicon-plus"></span></button></div>');
}
}
}
function updateApprovalTable() {
var html = '<tbody>';
for(var index in validators) {
var approved = validators[index].approved;
var glyphiconStyle = '';
if (approved == 0) {
glyphiconStyle += 'glyphicon-remove';
}
else {
glyphiconStyle += 'glyphicon-ok';
if(approved == 1) {
glyphiconStyle += ' soft-approved';
}
}
var template3 = $('#template3').html();
var validator = validators[index]
html += Mustache.render(template3, {name: validator.name, title: validator.title, glyphicon: glyphiconStyle})
}
html += '</tbody>';
$("#approvalTable").html(html);
}
function updateSaveHistory() {
var html = "";
for(var index in saveHistory) {
var save = saveHistory[saveHistory.length - 1 - index];
var add = '<p>' + save.name + ' at ' + save.date.toLocaleTimeString("en-US") + ' on ' + save.date.toLocaleDateString("en-US") + '</p>';
html += add;
}
$("#saveHistory").html(html);
}
//action functions
function updateTitle() {
var x = $("#titleTF");
if(x.val() == "") {
$("#title").html(x.attr('placeholder'));
}
else {
$("#title").html(x.val());
}
}
function saved() {
window.alert("Your Proposal has been saved!");
saveHistory.push(new Version("John Smith", new Date(Date.now())));
updateSaveHistory();
}
function softApprove(elmnt) {
var elmntNum = elmnt.parentElement.parentElement.parentElement.rowIndex;
if(validators[elmntNum].approved == 0) {
validators[elmntNum].approved = 1;
updateApprovalTable();
}
}
function hardApprove() {
validators[0].approved = 2;
updateApprovalTable();
}
function updateName() {
for(var index in validators) {
var name = document.getElementsByClassName("validatorName")[index].value;
validators[index].name = name;
}
updateApprovalTable();
}
function addValidator() {
var title = prompt("Enter the Title of an additional Validator:");
if(title.replace(/\s/g, '') != "") {
validators.push(new index(title, "", 0));
run();
}
}