59 lines
3.2 KiB
JavaScript
59 lines
3.2 KiB
JavaScript
function editUser(id) {
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '../Backend/controller/getUser.php',
|
|
data: { id: id },
|
|
success:function (data) {
|
|
Swal.fire({
|
|
title: 'Rediger Bruger',
|
|
html: '<label class="col-md-12 col-form-label text-md-right">Lad password forbliv blank, hvis det ikke skal ændres</label><div class="form-group row mb-4 justify-content-center"><label for="name" class="col-md-3 col-form-label text-md-right">Navn</label><div class="col-md-9"><input type="text" class="form-control" id="name" name="name" value="' + data[0].name + '" maxlength="255" required autofocus></div></div><div class="form-group row mb-4 justify-content-center"><label for="title" class="col-md-3 col-form-label text-md-right">Password</label><div class="col-md-9"><input type="password" class="form-control" id="password" name="password" maxlength="255" required autofocus></div></div><div class="form-group row mb-4 justify-content-center"><label for="title" class="col-md-3 col-form-label text-md-right">Confirm Password</label><div class="col-md-9"><input type="password" class="form-control" id="confirmPassword" name="confirmPassword" maxlength="255" required autofocus></div></div>',
|
|
showCancelButton: true,
|
|
confirmButtonColor: '#3085d6',
|
|
cancelButtonColor: '#d33',
|
|
confirmButtonText: 'Rediger',
|
|
focusConfirm: false,
|
|
preConfirm: () => {
|
|
const name = Swal.getPopup().querySelector('#name').value
|
|
const pass = Swal.getPopup().querySelector('#password').value
|
|
const conpass = Swal.getPopup().querySelector('#confirmPassword').value
|
|
if (!name) {
|
|
Swal.showValidationMessage(`Brugeren skal have et navn!`)
|
|
} else if (pass != conpass) {
|
|
Swal.showValidationMessage(`Password er ikke ens!`)
|
|
} else {
|
|
data.name = name;
|
|
data.password = pass;
|
|
}
|
|
return {name: name, pass: pass, conpass: conpass}
|
|
}
|
|
}).then((result) => {
|
|
if (result.isConfirmed)
|
|
$.ajax({
|
|
type: 'POST',
|
|
url: '../Backend/controller/updateUser.php',
|
|
data: {'id':id, 'upName': data.name, 'upPassword': data.password},
|
|
success:function () {
|
|
Swal.fire(
|
|
'Brugeren er redigeret!',
|
|
'',
|
|
'success'
|
|
).then(function() {
|
|
document.getElementById(id).children[0].innerHTML = data.name;
|
|
})
|
|
},
|
|
error:function (data) {
|
|
Swal.fire(
|
|
'Brugeren kunne ikke blive redigeret',
|
|
'',
|
|
'error'
|
|
)
|
|
}
|
|
});
|
|
})
|
|
},
|
|
error:function (data) {
|
|
console.log(data);
|
|
}
|
|
});
|
|
/**/
|
|
} |