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

dxScheduler - fix appointment popup on closing (T854500) #11754

Merged
merged 6 commits into from
Feb 4, 2020
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion js/ui/scheduler/appointmentPopup.js
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ export default class AppointmentPopup {
return {
height: 'auto',
maxHeight: '100%',
onHiding: () => { this._appointmentForm.resetValues(); this.scheduler.focus(); },
onHiding: () => { this.scheduler.focus(); },
contentTemplate: () => this._createPopupContent(),
defaultOptionsRules: [
{
Expand Down
72 changes: 32 additions & 40 deletions js/ui/scheduler/ui.scheduler.appointment_form.js
Original file line number Diff line number Diff line change
Expand Up @@ -30,13 +30,15 @@ const SchedulerAppointmentForm = {
},

_getAllDayStartDate: function(startDate) {
return startDate.setHours(0, 0, 0, 0);
return new Date(new Date(startDate).setHours(0, 0, 0, 0));
},

_getAllDayEndDate: function(startDate) {
const endDate = new Date(startDate);
endDate.setDate(startDate.getDate() + 1);
return endDate;
return new Date(new Date(startDate).setDate(startDate.getDate() + 1));
},

_getStartDateWithStartHour: function(startDate, startDayHour) {
return new Date(new Date(startDate).setHours(startDayHour));
},

_updateLabelLocation: function(formWidth) {
Expand Down Expand Up @@ -64,6 +66,19 @@ const SchedulerAppointmentForm = {
return this._appointmentForm;
},

_dateBoxValueChanged: function(args, dateExpr, isNeedCorrect) {
this._validateAppointmentFormDate(args.component, args.value, args.previousValue);

const value = dateSerialization.deserializeDate(args.value);
const previousValue = dateSerialization.deserializeDate(args.previousValue);
const dateEditor = this._appointmentForm.getEditor(dateExpr);
const dateValue = dateSerialization.deserializeDate(dateEditor.option('value'));
if(!this._appointmentForm._lockDateShiftFlag && dateValue && value && isNeedCorrect(dateValue, value)) {
const duration = previousValue ? dateValue.getTime() - previousValue.getTime() : 0;
dateEditor.option('value', new Date(value.getTime() + duration));
}
},

prepareAppointmentFormEditors: function(dataExprs, schedulerInst) {
const that = this;

Expand Down Expand Up @@ -91,17 +106,7 @@ const SchedulerAppointmentForm = {
firstDayOfWeek: schedulerInst.option('firstDayOfWeek')
},
onValueChanged: function(args) {
that._validateAppointmentFormDate(args.component, args.value, args.previousValue);

const value = dateSerialization.deserializeDate(args.value);
const previousValue = dateSerialization.deserializeDate(args.previousValue);
const endDateEditor = that._appointmentForm.getEditor(dataExprs.endDateExpr);
const endValue = dateSerialization.deserializeDate(endDateEditor.option('value'));
if(!that._appointmentForm._lockDateShiftFlag && typeUtils.isDefined(value) && typeUtils.isDefined(endValue)
&& !!endValue && endValue < value) {
const duration = endValue.getTime() - previousValue.getTime();
endDateEditor.option('value', new Date(value.getTime() + duration));
}
that._dateBoxValueChanged(args, dataExprs.endDateExpr, (endValue, startValue) => { return endValue < startValue; });
}
}
},
Expand Down Expand Up @@ -133,16 +138,7 @@ const SchedulerAppointmentForm = {
firstDayOfWeek: schedulerInst.option('firstDayOfWeek')
},
onValueChanged: function(args) {
that._validateAppointmentFormDate(args.component, args.value, args.previousValue);

const value = dateSerialization.deserializeDate(args.value);
const previousValue = dateSerialization.deserializeDate(args.previousValue);
const startDateEditor = that._appointmentForm.getEditor(dataExprs.startDateExpr);
const startValue = dateSerialization.deserializeDate(startDateEditor.option('value'));
if(!that._appointmentForm._lockDateShiftFlag && !!value && startValue > value) {
const duration = previousValue ? previousValue.getTime() - startValue.getTime() : 0;
startDateEditor.option('value', new Date(value.getTime() - duration));
}
that._dateBoxValueChanged(args, dataExprs.startDateExpr, (startValue, endValue) => { return endValue < startValue; });
}
}
},
Expand Down Expand Up @@ -171,26 +167,22 @@ const SchedulerAppointmentForm = {
const value = args.value;
const startDateEditor = that._appointmentForm.getEditor(dataExprs.startDateExpr);
const endDateEditor = that._appointmentForm.getEditor(dataExprs.endDateExpr);
const startDate = dateSerialization.deserializeDate(startDateEditor.option('value'));

if(startDateEditor && endDateEditor) {
startDateEditor.option('type', value ? 'date' : 'datetime');
endDateEditor.option('type', value ? 'date' : 'datetime');

if(!startDateEditor.option('value')) {
return;
}

const startDate = dateSerialization.deserializeDate(startDateEditor.option('value'));

if(!that._appointmentForm._lockDateShiftFlag && startDate) {
if(value) {
startDateEditor.option('value', that._getAllDayStartDate(startDate));
endDateEditor.option('value', that._getAllDayEndDate(startDate));
const allDayStartDate = that._getAllDayStartDate(startDate);
startDateEditor.option('value', allDayStartDate);
endDateEditor.option('value', that._getAllDayEndDate(allDayStartDate));
} else {
startDate.setHours(schedulerInst.option('startDayHour'));
startDateEditor.option('value', startDate);
endDateEditor.option('value', schedulerInst._workSpace.calculateEndDate(dateSerialization.deserializeDate(startDateEditor.option('value'))));
const startDateWithStartHour = that._getStartDateWithStartHour(startDate, schedulerInst.option('startDayHour'));
const endDate = schedulerInst._workSpace.calculateEndDate(startDateWithStartHour);
startDateEditor.option('value', startDateWithStartHour);
endDateEditor.option('value', endDate);
}
}
startDateEditor.option('type', value ? 'date' : 'datetime');
endDateEditor.option('type', value ? 'date' : 'datetime');
}
}
},
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,26 @@ QUnit.module('Appointment popup form', moduleConfig, () => {
});
});

QUnit.test('Appointment popup should be with correct dates after change allDay switch and w/o saving (T832711)', function(assert) {
const scheduler = createScheduler({ dataSource: [] });
const data = {
text: 'all day apo',
startDate: new Date(2017, 4, 1, 9, 30),
endDate: new Date(2017, 4, 1, 11),
allDay: true
};

scheduler.instance.showAppointmentPopup(data);
const allDayEditor = scheduler.appointmentForm.getEditor('allDay');
allDayEditor.option('value', false);
scheduler.appointmentPopup.clickCancelButton();

scheduler.instance.showAppointmentPopup(data);

assert.deepEqual(scheduler.appointmentForm.getEditor('startDate').option('value'), data.startDate);
assert.deepEqual(scheduler.appointmentForm.getEditor('endDate').option('value'), data.endDate);
});

QUnit.test('onAppointmentFormOpening event should handle e.cancel value', function(assert) {
const data = [{
text: 'Website Re-Design Plan',
Expand Down Expand Up @@ -740,7 +760,6 @@ QUnit.test('Popup should contains allDay editor', function(assert) {
});

QUnit.test('allDay changing should switch date & type in editors', function(assert) {

this.instance.option('startDayHour', 5);
this.instance.showAppointmentPopup({
startDate: new Date(2015, 1, 1, 6),
Expand All @@ -753,7 +772,6 @@ QUnit.test('allDay changing should switch date & type in editors', function(asse

allDayEditor.option('value', true);


const startDate = $popupContent.find('.dx-datebox').eq(0).dxDateBox('instance');
const endDate = $popupContent.find('.dx-datebox').eq(1).dxDateBox('instance');

Expand Down