improved role management
[osm/LW-UI.git] / static / src / rolehandler / role_list.js
1 /*
2 Copyright 2019 EveryUP srl
3
4 Licensed under the Apache License, Version 2.0 (the "License");
5 you may not use this file except in compliance with the License.
6 You may obtain a copy of the License at
7
8 http://www.apache.org/licenses/LICENSE-2.0
9
10 Unless required by applicable law or agreed to in writing, software
11 distributed under the License is distributed on an BASIS,
12 WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 See the License for the specific language governing permissions and
14 limitations under the License.
15 */
16
17 function openModalCreateRole(args) {
18
19 $('#modal_new_role').modal('show');
20 }
21
22 function openModalEditRole(args) {
23 var url = '/admin/roles/' + args.role_id;
24 var url_update = '/admin/roles/' + args.role_id+'/update';
25 var dialog = bootbox.dialog({
26 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
27 closeButton: false
28 });
29 $.ajax({
30 url: url,
31 type: 'GET',
32 headers: {
33 "Accept": 'application/json'
34 },
35 contentType: false,
36 processData: false
37 })
38 .done(function (response,textStatus, jqXHR) {
39 dialog.modal('hide');
40 $("#formEditRole").attr("action", url_update);
41 $('#modal_edit_role').modal('show');
42 $('#edit_rolename').val(response['name'])
43 $('#edit_definition').val(JSON.stringify(response['definition']))
44 if(response['root'] === true){
45 $("#edit_root").attr("checked", true);
46 }
47 else {
48 $("#edit_root").attr("checked", false);
49 }
50 }).fail(function(result){
51 dialog.modal('hide');
52 var data = result.responseJSON;
53 var title = "Error " + (data.code ? data.code: 'unknown');
54 var message = data.detail ? data.detail: 'No detail available.';
55 bootbox.alert({
56 title: title,
57 message: message
58 });
59 });
60
61 }
62
63 function deleteRole(role_id, name) {
64 var delete_url = '/admin/roles/' + role_id + '/delete';
65 bootbox.confirm("Are you sure want to delete " + name + "?", function (confirm) {
66 if (confirm) {
67 var dialog = bootbox.dialog({
68 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
69 closeButton: false
70 });
71 $.ajax({
72 url: delete_url,
73 type: 'GET',
74 headers: {
75 "Accept": 'application/json'
76 },
77 contentType: false,
78 processData: false
79 })
80 .done(function (response,textStatus, jqXHR) {
81 bootbox.alert({
82 title: "Result",
83 message: "Role deleted.",
84 callback: function () {
85 dialog.modal('hide');
86 table.ajax.reload();
87 }
88 });
89 }).fail(function(result){
90 dialog.modal('hide');
91 var data = result.responseJSON;
92 var title = "Error " + (data.code ? data.code: 'unknown');
93 var message = data.detail ? data.detail: 'No detail available.';
94 bootbox.alert({
95 title: title,
96 message: message
97 });
98 });
99 }
100 })
101
102 }