Delete user (client)

This commit is contained in:
Benjamin Gamard 2013-08-10 02:24:31 +02:00 committed by jendib
parent c48eb7a0fe
commit ac424b60cc
2 changed files with 48 additions and 10 deletions

View File

@ -3,7 +3,7 @@
/** /**
* Settings user edition page controller. * Settings user edition page controller.
*/ */
App.controller('SettingsUserEdit', function($scope, $state, $stateParams, Restangular) { App.controller('SettingsUserEdit', function($scope, $dialog, $state, $stateParams, Restangular) {
/** /**
* Returns true if in edit mode (false in add mode). * Returns true if in edit mode (false in add mode).
*/ */
@ -20,6 +20,9 @@ App.controller('SettingsUserEdit', function($scope, $state, $stateParams, Restan
}); });
} }
/**
* Update the current user.
*/
$scope.edit = function() { $scope.edit = function() {
var promise = null; var promise = null;
@ -38,4 +41,27 @@ App.controller('SettingsUserEdit', function($scope, $state, $stateParams, Restan
$state.transitionTo('settings.user'); $state.transitionTo('settings.user');
}); });
}; };
/**
* Delete the current user.
*/
$scope.remove = function () {
var title = 'Delete user';
var msg = 'Do you really want to delete this user? All associated documents, files and tags will be deleted';
var btns = [{result:'cancel', label: 'Cancel'}, {result:'ok', label: 'OK', cssClass: 'btn-primary'}];
$dialog.messageBox(title, msg, btns)
.open()
.then(function(result) {
if (result == 'ok') {
Restangular.one('user', $stateParams.username).remove().then(function() {
$scope.loadUsers();
$state.transitionTo('settings.user');
}, function () {
$state.transitionTo('settings.user');
});
}
});
};
}); });

View File

@ -1,11 +1,16 @@
<h2 ng-show="isEdit()">Edit <small>"{{ user.username }}"</small></h2> <h2 ng-show="isEdit()">Edit
<h2 ng-show="!isEdit()">Add <small>user</small></h2> <small>"{{ user.username }}"</small>
</h2>
<h2 ng-show="!isEdit()">Add
<small>user</small>
</h2>
<form class="form-horizontal" name="editUserForm" novalidate> <form class="form-horizontal" name="editUserForm" novalidate>
<div class="control-group" ng-class="{ error: !editUserForm.username.$valid, success: editUserForm.username.$valid }"> <div class="control-group" ng-class="{ error: !editUserForm.username.$valid, success: editUserForm.username.$valid }">
<label class="control-label" for="inputUsername">Username</label> <label class="control-label" for="inputUsername">Username</label>
<div class="controls"> <div class="controls">
<input name="username" type="text" id="inputUsername" required ng-disabled="isEdit()" <input name="username" type="text" id="inputUsername" required ng-disabled="isEdit()"
ng-minlength="3" ng-maxlength="50" placeholder="Username" ng-model="user.username" /> ng-minlength="3" ng-maxlength="50" placeholder="Username" ng-model="user.username"/>
<span class="help-inline" ng-show="editUserForm.username.$error.required">Required</span> <span class="help-inline" ng-show="editUserForm.username.$error.required">Required</span>
<span class="help-inline" ng-show="editUserForm.username.$error.minlength">Too short</span> <span class="help-inline" ng-show="editUserForm.username.$error.minlength">Too short</span>
<span class="help-inline" ng-show="editUserForm.username.$error.maxlength">Too long</span> <span class="help-inline" ng-show="editUserForm.username.$error.maxlength">Too long</span>
@ -13,9 +18,10 @@
</div> </div>
<div class="control-group" ng-class="{ error: !editUserForm.email.$valid, success: editUserForm.email.$valid }"> <div class="control-group" ng-class="{ error: !editUserForm.email.$valid, success: editUserForm.email.$valid }">
<label class="control-label" for="inputEmail">E-mail</label> <label class="control-label" for="inputEmail">E-mail</label>
<div class="controls"> <div class="controls">
<input name="email" type="email" id="inputEmail" required <input name="email" type="email" id="inputEmail" required
ng-minlength="3" ng-maxlength="50" placeholder="E-mail" ng-model="user.email" /> ng-minlength="3" ng-maxlength="50" placeholder="E-mail" ng-model="user.email"/>
<span class="help-inline" ng-show="editUserForm.email.$error.required">Required</span> <span class="help-inline" ng-show="editUserForm.email.$error.required">Required</span>
<span class="help-inline" ng-show="editUserForm.email.$error.email">Must be a valid e-mail</span> <span class="help-inline" ng-show="editUserForm.email.$error.email">Must be a valid e-mail</span>
<span class="help-inline" ng-show="editUserForm.email.$error.minlength">Too short</span> <span class="help-inline" ng-show="editUserForm.email.$error.minlength">Too short</span>
@ -24,20 +30,23 @@
</div> </div>
<div class="control-group" ng-class="{ error: !editUserForm.password.$valid, success: editUserForm.password.$valid }"> <div class="control-group" ng-class="{ error: !editUserForm.password.$valid, success: editUserForm.password.$valid }">
<label class="control-label" for="inputPassword">Password</label> <label class="control-label" for="inputPassword">Password</label>
<div class="controls"> <div class="controls">
<input name="password" type="password" id="inputPassword" ng-required="!isEdit()" <input name="password" type="password" id="inputPassword" ng-required="!isEdit()"
ng-minlength="8" ng-maxlength="50" placeholder="Password" ng-model="user.password" /> ng-minlength="8" ng-maxlength="50" placeholder="Password" ng-model="user.password"/>
<span class="help-inline" ng-show="editUserForm.password.$error.required">Required</span> <span class="help-inline" ng-show="editUserForm.password.$error.required">Required</span>
<span class="help-inline" ng-show="editUserForm.password.$error.minlength">Too short</span> <span class="help-inline" ng-show="editUserForm.password.$error.minlength">Too short</span>
<span class="help-inline" ng-show="editUserForm.password.$error.maxlength">Too long</span> <span class="help-inline" ng-show="editUserForm.password.$error.maxlength">Too long</span>
</div> </div>
</div> </div>
<div class="control-group" ng-class="{ error: !editUserForm.passwordconfirm.$valid, success: editUserForm.passwordconfirm.$valid }"> <div class="control-group"
ng-class="{ error: !editUserForm.passwordconfirm.$valid, success: editUserForm.passwordconfirm.$valid }">
<label class="control-label" for="inputPasswordConfirm">Password (confirm)</label> <label class="control-label" for="inputPasswordConfirm">Password (confirm)</label>
<div class="controls"> <div class="controls">
<input name="passwordconfirm" type="password" id="inputPasswordConfirm" ng-required="!isEdit()" <input name="passwordconfirm" type="password" id="inputPasswordConfirm" ng-required="!isEdit()"
ui-validate="'$value == user.password'" ui-validate-watch="'user.password'" ui-validate="'$value == user.password'" ui-validate-watch="'user.password'"
placeholder="Password (confirm)" ng-model="user.passwordconfirm" /> placeholder="Password (confirm)" ng-model="user.passwordconfirm"/>
<span class="help-inline" ng-show="editUserForm.passwordconfirm.$error.validator">Password and password confirmation must match</span> <span class="help-inline" ng-show="editUserForm.passwordconfirm.$error.validator">Password and password confirmation must match</span>
</div> </div>
</div> </div>
@ -45,6 +54,9 @@
<button type="submit" class="btn btn-primary" ng-click="edit()" ng-disabled="!editUserForm.$valid"> <button type="submit" class="btn btn-primary" ng-click="edit()" ng-disabled="!editUserForm.$valid">
<span class="icon-pencil icon-white"></span> {{ isEdit() ? 'Edit' : 'Add' }} <span class="icon-pencil icon-white"></span> {{ isEdit() ? 'Edit' : 'Add' }}
</button> </button>
<button type="button" class="btn btn-danger" ng-click="remove()">
<span class="icon-trash icon-white"></span> Delete
</button>
</div> </div>
</form> </form>
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{ alert.msg }}</alert> <alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{ alert.msg }}</alert>