styled users view
[myslice.git] / portal / templates / slice-tab-users-view.html
index 7d3dcbb..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>
-                               <button id="addusers" type="button" class="btn btn-default"><span class="glyphicon glyphicon-refresh"></span>Add users</button>
+
+                <!-- 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() {
+            // 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 = [];
-                       //console.log("the value you selected: " + selectedValue);
                $.post("/rest/user/",{'filters':{'parent_authority': "{{user_details.parent_authority}}"}}, function( data ) {
                var list_users = [];
                var table_users = [];
@@ -54,8 +61,8 @@
                                                if (element == "{{slice}}"){
                                                        //console.log("the slice is: "+ element);       
                                                        flag_checkbox = 1;
-                                                       slice_users.push (val.user_email)
-                                                       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){
                        table_users.push(user_row);
                 
                });
-                                console.log("slice users before")
-                                console.log(slice_users)
-
+            
                                $("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(function() {
-               $('input:checkbox.user').each(function (index) {
-               if(this.checked){
-                       var record_id = this.id;
-                                       console.log("checked")
-                                       console.log($(this)
-                                               .closest('tr') //get the enclosing tr
-                                               .find('td:eq(1)'));  //find any using td:eq(<index>)
-                                       slice_users.push ("yasin.upmc@gmail.com")
-                                       console.log("after")
-                                       console.log(slice_users)
-                                       //console.log(user_email)
-                       $.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();
-                       }else{
-                               alert("Rest Error for "+record_id+": "+data.error);
-                       }
-                       });
-                
-               }
-               });
-               // TODO: refresh table
-               //window.location="/portal/institution#slices";
-       });
+            }); // button#addusers click
 
-               });
-       //      });
-    });
+    }); // document ready
 </script>