4ec49ca2d88e3876c49af1525b817f50943204ac
[unfold.git] / portal / templates / 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"></div>
25                     </div>
26            </div>
27         </div>
28
29         <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
30                 <div class="col-md-12">
31                         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
32                                 <div id="user-tab-loaded" style="display:none;">
33                                 <table id="user-tab">
34                                         <tr>
35                                         <th>+/-</th>
36                                         <th>email</th>
37                                         <th>user_hrn</th>
38                                         <th>first name</th>
39                                         <th>last name</th>
40                                         <th>enabled</th>
41                                         </tr>
42                                 </table>
43                                 {%if 'is_pi'  in pi %}  
44                                 <div>
45                                         <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
46                                 </div>
47                                 {%endif%}
48                         </div>
49                 </div>
50         </div>
51         
52         <div class="tab-pane row" id="slices">
53             <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
54             <div id="slice-tab-loaded" style="display:none;">
55                 {%if 'is_pi'  in pi %}
56                 <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> create slice</button>
57                 {%else%}
58                 <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> request slice</button>
59                 {%endif%}
60                 <table id="slice-tab">
61                     <tr>
62                         <th>+/-</th>
63                         <th>slice_hrn</th>
64                         <th>users</th>
65                         <th>url</th>
66                         <th>nodes</th>
67                         <th>expiration</th>
68                     </tr>
69                 </table>
70                 <br>
71                         {%if 'is_pi'  in pi %}
72                 <div>
73                     <button id="renewslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
74                     <button id="deleteslices" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
75                 </div>
76                         {%endif%} 
77             </div>
78         </div>
79 </div>
80 <script>
81     $(document).ready(function() {
82         {% if person %}
83         {% if user_details.parent_authority %}
84         
85         $.post("/rest/authority/",{'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
86             var authority_data = [];
87             var onelab_data = [];
88                         /* 'city','enabled','legal','longitude','onelab_membership','address','parent_authority','slice','user','country',
89             'tech','abbreviated_name','url','postcode','description','scientific','authority_hrn','latitude','name'     */
90             $.each( data, function( key, val ) {
91                 authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
92                 authority_row += "<br>";
93                 authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
94                 authority_data.push(authority_row);
95             });
96             $("div#authority-data").html(authority_data.join( "" ));
97             $("div#onelab-data").html(onelab_data.join( "" ));
98             $("div#authority-tab-loaded").css("display","block");
99             $("div#authority-tab-loading").css("display","none");
100          });
101
102         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
103             var list_slices = [];
104             var table_slices = [];
105             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
106             $.each( data, function( key, val ) {
107                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
108                 if(val.nodes=="undefined" || val.nodes==null){
109                     nodes_length=0;
110                 }else{
111                     nodes_length=val.nodes.length;
112                 }
113                 if(val.users=="undefined" || val.users==null){
114                     users_length=0;
115                 }else{
116                     users_length=val.users.length;
117                 }
118
119                 if(val.slice_url=="undefined" || val.slice_url==null){
120                     slice_url="";
121                 }else{
122                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
123                 }
124                 
125                 slice_row = "<tr id='"+val.slice_hrn+"'>";
126                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
127                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
128                 slice_row += "<td>"+users_length+"</td>";
129                 slice_row += "<td>"+slice_url+"</td>";
130                 slice_row += "<td>"+nodes_length+"</td>";
131                 slice_row += "<td>"+val.slice_expires+"</td>";
132                 slice_row += "</tr>";
133                 table_slices.push(slice_row);
134                 
135             });
136            
137             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
138             $("table#slice-tab tr:last").after(table_slices.join( "" ));
139             $("div#slice-tab-loaded").css("display","block");
140             $("div#slice-tab-loading").css("display","none");
141         });
142
143                 $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
144              var list_users = [];
145              var table_users = [];
146                          /* Available fields
147                          user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
148                          user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
149                          */
150              $.each( data, function( key, val ) {
151                  list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
152                  user_row = "<tr id='"+val.user_hrn+"'>";
153                  user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
154                  user_row += "<td>"+val.user_email+"</td>";
155                  user_row += "<td>"+val.user_hrn+"</td>";
156                  user_row += "<td>"+val.user_first_name+"</td>";
157                  user_row += "<td>"+val.user_last_name+"</td>";
158                                  user_row += "<td>"+val.user_enabled+"</td>";
159                  user_row += "</tr>";
160                  table_users.push(user_row);
161 //                 
162              });
163              $("table#user-tab tr:last").after(table_users.join( "" ));
164              $("div#user-tab-loaded").css("display","block");
165              $("div#user-tab-loading").css("display","none");
166           });
167
168                 $('button#deleteusers').click(function() {
169                 $('input:checkbox.user').each(function (index) {
170                         if(this.checked){
171                         var record_id = this.id;
172                         $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
173                         if(data.success){
174                         $('tr[id="'+record_id+'"]').fadeOut("slow");
175                         $('tr[id="'+record_id+'"]').remove();
176                         }else{
177                         alert("Rest Error for "+record_id+": "+data.error);
178                         }   
179                 });     
180                 } 
181         }); 
182         }); 
183                 
184                 
185    {% endif %}
186    {% endif %}
187 });
188
189
190 </script>
191 {% endblock %}