Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: fix #1820, Added Create Self-Service User Form #2139

Merged
merged 4 commits into from Nov 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
5 changes: 5 additions & 0 deletions app/global-translations/locale-en.json
Expand Up @@ -309,6 +309,8 @@
"label.button.dividends": "Dividends",
"label.button.postdividends": "Post Dividends",
"label.button.proceed": "Proceed",
"label.button.activateselfservice": "Activate Self-Service Account",
"label.button.selfserviceactivatehelp": "Generate user ID and send details to client",

"#Misc Labels": "..",
"label.uniquelyidentifiedwithid": "Uniquely identified with Id",
Expand Down Expand Up @@ -440,6 +442,7 @@
"#Headings": "..",
"label.heading.waiveloancharge":"Waive Loan Charge",
"label.heading.payloancharge":"Pay Loan Charge",
"label.heading.selfserivceaccountactivated": "Self-Service Account Activated",

"#Anchors": "..",
"label.anchor.paycharge":"Pay Charge",
Expand Down Expand Up @@ -2061,6 +2064,8 @@
"label.newfixeddepositaccount":"New Fixed Deposit",
"label.newrecurringdepositaccount":"New Recurring Deposit",
"label.survey":"Survey",
"label.createselfserviceuser": "Create Self-Service User",
"label.createdselfserviceuser": "User was created successfully!",
"label.recurringdeposittype":"Recurring Deposit Type",
"label.recurring.deposit.amount":"Recurring Deposit Amount",
"label.recurring.deposit.every":"Recurring Deposit Frequency",
Expand Down
@@ -0,0 +1,98 @@
(function (module) {
mifosX.controllers = _.extend(module, {
CreateSelfServiceUserController: function (scope, resourceFactory, routeParams,$uibModal) {
// TODO: Add Account Is Active Logic through email validation
scope.accountActive = false;
scope.available = [];
scope.selected = [];
scope.selectedRoles = [] ;
scope.availableRoles = [];
scope.formData = {
isSelfServiceUser: true,
sendPasswordToEmail: true,
roles: []
};
scope.clientId = routeParams.clientId;
resourceFactory.userTemplateResource.get(function (data) {
scope.availableRoles = data.availableRoles;
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Do we need to retrieve all roles? For example 'Super User' is not applicable in this context.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nazeer1100126 Yes I did have doubts on this, What roles are the valid role for creation of the self-service user?
How do I fetch roles specific for creating the self-service user?
Can we update the template on the backend for normal user creation and a self-service user creation with appropriate roles?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe we need to have a separate API to retrieve only self service user roles so that we can filter out other roles.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes that would be great. I'll wait for self service template for available roles to be created. Thanks @nazeer1100126!

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@botraunak Can you try adding this API from platform side.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@nazeer1100126 I'm sorry I didn't get that? Could you explain a bit more?

});
resourceFactory.clientResource.get({clientId: scope.clientId},function(data){
scope.formData.firstname = data.firstname;
scope.formData.lastname = data.lastname;
scope.formData.email = '';
scope.formData.officeId = data.officeId;
scope.formData.staffId = data.staffId;
scope.formData.clients = [scope.clientId];
});

scope.addRole = function () {
for (var i in this.available) {
for (var j in scope.availableRoles) {
if (scope.availableRoles[j].id == this.available[i]) {
var temp = {};
temp.id = this.available[i];
temp.name = scope.availableRoles[j].name;
scope.selectedRoles.push(temp);
scope.availableRoles.splice(j, 1);
}
}
}
//We need to remove selected items outside of above loop. If we don't remove, we can see empty item appearing
//If we remove available items in above loop, all items will not be moved to selectedRoles
for (var i in this.available) {
for (var j in scope.selectedRoles) {
if (scope.selectedRoles[j].id == this.available[i]) {
scope.available.splice(i, 1);
}
}
}
};
scope.removeRole = function () {
for (var i in this.selected) {
for (var j in scope.selectedRoles) {
if (scope.selectedRoles[j].id == this.selected[i]) {
var temp = {};
temp.id = this.selected[i];
temp.name = scope.selectedRoles[j].name;
scope.availableRoles.push(temp);
scope.selectedRoles.splice(j, 1);
}
}
}
//We need to remove selected items outside of above loop. If we don't remove, we can see empty item appearing
//If we remove selected items in above loop, all items will not be moved to availableRoles
for (var i in this.selected) {
for (var j in scope.availableRoles) {
if (scope.availableRoles[j].id == this.selected[i]) {
scope.selected.splice(i, 1);
}
}
}
};

scope.submit = function(){
for (var i in scope.selectedRoles) {
scope.formData.roles.push(scope.selectedRoles[i].id) ;
}
resourceFactory.userListResource.save(this.formData, function (data) {
scope.accountActive = true;
$uibModal.open({
templateUrl: 'selfserviceModal.html',
controller: SuccessModalCtrl,
});
});

}

var SuccessModalCtrl = function ($scope, $uibModalInstance) {
$scope.cancel = function () {
$uibModalInstance.dismiss('cancel');
};
};

}
});
mifosX.ng.application.controller('CreateSelfServiceUserController', ['$scope', 'ResourceFactory', '$routeParams','$uibModal', mifosX.controllers.CreateSelfServiceUserController]).run(function ($log) {
$log.info("CreateSelfServiceUserController initialized");
});
}(mifosX.controllers || {}));
3 changes: 2 additions & 1 deletion app/scripts/mifosXComponents.js
Expand Up @@ -289,7 +289,8 @@ define(['Q', 'underscore', 'mifosX'], function (Q) {
'organization/smscampaigns/ViewSmsCampaignController',
'organization/smscampaigns/EditSmsCampaignController',
'organization/entitydatatablechecks/EntityDatatableChecksController',
'notification/NotificationsController'
'notification/NotificationsController',
'selfservice/CreateSelfServiceUserController',
],
filters: [
'StatusLookup',
Expand Down
3 changes: 3 additions & 0 deletions app/scripts/routes.js
Expand Up @@ -911,6 +911,9 @@
.when('/notifications', {
templateUrl: 'views/notification/notifications.html'
})
.when('/selfservice/createuser/:clientId',{
templateUrl: 'views/selfservice/createuser.html'
})
;
$locationProvider.html5Mode(false);
};
Expand Down
3 changes: 3 additions & 0 deletions app/views/clients/viewclient.html
Expand Up @@ -193,6 +193,9 @@ <h3 class="client-title">
<li class="{{button.icon}}">
<a href="#/survey/{{client.id}}">{{'label.survey' | translate}}</a>
</li>
<li class="{{button.icon}}">
<a href="#/selfservice/createuser/{{client.id}}">{{'label.createselfserviceuser' | translate}}</a>
</li>
</ul>
</span>
</div>
Expand Down
169 changes: 169 additions & 0 deletions app/views/selfservice/createuser.html
@@ -0,0 +1,169 @@
<div class="content-container" ng-controller="CreateSelfServiceUserController">
<ul class="breadcrumb">
<li><a href="#/viewclient/{{clientId}}">{{formData.firstname}} {{formData.lastname}}</a></li>
<li class="active">{{'label.createselfserviceuser' | translate}}</li>
</ul>
<div class="card">
<form name="createselfserviceuserform" novalidate="" class="card form-horizontal well" rc-submit="submit()">
<legend>{{'label.createselfserviceuser' | translate}}</legend>
<api-validate></api-validate>
<fieldset>
<div class="form-group">
<label class="control-label col-sm-2" for="username">{{'label.input.username' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="text" id="username" name="username" ng-model="formData.username" class="form-control" required late-Validate/>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createuserform" valattribute="username"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="firstname">{{'label.input.firstname' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="text" id="firstname" name="firstname" ng-model="formData.firstname" class="form-control" required
late-Validate ng-disabled="true"/>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createselfserviceuserform" valattribute="firstname"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="lastname">{{'label.input.lastname' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="text" id="lastname" name="lastname" ng-model="formData.lastname" class="form-control" required late-Validate ng-disabled="true"/>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createselfserviceuserform" valattribute="lastname"/>
</div>
</div>
<div data-ng-switch on="formData.sendPasswordToEmail">
<div data-ng-switch-when="true">
<div class="form-group">
<label class="control-label col-sm-2" for="email">{{'label.input.email' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="email" id="email" name="email" class="form-control" ng-model="formData.email" required late-Validate/>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createselfserviceuserform" valattribute="email"/>
</div>
</div>
</div>
<div data-ng-switch-when="false">
<div class="form-group" data-ng-show="!formData.sendPasswordToEmail">
<label class="control-label col-sm-2" for="email1">{{'label.input.email' | translate}}</label>

<div class="col-sm-3">
<input type="email" id="email1" name="email1" class="form-control" ng-model="formData.email"/>
</div>
</div>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">{{'label.input.autogeneratepassword' | translate}}</label>

<div class="col-sm-3">
<input type="checkbox" ng-model="formData.sendPasswordToEmail">
</div>

<label class="control-label col-sm-3">{{'label.input.overridepasswordexpiry' | translate}}
<i class="fa fa-question-circle control-label fa fa-align-left"
uib-tooltip="{{'label.tooltip.overridepasswordexpiry' | translate}}"></i></label>
<div class="col-sm-3">
<label class="checkbox">
<input type="checkbox" ng-model="formData.passwordNeverExpires">
</label>
</div>
</div>
<div data-ng-switch on="formData.sendPasswordToEmail">
<div data-ng-switch-when="false">
<div class="form-group">
<label class="control-label col-sm-2" for="password">{{'label.input.password' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="password" id="password" name="password" ng-model="formData.password" class="form-control" required
late-Validate>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createselfserviceuserform" valattribute="password"/>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2" for="repeatPassword">{{'label.input.repeatpassword' | translate}}<span
class="required">*</span></label>

<div class="col-sm-3">
<input type="password" id="repeatPassword" name="repeatPassword" class="form-control"
ng-model="formData.repeatPassword" required late-Validate>
</div>
<div class="col-sm-3">
<form-validate valattributeform="createselfserviceuserform" valattribute="repeatPassword"/>
</div>
</div>
</div>
</div>
<div class="form-group">
<div class="col-sm-3 col-md-3 col-md-offset-1">
<label class="control-label col-sm-9">{{ 'label.input.availableroles' | translate }}</label>
<select id="availableroles" ng-model="available" name="availableroles" class="form-control multiselectmin" multiple>
<option ng-repeat="availablerole in availableRoles" value="{{availablerole.id}}">
{{availablerole.name}}
</option>
</select>
</div>
<div class="col-sm-1 col-md-1 paddedtop25px">
<button type="button" class="btn btn-primary" data-ng-click="addRole()"><i
class="fa fa-angle-double-right"></i></button>
<br/>
<button type="button" class="btn btn-primary" data-ng-click="removeRole()"><i
class="fa fa-angle-double-left"></i></button>
</div>
<div class="col-sm-3 col-md-3">
<label class="control-label col-sm-9">{{ 'label.input.selectedroles' | translate}}<span
class="required">*</span></label>
<select id="roles" name="roles" ng-model="selected" name="role" class="form-control multiselectmin" multiple>
<option ng-repeat="availablerole in selectedRoles" value="{{availablerole.id}}">
{{availablerole.name}}
</option>
</select>
</div>
</div>
<div class="form-group">
<label class="control-label col-sm-2">{{'label.input.status' | translate}}</label>
<div class="col-sm-3">
{{ (accountActive ? 'label.tooltip.loanProduct.active' : 'label.tooltip.loanProduct.inActive') | translate }}
</div>
</div>
<div class="form-group">
<div class="col-sm-3 col-sm-offset-2">
<input type="submit" value="{{'label.button.activateselfservice' | translate }}" ng-disabled="accountActive" ng-class="accountActive ? 'btn btn-md btn-disabled' : 'btn btn-md btn-primary' "/>
</div>
<div class="col-sm-2">
<a uib-tooltip="{{'label.button.selfserviceactivatehelp' | translate}}" class="ng-binding">
<i class="fa fa-question-circle fa-2x"></i>
</a>
</div>
</div>
</fieldset>
</form>
</div>
<script type="text/ng-template" id="selfserviceModal.html">
<div class="modal-header silver">
<h3 class="bolder text-success"><i class="fa fa-check-circle"></i> {{'label.heading.selfserivceaccountactivated' | translate}}</h3>
</div>
<div class="modal-body">
<p>{{'label.createdselfserviceuser' | translate}}</p>
</div>
<div class="modal-footer">
<button class="btn btn-default" ng-click="cancel()">{{'label.button.close' | translate}}</button>
</div>
</script>
</div>