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