automatic reload on lists; new django decorator for ajax request
[osm/LW-UI.git] / static / src / userhandler / user_list.js
1 function openModalCreateUser(args) {
2 console.log(args)
3 // load projects list
4 select2_groups = $('#projects').select2({
5 placeholder: 'Select Projects',
6 width: '100%',
7 ajax: {
8 url: args.projects_list_url,
9 dataType: 'json',
10 processResults: function (data) {
11 projects = [];
12 if (data['projects']) {
13 for (d in data['projects']) {
14 var project = data['projects'][d];
15 projects.push({id: project['_id'], text: project['name']})
16 }
17 }
18
19 return {
20 results: projects
21 };
22 }
23 }
24 });
25
26 $('#modal_new_user').modal('show');
27 }
28
29 function deleteUser(user_id, name) {
30 var delete_url = '/admin/users/'+user_id+'/delete';
31 bootbox.confirm("Are you sure want to delete "+name+"?", function (confirm) {
32 if (confirm) {
33 var dialog = bootbox.dialog({
34 message: '<div class="text-center"><i class="fa fa-spin fa-spinner"></i> Loading...</div>',
35 closeButton: false
36 });
37 $.ajax({
38 url: delete_url,
39 dataType: "json",
40 contentType: "application/json;charset=utf-8",
41 success: function (result) {
42 //$('#modal_show_vim_body').empty();
43 dialog.modal('hide');
44 location.reload();
45 },
46 error: function (result) {
47 dialog.modal('hide');
48 bootbox.alert("An error occurred.");
49 }
50 });
51 }
52 })
53
54 }