mgt/slice tab: show only the first user (TO BE MODIFIED)
[myslice.git] / portal / templates / fibre / fibre_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 class="active"><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 <!--
31         <div class="tab-pane active row" id="about">
32         </div>
33 -->
34         <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
35                 <div class="col-md-12 el">
36                         <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
37                                 <div id="user-tab-loaded" style="display:none;">
38                                 <table id="user-tab" class="table">
39                                         <tr>
40                                         <th>+/-</th>
41                                         <th>User hrn </th>
42                                         <th>Email</th>
43                                         <th>First name</th>
44                                         <th>Last name</th>
45                                         <th>Enabled</th>
46                                         </tr>
47                                 </table>
48                                 
49                         </div>
50                         {%if 'is_pi'  in pi %}  
51                         <div>
52                                 <button id="deleteusers" type="button" class="btn btn-danger"><span class="glyphicon glyphicon-remove"></span> Delete selected users</button>
53                         </div>
54                         <p></p>
55                         <p></p>
56                         <div> <button type="button" class="btn btn-onelab" onclick="window.location.href='/'">Home</button> </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>Expiration</th>
73                     </tr>
74                 </table>                        
75             </div>
76         {% if 'is_pi'  in pi %}
77         <div>
78                 {% if 'is_pi'  in 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             <p></p>
86             <p></p>
87             <div><button type="button" class="btn btn-onelab" onclick="window.location.href='/'">Home</button></div>
88         </div>
89                 {% endif %} 
90            </div>
91         </div>
92         <div class="tab-pane row" id="requests">
93         </div>
94 </div>
95 <script>
96 $(document).ready(function() {
97     {% if person %}
98     {% if user_details.parent_authority %}
99
100         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
101             var username = "{{person.username}}";
102             var list_slices = [];
103             var table_slices = [];
104             /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
105             $.each( data, function( key, val ) {
106                 if(String(val.users[0]).indexOf("@") != -1){
107                 if(String(val.users[0]).split("@")[1] == username.split("@")[1]){
108                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
109                 if(val.nodes=="undefined" || val.nodes==null){
110                     nodes_length=0;
111                 }else{
112                     nodes_length=val.nodes.length;
113                 }
114                 console.log(val);
115                 if(val.users=="undefined" || val.users==null){
116                     users_length=0;
117                 }else{
118                     users_length=val.users.length;
119                 }
120
121                 if(val.slice_url=="undefined" || val.slice_url==null){
122                     slice_url="";
123                 }else{
124                     slice_url="<a href='"+val.slice_url+"' target='_blank'>"+val.slice_url+"</a>";
125                 }
126                 
127                 slice_row = "<tr id='"+val.slice_hrn+"'>";
128                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
129                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
130                 slice_row += "<td>"+val.users[0]+"</td>";
131                 slice_row += "<td>"+slice_url+"</td>";
132                 //slice_row += "<td>"+nodes_length+"</td>";
133                 slice_row += "<td>"+val.slice_expires+"</td>";
134                 slice_row += "</tr>";
135                 table_slices.push(slice_row);
136                 }
137               }
138             });
139            
140             /* $("div#slice-list").html($( "<ul/>", { html: list_slices.join( "" ) })); */
141             $("table#slice-tab tr:last").after(table_slices.join( "" ));
142             $("div#slice-tab-loaded").css("display","block");
143             $("div#slice-tab-loading").css("display","none");
144         });
145                 
146                 
147         $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
148             var username ="{{person.username}}";
149             var list_users = [];
150             var table_users = [];
151                     /* Available fields
152                     user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
153                     user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
154                     */
155             $.each( data, function( key, val ) {
156                 if (val.user_hrn.indexOf('@') != -1 ){
157                   if (val.user_hrn.split("@")[1] == username.split("@")[1]){
158                     list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
159                     user_row = "<tr id='"+val.user_hrn+"'>";
160                     user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
161                     user_row += "<td>"+val.user_hrn+"</td>";
162                     user_row += "<td>"+val.user_email+"</td>";
163                     user_row += "<td>"+val.user_first_name+"</td>";
164                     user_row += "<td>"+val.user_last_name+"</td>";
165                                 user_row += "<td>"+val.user_enabled+"</td>";
166                     user_row += "</tr>";
167                 table_users.push(user_row);}
168                 }
169             });
170             $("table#user-tab tr:last").after(table_users.join( "" ));
171             $("div#user-tab-loaded").css("display","block");
172             $("div#user-tab-loading").css("display","none");
173         });
174
175     {% endif %}
176     {% endif %}
177
178 }); // End document.ready
179
180 $(document).ready(function() {
181         $('.nav-tabs a').click(function (e) {
182                 e.preventDefault();
183                 $(this).tab('show');
184         var id = $(this).attr('href').substr(1);
185         if ((id == 'requests') || (id == 'about'))
186                 $("#" + id).load('/management/' + id);
187         });
188         var hash = window.location.hash;
189         if (hash) {
190                 $('.nav-tabs a[href='+hash+']').click();
191         } else {
192                 $('.nav-tabs a[href=#about]').click();
193         }
194 });
195 </script>
196 {% endblock %}