Limit user roles when register and edit

This commit is contained in:
Amir
2023-03-26 11:27:29 +08:00
parent 1d03b494f5
commit c63365ce73
2 changed files with 111 additions and 2 deletions
@@ -133,7 +133,7 @@
<div class="form-group col-md-9">
@foreach ($allRolesPluck as $namataraf)
<div class="col-4 form-check form-check-inline">
<input class="form-check-input" name="taraf{{$namataraf}}" type="checkbox" id="taraf{{$namataraf}}" value="{{$namataraf}}">
<input class="form-check-input checkbox" name="taraf{{$namataraf}}" onclick="checkboxRoles(this)" type="checkbox" id="taraf{{$namataraf}}" value="{{$namataraf}}">
<label class="form-check-label" for="taraf{{$namataraf}}">{{$namataraf}}</label>
</div>
@endforeach
@@ -150,6 +150,54 @@
</div>
<script>
var allRoles = JSON.parse('<?php echo json_encode($allRolesPluck) ?>');
var allRolesWithTaraf = [];
for (item of allRoles) {
var itemToAdded = "";
itemToAdded = itemToAdded.concat("taraf", item);
allRolesWithTaraf.push(itemToAdded);
}
function checkboxRoles(taraf) {
for (const item of allRolesWithTaraf) {
if (taraf.id == item) {
if (taraf.checked == true) {
if (taraf.id == "tarafadmin") {
$(".checkbox").each(function() {
$(this).not('#tarafadmin').prop("disabled", true);
});
} else if (taraf.id == "tarafaccount") {
$(".checkbox").each(function() {
$(this).not('#tarafaccount').prop("disabled", true);
});
} else if (taraf.id == "tarafcallcenter") {
$(".checkbox").each(function() {
$(this).not('#tarafcallcenter').prop("disabled", true);
});
} else if (taraf.id == "tarafpembida") {
$(".checkbox").each(function() {
$(this).not('#tarafpembida').prop("disabled", true);
});
} else if (taraf.id == "tarafpenilai" || taraf.id == "tarafkhazanah" || taraf.id == "tarafpengurus-cawangan") {
$(".checkbox").each(function() {
$(this).not('#tarafpenilai, #tarafkhazanah, #tarafpengurus-cawangan').prop("disabled", true);
});
} else if (taraf.id == "tarafoperasi" || taraf.id == "tarafjurulelong" || taraf.id == "tarafpengurus-operasi") {
$(".checkbox").each(function() {
$(this).not('#tarafoperasi, #tarafjurulelong, #tarafpengurus-operasi').prop("disabled", true);
});
}
} else {
$(".checkbox").each(function() {
if ($('.checkbox:checked').length == 0) {
$(this).prop("disabled", false);
}
});
}
}
}
}
//Enable tooltips everywhere
$(function() {
$('[data-toggle="tooltip"]').tooltip()
@@ -46,7 +46,7 @@
<div class="form-group col-md-9">
@foreach ($allroles as $namataraf)
<div class="col-4 form-check form-check-inline">
<input class="form-check-input" name="taraf{{$namataraf}}" type="checkbox" id="taraf{{$namataraf}}" value="{{$namataraf}}" @if (in_array($namataraf,$userroles)) checked @endif>
<input class="form-check-input checkbox get-roles" name="taraf{{$namataraf}}" type="checkbox" onclick="checkboxRoles(this)" id="taraf{{$namataraf}}" value="{{$namataraf}}" @if (in_array($namataraf,$userroles)) checked @endif>
{{-- <input type="hidden" id="alltaraf" value=""> --}}
<label class="form-check-label" for="taraf{{$namataraf}}">{{$namataraf}}</label>
</div>
@@ -78,6 +78,67 @@
</div>
</div>
<script>
window.onload = function(){
var x = document.getElementsByClassName("get-roles");
var y = [];
for (z of x) {
if(z.checked)
{
y.push(z);
}
}
checkboxRoles(y[0]);
};
var allRoles = JSON.parse('<?php echo json_encode($allroles) ?>');
var allRolesWithTaraf = [];
for (item of allRoles) {
var itemToAdded = "";
itemToAdded = itemToAdded.concat("taraf", item);
allRolesWithTaraf.push(itemToAdded);
}
function checkboxRoles(taraf) {
for (const item of allRolesWithTaraf) {
if (taraf.id == item) {
if (taraf.checked == true) {
if (taraf.id == "tarafadmin") {
$(".checkbox").each(function() {
$(this).not('#tarafadmin').prop("disabled", true);
});
} else if (taraf.id == "tarafaccount") {
$(".checkbox").each(function() {
$(this).not('#tarafaccount').prop("disabled", true);
});
} else if (taraf.id == "tarafcallcenter") {
$(".checkbox").each(function() {
$(this).not('#tarafcallcenter').prop("disabled", true);
});
} else if (taraf.id == "tarafpembida") {
$(".checkbox").each(function() {
$(this).not('#tarafpembida').prop("disabled", true);
});
} else if (taraf.id == "tarafpenilai" || taraf.id == "tarafkhazanah" || taraf.id == "tarafpengurus-cawangan") {
$(".checkbox").each(function() {
$(this).not('#tarafpenilai, #tarafkhazanah, #tarafpengurus-cawangan').prop("disabled", true);
});
} else if (taraf.id == "tarafoperasi" || taraf.id == "tarafjurulelong" || taraf.id == "tarafpengurus-operasi") {
$(".checkbox").each(function() {
$(this).not('#tarafoperasi, #tarafjurulelong, #tarafpengurus-operasi').prop("disabled", true);
});
}
} else {
$(".checkbox").each(function() {
if ($('.checkbox:checked').length == 0) {
$(this).prop("disabled", false);
}
});
}
}
}
}
function confirm() {
$.confirm({
title: 'Pengesahan',