28888fc2bdb389e08fabc9a04077645528bca3d6
[osm/LW-UI.git] / projecthandler / template / project / projectlist.html
1 {% extends "base.html" %}
2 {% load get %}
3 {% load date_tag %}
4 {% load staticfiles %}
5
6 {% block head_block %}
7 {{ block.super }}
8 <link rel="stylesheet" href="/static/bower_components/datatables.net-bs/css/dataTables.bootstrap.min.css">
9
10 {% endblock %}
11 {% block title_header_big %}
12 {{ block.super }}
13 {% endblock %}
14 {% block left_sidebar %}
15
16 {% include 'osm/osm_project_left_sidebar.html' %}
17
18 {% endblock %}
19
20
21 {% block breadcrumb_body %}
22 {{ block.super }}
23 <li><a href="{% url 'projects:projects_list' %}">Projects</a></li>
24 {% endblock %}
25
26 {% block content_body %}
27 {{ block.super }}
28 {% csrf_token %}
29 <div class="row">
30 <div class="col-md-12">
31 <div class="box">
32 <div class="box-header with-border">
33 <h3 class="box-title">Projects</h3>
34 <div class="box-tools">
35 <button type="button" class="btn btn-default" data-container="body"
36 data-toggle="tooltip" data-placement="top" title="New Project"
37 onclick="javascript:showModalNewProject()">
38 <i class="fa fa-plus"></i> New Project</button>
39 </div>
40 </div>
41 <div class="box-body">
42 <table id="projects_table" class="table table-bordered table-striped">
43 <thead>
44 <tr>
45 <th>Name</th>
46 <th>Modification Date</th>
47 <th>Creation Date</th>
48 <th>Actions</th>
49 </tr>
50 </thead>
51 <tbody>
52
53 </tbody>
54 </table>
55 </div>
56 </div>
57 </div>
58
59 </div>
60 {% include "modal/project_new.html" %}
61 {% include "modal/project_edit.html" %}
62 {% endblock %}
63
64 {% block resource_block %}
65 {{ block.super }}
66 <script src="/static/bower_components/datatables.net/js/jquery.dataTables.min.js"></script>
67 <script src="/static/bower_components/datatables.net-bs/js/dataTables.bootstrap.min.js"></script>
68
69 <script>
70 $(document).ready( function () {
71 var table = $('#projects_table').DataTable({
72 responsive: true,
73 "ajax": {
74 "url": "/projects/list",
75 "dataSrc": function (json) {
76 return json['projects'];
77 },
78 statusCode: {
79 401: function () {
80 console.log("no auth");
81 moveToLogin(window.location.pathname);
82 }
83 },
84 "error": function (hxr, error, thrown) {
85 console.log(hxr)
86 console.log(thrown)
87 console.log(error);
88 }
89
90 },
91 "columns": [
92 {
93 "render": function (data, type, row) {
94 return '<a href="/projects/'+row['name']+'/switch/" >'+row['name']+'</a>'
95 },
96 "targets": 0
97 },
98 {
99 "render": function (data, type, row) {
100 return moment.unix(row["_admin"]['modified']).format('YYYY-MM-DD hh:mm:ss a');
101 },
102 "targets": 1
103 },
104 {
105 "render": function (data, type, row) {
106 return moment.unix(row["_admin"]['created']).format('YYYY-MM-DD hh:mm:ss a');
107 },
108 "targets": 2
109 },
110 {
111 "render": function (data, type, row) {
112 return '<div class="btn-group">\n' +
113 ' <button type="button" class="btn btn-default dropdown-toggle"\n' +
114 ' data-toggle="dropdown" aria-expanded="false">Actions\n' +
115 ' <span class="fa fa-caret-down"></span></button>\n' +
116 ' <ul class="dropdown-menu">\n' +
117 ' <li><a href="#"\n' +
118 ' onclick="javascript:editProject(\''+ row['name']+'\')">\n' +
119 ' <i class="fa fa-edit"></i> Rename</a></li>\n' +
120 ' <li>\n' +
121 ' <a href="#" onclick="javascript:deleteProject(\''+ row['name']+'\')" style="color:red">\n' +
122 ' <i class="fa fa-trash" ></i> Delete</a>\n' +
123 ' </li>\n' +
124 ' </ul>\n' +
125 ' </div>';
126 },
127 "targets": 3,
128 "orderable": false
129 }
130 ]
131 });
132
133 setInterval(function () {
134 table.ajax.reload();
135 }, 10000);
136 });
137 </script>
138 <script>
139 function showModalNewProject(){
140 $('#modal_new_project').modal('show');
141 }
142
143 function editProject(project_id){
144 var url = "/projects/" + project_id+"/edit";
145 $("#formEditProject").attr("action", url);
146 $('#modal_edit_project').modal('show');
147 }
148
149 function deleteProject(project_id) {
150 var url = "/projects/" + project_id+"/delete";
151 bootbox.confirm("Are you sure want to delete?", function (result) {
152 if (result) {
153 $.ajax({
154 url: url,
155 type: 'GET',
156 headers: {
157 "Accept": 'application/json'
158 },
159 contentType: false,
160 processData: false
161 }).done(function (response,textStatus, jqXHR) {
162 bootbox.alert({
163 title: "Result",
164 message: "Project deleted.",
165 callback: function () {
166 location.reload();
167 }
168 });
169 }).fail(function(result){
170 var data = result.responseJSON;
171 var title = "Error " + (data.code ? data.code: 'unknown');
172 var message = data.detail ? data.detail: 'No detail available.';
173 bootbox.alert({
174 title: title,
175 message: message
176 });
177 });
178 }
179 })
180 }
181
182 $(document).ready(function () {
183 $("#formNewProject").submit(function (event) {
184 event.preventDefault(); //prevent default action
185 var post_url = $(this).attr("action"); //get form action url
186 var request_method = $(this).attr("method"); //get form GET/POST method
187 var form_data = new FormData(this); //Encode form elements for submission
188 console.log(post_url);
189 $.ajax({
190 url: post_url,
191 type: request_method,
192 data: form_data,
193 headers: {
194 "Accept": 'application/json'
195 },
196 contentType: false,
197 processData: false
198 }).done(function (response,textStatus, jqXHR) {
199 bootbox.alert({
200 title: "Result",
201 message: "Project created.",
202 callback: function () {
203 location.reload();
204 }
205 });
206 }).fail(function(result){
207 var data = result.responseJSON;
208 var title = "Error " + (data.code ? data.code: 'unknown');
209 var message = data.detail ? data.detail: 'No detail available.';
210 bootbox.alert({
211 title: title,
212 message: message
213 });
214 });
215 });
216 });
217
218
219
220
221 </script>
222
223
224 {% endblock %}