Advertisement
Guest User

Untitled

a guest
Mar 22nd, 2016
80
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.89 KB | None | 0 0
  1. angular.module('watchApp').controller('userController', ['$scope', function ($scope) {
  2. $scope.users = users;
  3.  
  4. clearBoxes();
  5. clearUser();
  6.  
  7.  
  8. $scope.addUser = function (e) {
  9. if (e.confirmpassword === e.password) {
  10. $scope.users.push(e);
  11. clearUser();
  12. $scope.newUser = false;
  13. }
  14. else {
  15. alert("Password's don't match!")
  16. }
  17. }
  18.  
  19. $scope.removeUser = function (h) {
  20. if ($scope.checkBox.value) {
  21. for (var i = 0; i < $scope.users.length; i++) {
  22. if($scope.users[i].user == h.user){
  23. console.log("found at pos", i);
  24. $scope.users.splice(i, 1);
  25. }
  26. }
  27. //
  28. //clearBoxes();
  29.  
  30. }
  31. }
  32.  
  33. function clearUser() {
  34. $scope.e = {};
  35. $scope.e.users = $scope.users[0];
  36. $scope.newUser = false;
  37. }
  38.  
  39. function clearBoxes() {
  40. $scope.checkBox = {};
  41. }
  42. }]);
  43.  
  44. ------------------------------------------------------------------------------
  45.  
  46. <div ng-controller="userController" class="container">
  47. <div class="row">
  48. <div class="col-md-3">
  49. <form class="form">
  50. <button type="button" class="btn btn-default" ng-click="newUser = true">Add New User</button>
  51. <br />
  52. <br />
  53. <div class="form-group" ng-show="newUser">
  54. <label for="userid">User Name</label>
  55. <input type="text" class="form-control" id="user-name" placeholder="Username" ng-model="e.user" />
  56. <br />
  57. <label for="userpass">Desired Password</label>
  58. <input type="password" class="form-control" id="user-password" placeholder="Desired Password" ng-model="e.password" />
  59. <br />
  60. <label for="userpass">Confirm Password</label>
  61. <input type="password" class="form-control" id="user-password" placeholder="Desired Password" ng-model="e.confirmpassword" />
  62. <br />
  63. <label for="userDesc">User Description</label>
  64. <input type="text" class="form-control" id="user-desc" placeholder="Description" ng-model="e.desc" />
  65. <br />
  66. <label for="userActive">Is user active?</label>
  67. <select class="form-control" ng-model="e.active">
  68. <option value="true">Active</option>
  69. <option value="false">Inactive</option>
  70. </select>
  71. <br />
  72. <button type="submit" class="btn btn-default" ng-click="addUser(e)">Add User</button>
  73. </div>
  74.  
  75. </form>
  76. </div>
  77. <div class="col-md-9">
  78. <div class="panel panel-default">
  79. <div class="panel-heading">
  80. <span>Active Users</span>
  81. </div>
  82. <div class="panel-body">
  83. <div ng-repeat="h in users">
  84. <table class="table">
  85. <thead>
  86. <tr>
  87. <th class="col-md-10">Name</th>
  88. <th>Active</th>
  89. </tr>
  90. </thead>
  91. <tbody>
  92. <tr>
  93. <td>{{h.user}}</td>
  94. <td>
  95. <select ng-model="h.active">
  96. <option value="true">Active</option>
  97. <option value="false">Inactive</option>
  98. </select>
  99. </td>
  100. </tr>
  101. </tbody>
  102. <thead>
  103. <tr>
  104. <th class="col-md-12">Description</th>
  105. </tr>
  106. </thead>
  107. <tbody>
  108. <tr>
  109. <td>{{h.desc}}</td>
  110. <td><input type="checkbox" id="remove" ng-model="checkBox.value" /></td>
  111. </tr>
  112. </tbody>
  113. </table>
  114. <button type="submit" class="btn btn-default" ng-click="removeUser(h)">Remove Selected</button>
  115.  
  116. </div>
  117. </div>
  118. </div>
  119. <div class="col-md-10"></div>
  120.  
  121. </div>
  122. </div>
  123. </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement