Skip to content
Snippets Groups Projects
Commit cecf7c18 authored by Seb Barnard's avatar Seb Barnard :speech_balloon:
Browse files

Added validation to staff member input

parent 7aad4cef
No related branches found
No related tags found
3 merge requests!114LoggingService service class, new method to add a log to the "Logs" table when...,!104Branch Update,!103Issue thirty four
...@@ -3,25 +3,25 @@ function submit(shopId, email={"value":""}){ ...@@ -3,25 +3,25 @@ function submit(shopId, email={"value":""}){
if(email.parentElement.children[0].classList.contains("subtitle")){ if(email.parentElement.children[0].classList.contains("subtitle")){
emailValue = email.parentElement.children[0].innerHTML emailValue = email.parentElement.children[0].innerHTML
email.parentElement.parentElement.remove()
}else{ }else{
emailValue = email.parentElement.children[0].value emailValue = email.parentElement.children[0].value
document.getElementById("staffManagement").innerHTML+= emailArray = []
`<div id="staffManagement">
<div class="staffManagementContainer"> document.getElementsByName("staffEmail").forEach(x => emailArray.push(x.innerHTML))
<p class="subtitle is-6" style="width:50%; margin-bottom: 0">${emailValue}</p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid black" if(emailArray.includes(emailValue)){
onclick="submit(${document.getElementById("shopId").value},this);"> document.getElementById("emailErrorField").innerHTML = "User already added"
<span class="icon is-small"> return
<i class="fas fa-times is-danger"></i> }
</span> }
</button>
</div> if(emailValue == ""){
<p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"></p> document.getElementById("emailErrorField").innerHTML = "Field blank"
</div>` return
} }
let params = "shopId="+ shopId let params = "shopId="+ shopId
if(emailValue=="") { if(emailValue=="") {
params += "&email=" + document.getElementById("emailAddress").value params += "&email=" + document.getElementById("emailAddress").value
...@@ -33,7 +33,27 @@ function submit(shopId, email={"value":""}){ ...@@ -33,7 +33,27 @@ function submit(shopId, email={"value":""}){
xhttp.onload = function() { xhttp.onload = function() {
if (xhttp.readyState === 4 && xhttp.status === 200) { if (xhttp.readyState === 4 && xhttp.status === 200) {
var response = xhttp.responseText var response = xhttp.responseText
if (response == "success"){ if (response == "OK" || response == "USER REMOVED"){
if(email.parentElement.children[0].classList.contains("subtitle")){
email.parentElement.parentElement.remove()
}else{
document.getElementById("staffManagement").innerHTML+=
`<div id="staffManagement">
<div class="staffManagementContainer">
<p class="subtitle is-6" style="width:50%; margin-bottom: 0">${emailValue}</p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid"
onclick="submit(${document.getElementById("shopId").value},this);">
<span class="icon is-small">
<i class="fas fa-times is-danger"></i>
</span>
</button>
</div>
<p id="blackLine" class="subtitle is-6" style="border-bottom: 1px solid #00b89c; margin-bottom:1%; width:50%"></p>
</div>`
}
}else{ }else{
} }
} else { } else {
......
...@@ -17,11 +17,12 @@ ...@@ -17,11 +17,12 @@
</span> </span>
</button> </button>
</div> </div>
<p class="help is-danger" id="emailErrorField"></p>
<p><br>Current Admins</p> <p><br>Current Admins</p>
<div id="staffManagement"></div> <div id="staffManagement"></div>
<div id="staffManagement" th:each="user : ${staffMembers}"> <div id="staffManagement" th:each="user : ${staffMembers}">
<div class="staffManagementContainer"> <div class="staffManagementContainer">
<p class="subtitle is-6" th:text="${user.userEmail}" style="width:50%; margin-bottom: 0"></p> <p class="subtitle is-6" name="staffEmail" th:text="${user.userEmail}" style="width:50%; margin-bottom: 0"></p>
<button class="button is-danger is-outlined" style="border-bottom: 1px solid black" th:onclick="'submit('+${shop.shopId}+',this);'"> <button class="button is-danger is-outlined" style="border-bottom: 1px solid black" th:onclick="'submit('+${shop.shopId}+',this);'">
<span class="icon is-small"> <span class="icon is-small">
<i class="fas fa-times is-danger"></i> <i class="fas fa-times is-danger"></i>
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment