-
Notifications
You must be signed in to change notification settings - Fork 0
/
index.js
87 lines (68 loc) · 2.63 KB
/
index.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
document.getElementById('issueInputForm').addEventListener('submit', saveIssue);
function saveIssue(e) {
var issueId = chance.guid();
var issueDesc = document.getElementById('issueDescInput').value;
var issueSeverity = document.getElementById('issueSeverityInput').value;
var issueAssignedTo = document.getElementById('issueAssignedToInput').value;
var issueStatus = 'Open';
var issue = {
id: issueId,
description: issueDesc,
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();
fetchIssues();
e.preventDefault();
}
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));
fetchIssues();
}
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));
fetchIssues();
}
function fetchIssues () {
var issues = JSON.parse(localStorage.getItem('issues'));
var issuesList = document.getElementById('issuesList');
issuesList.innerHTML = '';
for (var i = 0; i < issues.length; i++) {
var id = issues[i].id;
var desc = issues[i].description;
var severity = issues[i].severity;
var assignedTo = issues[i].assignedTo;
var status = issues[i].status;
issuesList.innerHTML += '<div class="well">'+
'<h6>Issue ID: ' + id + '</h6>'+
'<p><span class="label label-info">' + status + '</span></p>'+
'<h3>' + desc + '</h3>'+
'<p><span class="glyphicon glyphicon-time"></span> ' + severity + ' '+
'<span class="glyphicon glyphicon-user"></span> ' + assignedTo + '</p>'+
'<a href="#" class="btn btn-warning" onclick="setStatusClosed(\''+id+'\')">Close</a> '+
'<a href="#" class="btn btn-danger" onclick="deleteIssue(\''+id+'\')">Delete</a>'+
'</div>';
}
}