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