Skip to content

Commit

Permalink
(js) Fix handling of times in task/event editors
Browse files Browse the repository at this point in the history
Fixes #4497
Fixes #4845
  • Loading branch information
cgx committed Oct 10, 2019
1 parent 4fb483d commit 7bc73b6
Show file tree
Hide file tree
Showing 3 changed files with 70 additions and 23 deletions.
11 changes: 8 additions & 3 deletions UI/Templates/SchedulerUI/UIxAppointmentEditorTemplate.wox
Expand Up @@ -140,7 +140,7 @@
<div layout="row">
<md-checkbox flex="50"
ng-model="editor.component.isAllDay"
ng-change="editor.updateFreeBusyCoverage()"
ng-change="editor.adjustAllDay()"
ng-true-value="1"
ng-false-value="0"
label:aria-label="All day Event">
Expand All @@ -163,10 +163,12 @@
</div>
<div layout="row" layout-align="start end" layout-wrap="layout-wrap">
<md-datepicker ng-model="editor.component.start"
required="required"
ng-change="editor.adjustStartTime()"
label:md-placeholder="From"><!-- date picker --></md-datepicker>
<sg-timepicker ng-model="editor.component.start"
<sg-timepicker ng-model="editor.startTime"
ng-change="editor.adjustStartTime()"
ng-required="!editor.component.isAllDay"
ng-hide="editor.component.isAllDay"><!-- time picker --></sg-timepicker>
</div>
</div>
Expand All @@ -176,10 +178,13 @@
</div>
<div layout="row" layout-align="start end" layout-wrap="layout-wrap">
<md-datepicker ng-model="editor.component.end"
required="required"
ng-change="editor.adjustEndTime()"
md-min-date="editor.component.start"
label:md-placeholder="To"><!-- date picker --></md-datepicker>
<sg-timepicker ng-model="editor.component.end"
<sg-timepicker ng-model="editor.endTime"
ng-change="editor.adjustEndTime()"
ng-required="!editor.component.isAllDay"
ng-hide="editor.component.isAllDay"><!-- time picker --></sg-timepicker>
</div>
</div>
Expand Down
10 changes: 6 additions & 4 deletions UI/Templates/SchedulerUI/UIxTaskEditorTemplate.wox
Expand Up @@ -118,7 +118,7 @@

<div class="sg-form-section">
<!-- start -->
<div ng-show="editor.component.start">
<div ng-if="editor.component.start">
<div class="pseudo-input-container">
<label class="pseudo-input-label"><var:string label:value="From"/></label>
</div>
Expand All @@ -129,7 +129,8 @@
<md-datepicker ng-model="editor.component.start"
ng-change="editor.adjustStartTime()"
label:md-placeholder="From"> <!-- date picker--></md-datepicker>
<sg-timepicker ng-model="editor.component.start"
<sg-timepicker ng-model="editor.startTime"
ng-required="editor.component.start"
ng-change="editor.adjustStartTime()"><!-- time picker --></sg-timepicker>
</div>
</div>
Expand All @@ -140,7 +141,7 @@
<label class="button-label"><var:string label:value="Add From"/></label>
</div>
<!-- due -->
<div ng-show="editor.component.due">
<div ng-if="editor.component.due">
<div class="pseudo-input-container">
<label class="pseudo-input-label"><var:string label:value="Due"/></label>
</div>
Expand All @@ -151,7 +152,8 @@
<md-datepicker ng-model="editor.component.due"
ng-change="editor.adjustDueTime()"
label:md-placeholder="Due"><!-- date picker--></md-datepicker>
<sg-timepicker ng-model="editor.component.due"
<sg-timepicker ng-model="editor.dueTime"
ng-required="editor.component.due"
ng-change="editor.adjustDueTime()"><!-- time picker --></sg-timepicker>
</div>
</div>
Expand Down
72 changes: 56 additions & 16 deletions UI/WebServerResources/js/Scheduler/ComponentController.js
Expand Up @@ -205,19 +205,15 @@
/**
* @ngInject
*/
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$element', '$mdDialog', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Alarm', 'stateComponent'];
function ComponentEditorController($rootScope, $scope, $log, $timeout, $element, $mdDialog, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Alarm, stateComponent) {
var vm = this, component, oldStartDate, oldEndDate, oldDueDate;
ComponentEditorController.$inject = ['$rootScope', '$scope', '$log', '$timeout', '$element', '$mdDialog', 'sgFocus', 'User', 'CalendarSettings', 'Calendar', 'Component', 'Attendees', 'AddressBook', 'Card', 'Alarm', 'Preferences', 'stateComponent'];
function ComponentEditorController($rootScope, $scope, $log, $timeout, $element, $mdDialog, focus, User, CalendarSettings, Calendar, Component, Attendees, AddressBook, Card, Alarm, Preferences, stateComponent) {
var vm = this, component, oldStartDate, oldEndDate, oldDueDate, dayStartTime, dayEndTime;

this.$onInit = function () {
stateComponent.initAttendees();
this.service = Calendar;
this.component = stateComponent;
this.categories = {};
this.updateFreeBusyCoverage =
angular.bind(this.component.$attendees, this.component.$attendees.updateFreeBusyCoverage);
this.coversFreeBusy =
angular.bind(this.component.$attendees, this.component.$attendees.coversFreeBusy);
this.showRecurrenceEditor = this.component.$hasCustomRepeat;
this.showAttendeesEditor = this.component.attendees && this.component.attendees.length;
//this.searchText = null;
Expand All @@ -228,15 +224,24 @@
containerElement: $element[0].querySelector('#freebusy')
};

if (this.component.start)
if (this.component.start) {
oldStartDate = new Date(this.component.start.getTime());
if (this.component.end)
this.startTime = new Date(this.component.start.getTime());
}
if (this.component.end) {
oldEndDate = new Date(this.component.end.getTime());
if (this.component.due)
this.endTime = new Date(this.component.end.getTime());
}
if (this.component.due) {
oldDueDate = new Date(this.component.due.getTime());
this.dueTime = new Date(this.component.due.getTime());
}

if (this.component.attendees)
$timeout(scrollToStart);

dayStartTime = parseInt(Preferences.defaults.SOGoDayStartTime);
dayEndTime = parseInt(Preferences.defaults.SOGoDayEndTime);
};

this.addAttachUrl = function () {
Expand Down Expand Up @@ -462,10 +467,12 @@
this.addStartDate = function (form) {
this.component.$addStartDate();
oldStartDate = new Date(this.component.start.getTime());
this.startTime = new Date(this.component.start.getTime());
if (!this.component.due) {
this.component.alarm.relation = 'START';
}
this.changeAlarmRelation(form);
form.$setDirty();
};

this.removeStartDate = function (form) {
Expand All @@ -474,15 +481,18 @@
this.component.alarm.relation = 'END';
}
this.changeAlarmRelation(form);
form.$setDirty();
};

this.addDueDate = function (form) {
this.component.$addDueDate();
oldDueDate = new Date(this.component.due.getTime());
this.dueTime = new Date(this.component.due.getTime());
if (!this.component.start) {
this.component.alarm.relation = 'END';
}
this.changeAlarmRelation(form);
form.$setDirty();
};

this.removeDueDate = function (form) {
Expand All @@ -491,18 +501,38 @@
this.component.alarm.relation = 'START';
}
this.changeAlarmRelation(form);
form.$setDirty();
};

this.adjustAllDay = function () {
if (!this.component.isAllDay) {
this.component.start.setHours(dayStartTime);
this.component.start.setMinutes(0);
this.startTime = new Date(this.component.start.getTime());
oldStartDate = new Date(this.component.start.getTime());
this.component.end.setHours(dayEndTime);
this.component.end.setMinutes(0);
this.endTime = new Date(this.component.end.getTime());
oldEndDate = new Date(this.component.end.getTime());
this.component.delta = this.component.start.minutesTo(this.component.end);
}
this.component.$attendees.updateFreeBusyCoverage();
};

this.adjustStartTime = function () {
if (this.component.start) {
var delta;
if (this.component.start && this.startTime) {
// Update the component start date
this.component.start.setHours(this.startTime.getHours());
this.component.start.setMinutes(this.startTime.getMinutes());
// Preserve the delta between the start and end dates
var delta;
delta = oldStartDate.valueOf() - this.component.start.valueOf();
if (delta !== 0) {
oldStartDate = new Date(this.component.start.getTime());
if (this.component.type === 'appointment') {
this.component.end = new Date(this.component.start.getTime());
this.component.end.addMinutes(this.component.delta);
this.endTime = new Date(this.component.end.getTime());
oldEndDate = new Date(this.component.end.getTime());
}
updateFreeBusy();
Expand All @@ -511,13 +541,19 @@
};

this.adjustEndTime = function () {
if (this.component.end) {
var delta;
if (this.component.end && this.endTime) {
// Update the component start date
this.component.end.setHours(this.endTime.getHours());
this.component.end.setMinutes(this.endTime.getMinutes());
// The end date must be after the start date
var delta = oldEndDate.valueOf() - this.component.end.valueOf();
delta = oldEndDate.valueOf() - this.component.end.valueOf();
if (delta !== 0) {
delta = this.component.start.minutesTo(this.component.end);
if (delta < 0)
if (delta < 0) {
this.component.end = new Date(oldEndDate.getTime());
this.endTime = new Date(this.component.end.getTime());
}
else {
this.component.delta = delta;
oldEndDate = new Date(this.component.end.getTime());
Expand All @@ -528,7 +564,11 @@
};

this.adjustDueTime = function () {
oldDueDate = new Date(this.component.due.getTime());
if (this.component.due && this.dueTime) {
this.component.due.setHours(this.dueTime.getHours());
this.component.due.setMinutes(this.dueTime.getMinutes());
oldDueDate = new Date(this.component.due.getTime());
}
};

function updateFreeBusy() {
Expand Down

0 comments on commit 7bc73b6

Please sign in to comment.