【ツール】パーミッションの数字表記と記号表記

  • URLをコピーしました!
ユーザー読み込み書き込み実行
所有者
グループメンバー
その他

000

———

数字表記:読み込み=4、書き込み=2、実行=1、なし=0
記号表記:読み込み=r、書き込み=w、実行=x、なし=-

<table>
    <tbody><tr><td>ユーザー</td><td>読み込み</td><td>書き込み</td><td>実行</td></tr>
    <tr><td>所有者</td><td><input type="checkbox" id="owner_read"></td><td><input type="checkbox" id="owner_write"></td><td><input type="checkbox" id="owner_run"></td></tr>
    <tr><td>グループメンバー</td><td><input type="checkbox" id="member_read"></td><td><input type="checkbox" id="member_write"></td><td><input type="checkbox" id="member_run"></td></tr>
    <tr><td>その他</td><td><input type="checkbox" id="other_read"></td><td><input type="checkbox" id="other_write"></td><td><input type="checkbox" id="other_run"></td></tr>

</tbody></table>

<p><label>数字表記:</label><span id="permission_number">000</span></p>
<p><label>記号表記:</label><span id="permission_symbol">---------</span></p>

<script> 

    $('input[type="checkbox"]').change(function(){
        let owner_read_num; let owner_read_sym;
        let owner_write_num; let owner_write_sym;
        let owner_run_num; let owner_run_sym;

        if($("#owner_read").prop("checked")){
            owner_read_num = 4;
            owner_read_sym = "r";
        }else{
            owner_read_num = 0;
            owner_read_sym = "-";
        }
        if($("#owner_write").prop("checked")){
            owner_write_num = 2;
            owner_write_sym = "w";
        }else{
            owner_write_num = 0;
            owner_write_sym = "-";
        }
        if($("#owner_run").prop("checked")){
            owner_run_num = 1;
            owner_run_sym = "x";
        }else{
            owner_run_num = 0;
            owner_run_sym = "-";
        }

        let owner_num = owner_read_num + owner_write_num + owner_run_num;
        let owner_sym = owner_read_sym + owner_write_sym + owner_run_sym;

        let member_read_num; let member_read_sym;
        let member_write_num; let member_write_sym;
        let member_run_num; let member_run_sym;

        if($("#member_read").prop("checked")){
            member_read_num = 4;
            member_read_sym = "r";
        }else{
            member_read_num = 0;
            member_read_sym = "-";
        }
        if($("#member_write").prop("checked")){
            member_write_num = 2;
            member_write_sym = "w";
        }else{
            member_write_num = 0;
            member_write_sym = "-";
        }
        if($("#member_run").prop("checked")){
            member_run_num = 1;
            member_run_sym = "x";
        }else{
            member_run_num = 0;
            member_run_sym = "-";
        }

        let group_num = member_read_num + member_write_num + member_run_num;
        let group_sym = member_read_sym + member_write_sym + member_run_sym;

        let other_read_num; let other_read_sym;
        let other_write_num; let other_write_sym;
        let other_run_num; let other_run_sym;

        if($("#other_read").prop("checked")){
            other_read_num = 4;
            other_read_sym = "r";
        }else{
            other_read_num = 0;
            other_read_sym = "-";
        }
        if($("#other_write").prop("checked")){
            other_write_num = 2;
            other_write_sym = "w";
        }else{
            other_write_num = 0;
            other_write_sym = "-";
        }
        if($("#other_run").prop("checked")){
            other_run_num = 1;
            other_run_sym = "x";
        }else{
            other_run_num = 0;
            other_run_sym = "-";
        }

        let other_num = other_read_num + other_write_num + other_run_num;
        let other_sym = other_read_sym + other_write_sym + other_run_sym;

        let permission_num = String(owner_num) + String(group_num) + String(other_num);
        let permission_sym = owner_sym + group_sym + other_sym;

        $("#permission_number").text(permission_num);
        $("#permission_symbol").text(permission_sym);

    });

</script>
よかったらシェアしてね!
  • URLをコピーしました!

コメント

コメントする

目次