Institution list of slices: fixed number of users per slice
[myslice.git] / portal / templates / onelab / onelab_institution.html
index ad4f236..0a424fa 100644 (file)
        
        <div class="tab-pane row" id="users" data-authority="{{user_details.parent_authority}}">
                <div class="col-md-12">
-                       <table class="table"><tr><td><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></td></tr></table>
-                       {%if 'is_pi'  in pi %}  
-                       <div>
-                               <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
+                       <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Slices" /></div>
+                               <div id="user-tab-loaded" style="display:none;">
+                               <table id="user-tab">
+                                       <tr>
+                                       <th>+/-</th>
+                                       <th>email</th>
+                                       <th>user_hrn</th>
+                                       <th>first name</th>
+                                       <th>last name</th>
+                                       <th>enabled</th>
+                                       </tr>
+                               </table>
+                               {%if 'is_pi'  in pi %}  
+                               <div>
+                                       <button id="deleteusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-remove"></span> Delete Users</button>
+                               </div>
+                               {%endif%}
                        </div>
-                       {%endif%}
                </div>
-       </div>
+       </div>
+
        <div class="tab-pane row" id="slices">
                {%if 'is_pi'  in pi %}
                <button id="createslice" type="button" class="btn btn-default"><span class="glyphicon glyphicon-plus"></span> create slice</button>
                 authority_row = "<img src='{{ STATIC_URL }}img/institutions/{{user_details.parent_authority}}.gif' alt='' /><br>";
                 authority_row += "<br>";
                 authority_row += "<b>authority:</b> "+val.authority_hrn+"<br>";
+                               authority_row += "<br>";
+                authority_row += "<b>"+val.name+"</b><br>";
+                authority_row += "<br>";
+                authority_row += "<b>Address:</b> "+val.address+"<br>";
+                authority_row += "<b>City:</b> "+val.postcode+" "+val.city+"<br>";
+                authority_row += "<br>";
+                authority_row += "<b>Country:</b> "+val.country+"<br>";
+                authority_row += "<br>";
+                authority_row += "<br>";
+                authority_row += "<h2>Contacts</h2>";
+                authority_row += "<b>Legal:</b> ";
+                               /*
+
+                TODO: find a way to express JSON correctly given the constrains: CSV / JSON
+
+                legal = jQuery.parseJSON(val.legal);
+                if($.isArray(legal)){
+                    $.each(legal, function(k,v){
+                        authority_row += k+" "+v+"<br>";
+                    });
+                }else{
+                */
+                    authority_row += val.legal+"<br>";
+                //}
+                authority_row += "<br>";
+                authority_row += "<b>Scientific:</b> ";
+                /*
+                scientific = jQuery.parseJSON(val.scientific);
+                if($.isArray(scientific)){
+                    $.each(scientific, function(v){
+                        authority_row += v+", ";
+                    });
+                }else{
+                */
+                    authority_row += val.scientific+"<br>";
+                //}
+                onelab_membership = "<b>Status: </b>"+val.onelab_membership;
+                onelab_data.push(onelab_membership);
                 authority_data.push(authority_row);
+
             });
             $("div#authority-data").html(authority_data.join( "" ));
             $("div#onelab-data").html(onelab_data.join( "" ));
         $.post("/rest/slice/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
             var list_slices = [];
             var table_slices = [];
-            /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "user", "slice_urn", "slice_expires" */
+            /* "slice_hrn", "slice_description", "slice_type", "parent_authority", "created", "nodes", "slice_url", "slice_last_updated", "users", "slice_urn", "slice_expires" */
             $.each( data, function( key, val ) {
                 list_slices.push( "<li><a href=\"portal/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></li>" );
                 if(val.nodes=="undefined" || val.nodes==null){
                 }else{
                     nodes_length=val.nodes.length;
                 }
-
-                if(val.user=="undefined" || val.user==null){
-                    user_length=0;
+                console.log(val);
+                if(val.users=="undefined" || val.users==null){
+                    users_length=0;
                 }else{
-                    user_length=val.user.length;
+                    users_length=val.users.length;
                 }
 
                 if(val.slice_url=="undefined" || val.slice_url==null){
                 slice_row = "<tr id='"+val.slice_hrn+"'>";
                 slice_row += "<td><input type='checkbox' class='slice' id='"+val.slice_hrn+"'></td>";
                 slice_row += "<td><a href=\"/slice/"+val.slice_hrn+"\">" + val.slice_hrn + "</a></td>";
-                slice_row += "<td>"+user_length+"</td>";
+                slice_row += "<td>"+users_length+"</td>";
                 slice_row += "<td>"+slice_url+"</td>";
                 slice_row += "<td>"+nodes_length+"</td>";
                 slice_row += "<td>"+val.slice_expires+"</td>";
         });
                
                
-        // $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
-            // var list_users = [];
-            // var table_users = [];
-                       // /* Available fields
-                       // user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
-                       // user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
-                       // */
-            // $.each( data, function( key, val ) {
-                // list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
-// 
-                // user_row = "<tr id='"+val.user_hrn+"'>";
-                // user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
-                // user_row += "<td>"+val.user_email+"</td>";
-                // user_row += "<td>"+val.user_hrn+"</td>";
-                // user_row += "<td>"+val.user_first_name+"</td>";
-                // user_row += "<td>"+val.user_last_name+"</td>";
-                               // user_row += "<td>"+val.user_enabled+"</td>";
-                // user_row += "</tr>";
-                // table_users.push(user_row);
+         $.post("/rest/user/",{'filters':{'parent_authority':'{{user_details.parent_authority}}'}}, function( data ) {
+             var list_users = [];
+             var table_users = [];
+                        /* Available fields
+                        user_gid, user_enabled, slices, pi_authorities, keys, parent_authority, user_first_name,
+                        user_urn, user_last_name, user_phone, user_hrn, user_email, user_type
+                        */
+             $.each( data, function( key, val ) {
+                 list_users.push( "<li><a href=\"portal/user/"+val.user_email+"\">" + val.user_email + "</a></li>" );
+                 user_row = "<tr id='"+val.user_hrn+"'>";
+                 user_row += "<td><input type='checkbox' class='user' id='"+val.user_hrn+"'></td>";
+                 user_row += "<td>"+val.user_email+"</td>";
+                 user_row += "<td>"+val.user_hrn+"</td>";
+                 user_row += "<td>"+val.user_first_name+"</td>";
+                 user_row += "<td>"+val.user_last_name+"</td>";
+                                user_row += "<td>"+val.user_enabled+"</td>";
+                 user_row += "</tr>";
+                 table_users.push(user_row);
 //                 
-            // });
-            // $("table#user-tab tr:last").after(table_users.join( "" ));
-            // $("div#user-tab-loaded").css("display","block");
-            // $("div#user-tab-loading").css("display","none");
-         // });
-         {% endif %}
-         {% endif %}
-    });
+             });
+             $("table#user-tab tr:last").after(table_users.join( "" ));
+             $("div#user-tab-loaded").css("display","block");
+             $("div#user-tab-loading").css("display","none");
+          });
+
+               $('button#deleteusers').click(function() {
+               $('input:checkbox.user').each(function (index) {
+                       if(this.checked){
+                       var record_id = this.id;
+                       $.post("/delete/user/",{'filters':{'user_hrn':this.id}}, function(data) {
+                       if(data.success){
+                       $('tr[id="'+record_id+'"]').fadeOut("slow");
+                       $('tr[id="'+record_id+'"]').remove();
+                       }else{
+                       alert("Rest Error for "+record_id+": "+data.error);
+                       }   
+               });     
+               } 
+       }); 
+       }); 
+ {% endif %}
+ {% endif %}
+});
 
 
 </script>