editor.jsp 9.58 KB
Newer Older
1
<%@ taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
Matija Obreza's avatar
Matija Obreza committed
2 3
<!DOCTYPE html>

4
<%@ include file="/WEB-INF/jsp/init.jsp" %>
Matija Obreza's avatar
Matija Obreza committed
5 6 7

<html>
<head>
8
    <title><spring:message code="acl.page.permission-manager"/></title>
Matija Obreza's avatar
Matija Obreza committed
9 10
</head>
<body>
11
<h1>
Matija Obreza's avatar
Matija Obreza committed
12 13
    <small><c:out value="${aclObjectIdentity.aclClass.aclClass}"/></small>
    <c:out value="${aclObjectIdentity.objectIdIdentity}"/>
14 15 16
</h1>


Matija Obreza's avatar
Matija Obreza committed
17
<p><spring:message code="acl.owner"/>: <c:out value="${jspHelper.userByUuid(aclObjectIdentity.ownerSid.sid).email}"/></p>
18 19 20 21 22 23 24 25 26 27 28 29 30
<table class="accessions">
    <thead>
    <tr>
        <td><spring:message code="acl.sid" /></td>
        <c:forEach items="${aclPermissions}" var="aclPermission">
            <td><spring:message code="acl.permission.${aclPermission.mask}" /></td>
        </c:forEach>
    </tr>
    </thead>
    <tbody>

    <c:forEach items="${aclSids}" var="aclSid" varStatus="status">
        <tr class="${status.count % 2 == 0 ? 'even' : 'odd'}">
Alexander Basov's avatar
Alexander Basov committed
31 32 33 34 35 36 37 38 39 40
            <td>
                <c:choose>
                    <c:when test="${aclSid.principal == true}">
                        <c:out value="${jspHelper.userByUuid(aclSid.sid).email}"/>
                    </c:when>
                    <c:when test="${aclSid.principal == false}">
                        <c:out value="${aclSid.sid}"/>
                    </c:when>
                </c:choose>
            </td>
41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68

            <input type="hidden" name="aclSid" class="aclSid" value="${aclSid.sid}"/>

            <c:forEach items="${aclPermissions}" var="aclPermission">
                <td><input type="checkbox" value="1" class="check"
                           name="permissionValue${aclPermission.mask}"
                           id="permissionValue${aclPermission.mask}" disabled="disabled"
                    ${aclEntries[aclSid.sid][aclPermission.mask] ? 'checked' : '' }/></td>
            </c:forEach>

            <td><input type="button" class="btn btn-primary edit" value="<spring:message code="edit" />" /></td>
            <td><input type="submit" class="btn btn-primary save" style="display: none"  value="<spring:message code="save"/>">
                <button class="btn btn-default cancel" style="display: none"><spring:message code="cancel"/></button></td>
        </tr>
    </c:forEach>

    <tr id="permissionAdder" class="${aclSids.size()-1 % 2 == 0 ? 'even' : 'odd'}">
        <td><input type="text" class="required form-control" name="uuid" id="autocomplete" /></td>

        <c:forEach items="${aclPermissions}" var="aclPermission">
            <td><input type="checkbox" id="autoCheck${aclPermission.mask}" value="1"
                       name="acPermissionValue${aclPermission.mask}"
                ${aclEntries[aclSid.sid][aclPermission.mask] ? 'checked' : '' }/></td>
        </c:forEach>

        <td><input type="button" class="btn btn-primary" value="<spring:message code="add" />" /></td>
        <td></td>
    </tr>
Alexander Basov's avatar
Alexander Basov committed
69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87
    <tr id="permissionAdderByRole" class="${aclSids.size()-1 % 2 == 0 ? 'even' : 'odd'}">
        <td>
            <select class="required form-control" name="uuid" id="" title="roles">
                <option disabled="disabled" selected="selected">SELECT ROLE</option>
                <c:forEach var="role" items="${roles}">
                    <option value="${role}">${role}</option>
                </c:forEach>
            </select>
        </td>

        <c:forEach items="${aclPermissions}" var="aclPermission">
            <td><input type="checkbox" id="rAutoCheck${aclPermission.mask}" value="1"
                       name="acPermissionValue${aclPermission.mask}"
                ${aclEntries[aclSid.sid][aclPermission.mask] ? 'checked' : '' }/></td>
        </c:forEach>

        <td><input type="button" class="btn btn-primary" value="<spring:message code="add" />"/></td>
        <td></td>
    </tr>
88 89 90 91 92
    </tbody>
</table>

<a href="<c:url value="${backUrl}" />" class="btn btn-default"><spring:message code="cancel" /></a>

Matija Obreza's avatar
Matija Obreza committed
93
<content tag="javascript">
94 95
<script type="text/javascript">
    jQuery(document).ready(function() {
Alexander Basov's avatar
Alexander Basov committed
96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137
        if ($('#permissionAdderByRole select')[0].value == 'SELECT ROLE') {
            $("#permissionAdderByRole input[type=button]").prop('disabled', true);
        }
        $('#permissionAdderByRole select').on('change', function () {
            if ($('#permissionAdderByRole select')[0].value == 'SELECT ROLE') {
                $("#permissionAdderByRole input[type=button]").prop('disabled', true);
            } else {
                $("#permissionAdderByRole input[type=button]").prop('disabled', false);
            }
        });
        $("#permissionAdderByRole input[type=button]").on("click", function (a, b, c) {

            var object = {
                "oid": ${aclObjectIdentity.objectIdIdentity},
                "clazz": "${aclObjectIdentity.aclClass.aclClass}",
                "uuid": $('#permissionAdderByRole select')[0].value,
                "principal": false,
                "create": $("#rAutoCheck4").is(':checked'),
                "read": $("#rAutoCheck1").is(':checked'),
                "write": $("#rAutoCheck2").is(':checked'),
                "delete": $("#rAutoCheck8").is(':checked'),
                "manage": $("#rAutoCheck16").is(':checked')
            };

            $.ajax("<c:url value="/json/v0/permission/add" />", {
                type: 'POST',
                dataType: 'json',
                contentType: 'application/json; charset=utf-8',
                data: (object == null ? null : JSON.stringify(object)),
                beforeSend: function (xhr) {

                },
                success: function (respObject) {
                    window.location.reload();
                    console.log(respObject);
                },
                error: function (jqXHR, textStatus, errorThrown) {
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        });
138 139 140 141 142 143 144 145 146 147
        $("#permissionAdder input[type=button]").on("click", function(a,b,c) {

            var create=$("#autoCheck4").is(':checked');
            var read=$("#autoCheck1").is(':checked');
            var write=$("#autoCheck2").is(':checked');
            var remove=$("#autoCheck8").is(':checked');
            var manage=$("#autoCheck16").is(':checked');

            var object = { "oid": ${aclObjectIdentity.objectIdIdentity},"clazz":"${aclObjectIdentity.aclClass.aclClass}","uuid":$("#permissionAdder input[type=text]")[0].value,"principal":true,
                "create":create,"read":read,"write":write,"delete":remove,"manage":manage};
148
            //debugger;
Matija Obreza's avatar
Matija Obreza committed
149
            $.ajax("<c:url value="/json/v0/permission/add" />", {
150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179
                type : 'POST',
                dataType : 'json',
                contentType: 'application/json; charset=utf-8',
                data: (object==null ? null : JSON.stringify(object)),
                beforeSend : function(xhr) {

                },
                success : function(respObject) {
                    window.location.reload();
                    console.log(respObject);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        });

        $(".save").on("click", function() {

            var create=$(this).parent().parent().find('#permissionValue4').is(':checked');
            var read=$(this).parent().parent().find('#permissionValue1').is(':checked');
            var write=$(this).parent().parent().find('#permissionValue2').is(':checked');
            var remove=$(this).parent().parent().find('#permissionValue8').is(':checked');
            var manage=$(this).parent().parent().find('#permissionValue16').is(':checked');
            var uuid=$(this).parent().parent().find('.aclSid').val();

            var object = { "oid": ${aclObjectIdentity.objectIdIdentity},"clazz":"${aclObjectIdentity.aclClass.aclClass}","uuid":uuid,"principal":true,
                "create":create,"read":read,"write":write,"delete":remove,"manage":manage};

180
            $.ajax("<c:url value="/json/v0/permission/update" />", {
181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219
                type : 'POST',
                dataType : 'json',
                contentType: 'application/json; charset=utf-8',
                data: (object==null ? null : JSON.stringify(object)),
                beforeSend : function(xhr) {

                },
                success : function(respObject) {
                    window.location.reload();
                    console.log(respObject);
                },
                error: function(jqXHR, textStatus, errorThrown) {
                    console.log(textStatus);
                    console.log(errorThrown);
                }
            });
        });

        $(".edit").click(function(){
            $(".check").prop("disabled",true);
            $("input:submit").hide();
            $(".cancel").hide();
            $(this).parent().parent().find('input:checkbox').prop("disabled",false);
            $(this).parent().parent().find('input:submit').show();
            $(this).parent().parent().find('.cancel').show();
        })

        $(".cancel").click(function(){
            $(".check").prop("disabled",true);
            $("input:submit").hide();
            $(this).hide();
        })


        $(function () {
            var tags = [];
            <c:forEach items="${userNames}" var="userName">
            tags.push("${userName}");
            </c:forEach>
220 221 222 223
            $("#autocomplete").autocomplete(
	            { delay: 200, minLength: 4, source: "<c:url value="/json/v0/permission/autocompleteuser" />",  
				messages: { noResults: '', results: function() {} } }
            );
224 225 226 227

        });
    });
</script>
Matija Obreza's avatar
Matija Obreza committed
228
</content>
Matija Obreza's avatar
Matija Obreza committed
229 230
</body>
</html>