Skip to content

Commit

Permalink
Merge pull request #1999 from civicrm/PCHR-2395-fix-admin-self-leave-…
Browse files Browse the repository at this point in the history
…request-popup

PCHR-2395: Fix admin self leave request popup
  • Loading branch information
igorpavlov authored Jul 13, 2017
2 parents 920db65 + 726cf8a commit 17d0009
Show file tree
Hide file tree
Showing 17 changed files with 85 additions and 35 deletions.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ define([
bindings: {
btnClass: '@',
contactId: '<',
selectedContactId: '<'
selectedContactId: '<',
isSelfRecord: '<'
},
templateUrl: ['shared-settings', function (sharedSettings) {
return sharedSettings.sharedPathTpl + 'components/leave-request-create-dropdown.html';
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,7 @@ define([
this.canManage = false; // this flag is set on initialisation of the controller
this.contactName = null;
this.errors = [];
this.isSelfRecord = false; // this flag is set on initialisation of the controller
this.managedContacts = [];
this.mode = ''; // can be edit, create, view
this.newStatusOnSave = null;
Expand Down Expand Up @@ -713,11 +714,11 @@ define([

/**
* Changes status of the leave request before saving it
* For staff the status_id should be always set to awaitingApproval before saving
* If manager has changed the status through dropdown, assign the same before calling API
* When recording for yourself the status_id should be always set to awaitingApproval before saving
* If manager or admin have changed the status through dropdown, assign the same before calling API
*/
function changeStatusBeforeSave () {
if (this.isRole('staff')) {
if (this.isSelfRecord) {
this.request.status_id = this.requestStatuses[sharedSettings.statusNames.awaitingApproval].value;
} else if (this.canManage) {
this.request.status_id = this.newStatusOnSave || this.request.status_id;
Expand Down Expand Up @@ -982,6 +983,7 @@ define([
})
.finally(function () {
this.canManage = this.isRole('manager') || this.isRole('admin');
this.isSelfRecord = this.directiveOptions.isSelfRecord;
}.bind(this));
}

Expand Down Expand Up @@ -1027,7 +1029,10 @@ define([
// When in Admin Dashboard
return Contact.all()
.then(function (contacts) {
this.managedContacts = contacts.list;
this.managedContacts = _.remove(contacts.list, function (contact) {
// Removes the admin from the list of managees
return contact.id !== this.directiveOptions.contactId;
}.bind(this));
}.bind(this));
} else {
// Everywhere else
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ define([
contactId: '<',
leaveRequest: '<',
leaveType: '@',
selectedContactId: '<'
selectedContactId: '<',
isSelfRecord: '<'
},
restrict: 'EA',
link: function (scope, element) {
Expand All @@ -55,7 +56,8 @@ define([
return {
contactId: scope.contactId,
leaveRequest: scope.leaveRequest,
selectedContactId: scope.selectedContactId
selectedContactId: scope.selectedContactId,
isSelfRecord: scope.isSelfRecord
};
},
// to set HR_settings DateFormat
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,8 @@
describe('staff opens request popup', function () {
beforeEach(inject(function () {
var directiveOptions = {
contactId: CRM.vars.leaveAndAbsences.contactId
contactId: CRM.vars.leaveAndAbsences.contactId,
isSelfRecord: true
};

initTestController(directiveOptions);
Expand Down Expand Up @@ -754,6 +755,7 @@
leaveRequest.contact_id = CRM.vars.leaveAndAbsences.contactId.toString();
var directiveOptions = {
contactId: leaveRequest.contact_id, // staff's contact id
isSelfRecord: true,
leaveRequest: leaveRequest
};

Expand Down Expand Up @@ -845,6 +847,7 @@
leaveRequest.contact_id = CRM.vars.leaveAndAbsences.contactId.toString();
var directiveOptions = {
contactId: leaveRequest.contact_id, // staff's contact id
isSelfRecord: true,
leaveRequest: leaveRequest
};

Expand All @@ -866,6 +869,7 @@
leaveRequest.contact_id = CRM.vars.leaveAndAbsences.contactId.toString();
var directiveOptions = {
contactId: leaveRequest.contact_id, // staff's contact id
isSelfRecord: true,
leaveRequest: leaveRequest
};

Expand Down Expand Up @@ -906,6 +910,7 @@

initTestController({
contactId: leaveRequest.contact_id, // staff's contact id
isSelfRecord: true,
leaveRequest: leaveRequest
});
});
Expand Down Expand Up @@ -934,6 +939,7 @@
leaveRequest.contact_id = CRM.vars.leaveAndAbsences.contactId.toString();
var directiveOptions = {
contactId: leaveRequest.contact_id, // staff's contact id
isSelfRecord: true,
leaveRequest: leaveRequest
};

Expand Down Expand Up @@ -1199,6 +1205,33 @@
});

describe('admin opens leave request popup in create mode', function () {
var adminId = 206;

beforeEach(function () {
$ctrl.request.contact_id = adminId.toString();

role = 'admin';
initTestController({
contactId: adminId
});
});

describe('on initialization', function () {
it('is in create mode', function () {
expect($ctrl.isMode('create')).toBeTruthy();
});

it('has admin role', function () {
expect($ctrl.isRole('admin')).toBeTruthy();
});

it('does not contain admin in the list of managees', function () {
expect(_.find($ctrl.managedContacts, { 'id': adminId })).toBeUndefined();
});
});
});

describe('admin opens leave request popup in create mode for a pre-selected contact', function () {
var selectedContactId = 208;
var adminId = 206;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,8 @@

beforeEach(function () {
var directiveOptions = {
contactId: CRM.vars.leaveAndAbsences.contactId
contactId: CRM.vars.leaveAndAbsences.contactId,
isSelfRecord: true
};

initTestController(directiveOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,8 @@

beforeEach(function () {
var directiveOptions = {
contactId: CRM.vars.leaveAndAbsences.contactId
contactId: CRM.vars.leaveAndAbsences.contactId,
isSelfRecord: true
};

initTestController(directiveOptions);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,9 @@
<div class="button-container">
<leave-request-create-dropdown
btn-class="btn-primary"
contact-id="myleave.contactId">
contact-id="myleave.contactId"
selected-contact-id="myleave.contactId"
is-self-record="true">
</leave-request-create-dropdown>
</div>
<div class="tabs-container">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@
href="#"
leave-request-popup leave-type="{{option.type}}"
contact-id="vm.contactId"
selected-contact-id="vm.selectedContactId">
selected-contact-id="vm.selectedContactId"
is-self-record="vm.isSelfRecord">
<i class="fa fa-{{option.icon}}" aria-hidden="true"></i> {{option.label}}
</a>
</li>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ <h2 class="panel-title">{{calendar.monthLabels[month.month] + " " + month.year}}
<a ng-if="day.leaveRequest"
contact-id="calendar.contactId"
selected-contact-id="$root.settings.contactId"
is-self-record="true"
leave-request-popup
leave-request="day.leaveRequest"
title="Click to open this leave request">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,8 @@
ng-switch-when="true"
leave-request-popup
leave-request="request"
contact-id="report.contactId">
contact-id="report.contactId"
is-self-record="true">
{{action}}
</a>
<a href ng-switch-default ng-click="report.action(request, action)">
Expand Down Expand Up @@ -398,7 +399,8 @@
ng-switch-when="true"
leave-request-popup
leave-request="request"
contact-id="report.contactId">
contact-id="report.contactId"
is-self-record="true">
{{action}}
</a>
<a href ng-switch-default ng-click="report.action(request, action)">
Expand Down Expand Up @@ -500,7 +502,8 @@
ng-switch-when="true"
leave-request-popup
leave-request="request"
contact-id="report.contactId">
contact-id="report.contactId"
is-self-record="true">
{{action}}
</a>
<a href ng-switch-default ng-click="report.action(request, action)">
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,10 +92,10 @@
<div class="col-xs-4">
<span
class="chr_leave-request-modal__span-expiry"
ng-if="!$ctrl.canManage">
ng-if="!$ctrl.canManage || $ctrl.isSelfRecord">
{{$ctrl.request.toil_expiry_date | date: $ctrl.uiOptions.userDateFormat}}
</span>
<div ng-if="$ctrl.canManage" class="input-group">
<div ng-if="$ctrl.canManage && !$ctrl.isSelfRecord" class="input-group">
<input
type="text"
class="form-control"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
</button>
<a
class="text-danger pull-left pointer chr_leave-request-modal__delete"
ng-if="$ctrl.isRole('admin') && $ctrl.directiveOptions.leaveRequest.id"
ng-if="$ctrl.isRole('admin') && $ctrl.directiveOptions.leaveRequest.id && !$ctrl.isSelfRecord"
ng-click="$ctrl.deleteLeaveRequest()">
<i class="fa fa-trash-o" aria-hidden="true"></i> Delete
</a>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,14 @@

<crm-loading show="!$ctrl.loading.absenceTypes">
<div
ng-show="$ctrl.canManage && !$ctrl.isMode('create')"
ng-show="$ctrl.canManage && !$ctrl.isMode('create') && !$ctrl.isSelfRecord"
class="row chr_leave-request-modal__user-info">
<span class="col-xs-6">{{$ctrl.contactName}}</span>
<span class="col-xs-6">{{::$ctrl.getStatusFromValue($ctrl.request.status_id).label}}</span>
</div>
<!-- ng-show is required in model as it was not showing the list of managees for ui-select-choices-->
<div class="modal-body chr_leave-request-modal__form">
<div ng-show="$ctrl.canManage && !$ctrl.isMode('edit')">
<div class="modal-body chr_leave-request-modal__form" ng-if="!$ctrl.loading.absenceTypes">
<div ng-show="$ctrl.canManage && !$ctrl.isMode('edit') && !$ctrl.isSelfRecord">
<ui-select
autofocus
ng-model="$ctrl.request.contact_id"
Expand Down Expand Up @@ -74,7 +74,7 @@
</div>
</div>
<div
ng-show="$ctrl.canManage"
ng-show="$ctrl.canManage && !$ctrl.isSelfRecord"
class="row chr_leave-request-modal__response">
<div class="col-xs-12 form-horizontal">
<div class="form-group">
Expand Down

0 comments on commit 17d0009

Please sign in to comment.