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