Merge "Converted docker/Dockerfile to ASCII"
[osm/LW-UI.git] / static / src / userhandler / user_list.js
1 /*
2 Copyright 2018 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 openModalCreateUser(args) {
18
19 select2_groups = $('#projects').select2({
20 placeholder: 'Select Projects',
21 width: '100%',
22 ajax: {
23 url: args.projects_list_url,
24 dataType: 'json',
25 processResults: function (data) {
26 projects = [];
27 if (data['projects']) {
28 for (d in data['projects']) {
29 var project = data['projects'][d];
30 projects.push({id: project['_id'], text: project['name']})
31 }
32 }
33
34 return {
35 results: projects
36 };
37 }
38 }
39 });
40
41 $('#modal_new_user').modal('show');
42 }
43
44 function openModalEditUser(args) {
45 var url = '/admin/users/' + args.user_id;
46 var user_projects = args.projects ? args.projects.split(',') : [];
47 $("#formEditUser").attr("action", url);
48 $("#projects_old").val(user_projects.toString());
49 $('#projects_edit').val(null).trigger('change');
50 $('#default_project_edit').val(null).trigger('change');
51 $('#edit_password').val('');
52 if (user_projects.length > 0) {
53 // Create a DOM Option and pre-select by default
54 var newOption = new Option(user_projects[0], user_projects[0], true, true);
55 // Append it to the select
56 $('#default_project_edit').append(newOption).trigger('change');
57
58 for (var d in user_projects) {
59 var project = user_projects[d];
60 // Create a DOM Option and pre-select by default
61 var newOption = new Option(project, project, true, true);
62 // Append it to the select
63 $('#projects_edit').append(newOption).trigger('change');
64 }
65
66 }
67
68
69 $('#modal_edit_user').modal('show');
70 }
71
72 function deleteUser(user_id, name) {
73 var delete_url = '/admin/users/' + user_id + '/delete';
74 bootbox.confirm("Are you sure want to delete " + name + "?", function (confirm) {
75 if (confirm) {
76 var dialog = bootbox.dialog({
77 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
78 closeButton: false
79 });
80 $.ajax({
81 url: delete_url,
82 dataType: "json",
83 contentType: "application/json;charset=utf-8",
84 success: function (result) {
85 //$('#modal_show_vim_body').empty();
86 dialog.modal('hide');
87 location.reload();
88 },
89 error: function (result) {
90 dialog.modal('hide');
91 bootbox.alert("An error occurred.");
92 }
93 });
94 }
95 })
96
97 }