fix: PI check with a function
[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                          <div class="breadcrumbs">
12                                  Management &nbsp;>&nbsp; Institution: <span id="authority_name"></span>
13                          </div>
14                 </div>
15         </div>
16 </div>
17 <div class="container">
18         <div class="row">
19                 <div class="col-md-12">
20                         <ul class="nav nav-tabs nav-section">
21                                 <li class="active"><a href="#about">About</a></li>
22                                 <li><a href="#users">Users</a></li>
23                                 <li><a href="#slices">Slices</a></li>
24                                 <li><a href="#requests">Requests</a></li>
25                         </ul>
26             </div>
27         </div>
28 </div>
29 <div class="container tab-content">
30         <div class="tab-pane active row" id="about">
31         </div>
32         
33         <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
34                 <div class="col-md-12 el">
35                         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
36                                 <div id="user-tab-loaded" style="display:none;">
37                                 <table id="user-tab" class="table">
38                                         <tr>
39                                         <th>+/-</th>
40                                         <th>Email</th>
41                                         <th>User hrn</th>
42                             <!--
43                                         <th>First name</th>
44                                         <th>Last name</th>
45                                         <th>Enabled</th>
46                             -->
47                                         </tr>
48                                 </table>
49                                 
50                         </div>
51                         {%if  pi %}     
52                         <div>
53                                 <button id="makepi" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-plus"></span> Upgrade to PI</button>
54                                 <button id="removepi" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Downgrade to  user</button>
55                                 <button id="deleteusers" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected users</button>
56                         </div>
57                         {% endif %}
58                 </div>
59         </div>
60
61         <div class="tab-pane row" id="slices">
62                 <div class="col-md-12 el">
63             <div id="slice-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
64             <div id="slice-tab-loaded" style="display:none;">
65                 <table id="slice-tab" class="table">
66                     <tr>
67                         <th>+/-</th>
68                         <th>Slice hrn</th>
69                         <th>Users</th>
70                         <th>Url</th>
71                         <!-- <th>nodes</th> -->
72                         <th>Creation</th>
73                     </tr>
74                 </table>                        
75             </div>
76         {% if pi %}
77         <div>
78                 {% if  pi %}
79                         <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Create slice</button>
80                         {% else %}
81                         <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> Request slice</button>
82                         {% endif %}
83             <button id="renewslices" type="button" class="btn btn-primary"><span class="glyphicon glyphicon-refresh"></span> Renew Slices</button>
84             <button id="deleteslices" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete Slices</button>
85         </div>
86                 {% endif %} 
87            </div>
88         </div>
89         <div class="tab-pane row" id="requests">
90         </div>
91 </div>
92 <script>
93 $(document).ready(function() {
94     {% if person %}
95     {% if user_details.parent_authority %}
96
97         $.post("/rest/myslice:slice/",{'fields':['slice_hrn','users','url','slice_date_created'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
98             var list_slices = [];
99             var table_slices = [];
100             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
101             $.each( data, function( key, val ) {
102                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
103                 if(val.nodes=="undefined" || val.nodes==null){
104                     nodes_length=0;
105                 }else{
106                     nodes_length=val.nodes.length;
107                 }
108                 //console.log(val);
109                 if(val.users=="undefined" || val.users==null){
110                     users_length=0;
111                 }else{
112                     users_length=val.users.length;
113                 }
114
115                 if(val.url=="undefined" || val.url==null){
116                     slice_url="";
117                 }else{
118                     slice_url="<a href='"+val.url+"' target='_blank'>"+val.url+"</a>";
119                 }
120                 
121                 slice_row = "<tr id='"+val.slice_hrn+"'>";
122                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
123                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
124                 slice_row += "<td>"+users_length+"</td>";
125                 slice_row += "<td>"+slice_url+"</td>";
126                 //slice_row += "<td>"+nodes_length+"</td>";
127                 slice_row += "<td>"+val.slice_date_created+"</td>";
128                 slice_row += "</tr>";
129                 table_slices.push(slice_row);
130                 
131             });
132            
133             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
134             $("table#slice-tab tr:last").after(table_slices.join( "" ));
135             $("div#slice-tab-loaded").css("display","block");
136             $("div#slice-tab-loading").css("display","none");
137         });
138                 
139         {% if project %}
140         // XXX LOIC CACHE PB IF PREFIXED !
141                 $.post("/rest/authority/",{'fields':['pi_users'],'filters':{'authority_hrn':'{{user_details.parent_authority}}'}}, function( data ) {
142            
143             var table_users = [];
144             $.each( data[0].pi_users, function( key, val ) {
145                 console.log(val);
146                 user_row = "<tr id='"+val+"'>";
147                 user_row += "<td><input type='checkbox' class='user' id='"+val+"'></td>";
148                 user_row += "<td></td>";
149                 user_row += "<td>"+val+"</td>";
150                 user_row += "</tr>";
151                 table_users.push(user_row);
152             });
153             $("table#user-tab tr:last").after(table_users.join( "" ));
154             $("div#user-tab-loaded").css("display","block");
155             $("div#user-tab-loading").css("display","none");
156
157         });
158         {% else %}
159         $.post("/rest/user/",{'fields':['user_hrn','user_email'],'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
160             var list_users = [];
161             var table_users = [];
162                     /* Available fields
163                     user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
164                     user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
165                     */
166             $.each( data, function( key, val ) {
167                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
168                 user_row = "<tr id='"+val.user_hrn+"'>";
169                 user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
170                 user_row += "<td>"+val.user_email+"</td>";
171                 user_row += "<td>"+val.user_hrn+"</td>";
172                 /*
173                 user_row += "<td>"+val.user_first_name+"</td>";
174                 user_row += "<td>"+val.user_last_name+"</td>";
175                             user_row += "<td>"+val.user_enabled+"</td>";
176                 */
177                 user_row += "</tr>";
178                 table_users.push(user_row);
179             });
180             $("table#user-tab tr:last").after(table_users.join( "" ));
181             $("div#user-tab-loaded").css("display","block");
182             $("div#user-tab-loading").css("display","none");
183         });
184
185         {% endif %}
186     {% endif %}
187     {% endif %}
188
189 }); // End document.ready
190
191 $(document).ready(function() {
192         $('.nav-tabs a').click(function (e) {
193                 e.preventDefault();
194                 $(this).tab('show');
195         var id = $(this).attr('href').substr(1);
196         /*
197         if ((id == 'requests') || (id == 'about'))
198                 $("#" + id).load('/management/' + id);
199         */
200         });
201         var hash = window.location.hash;
202         if (hash) {
203                 $('.nav-tabs a[href='+hash+']').click();
204         } else {
205                 $('.nav-tabs a[href=#about]').click();
206         }
207 });
208 </script>
209 {% endblock %}