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.
*/
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).
*/
@ -19,7 +19,10 @@ App.controller('SettingsUserEdit', function($scope, $state, $stateParams, Restan
$scope.user = data;
});
}
/**
* Update the current user.
*/
$scope.edit = function() {
var promise = null;
@ -38,4 +41,27 @@ App.controller('SettingsUserEdit', function($scope, $state, $stateParams, Restan
$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()">Add <small>user</small></h2>
<h2 ng-show="isEdit()">Edit
<small>"{{ user.username }}"</small>
</h2>
<h2 ng-show="!isEdit()">Add
<small>user</small>
</h2>
<form class="form-horizontal" name="editUserForm" novalidate>
<div class="control-group" ng-class="{ error: !editUserForm.username.$valid, success: editUserForm.username.$valid }">
<label class="control-label" for="inputUsername">Username</label>
<div class="controls">
<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.minlength">Too short</span>
<span class="help-inline" ng-show="editUserForm.username.$error.maxlength">Too long</span>
@ -13,9 +18,10 @@
</div>
<div class="control-group" ng-class="{ error: !editUserForm.email.$valid, success: editUserForm.email.$valid }">
<label class="control-label" for="inputEmail">E-mail</label>
<div class="controls">
<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.email">Must be a valid e-mail</span>
<span class="help-inline" ng-show="editUserForm.email.$error.minlength">Too short</span>
@ -24,20 +30,23 @@
</div>
<div class="control-group" ng-class="{ error: !editUserForm.password.$valid, success: editUserForm.password.$valid }">
<label class="control-label" for="inputPassword">Password</label>
<div class="controls">
<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.minlength">Too short</span>
<span class="help-inline" ng-show="editUserForm.password.$error.maxlength">Too long</span>
</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>
<div class="controls">
<input name="passwordconfirm" type="password" id="inputPasswordConfirm" ng-required="!isEdit()"
ui-validate="'$value == user.password'" ui-validate-watch="'user.password'"
placeholder="Password (confirm)" ng-model="user.passwordconfirm" />
ui-validate="'$value == user.password'" ui-validate-watch="'user.password'"
placeholder="Password (confirm)" ng-model="user.passwordconfirm"/>
<span class="help-inline" ng-show="editUserForm.passwordconfirm.$error.validator">Password and password confirmation must match</span>
</div>
</div>
@ -45,6 +54,9 @@
<button type="submit" class="btn btn-primary" ng-click="edit()" ng-disabled="!editUserForm.$valid">
<span class="icon-pencil icon-white"></span> {{ isEdit() ? 'Edit' : 'Add' }}
</button>
<button type="button" class="btn btn-danger" ng-click="remove()">
<span class="icon-trash icon-white"></span> Delete
</button>
</div>
</form>
<alert ng-repeat="alert in alerts" type="alert.type" close="closeAlert($index)">{{ alert.msg }}</alert>