Module Permissions

Set permissions for profile of a system by checkbox checks or uncheck

by lfinfor

HTML

<!DOCTYPE html>
<html>
    <head>
        <title></title>
        <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/css/bootstrap.min.css">
        <script src="https://ajax.googleapis.com/ajax/libs/jquery/3.4.1/jquery.min.js"></script>
        <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.16.0/umd/popper.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.4.1/js/bootstrap.min.js"></script>
        <style type="text/css">

        </style>
    </head>
    <body>
        <div id="permission-clients">
            <div class="col-md-6  hide-1">
                <div class="box-modules">
                    <div class="title-modules">Permissões em Endereços</div>
                    <div class="col-12 iten-modules">
                        <input type="checkbox" id="check_all1" class="filled-in">
                        <label for="check_all1">Todas as permissões</label>
                    </div>
                    <div class="col-12 iten-modules">
                        <input type="checkbox" id="address-index" name="permissions[]" class="filled-in" onclick="1" value="1">
                        <label for="address-index">Página "base"</label>
                    </div>
                    <div class="col-12 iten-modules">
                        <input type="checkbox" id="address-all" name="permissions[]" class="filled-in" onclick="1" value="2">
                        <label for="address-all">Listar</label>
                    </div>
                    <div class="col-12 iten-modules">
                        <input type="checkbox" id="address-view" name="permissions[]" class="filled-in" onclick="1" value="3">
                        <label for="address-view">Ver informações de um único item</label>
                    </div>
                    <div class="col-12 iten-modules">
                        <input type="checkbox" id="address-store" name="permissions[]" class="filled-in"...

JavaScript

for (var i = 1; i <= 20; i++) {
            $("#check_all" + i).click(function() {
                // Address
                if ($(this).attr("id") == "check_all1") {
                    if (this.checked) {
                        changeCheckboxAll("address", "true");
                        $("#city-all").prop("checked", true);
                        $("#state-all").prop("checked", true);
                        $("#country-all").prop("checked", true);
                    } else {
                        $("#city-all").prop("checked", false);
                        $("#state-all").prop("checked", false);
                        $("#country-all").prop("checked", false);
                        changeCheckboxAll("address", "false");
                    }
                }
            });

            $("#check_all" + i).click(function() {
                // Client 1, 2, 10, 14
                if ($(this).attr("id") == "check_all14") {
                    if (this.checked) {
                        changeCheckboxAll("client", "true");
                        $("#address-all").prop("checked", true);
                        $("#address-store").prop("checked", true);
                        $("#address-update").prop("checked", true);
                        $("#answer-store").prop("checked", true);
                        $("#answer-update").prop("checked", true);
                        $("#profile-all").prop("checked", true);
                    } else {
                        changeCheckboxAll("client", "false");
                        $("#address-all").prop("checked", false);
                        $("#address-store").prop("checked", false);
                        $("#address-update").prop("checked", false);
                        $("#answer-store").prop("checked", false);
                        $("#answer-update").prop("checked", false);
                        $("#profile-all").prop("checked", false);
                    }
                }
           ...