automatic reload on lists; new django decorator for ajax request
[osm/LW-UI.git] / userhandler / templates / user_list.html
1 {% extends "base.html" %}
2 {% load get %}
3 {% load date_tag %}
4 {% load staticfiles %}
5
6
7 {% block head_block %}
8 {{ block.super }}
9 <link rel="stylesheet" href="/static/bower_components/select2/dist/css/select2.min.css">
10 <link rel="stylesheet" href="/static/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
11 {% endblock %}
12 {% block title_header_big %}
13 {{ block.super }}
14 {% endblock %}
15 {% block left_sidebar %}
16 {% include 'osm/osm_project_left_sidebar.html' %}
17 {% endblock %}
18
19
20 {% block breadcrumb_body %}
21 {{ block.super }}
22 <li><a href="#">Users</a></li>
23 {% endblock %}
24
25 {% block content_body %}
26 {{ block.super }}
27 {% include 'modal/user_details.html' %}
28 {% include 'modal/user_create.html' %}
29 {% csrf_token %}
30 <div class="row">
31 <div class="col-md-12">
32
33 <div class="box">
34 <div class="box-header with-border">
35 <h3 class="box-title">Users</h3>
36 <div class="box-tools">
37 <button type="button" class="btn btn-default" data-container="body"
38 onclick="javascript:openModalCreateUser({'projects_list_url': '{% url "projects:projects_list" %}'})"
39 data-toggle="tooltip" data-placement="top" title="New User">
40
41 <i class="fa fa-plus"></i> Create User</button>
42
43 </div>
44 </div>
45 <div class="box-body">
46 <table id="users_table" class="table table-bordered table-striped">
47 <thead>
48 <tr>
49 <th>Name</th>
50 <th>Projects</th>
51 <th>Identifier</th>
52 <th>Modified</th>
53 <th>Created</th>
54 <th>Actions</th>
55
56 </tr>
57 </thead>
58 <tbody>
59
60 </tbody>
61 </table>
62 </div>
63 </div>
64 </div>
65
66 </div>
67 {% endblock %}
68
69 {% block resource_block %}
70 {{ block.super }}
71 <script src="/static/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
72 <script src="/static/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
73 <script src="/static/bower_components/select2/dist/js/select2.js"></script>
74 <script src="/static/src/userhandler/user_list.js"></script>
75 <script>
76 $(document).ready( function () {
77 var table = $('#users_table').DataTable({
78 responsive: true,
79 "ajax": {
80 "url": "/admin/users/list",
81 "dataSrc": function (json) {
82 return json['users'];
83 },
84 statusCode: {
85 401: function () {
86 console.log("no auth");
87 moveToLogin(window.location.pathname);
88 }
89 },
90 "error": function (hxr, error, thrown) {
91 console.log(hxr)
92 console.log(thrown)
93 console.log(error);
94 }
95
96 },
97 "columns": [
98 {
99 "render": function (data, type, row) {
100 return row["username"];
101 },
102 "targets": 0
103 },
104 {
105 "render": function (data, type, row) {
106 return row['projects'];
107 },
108 "targets": 1
109 },
110 {
111 "render": function (data, type, row) {
112 return row['_id'];
113 },
114 "targets": 2
115 },
116 {
117 "render": function (data, type, row) {
118 return moment.unix(row["_admin"]['modified']).format('YYYY-MM-DD hh:mm:ss a');
119 },
120 "targets": 3
121 },
122 {
123 "render": function (data, type, row) {
124 return moment.unix(row["_admin"]['created']).format('YYYY-MM-DD hh:mm:ss a');;
125 },
126 "targets": 4
127 },
128 {
129 "render": function (data, type, row) {
130 return '<div class="btn-group">' +
131 '<button type="button" class="btn btn-default dropdown-toggle"' +
132 'data-toggle="dropdown" aria-expanded="false">Actions ' +
133 '<span class="fa fa-caret-down"></span></button> ' +
134 '<ul class="dropdown-menu">' +
135 '<li> <a href="#" onclick="javascript:deleteUser(\'' + row['_id'] + '\', \''+row['username']+'\')"' +
136 'style="color:red"><i class="fa fa-trash"></i> Delete</a></li> </ul></div>';
137 },
138 "targets": 5
139 }
140 ]
141 });
142
143 setInterval(function () {
144 table.ajax.reload();
145 }, 10000);
146 });
147 </script>
148
149
150 {% endblock %}
151
152 {% block footer %}
153 {% include "footer.html" %}
154 {% endblock %}