-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathscript.js
91 lines (72 loc) · 2.52 KB
/
script.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
document.getElementById('issueInputForm').addEventListener('submit', saveIssue);
/* save issue to local storage */
function saveIssue(e){
var issueId = chance.guid();
var issueStatus = 'Open';
var issueDescription = document.getElementById('issueDescriptionInput').value;
var issueSeverity = document.getElementById('issueSeverityInput').value;
var issueAssignedTo = document.getElementById('issueAssignedToInput').value;
var issue = {
id: issueId,
description: issueDescription,
severity: issueSeverity,
assignedTo: issueAssignedTo,
status: issueStatus
}
if(localStorage.getItem('issues') == null){
var issues = [];
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
}else{
var issues = JSON.parse(localStorage.getItem('issues'));
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
}
document.getElementById('issueInputForm').reset();
displayIssues();
e.preventDefault();
}
/* changing the status of issue */
function setStatusClosed(id){
var issues = JSON.parse(localStorage.getItem('issues'));
for(var i = 0; i < issues.length; i++){
if(issues[i].id === id){
issues[i].status = 'Closed';
}
}
localStorage.setItem('issues', JSON.stringify(issues));
displayIssues();
}
/* deleting the issue */
function deleteIssue(id){
var issues = JSON.parse(localStorage.getItem('issues'));
for(var i = 0; i < issues.length; i++){
if(issues[i].id === id){
issues.splice(i, 1);
}
}
localStorage.setItem('issues', JSON.stringify(issues));
displayIssues();
}
/* display issue */
function displayIssues() {
var issues = JSON.parse(localStorage.getItem('issues'));
var issueList = document.getElementById('issueList');
issueList.innerHTML = '';
for(var i = 0; i < issues.length; i++){
var id = issues[i].id;
var description = issues[i].description;
var severity = issues[i].severity;
var assignedTo = issues[i].assignedTo;
var status = issues[i].status;
issueList.innerHTML += '<div class="well">' +
'<h6>Issue ID: '+ id +'</h6>' +
'<p> <span class="label label-info"> '+ status +' </span> </p>' +
'<h3> '+ description +' </h3>' +
'<p> <span class="glyphicon glyphicon-time"> '+ severity +' </span> </p>' +
'<p> <span class="glyphicon glyphicon-user"> '+ assignedTo +' </span> </p>' +
'<a href="#" onClick="setStatusClosed(\''+ id +'\')" class="btn btn-warning"> Close </a> ' +
'<a href="#" onClick="deleteIssue(\''+ id +'\')" class="btn btn-danger"> Delete </a>' +
'</div>'
}
}