Institution list of slices: fixed number of users per slice
[unfold.git] / portal / templates / onelab / onelab_institution.html
1 {% extends "layout_wide.html" %}
2
3 {% block head %} 
4 <script type="text/javascript" src="{{STATIC_URL}}/js/institution.js"></script>
5 {% endblock head %}
6
7 {% block content %}
8 <div class="container">
9         <div class="row">
10                 <div class="col-md-12">
11                         <ul class="nav nav-tabs nav-section">
12                                 <li class="active"><a href="#info"><img src="{{ STATIC_URL }}icons/authority-xs.png" alt="Institution" /> Institution {{user_details.parent_authority}}</a></li>
13                                 <li><a href="#users">Users</a></li>
14                                 <li><a href="#slices">Slices</a></li>
15                         </ul>
16             </div>
17         </div>
18 </div>
19 <div class="container tab-content">
20         <div class="tab-pane active row" id="info">
21                 <div class="col-md-12">
22                         <div id="authority-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Authority" /></div>
23                     <div id="authority-tab-loaded" style="display:none;">
24                         <div id="authority-data" style="float:left; width:50%;"></div>
25                                 <div id="onelab_membership" style="float:right; width:50%;">
26                                     <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
27                                 <div id="onelab-data"></div>
28                                 </div>
29                     </div>
30            </div>
31         </div>
32         
33         <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
34                 <div class="col-md-12">
35                         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
36                                 <div id="user-tab-loaded" style="display:none;">
37                                 <table id="user-tab">
38                                         <tr>
39                                         <th>+/-</th>
40                                         <th>email</th>
41                                         <th>user_hrn</th>
42                                         <th>first name</th>
43                                         <th>last name</th>
44                                         <th>enabled</th>
45                                         </tr>
46                                 </table>
47                                 {%if 'is_pi'  in pi %}  
48                                 <div>
49                                         <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
50                                 </div>
51                                 {%endif%}
52                         </div>
53                 </div>
54         </div>
55
56         <div class="tab-pane row" id="slices">
57                 {%if 'is_pi'  in pi %}
58                 <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> create slice</button>
59                 {%else%}
60                 <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> request slice</button>
61                 {%endif%}
62             <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
63             <div id="slice-tab-loaded" style="display:none;">
64                 <table id="slice-tab">
65                     <tr>
66                         <th>+/-</th>
67                         <th>slice_hrn</th>
68                         <th>users</th>
69                         <th>url</th>
70                         <th>nodes</th>
71                         <th>expiration</th>
72                     </tr>
73                 </table>
74                 <br>
75                         {%if 'is_pi'  in pi %}
76                 <div>
77                     <button id="renewslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
78                     <button id="deleteslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
79                 </div>
80                         {%endif%} 
81             </div>
82         </div>
83 </div>
84 <script>
85     $(document).ready(function() {
86         {% if person %}
87         {% if user_details.parent_authority %}
88         
89         $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
90             var authority_data = [];
91             var onelab_data = [];
92                         /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
93             'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'     */
94             $.each( data, function( key, val ) {
95                 authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
96                 authority_row += "<br>";
97                 authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
98                                 authority_row += "<br>";
99                 authority_row += "<b>"+val.name+"</b><br>";
100                 authority_row += "<br>";
101                 authority_row += "<b>Address:</b> "+val.address+"<br>";
102                 authority_row += "<b>City:</b> "+val.postcode+" "+val.city+"<br>";
103                 authority_row += "<br>";
104                 authority_row += "<b>Country:</b> "+val.country+"<br>";
105                 authority_row += "<br>";
106                 authority_row += "<br>";
107                 authority_row += "<h2>Contacts</h2>";
108                 authority_row += "<b>Legal:</b> ";
109                                 /*
110
111                 TODO: find a way to express JSON correctly given the constrains: CSV / JSON
112
113                 legal = jQuery.parseJSON(val.legal);
114                 if($.isArray(legal)){
115                     $.each(legal, function(k,v){
116                         authority_row += k+" "+v+"<br>";
117                     });
118                 }else{
119                 */
120                     authority_row += val.legal+"<br>";
121                 //}
122                 authority_row += "<br>";
123                 authority_row += "<b>Scientific:</b> ";
124                 /*
125                 scientific = jQuery.parseJSON(val.scientific);
126                 if($.isArray(scientific)){
127                     $.each(scientific, function(v){
128                         authority_row += v+", ";
129                     });
130                 }else{
131                 */
132                     authority_row += val.scientific+"<br>";
133                 //}
134                 onelab_membership = "<b>Status: </b>"+val.onelab_membership;
135                 onelab_data.push(onelab_membership);
136                 authority_data.push(authority_row);
137
138             });
139             $("div#authority-data").html(authority_data.join( "" ));
140             $("div#onelab-data").html(onelab_data.join( "" ));
141             $("div#authority-tab-loaded").css("display","block");
142             $("div#authority-tab-loading").css("display","none");
143          });
144
145         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
146             var list_slices = [];
147             var table_slices = [];
148             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
149             $.each( data, function( key, val ) {
150                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
151                 if(val.nodes=="undefined" || val.nodes==null){
152                     nodes_length=0;
153                 }else{
154                     nodes_length=val.nodes.length;
155                 }
156                 console.log(val);
157                 if(val.users=="undefined" || val.users==null){
158                     users_length=0;
159                 }else{
160                     users_length=val.users.length;
161                 }
162
163                 if(val.slice_url=="undefined" || val.slice_url==null){
164                     slice_url="";
165                 }else{
166                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
167                 }
168                 
169                 slice_row = "<tr id='"+val.slice_hrn+"'>";
170                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
171                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
172                 slice_row += "<td>"+users_length+"</td>";
173                 slice_row += "<td>"+slice_url+"</td>";
174                 slice_row += "<td>"+nodes_length+"</td>";
175                 slice_row += "<td>"+val.slice_expires+"</td>";
176                 slice_row += "</tr>";
177                 table_slices.push(slice_row);
178                 
179             });
180            
181             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
182             $("table#slice-tab tr:last").after(table_slices.join( "" ));
183             $("div#slice-tab-loaded").css("display","block");
184             $("div#slice-tab-loading").css("display","none");
185         });
186                 
187                 
188          $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
189              var list_users = [];
190              var table_users = [];
191                          /* Available fields
192                          user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
193                          user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
194                          */
195              $.each( data, function( key, val ) {
196                  list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
197                  user_row = "<tr id='"+val.user_hrn+"'>";
198                  user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
199                  user_row += "<td>"+val.user_email+"</td>";
200                  user_row += "<td>"+val.user_hrn+"</td>";
201                  user_row += "<td>"+val.user_first_name+"</td>";
202                  user_row += "<td>"+val.user_last_name+"</td>";
203                                  user_row += "<td>"+val.user_enabled+"</td>";
204                  user_row += "</tr>";
205                  table_users.push(user_row);
206 //                 
207              });
208              $("table#user-tab tr:last").after(table_users.join( "" ));
209              $("div#user-tab-loaded").css("display","block");
210              $("div#user-tab-loading").css("display","none");
211           });
212
213                 $('button#deleteusers').click(function() {
214                 $('input:checkbox.user').each(function (index) {
215                         if(this.checked){
216                         var record_id = this.id;
217                         $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
218                         if(data.success){
219                         $('tr[id="'+record_id+'"]').fadeOut("slow");
220                         $('tr[id="'+record_id+'"]').remove();
221                         }else{
222                         alert("Rest Error for "+record_id+": "+data.error);
223                         }   
224                 });     
225                 } 
226         }); 
227         }); 
228  {% endif %}
229  {% endif %}
230 });
231
232
233 </script>
234 {% endblock %}