-
Notifications
You must be signed in to change notification settings - Fork 0
/
brain.js
150 lines (124 loc) · 5.13 KB
/
brain.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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
// document.getElementById("issueForm").addEventListener("submit", saveIssue)
function saveIssue(e) {
var empname = document.getElementById("name").value
var empid = document.getElementById("empid").value
var department = document.getElementById("department").value
var description = document.getElementById("description").value
var issueId = chance.guid()
var ticketNo = chance.zip()
var assignedFirst = chance.first()
var assignedLast = chance.last()
var assigned = assignedFirst + " " + assignedLast
var assignedContact = assignedFirst.toLowerCase() + assignedLast.toLowerCase()
var issueStatus = "Open"
// console.log(empname)
// console.log(empid)
// console.log(department)
// console.log(description)
// console.log(issueId)
// console.log(ticketNo)
var issue = {
id: issueId,
ticket: ticketNo,
name: empname,
empid: empid,
dep: department,
desc: description,
assist: assigned,
assistEmail: assignedContact,
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("issueForm").reset()
e.preventDefault()
getAllIssues()
}
var 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))
getAllIssues()
}
var 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))
getAllIssues()
}
var validateBtn = () => {
var empname = document.getElementById("name").value
var empid = document.getElementById("empid").value
var department = document.getElementById("department").value
var description = document.getElementById("description").value
var submitBtn = document.getElementById("mainBtn")
var mustMessage = document.getElementById("must")
if(empname != "" && empid != "" && department != "none" && description != "") {
submitBtn.disabled = false
mustMessage.innerHTML = ""
} else {
submitBtn.disabled = true
mustMessage.innerHTML = "asterick (*) marked fields are required!"
}
}
// var copyTicket = () => {
// var copyText = document.getElementById("ticket")
// navigator.clipboard.writeText(copyText.value)
// }
var getAllIssues = () => {
var issues = JSON.parse(localStorage.getItem("issues"))
var issuesList = document.getElementById("issuesList")
issuesList.innerHTML = ''
for (var i = 0; i < issues.length; i++) {
// var assignedFirst = chance.first()
// var assignedLast = chance.last()
// var assigned = assignedFirst + " " + assignedLast
// var assignedContact = assignedFirst.toLowerCase() + assignedLast.toLowerCase()
// console.log(assignedContact)
if(issues[i].status == "Open") {
issuesList.innerHTML += '<div class="card">' +
// '<h3 class="card-header">' + issues[i].desc + '</h3>' +
'<div class="card-body">'+
'<h6>Issue ID: ' + issues[i].id + '</h6>' +
'<h5>Ticket No.: <span id="ticket">' + issues[i].ticket + '</span></h5>' +
'<p><span class="badge rounded-pill bg-success text-light">' + issues[i].status + '</span></p>' +
'<h3>' + issues[i].desc + '</h3>' +
'<p><b>Issued By</b>: ' + issues[i].name + ' - ' + issues[i].empid + '</p>' +
// '<p><b>Assigned To</b>: <a href="' + assignedContact + '@gmail.com">' + assigned + '</a></p>' +
'<p><b>Assigned To</b>: ' + issues[i].assist + ' (' + issues[i].assistEmail + '@gmail.com)</p>' +
'<button class="btn btn-warning" onclick="setStatusClosed(\''+ issues[i].id +'\')">Close</button> ' +
'<button class="btn btn-danger" onclick="deleteIssue(\''+ issues[i].id +'\')">Delete</button> ' +
// '<button class="btn btn-primary" onclick="copyTicket()"><i class="fas fa-copy"></i></button>'
'</div>' +
'</div><br>'
} else {
issuesList.innerHTML += '<div class="card">' +
'<div class="card-body">'+
'<h6>Issue ID: ' + issues[i].id + '</h6>' +
'<h5>Ticket No.: ' + issues[i].ticket + '</h5>' +
'<p><span class="badge rounded-pill bg-danger text-light">' + issues[i].status + '</span></p>' +
'<h3>' + issues[i].desc + '</h3>' +
'<p><b>Issued By:</b> ' + issues[i].name + ' - ' + issues[i].empid + '</p>' +
// '<p><b>Assigned To</b>: <a href="' + assignedContact + '@gmail.com">' + assigned + '</a></p>' +
'<p><b>Assigned To</b>: ' + issues[i].assist + ' (' + issues[i].assistEmail + '@gmail.com)</p>' +
'<button class="btn btn-danger" onclick="deleteIssue(\''+ issues[i].id +'\')">Delete</button>' +
'</div>' +
'</div><br>'
}
}
}