-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.js
86 lines (81 loc) · 3.05 KB
/
main.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
function saveIssue(e){
//getting the input values from the form
var issueId = chance.guid(); //Unique issue identifier //internet required to call chancejs
var issueDesc = document.getElementById('issueDesc').value;
var issueSeverity = document.getElementById('issueSev').value;
var issueAssignTo = document.getElementById('issueAssign').value;
var issueStatus = 'Open';
var today = new Date();
//Json type object created to store it into localStroage
var issue = {
id:issueId,
description:issueDesc,
severity:issueSeverity,
assignTo:issueAssignTo,
status:issueStatus,
date: today.toLocaleString("en-US")
}
var issues = [];
//Verifying the item in localStorage
if(localStorage.issues){
issues = JSON.parse(localStorage.getItem('issues'));
}
issues.push(issue);
localStorage.setItem('issues', JSON.stringify(issues));
//Reseting the input form
document.getElementById('issueInputForm').reset();
//fetchIssues() function called to reflect changes
fetchIssues();
//e.preventDefault() will prevent the form from the default submit action
e.preventDefault();
}
function fetchIssues(){
var issues = [];
//Verifying the item in localStorage
if(localStorage.issues){
//parsing the storage JSON data
issues = JSON.parse(localStorage.getItem('issues'));
}
var issuesList = document.getElementById('issueList');
issuesList.innerHTML = '';
//generating html for each issue card
for(var i=0; i<issues.length; i++){
var id = issues[i].id;
var desc = issues[i].description;
var severity = issues[i].severity;
var assignTo = issues[i].assignTo;
var status = issues[i].status;
var date = issues[i].date;
issuesList.innerHTML += '<div class="well bg-info">' +
'<h6> ISSUE ID: #' + id + '</h6>' +
'<p><span class="label label-info">' + status + '</span> '+
'<span class="label label-info">' + date +'</span></p>' +
'<h4>' + desc + '</h4>' +
'<p><span class="glyphicon glyphicon-time"></span> ' + severity + ' '+ '<span class="glyphicon glyphicon-user"></span> ' + assignTo + '</p>' +
'<a href="#" class="btn btn-warning" onClick="setStatusClosed(\''+ id +'\')">Close</a>' +
' <a href="#" class="btn btn-danger" onClick="deleteIssue(\'' + id + '\')">Delete</a>' +
'</div>';
}
}
function setStatusClosed(id){
//parsing the JSON data
var issues = JSON.parse(localStorage.getItem('issues'));
for(var x = 0; x<issues.length; x++){
if(issues[x].id == id){
issues[x].status = "Closed";
}
}
localStorage.setItem('issues',JSON.stringify(issues));
fetchIssues();
}
function deleteIssue(id){
var issues = JSON.parse(localStorage.getItem('issues'));
for(var n = 0; n<issues.length; n++){
//identifying the particular issue id to delete
if(issues[n].id == id){
issues.splice(n,1);
}
}
localStorage.setItem('issues',JSON.stringify(issues));
fetchIssues();
}