-
Notifications
You must be signed in to change notification settings - Fork 639
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
6 changed files
with
263 additions
and
88 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,65 @@ | ||
(function() { | ||
'use strict'; | ||
|
||
angular.module('theHiveControllers').controller('AdminUserDialogCtrl', function($scope, $uibModalInstance, UserSrv, NotificationSrv, user) { | ||
var self = this; | ||
|
||
self.user = user; | ||
self.isEdit = user.id; | ||
|
||
self.formData = _.defaults(_.pick(self.user, 'id', 'name', 'roles'), { | ||
id: null, | ||
name: null, | ||
roles: [], | ||
alert: false | ||
}); | ||
self.formData.alert = self.formData.roles.indexOf('alert') !== -1; | ||
|
||
var onSuccess = function(data) { | ||
$uibModalInstance.close(data); | ||
}; | ||
|
||
var onFailure = function(response) { | ||
NotificationSrv.error('AdminUserDialogCtrl', response.data, response.status); | ||
}; | ||
|
||
var buildRoles = function(roles, alert) { | ||
var result = angular.copy(roles) || []; | ||
|
||
if(alert && roles.indexOf('alert') === -1) { | ||
result.push('alert'); | ||
} else if (!alert && roles.indexOf('alert') !== -1) { | ||
result = _.omit(result, 'alert'); | ||
} | ||
|
||
return result; | ||
}; | ||
|
||
self.saveUser = function(form) { | ||
if (!form.$valid) { | ||
return; | ||
} | ||
|
||
var postData = {}; | ||
|
||
if (self.user.id) { | ||
postData = { | ||
name: self.formData.name, | ||
roles: buildRoles(self.formData.roles, self.formData.alert) | ||
}; | ||
UserSrv.update({'userId': self.user.id}, postData, onSuccess, onFailure); | ||
} else { | ||
postData = { | ||
login: angular.lowercase(self.formData.id), | ||
name: self.formData.name, | ||
roles: buildRoles(self.formData.roles, self.formData.alert) | ||
}; | ||
UserSrv.save(postData, onSuccess, onFailure); | ||
} | ||
}; | ||
|
||
self.cancel = function() { | ||
$uibModalInstance.dismiss(); | ||
} | ||
}); | ||
})(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,75 @@ | ||
<form class="form-horizontal" name="userForm" ng-submit="$vm.saveUser(userForm)" novalidate> | ||
<div class="modal-header bg-primary"> | ||
<h3 class="modal-title">{{$vm.formData.id ? 'Update' : 'Add'}} user</h3> | ||
</div> | ||
<div class="modal-body"> | ||
<div class="form-group" ng-class="{ 'has-error' : userForm.id.$invalid && !userForm.id.$pristine }"> | ||
<label class="col-sm-3 control-label"> | ||
Login | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-9"> | ||
<input class="form-control" name="id" | ||
placeholder="User's login" | ||
ng-disabled="$vm.isEdit" | ||
ng-model="$vm.formData.id" | ||
required type="text"> | ||
<p class="help-block" ng-show="userForm.id.$invalid && !userForm.id.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group" ng-class="{ 'has-error' : userForm.name.$invalid && !userForm.name.$pristine }"> | ||
<label class="col-sm-3 control-label"> | ||
Full name | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-9"> | ||
<input class="form-control" name="login" | ||
placeholder="User's name" | ||
ng-model="$vm.formData.name" | ||
required type="text"> | ||
<p class="help-block" ng-show="userForm.name.$invalid && !userForm.name.$pristine">This field is required.</p> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label class="col-sm-3 control-label"> | ||
Roles | ||
<i class="fa fa-asterisk text-danger"></i> | ||
</label> | ||
<div class="col-sm-9"> | ||
<div class="btn-group" uib-dropdown> | ||
<button class="btn btn-sm dropdown-toggle" uib-dropdown-toggle type="button"> | ||
{{$vm.formData.roles.join(', ') || 'none'}} | ||
<span class="caret"></span> | ||
</button> | ||
<ul class="dropdown-menu" uib-dropdown-menu> | ||
<li> | ||
<a ng-click="$vm.formData.roles = []">none</a> | ||
<a ng-click="$vm.formData.roles = ['read']">read</a> | ||
<a ng-click="$vm.formData.roles = ['read','write']">read, write</a> | ||
<a ng-click="$vm.formData.roles = ['read','write','admin']">read, write, admin</a> | ||
</li> | ||
</ul> | ||
</div> | ||
</div> | ||
</div> | ||
|
||
<div class="form-group"> | ||
<label class="col-sm-3 control-label"> | ||
Additional Permissions | ||
</label> | ||
<div class="col-sm-9"> | ||
<div class="checkbox"> | ||
<label> | ||
<input type="checkbox" ng-model="$vm.formData.alert"> Allow alerts creation | ||
</label> | ||
</div> | ||
</div> | ||
</div> | ||
</div> | ||
<div class="modal-footer text-left"> | ||
<button class="btn btn-default" ng-click="$vm.cancel()" type="button">Cancel</button> | ||
<button class="btn btn-primary pull-right" ng-disabled="userForm.$invalid" type="submit">Save user</button> | ||
</div> | ||
</form> |
Oops, something went wrong.