layout and style changes
[myslice.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="" /> Affiliation to an Institution</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="#">INSTITUTION</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="onelab_membership" style="float:left; width:30%;">
17                 <img src="{{ STATIC_URL }}img/onelab-logo.png" alt="" /><br>
18                 <div id="onelab-data"></div>
19             </div>
20             <div id="authority-data" style="float:right; width:70%;">
21             </div>
22         </div>
23     </div>
24     <div class="home-panel" id="users" style="display:none;">
25                 <br>
26         <h1>Users: {{user_details.parent_authority}}</button></h1>
27         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
28         <div id="user-tab-loaded" style="display:none;">
29             <table id="user-tab">
30                 <tr>
31                     <th>+/-</th>
32                     <th>Email</th>
33                     <th>user_hrn</th>
34                     <th>First name</th>
35                     <th>Last name</th>
36                     <th>Enabled</th>
37                 </tr>
38             </table>
39             <br>
40             <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
41         </div>
42         </div>
43     <div class="home-panel" id="slices" style="display:none;">
44         <br>
45         <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>
46         <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
47         <div id="slice-tab-loaded" style="display:none;">
48             <table id="slice-tab">
49                 <tr>
50                     <th>+/-</th>
51                     <th>slice_hrn</th>
52                     <th>users</th>
53                     <th>url</th>
54                     <th>nodes</th>
55                     <th>expiration</th>
56                 </tr>
57             </table>
58             <br>
59             <div>
60                 <button id="renewslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
61                 <button id="deleteslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
62             </div>
63         </div>
64     </div>
65 </div>
66 <script>
67     $(document).ready(function() {
68         $('a.home-tab').click(function() {
69             $('ul.nav-tabs li').removeClass('active');
70             $(this).parent().addClass('active');
71             $('div.home-panel').hide();
72             $('div#'+$(this).data('panel')).show();
73         });
74         var url = window.location;
75         if(url.hash) {
76             // Fragment exists 
77             tab = url.href.split("#")[1];
78             tab_exists = $('div#'+tab).length;
79             if (tab_exists) {
80                $('ul.nav-tabs li').removeClass('active');
81                $('li#'+tab+'-tab').addClass('active');
82                $('div.home-panel').hide();            
83                $('div#'+tab).show();
84             }
85         }
86         $('button#createslice').click(function() {
87             window.location="/portal/slice_request/";
88         })
89         ;$('button#slicerequestbtn').click(function() {
90             /*
91             window.location="/portal/slice_request/";
92             */
93         });
94         {% if person %}
95         {% if user_details.parent_authority %}
96         $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
97             var authority_data = [];
98             var onelab_data = [];
99                         /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
100             'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'     */
101             $.each( data, function( key, val ) {
102                 authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
103                 authority_row += "<br>";
104                 authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
105                 authority_row += "<br>";
106                 authority_row += "<b>"+val.name+"</b><br>";
107                 authority_row += "<br>";
108                 authority_row += "<b>Address:</b> "+val.address+"<br>";
109                 authority_row += "<b>City:</b> "+val.postcode+" "+val.city+"<br>";
110                 authority_row += "<br>";
111                 authority_row += "<b>Country:</b> "+val.country+"<br>";
112                 authority_row += "<br>";
113                 authority_row += "<br>";
114                 authority_row += "<h2>Contacts</h2>";
115                 authority_row += "<b>Legal:</b> ";
116                 /*
117
118                 TODO: find a way to express JSON correctly given the constrains: CSV / JSON
119
120                 legal = jQuery.parseJSON(val.legal);
121                 if($.isArray(legal)){
122                     $.each(legal, function(k,v){
123                         authority_row += k+" "+v+"<br>";
124                     });
125                 }else{
126                 */
127                     authority_row += val.legal+"<br>";
128                 //}
129                 authority_row += "<br>";
130                 authority_row += "<b>Scientific:</b> ";
131                 /*
132                 scientific = jQuery.parseJSON(val.scientific);
133                 if($.isArray(scientific)){
134                     $.each(scientific, function(v){
135                         authority_row += v+", ";
136                     });
137                 }else{
138                 */
139                     authority_row += val.scientific+"<br>";
140                 //}
141                 onelab_membership = "<b>Membership:</b> "+val.onelab_membership;
142                 onelab_data.push(onelab_membership);
143                 authority_data.push(authority_row);
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", "user", "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
163                 if(val.user=="undefined" || val.user==null){
164                     user_length=0;
165                 }else{
166                     user_length=val.user.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>";
176                 slice_row += "<td><input type='checkbox'></td>";
177                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
178                 slice_row += "<td>"+user_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         $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
194             var list_users = [];
195             var table_users = [];
196                         /*
197                         "enabled", "keys", "parent_authority", "user_first_name", "user_last_name", "user_phone", "user_hrn", "slice", "user_email"
198                         */
199             $.each( data, function( key, val ) {
200                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
201                 user_row = "<tr>";
202                 user_row += "<td><input type='checkbox'></td>";
203                 user_row += "<td>"+val.user_email+"</td>";
204                 user_row += "<td>"+val.user_hrn+"</td>";
205                 user_row += "<td>"+val.user_first_name+"</td>";
206                 user_row += "<td>"+val.user_last_name+"</td>";
207                                 user_row += "<td>"+val.enabled+"</td>";
208                 user_row += "</tr>";
209                 table_users.push(user_row);
210                 
211             });
212             $("table#user-tab tr:last").after(table_users.join( "" ));
213             $("div#user-tab-loaded").css("display","block");
214             $("div#user-tab-loading").css("display","none");
215          });
216          {% endif %}
217          {% endif %}
218     });
219 </script>
220 {% endblock %}