styled users view
[myslice.git] / portal / templates / slice-tab-users-view.html
index 1751ce9..f0cb9b0 100644 (file)
@@ -12,9 +12,7 @@
                        </select> -->
                  </li>
                  <li class="list-group-item">Filter: slice</li>
-                 <li class="list-group-item">...</li>
-                 <li class="list-group-item">...</li>
-                 <li class="list-group-item">...</li>
+                
                </ul>
        
        </div>
                </div>
                <div id="user-tab-loading"><img src="{{ STATIC_URL }}img/loading.gif" alt="Loading Useres" /></div>
                <div id="user-tab-loaded" style="display:none;">
-               <table id="user-tab">
+               <table id="user-tab" class="table">
                        <tr>
                        <th>+/-</th>
                        <th>Email</th>
-                       <th>user_hrn</th>
+                       <th>User hrn</th>
                        <th>Enabled</th>
                        </tr>
                </table>
+
+                <!-- XXX TODO: for the moment only PIs have access to Update but users that have slice credentials should also have access to that -->
+
+                               {% if 'is_pi'  in pi %}
+                               <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-ok"></span> Update users</button>
+                               {%endif%}
                </div>
 <script>
     $(document).ready(function() {
-                       //console.log("the value you selected: " + selectedValue);
+            // TODO: Add a filter based on the list of authorities
+               $.post("/rest/authority/",{'fields':['authority_hrn']}, function( data ) {
+                console.log(data);
+            }); // post rest/authority
+
+                       var slice_users = [];
                $.post("/rest/user/",{'filters':{'parent_authority': "{{user_details.parent_authority}}"}}, function( data ) {
                var list_users = [];
                var table_users = [];
                                                if (element == "{{slice}}"){
                                                        //console.log("the slice is: "+ element);       
                                                        flag_checkbox = 1;
-                                                       user_row += "<td><input type='checkbox' checked='True'></td>";
+                                                       slice_users.push (val.user_hrn)
+                                                       user_row += "<td><input type='checkbox' checked='True' class='user'></td>";
                                                }
                                        }
                                        if(flag_checkbox != 1){
-                               user_row += "<td><input type='checkbox'></td>";
+                               user_row += "<td><input type='checkbox' class='user'></td>";
                                        }
                        user_row += "<td>"+val.user_email+"</td>";
                        user_row += "<td>"+val.user_hrn+"</td>";
                        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");
-               });
-       //      });
-    });
+                $("input:checkbox.user").click(function() {
+                    user_hrn = $(this).closest('tr').find('td:eq(2)').html();
+                    if(this.checked){
+                        var record_id = this.id;
+                        slice_users.push (user_hrn);
+                    }else{
+                        console.log(slice_users);
+                    }
+                });
+           
+               }); // post rest/user
+               $('button#addusers').click(function() {
+                $.post("/update/slice/",{'filters':{'slice_hrn':'{{slice}}'},'params':{'users':slice_users}}, function(data) {
+                       if(data.success){
+                       // TODO: highlight row after success
+                       //$('tr[id="'+record_id+'"]').highlight();
+                       mysliceAlert('Success: slice updated','success', true);
+                       }else{
+                       mysliceAlert('Rest Error for: '+data.error,'warning', true);
+                       }
+                }); // post update slice
+            
+               // TODO: refresh table
+               //window.location="/portal/institution#slices";
+
+            }); // button#addusers click
+
+    }); // document ready
 </script>