editor.jsp 15.3 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

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

    <p>
      <spring:message code="acl.owner"/>:
18
19
20
      <c:set var="sid" value="${jspHelper.aclSidById(aclObjectIdentity.ownerSid.id)}" />
      <c:out value="${sid.fullName}"/>
      <c:catch><a href="<c:url value='mailto:${sid.email}' />"><c:out value="${sid.email}" /></a></c:catch>
Maxym Borodenko's avatar
Maxym Borodenko committed
21
22
23
24
25
26
27
28
29
30
31
    </p>
    <table class="table table-striped">
      <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>
32

Maxym Borodenko's avatar
Maxym Borodenko committed
33
        <c:forEach items="${aclSids}" var="aclSid" varStatus="status">
34
          <c:set var="sid" value="${jspHelper.aclSidById(aclSid.id)}" />
Maxym Borodenko's avatar
Maxym Borodenko committed
35
          <tr class="${status.count % 2 == 0 ? 'even' : 'odd'}">
Alexander Basov's avatar
Alexander Basov committed
36
            <td>
37
38
              <c:out value="${sid.fullName}"/>
              <c:catch><a href="<c:url value='mailto:${sid.email}' />"><c:out value="${sid.email}" /></a></c:catch>
Alexander Basov's avatar
Alexander Basov committed
39
            </td>
40

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

            <c:forEach items="${aclPermissions}" var="aclPermission">
Maxym Borodenko's avatar
Maxym Borodenko committed
44
              <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>
45
46
            </c:forEach>

Maxym Borodenko's avatar
Maxym Borodenko committed
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
            <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>

              <input type="button" class="btn btn-primary edit" value="<spring:message code='edit' />"/>
            </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-email" placeholder="User email"/></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>
66
        </tr>
Maxym Borodenko's avatar
Maxym Borodenko committed
67
68
        <tr id="permissionAdderByOAuthClient" class="${aclSids.size()-1 % 2 == 0 ? 'even' : 'odd'}">
          <td><input type="text" class="required form-control" name="uuid" id="autocomplete-oauth-client" placeholder="OAuth client"/></td>
69

Maxym Borodenko's avatar
Maxym Borodenko committed
70
71
72
73
74
          <c:forEach items="${aclPermissions}" var="aclPermission">
            <td>
              <input type="checkbox" id="oauthAutoCheck${aclPermission.mask}" value="1" name="acPermissionValue${aclPermission.mask}" ${aclEntries[aclSid.sid][aclPermission.mask] ? 'checked' : '' }/>
            </td>
          </c:forEach>
75

Maxym Borodenko's avatar
Maxym Borodenko committed
76
77
78
          <td>
            <input type="button" class="btn btn-primary" value="<spring:message code='add' />"/></td>
        </tr>
79

Maxym Borodenko's avatar
Maxym Borodenko committed
80
81
        <tr id="permissionAdderByRole" class="${aclSids.size()-1 % 2 == 0 ? 'even' : 'odd'}">
          <td>
Alexander Basov's avatar
Alexander Basov committed
82
            <select class="required form-control" name="uuid" id="" title="roles">
Maxym Borodenko's avatar
Maxym Borodenko committed
83
84
85
86
              <option disabled="disabled" selected="selected">SELECT ROLE</option>
              <c:forEach var="role" items="${roles}">
                <option value="${role}"><c:out value="${role}"/></option>
              </c:forEach>
Alexander Basov's avatar
Alexander Basov committed
87
            </select>
Maxym Borodenko's avatar
Maxym Borodenko committed
88
          </td>
Alexander Basov's avatar
Alexander Basov committed
89

Maxym Borodenko's avatar
Maxym Borodenko committed
90
91
92
          <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>
Alexander Basov's avatar
Alexander Basov committed
93

Maxym Borodenko's avatar
Maxym Borodenko committed
94
95
96
97
98
99
100
101
102
103
          <td><input type="button" class="btn btn-primary" value="<spring:message code='add' />"/></td>
        </tr>
      </tbody>
    </table>

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

    <content tag="javascript">
      <script type="text/javascript">
          jQuery(document).ready(function() {
104
              var oAuthClientMap, userMap;
Maxym Borodenko's avatar
Maxym Borodenko committed
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120

              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}",
121
                      "authority": $('#permissionAdderByRole select')[0].value,
Maxym Borodenko's avatar
Maxym Borodenko committed
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
                      "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);
                      }
                  });
              });

              $("#permissionAdderByOAuthClient input[type=button]").on("click", function (a, b, c) {

                  var object = {
                      "oid": ${aclObjectIdentity.objectIdIdentity},
                      "clazz": "${aclObjectIdentity.aclClass.aclClass}",
153
                      "sid": oAuthClientMap[$("#permissionAdderByOAuthClient input[type=text]")[0].value],
Maxym Borodenko's avatar
Maxym Borodenko committed
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
180
181
182
183
184
185
186
187
188
189
190
                      "create": $("#oauthAutoCheck4").is(':checked'),
                      "read": $("#oauthAutoCheck1").is(':checked'),
                      "write": $("#oauthAutoCheck2").is(':checked'),
                      "delete": $("#oauthAutoCheck8").is(':checked'),
                      "manage": $("#oauthAutoCheck16").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);
                      }
                  });
              });

              $("#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}",
191
                      "sid": userMap[$("#permissionAdder input[type=text]")[0].value],
Maxym Borodenko's avatar
Maxym Borodenko committed
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
220
221
222
223
                      "create": create,
                      "read": read,
                      "write": write,
                      "delete": remove,
                      "manage": manage
                  };
                  $.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);
                      }
                  });
              });

              $(".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');
224
                  var sid=$(this).parent().parent().find('.aclSid').val();
Maxym Borodenko's avatar
Maxym Borodenko committed
225
226
227
228

                  var object = {
                      "oid": ${aclObjectIdentity.objectIdIdentity},
                      "clazz": "${aclObjectIdentity.aclClass.aclClass}",
229
                      "sid": sid,
Maxym Borodenko's avatar
Maxym Borodenko committed
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
                      "create": create,
                      "read": read,
                      "write": write,
                      "delete": remove,
                      "manage": manage
                  };

                  $.ajax("<c:url value='/json/v0/permission/update' />", {
                      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>
                  $("#autocomplete-email").autocomplete({
                      delay: 200,
                      minLength: 4,
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
                      source: function(request, response) {
                          $.ajax("<c:url value='/json/v0/permission/autocompleteuser' />",{
                              type: "GET",
                              contentType: "application/json; charset=utf-8",
                              dataType: "json",
                              data: {
                                  "term": $("#permissionAdder input[type=text]")[0].value
                              },
                              success: function (data) {
                                  var titles = [];
                                  $.each(data, function(key, element) {
                                      titles.push(key);
                                  });
                                  userMap = data;
                                  response(titles);
                              },
                              error: function(result) {
                                  alert("Error");
                              }
                          })
                      },
Maxym Borodenko's avatar
Maxym Borodenko committed
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
      				        messages: {
                        noResults: '',
                        results: function() {}
                      }
                  });

                  $("#autocomplete-oauth-client").autocomplete({
                      delay: 200,
                      minLength: 4,
                      source: function(request, response) {
                          $.ajax("<c:url value='/json/v0/permission/autocomplete-oauth-client' />",{
                              type: "GET",
                              contentType: "application/json; charset=utf-8",
                              dataType: "json",
                              data: {
                                  "term": $("#permissionAdderByOAuthClient input[type=text]")[0].value
                              },
                              success: function (data) {
                                  var titles = [];
                                  $.each(data, function(key, element) {
                                      titles.push(key);
                                  });
                                  oAuthClientMap = data;
                                  response(titles);
                              },
                              error: function(result) {
                                  alert("Error");
                              }
                          })
                      },
                      messages: {
                          noResults: '',
                          results: function() {}
                      }
                  });
              });
          });
      </script>
    </content>
  </body>
Matija Obreza's avatar
Matija Obreza committed
340
</html>