Skip to content

Commit

Permalink
Datepicker feedback changed #2316
Browse files Browse the repository at this point in the history
  • Loading branch information
Persijn Kwekkeboom committed Jan 14, 2022
1 parent c4cf833 commit 15a89aa
Show file tree
Hide file tree
Showing 6 changed files with 50 additions and 55 deletions.
13 changes: 5 additions & 8 deletions src/main/resources/assets/admin/common/js/ui/time/DatePicker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,10 @@ export class DatePickerBuilder {

closeOnSelect: boolean = true;

setDefaultDate(value: Date): DatePickerBuilder {
this.defaultDate = value;
setDefaultDate(value: Date | undefined): DatePickerBuilder {
if (value) {
this.defaultDate = value;
}
return this;
}

Expand Down Expand Up @@ -54,12 +56,7 @@ export class DatePicker
}

if (builder.defaultDate) {
this.setDefaultHandler(
() => {
this.setSelectedDate(builder.defaultDate);
},
builder.defaultDate
);
this.setDefaultValueHandler(() => this.setSelectedDate(builder.defaultDate));
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,11 @@ export class DateTimePickerBuilder {
// use local timezone if timezone value is not initialized
useLocalTimezoneIfNotPresent: boolean = false;

setDefaultDate(value: Date): DateTimePickerBuilder {
this.defaultDate = value;
setDefaultDate(value: Date | undefined): DateTimePickerBuilder {
// We don't want the set default button to appear when there is no default date
if (value) {
this.defaultDate = value;
}
return this;
}

Expand Down Expand Up @@ -81,12 +84,7 @@ export class DateTimePicker
}

if (builder.defaultDate) {
this.setDefaultHandler(
() => {
this.setSelectedDateTime(builder.defaultDate);
},
builder.defaultDate
);
this.setDefaultValueHandler(() => this.setSelectedDateTime(builder.defaultDate));
}
}

Expand Down
56 changes: 22 additions & 34 deletions src/main/resources/assets/admin/common/js/ui/time/Picker.ts
Original file line number Diff line number Diff line change
Expand Up @@ -12,23 +12,15 @@ import {SelectedDateChangedEvent} from './SelectedDateChangedEvent';
export class Picker<T extends Element>
extends DivEl {

private showDefaultButton: Boolean = false;

protected popup: T;

protected popupOkButton: Button;

protected popupDefaultButton: Button;

protected selectedDate: Date;

protected input: TextInput;

protected defaultDate: Date;

protected validUserInput: boolean;

private defaultHandler: Function;
private defaultValueHandler: Function;

private builder: any;

Expand All @@ -55,11 +47,8 @@ export class Picker<T extends Element>
this.input.resetBaseValues();
}

public setDefaultHandler(setDefault: Function, defaultDate: Date | undefined): void {
if (defaultDate) {
this.showDefaultButton = true;
}
this.defaultHandler = setDefault;
public setDefaultValueHandler(handler: Function): void {
this.defaultValueHandler = handler;
}

getTextInput(): TextInput {
Expand Down Expand Up @@ -202,25 +191,23 @@ export class Picker<T extends Element>
}
}

private initDefaultButton() {
this.popupDefaultButton = new Button(i18n('action.setDefault'));
this.popupDefaultButton.addClass('default-button');
this.popupDefaultButton.onClicked(() => {
if (this.setDefaultHandler) {
this.defaultHandler();
}
private initDefaultButton(): Button {
const popupDefaultButton = new Button(i18n('action.setDefault'));
popupDefaultButton.addClass('default-button');
popupDefaultButton.onClicked(() => {
this.defaultValueHandler();
});
return this.popupDefaultButton;
return popupDefaultButton;
}

private initCloseButton() {
this.popupOkButton = new Button(i18n('action.ok'));
this.popupOkButton.addClass('ok-button');
this.popupOkButton.onClicked(() => {
private initCloseButton(): Button {
const popupCloseButton = new Button(i18n('action.ok'));
popupCloseButton.addClass('close-button');
popupCloseButton.onClicked(() => {
this.hidePopup();
});

return this.popupOkButton;
return popupCloseButton;
}

private createPopup() {
Expand All @@ -230,16 +217,17 @@ export class Picker<T extends Element>

this.initPopup(this.builder);
this.setupPopupListeners(this.builder);
const buttonContainer = new DivEl('btn-container');

if (this.showDefaultButton) {
buttonContainer.appendChild(this.initDefaultButton());
}
const popUpItems = new DivEl();

const okButton = this.initCloseButton();
buttonContainer.appendChild(okButton);
if (this.defaultValueHandler) {
// Adds the needed css to align the buttons
popUpItems.setClass('btn-container');
popUpItems.appendChild(this.initDefaultButton());
}
popUpItems.appendChild(this.initCloseButton());

this.popup.appendChild(buttonContainer);
this.popup.appendChild(popUpItems);

this.popup.insertAfterEl(this.input);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@

.btn-container {
display: flex;
justify-content: flex-end;
justify-content: space-between;
}

.year-container,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@

.btn-container {
display: flex;
justify-content: flex-end;
justify-content: space-between;
}

.date-picker-dialog,
Expand Down
18 changes: 15 additions & 3 deletions src/main/resources/assets/admin/common/styles/mixins.less
Original file line number Diff line number Diff line change
Expand Up @@ -17,16 +17,28 @@
}

.picker-dialog-button(@margin, @display: block) {
.ok-button {
background: @admin-button-blue2;
.picker-btn() {
padding: 4px 19px 4px 19px;
position: relative;
display: @display;
margin: @margin;
}

.close-button {
.picker-btn();

background-color: @admin-button-blue2;
margin-left: auto;

span {
display: block;
}
}

.default-button {
.ok-button();
.picker-btn();

background-color: @form-button-bg;
}
}

Expand Down

0 comments on commit 15a89aa

Please sign in to comment.