-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathapplication.js
98 lines (78 loc) · 2.11 KB
/
application.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
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
//
var app = new function()
{
this.el = document.getElementById('applications');
this.applications = [];
this.FetchAll = function()
{
var data = '';
if (this.applications.length > 0)
{
for (i = 0; i < this.applications.length; i++)
{
data += '<tr>';
data += '<td>'+(i+1)+". " + this.applications[i] + '</td>';
data += '<td><button onclick="app.Edit(' + i + ')"">Edit</button></td>';
data += '<td><button onclick="app.Delete(' + i + ')"">X</button></td>';
data += '</tr>';
}
}
this.Count(this.applications.length);
return this.el.innerHTML = data;
};
this.Add = function ()
{
el = document.getElementById('addApplication');
var task = el.value;
if (task)
{
this.applications.push(task.trim());
el.value = '';
this.FetchAll();
}
};
this.Edit = function (item)
{
var el = document.getElementById('editApplications');
el.value = this.applications[item];
document.getElementById('edit-box').style.display = 'block';
self = this;
document.getElementById('save-edit').onsubmit = function()
{
var task = el.value;
if (task)
{
self.applications.splice(item, 1, task.trim());
self.FetchAll();
CloseInput();
}
}
};
this.Delete = function (item)
{
this.applications.splice(item, 1);
this.FetchAll();
};
this.Count = function(data)
{
var el = document.getElementById('counter');
var name = 'Applicants';
if (data)
{
if(data ==1)
{
name = 'Applicant'
}
el.innerHTML = data + ' ' + name ;
}
else
{
el.innerHTML = 'No ' + name;
}
};
}
app.FetchAll();
function CloseInput()
{
document.getElementById('edit-box').style.display = 'none';
}