Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- angular.module('watchApp').controller('userController', ['$scope', function ($scope) {
- $scope.users = users;
- clearBoxes();
- clearUser();
- $scope.addUser = function (e) {
- if (e.confirmpassword === e.password) {
- $scope.users.push(e);
- clearUser();
- $scope.newUser = false;
- }
- else {
- alert("Password's don't match!")
- }
- }
- $scope.removeUser = function (h) {
- if ($scope.checkBox.value) {
- for (var i = 0; i < $scope.users.length; i++) {
- if($scope.users[i].user == h.user){
- console.log("found at pos", i);
- $scope.users.splice(i, 1);
- }
- }
- //
- //clearBoxes();
- }
- }
- function clearUser() {
- $scope.e = {};
- $scope.e.users = $scope.users[0];
- $scope.newUser = false;
- }
- function clearBoxes() {
- $scope.checkBox = {};
- }
- }]);
- ------------------------------------------------------------------------------
- <div ng-controller="userController" class="container">
- <div class="row">
- <div class="col-md-3">
- <form class="form">
- <button type="button" class="btn btn-default" ng-click="newUser = true">Add New User</button>
- <br />
- <br />
- <div class="form-group" ng-show="newUser">
- <label for="userid">User Name</label>
- <input type="text" class="form-control" id="user-name" placeholder="Username" ng-model="e.user" />
- <br />
- <label for="userpass">Desired Password</label>
- <input type="password" class="form-control" id="user-password" placeholder="Desired Password" ng-model="e.password" />
- <br />
- <label for="userpass">Confirm Password</label>
- <input type="password" class="form-control" id="user-password" placeholder="Desired Password" ng-model="e.confirmpassword" />
- <br />
- <label for="userDesc">User Description</label>
- <input type="text" class="form-control" id="user-desc" placeholder="Description" ng-model="e.desc" />
- <br />
- <label for="userActive">Is user active?</label>
- <select class="form-control" ng-model="e.active">
- <option value="true">Active</option>
- <option value="false">Inactive</option>
- </select>
- <br />
- <button type="submit" class="btn btn-default" ng-click="addUser(e)">Add User</button>
- </div>
- </form>
- </div>
- <div class="col-md-9">
- <div class="panel panel-default">
- <div class="panel-heading">
- <span>Active Users</span>
- </div>
- <div class="panel-body">
- <div ng-repeat="h in users">
- <table class="table">
- <thead>
- <tr>
- <th class="col-md-10">Name</th>
- <th>Active</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>{{h.user}}</td>
- <td>
- <select ng-model="h.active">
- <option value="true">Active</option>
- <option value="false">Inactive</option>
- </select>
- </td>
- </tr>
- </tbody>
- <thead>
- <tr>
- <th class="col-md-12">Description</th>
- </tr>
- </thead>
- <tbody>
- <tr>
- <td>{{h.desc}}</td>
- <td><input type="checkbox" id="remove" ng-model="checkBox.value" /></td>
- </tr>
- </tbody>
- </table>
- <button type="submit" class="btn btn-default" ng-click="removeUser(h)">Remove Selected</button>
- </div>
- </div>
- </div>
- <div class="col-md-10"></div>
- </div>
- </div>
- </div>
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement