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