Skip to content
This repository has been archived by the owner on Dec 27, 2023. It is now read-only.

Commit

Permalink
fix(HumanResources): have allowed freetime types in planning only
Browse files Browse the repository at this point in the history
  • Loading branch information
corneliusweiss committed Mar 15, 2022
1 parent a8408e7 commit 03c7f1e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 7 deletions.
20 changes: 15 additions & 5 deletions tine20/HumanResources/js/FreeTimeEditDialog.js
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,7 @@ Tine.HumanResources.FreeTimeEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
}
let isNewRecord = !this.record.get('creation_time');
const grants = _.get(employee, 'data.division_id.account_grants', {});
const isNew = !this.record.get('creation_time');
const isOwn = Tine.Tinebase.registry.get('currentAccount').accountId === _.get(employee, 'data.account_id.accountId');
const processStatus = this.processStatusPicker.getValue();
const allowUpdate = grants.adminGrant || grants.updateChangeRequestGrant ||
Expand All @@ -100,9 +101,16 @@ Tine.HumanResources.FreeTimeEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
this.typePicker.setReadOnly(!isNewRecord || this.fixedFields.indexOfKey('type') >= 0);

this.processStatusPicker.setDisabled(!(grants.updateChangeRequestGrant || grants.adminGrant));
if (isNew && employee !== this.processStatusPicker.employee && (grants.updateChangeRequestGrant || grants.adminGrant)) {
this.processStatusPicker.employee = employee;
this.processStatusPicker.setValue('ACCEPTED');
}
this.typeStatusPicker[type.id === 'sickness' ? 'show' : 'hide']();
this.accountPicker[type.id === 'vacation' ? 'show' : 'hide']();
this.accountPicker.setReadOnly(!employee);
this.possibleVacationDays[type.id === 'vacation' ? 'show' : 'hide']();
this.requestedDaysField[type.id === 'vacation' ? 'show' : 'hide']();
this.acceptedDaysField[type.id === 'vacation' ? 'show' : 'hide']();
this.remainingDaysField[type.id === 'vacation' ? 'show' : 'hide']();

[this.typeStatusPicker, this.datePicker, this.getForm().findField('description'), this.attachmentsPanel, this.action_saveAndClose].forEach((item) => {
Expand All @@ -119,18 +127,18 @@ Tine.HumanResources.FreeTimeEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
const originalStatus = this.record.get('creation_time') ? _.get(this.record, 'modified.process_status', currentStatus) : 'REQUESTED';

const possible = _.get(feastAndFreeDays, 'vacation.possible_vacation_days', 0);
this.form.findField('possible_vacation_days').setValue(year && feastAndFreeDays ? possible : '');
this.possibleVacationDays.setValue(year && feastAndFreeDays ? possible : '');

let requested = _.get(feastAndFreeDays, 'vacation.scheduled_requested_vacation_days', 0);
requested = requested - (originalStatus === 'REQUESTED' ? originalDays : 0) + (currentStatus === 'REQUESTED' ? currentDays : 0);
this.form.findField('scheduled_requested_vacation_days').setValue(year && feastAndFreeDays ? requested : '');
this.requestedDaysField.setValue(year && feastAndFreeDays ? requested : '');

let taken = _.get(feastAndFreeDays, 'vacation.scheduled_taken_vacation_days', 0);
taken = taken - (originalStatus === 'ACCEPTED' ? originalDays : 0) + (currentStatus === 'ACCEPTED' ? currentDays : 0);
this.form.findField('scheduled_taken_vacation_days').setValue(year && feastAndFreeDays ? taken : '');
this.acceptedDaysField.setValue(year && feastAndFreeDays ? taken : '');

const remaining = possible - requested - taken;
this.form.findField('scheduled_remaining_vacation_days').setValue(year && feastAndFreeDays ? remaining : '');
this.remainingDaysField.setValue(year && feastAndFreeDays ? remaining : '');
},

/**
Expand Down Expand Up @@ -375,7 +383,9 @@ Tine.HumanResources.FreeTimeEditDialog = Ext.extend(Tine.widgets.dialog.EditDial
},

initTypePicker: function() {
this.typePicker = Tine.widgets.form.FieldManager.get('HumanResources', 'FreeTime', 'type', Tine.widgets.form.FieldManager.CATEGORY_EDITDIALOG);
this.typePicker = Tine.widgets.form.FieldManager.get('HumanResources', 'FreeTime', 'type', Tine.widgets.form.FieldManager.CATEGORY_EDITDIALOG, {
additionalFilters: [{field: 'allow_planning', operator: 'equals', value: true}]
});
},

getRecordFormItems: function() {
Expand Down
2 changes: 1 addition & 1 deletion tine20/HumanResources/js/FreeTimePlanningPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -142,7 +142,7 @@ Tine.HumanResources.FreeTimePlanningPanel = Ext.extend(Tine.widgets.grid.GridPan

initFreeTimeTypes: async function() {
this.freeTimeTypes = [];
this.freeTimeTypes = _.get(await Tine.HumanResources.searchFreeTimeTypes({}), 'results', []);
this.freeTimeTypes = _.get(await Tine.HumanResources.searchFreeTimeTypes([{field: 'allow_planning', operator: 'equals', value: true}]), 'results', []);
},

renderFreeDay: function(value, metaData, record, rowIndex, colIndex, store, day) {
Expand Down
7 changes: 6 additions & 1 deletion tine20/HumanResources/js/FreeTimePlanningWestPanel.js
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ const colorLegend = Ext.extend(Ext.Panel, {
// make sure grid is updated after group changed
this.onUpdateRecord = _.bind(this.onUpdateRecord, this, _, 'local');

Tine.Addressbook.contactListsGridPanel.superclass.initComponent.call(this);
Tine.HumanResources.FreeTimeTypeGridPanel.prototype.initComponent.call(this);
this.store.on('load', () => {
this.setHeight(this.grid.view.el.child('.x-grid3-body').getHeight() + this.grid.view.el.child('.x-grid3-header').getHeight());
})
Expand All @@ -45,6 +45,11 @@ const colorLegend = Ext.extend(Ext.Panel, {
{id: 'type', header: this.app.i18n._(' '), dataIndex: 'color', width: 10, hidden: false, renderer: Tine.Tinebase.common.colorRenderer,},
{id: 'name', header: this.app.i18n._('Name'), width: 100, sortable: true, dataIndex: 'name'}
];
},

onStoreBeforeload: function(store, options) {
Tine.HumanResources.FreeTimeTypeGridPanel.prototype.onStoreBeforeload.call(this, store, options);
options.params.filter.push({field: 'allow_planning', operator: 'equals', value: true});
}
})

Expand Down

0 comments on commit 03c7f1e

Please sign in to comment.