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