management requests table reorganization
[unfold.git] / portal / templates / management-tab-requests.html
1 <script type="text/javascript">
2         $(document).ready(function() {
3                 $("li#nav-request").addClass("active");
4                 $('table.requests').dataTable();
5         });
6         function on_click_event() {
7                 var ids = []; 
8                 $('.portal__validate__checkbox').each(function(i, el) {
9                         if ($(el).prop('checked')) {
10                                 // portal__validate__checkbox__slice__2
11                                 var id_array = $(el).attr('id').split('__');
12                                 // push(slice__2)
13                                 ids.push(id_array[3] + '__' + id_array[4]);
14                         }
15                 });
16                 if (ids.length > 0) {
17                         var id_str = ids.join('/');
18
19                         // XXX spinner
20
21                         $.getJSON('/portal/validate_action/' + id_str,
22                                 function(status) {
23                                         $.each(status, function(request_type__id, request_status) {
24                                                 // request_status: NAME -> dict (status, description)
25                                                 var status_str = '';
26                                                 $.each(request_status, function(name, result) {
27                                                         if (status_str != '')
28                                                                 status_str += ' -- ';
29
30                                                         if (result.status) {
31                                                                 status_str += '<font color="green">OK</font>';
32                                                                 $('#portal__validate__checkbox__' + request_type__id).hide();
33                                                         } else {
34                                                                 status_str += '<font color="red">ERROR: ' + result.description + '</font>';
35                                                         }
36                                                 });
37                                                 $('#portal__status__' + request_type__id).html(status_str);
38
39
40                                         });
41                                 }
42                         );
43                 }
44         }
45         function on_click_reject() {
46                 var ids = []; 
47                 $('.portal__validate__checkbox').each(function(i, el) {
48                         if ($(el).prop('checked')) {
49                                 // portal__validate__checkbox__slice__2
50                                 var id_array = $(el).attr('id').split('__');
51                                 // push(slice__2)
52                                 ids.push(id_array[3] + '__' + id_array[4]);
53                         }
54                 });
55                 if (ids.length > 0) {
56                         var id_str = ids.join('/');
57
58                         // XXX spinner
59
60                         $.getJSON('/portal/reject_action/' + id_str,
61                                 function(status) {
62                                         $.each(status, function(request_type__id, request_status) {
63                                                 // request_status: NAME -> dict (status, description)
64                                                 var status_str = '';
65                                                 $.each(request_status, function(name, result) {
66                                                         if (status_str != '')
67                                                                 status_str += ' -- ';
68
69                                                         if (result.status) {
70                                                                 status_str += '<font color="green">Rejected</font>';
71                                                                 $('#portal__validate__checkbox__' + request_type__id).hide();
72                                                         } else {
73                                                                 status_str += '<font color="red">ERROR: ' + result.description + '</font>';
74                                                         }
75                                                 });
76                                                 $('#portal__status__' + request_type__id).html(status_str);
77
78
79                                         });
80                                 }
81                         );
82                 }
83         }
84 </script>
85
86 <div class="container-fluid">
87 <div class="col-md-12">
88         <h2>From your authorities</h2>
89 </div>
90 {% if my_authorities %}
91         <table class="table-responsive requests">
92             <thead>
93         <tr>
94             <th>ID</th>
95             <th></th>
96             <th>Type</th>
97             <th>Authority</th>
98             <th>Info</th>
99             <th>Date</th>
100         </tr>
101         </thead>
102         <tbody>
103         {% for authority, requests in my_authorities.items %}
104         
105         {% for request in requests %}
106         
107         {% if request.type == 'user' %}
108         <tr>
109         {% elif request.type == 'slice' %}
110         <tr class="info">
111         {% else %}
112         <tr class="active">
113         {% endif %}
114             <td><span class="gray small">{{ request.id }}</span></td>
115             <td>
116             {% if request.allowed == 'allowed' %}
117             <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
118             {% else %}
119                 {% if request.allowed == 'expired' %}expired{% else %}denied{% endif %}
120             {% endif %}
121             </td>
122             <td><span class="type">{{ request.type }}</span></td>
123             <td><i>{{authority}}{{request.site_authority}}</i></td>
124                 <td>
125             {% if request.type == 'user' %}
126                 <b>{{request.first_name}} {{request.last_name}}</b> &lt;<a href="mailto:{{request.email}}">{{request.email}}</a>&gt;
127             {% elif request.type == 'slice' %}
128             <b>{{request.slice_name}}</b> -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
129             {% else %}
130             <b>{{request.site_name}}</b> ({{request.site_authority}}) -- {{request.address_city}}, {{request.address_country}}
131             {% endif %}
132                 </td>
133                 <td>{{ request.timestamp }}</td>
134                 
135                 <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
136     
137         <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
138           </tr>
139     
140         {% endfor %}
141         
142         {% endfor %}
143            </tbody>
144     </table>
145 {% else %}
146         <div class="col-md-12">
147                 <i>There is no pending request waiting for validation.</i>
148         </div>
149 {% endif %}
150 </div>
151
152
153 <br />
154 <div class="col-md-12">
155         <h2>From your sub-authorities</h2>
156 </div>
157 {% if sub_authorities %}
158         
159         {% for authority, requests in sub_authorities.items %}
160         <div class="col-md-12">
161         <h3>{{authority}}</h3>
162             <table class="table">
163               <th>
164                 <td>Type</td>
165                 <td>Id</td>
166                 <td>Details</td>
167                 <td>Timestamp</td>
168                 <td>Status</td>
169               </th>
170             {% for request in requests %}
171                   <tr>
172                         <td>
173                         {% if request.allowed == 'allowed' %}
174                         <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
175                         {% else %}
176                                 {% if request.allowed == 'expired' %}
177                                         expired
178                                 {% else %} {# denied #}
179                                         denied
180                                 {% endif %}
181                         {% endif %}
182                         </td>
183                         <td>{{ request.type }}</td>
184                         <td>{{ request.id }}</td>
185                         <td>
186                 {% if request.type == 'user' %}
187                 Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
188                 {% else %}
189                     {% if request.type == 'slice' %}
190                 Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
191                     {% else %} {# authority #}
192                 Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
193                     {% endif %}
194                 {% endif %}
195                         </td>
196                         <td>{{ request.timestamp }}</td>
197                         
198                         <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
199         
200             <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
201                   </tr>
202             {% endfor %}
203             </table>
204         </div>
205         {% endfor %}
206 {% else %}
207 <div class="col-md-12">
208         <i>There is no pending request waiting for validation.</i>
209 </div>
210 {% endif %}
211 <br />
212 <div class="col-md-12">
213         <h2>From your authorities with delegation</h2>
214 </div>
215
216 {% if delegation_authorities %}
217         
218         {% for authority, requests in delegation_authorities.items %}
219         <div class="col-md-12">
220                 <h3>{{authority}}</h3>
221                     <table class="table">
222                       <th>
223                         <td>Type</td>
224                         <td>Id</td>
225                         <td>Details</td>
226                         <td>Timestamp</td>
227                         <td>Status</td>
228                       </th>
229                     {% for request in requests %}
230                           <tr>
231                                 <td>
232                                 {% if request.allowed == 'allowed' %}
233                                 <input class='portal__validate__checkbox' id='portal__validate__checkbox__{{request.type}}__{{request.id}}' type='checkbox'/>
234                                 {% else %}
235                                         {% if request.allowed == 'expired' %}
236                                                 expired
237                                         {% else %} {# denied #}
238                                                 denied
239                                         {% endif %}
240                                 {% endif %}
241                                 </td>
242                                 <td>{{ request.type }}</td>
243                                 <td>{{ request.id }}</td>
244                                 <td>
245                         {% if request.type == 'user' %}
246                         Login: {{request.login}} -- First name: {{request.first_name}} -- Last name: {{request.last_name}} -- Email: {{request.email}}
247                         {% else %}
248                             {% if request.type == 'slice' %}
249                         Slice name: {{request.slice_name}} -- Number of nodes: {{request.number_of_nodes}} -- Type of nodes: {{request.type_of_nodes}} -- Purpose: {{request.purpose}}
250                             {% else %} {# authority #}
251                         Authority name: {{request.site_name}} -- authority_hrn: {{request.site_authority}} -- City: {{request.address_city}} -- Country: {{request.address_country}}
252                             {% endif %}
253                        {% endif %}
254                                 </td>
255                                 <td>{{ request.timestamp }}</td>
256                                 
257                                 <td><span id='portal__status__{{request.type}}__{{request.id}}'></span></td>
258                 
259                     <!--<div class='portal_validate_request {{request.type}} {% if forloop.counter|divisibleby:2 %}even{% else %}odd{% endif %}'> -->
260                           </tr>
261                     {% endfor %}
262                     </table>
263                 </div>
264                 {% endfor %}
265 {% else %}
266 <div class="col-md-12">
267         <i>There is no pending request waiting for validation.</i>
268 </div>
269 {% endif %}
270 <br />
271 <div class="col-md-12">
272         <button class="btn btn-onelab" type="button" id="portal__validate" onclick="on_click_event();"><span class="glyphicon glyphicon-ok"></span> Validate</button>
273         <button class="btn btn-danger" type="button" id="portal__reject" onclick="on_click_reject();"><span class="glyphicon glyphicon-remove"></span> Reject</button>
274 </div>