Merge branch 'onelab' of ssh://git.onelab.eu/git/myslice into onelab
[myslice.git] / portal / templates / institution.html
1 {% extends "layout-unfold1.html" %}
2
3 {% block unfold_main %}
4 <div class="wrapper" id="institution">
5     <ul class="nav nav-tabs">
6       <li class="active" id="authority-tab"><a class="home-tab" data-panel="institution" href="#">INSTITUTION</a></li>
7       <li id="users-tab"><a class="home-tab" data-panel="users" href="#">USERS</a></li>
8       <li id="slices-tab"><a class="home-tab" data-panel="slices" href="#">SLICES</a></li>
9     </ul>
10     <div class="home-panel" id="institution">
11         <h1><img src="{{ STATIC_URL }}img/icon_authority_color_small.png" alt="" /> Affiliation to an Institution</h1>
12         <br>
13         <div id="authority-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Authority" /></div>
14         <div id="authority-tab-loaded" style="display:none;">
15             <div id="onelab_membership" style="float:left; width:30%;">
16                 <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
17                 <div id="onelab-data"></div>
18             </div>
19             <div id="authority-data" style="float:right; width:70%;">
20             </div>
21         </div>
22     </div>
23     <div class="home-panel" id="users" style="display:none;">
24                 <br>
25         <h1>Users: {{user_details.parent_authority}}</button></h1>
26         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
27         <div id="user-tab-loaded" style="display:none;">
28             <table id="user-tab">
29                 <tr>
30                     <th>+/-</th>
31                     <th>Email</th>
32                     <th>user_hrn</th>
33                     <th>First name</th>
34                     <th>Last name</th>
35                     <th>Enabled</th>
36                 </tr>
37             </table>
38             <br>
39             <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
40         </div>
41         </div>
42     <div class="home-panel" id="slices" style="display:none;">
43         <br>
44         <h1>Slices: {{user_details.parent_authority}} <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create a Slice</button></h1>
45         <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
46         <div id="slice-tab-loaded" style="display:none;">
47             <table id="slice-tab">
48                 <tr>
49                     <th>+/-</th>
50                     <th>slice_hrn</th>
51                     <th>users</th>
52                     <th>url</th>
53                     <th>nodes</th>
54                     <th>expiration</th>
55                 </tr>
56             </table>
57             <br>
58             <div>
59                 <button id="renewslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
60                 <button id="deleteslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
61             </div>
62         </div>
63     </div>
64 </div>
65 <script>
66     $(document).ready(function() {
67         $('a.home-tab').click(function() {
68             $('ul.nav-tabs li').removeClass('active');
69             $(this).parent().addClass('active');
70             $('div.home-panel').hide();
71             $('div#'+$(this).data('panel')).show();
72         });
73         var url = window.location;
74         if(url.hash) {
75             // Fragment exists 
76             tab = url.href.split("#")[1];
77             tab_exists = $('div#'+tab).length;
78             if (tab_exists) {
79                $('ul.nav-tabs li').removeClass('active');
80                $('li#'+tab+'-tab').addClass('active');
81                $('div.home-panel').hide();            
82                $('div#'+tab).show();
83             }
84         }
85         $('button#createslice').click(function() {
86             window.location="/portal/slice_request/";
87         })
88         ;$('button#slicerequestbtn').click(function() {
89             /*
90             window.location="/portal/slice_request/";
91             */
92         });
93         {% if person %}
94         {% if user_details.parent_authority %}
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>Membership:</b> "+val.onelab_membership;
141                 onelab_data.push(onelab_membership);
142                 authority_data.push(authority_row);
143             });
144             $("div#authority-data").html(authority_data.join( "" ));
145             $("div#onelab-data").html(onelab_data.join( "" ));
146             $("div#authority-tab-loaded").css("display","block");
147             $("div#authority-tab-loading").css("display","none");
148          });
149
150         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
151             var list_slices = [];
152             var table_slices = [];
153             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "user", "slice_urn", "slice_expires" */
154             $.each( data, function( key, val ) {
155                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
156                 if(val.nodes=="undefined" || val.nodes==null){
157                     nodes_length=0;
158                 }else{
159                     nodes_length=val.nodes.length;
160                 }
161
162                 if(val.user=="undefined" || val.user==null){
163                     user_length=0;
164                 }else{
165                     user_length=val.user.length;
166                 }
167
168                 if(val.slice_url=="undefined" || val.slice_url==null){
169                     slice_url="";
170                 }else{
171                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
172                 }
173                 
174                 slice_row = "<tr>";
175                 slice_row += "<td><input type='checkbox'></td>";
176                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
177                 slice_row += "<td>"+user_length+"</td>";
178                 slice_row += "<td>"+slice_url+"</td>";
179                 slice_row += "<td>"+nodes_length+"</td>";
180                 slice_row += "<td>"+val.slice_expires+"</td>";
181                 slice_row += "</tr>";
182                 table_slices.push(slice_row);
183                 
184             });
185            
186             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
187             $("table#slice-tab tr:last").after(table_slices.join( "" ));
188             $("div#slice-tab-loaded").css("display","block");
189             $("div#slice-tab-loading").css("display","none");
190         });
191
192         $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
193             var list_users = [];
194             var table_users = [];
195                         /*
196                         "enabled", "keys", "parent_authority", "user_first_name", "user_last_name", "user_phone", "user_hrn", "slice", "user_email"
197                         */
198             $.each( data, function( key, val ) {
199                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
200                 user_row = "<tr>";
201                 user_row += "<td><input type='checkbox'></td>";
202                 user_row += "<td>"+val.user_email+"</td>";
203                 user_row += "<td>"+val.user_hrn+"</td>";
204                 user_row += "<td>"+val.user_first_name+"</td>";
205                 user_row += "<td>"+val.user_last_name+"</td>";
206                                 user_row += "<td>"+val.enabled+"</td>";
207                 user_row += "</tr>";
208                 table_users.push(user_row);
209                 
210             });
211             $("table#user-tab tr:last").after(table_users.join( "" ));
212             $("div#user-tab-loaded").css("display","block");
213             $("div#user-tab-loading").css("display","none");
214          });
215          {% endif %}
216          {% endif %}
217     });
218 </script>
219 {% endblock unfold_main %}