From dcc6d1eb839555e7b85dadbd8b533700a74b1a57 Mon Sep 17 00:00:00 2001 From: nathan Date: Fri, 14 Oct 2022 10:05:59 -0600 Subject: [PATCH] Et2Date: change "Today" button label to "Now" for widgets with time (Et2DateTime, Et2Timeonly, etc.) --- api/js/etemplate/Et2Date/Et2Date.ts | 23 ++++++++++++++++------- api/js/etemplate/Et2Date/Et2DateTime.ts | 13 +++++++++++++ 2 files changed, 29 insertions(+), 7 deletions(-) diff --git a/api/js/etemplate/Et2Date/Et2Date.ts b/api/js/etemplate/Et2Date/Et2Date.ts index 92eaa30f73..d74a9ef12d 100644 --- a/api/js/etemplate/Et2Date/Et2Date.ts +++ b/api/js/etemplate/Et2Date/Et2Date.ts @@ -374,8 +374,8 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl disconnectedCallback() { super.disconnectedCallback(); - this._inputNode.removeEventListener('change', this._onChange); - this._inputNode.removeEventListener("input", this._handleInputChange); + this._inputNode?.removeEventListener('change', this._onChange); + this._inputNode?.removeEventListener("input", this._handleInputChange); this.destroy(); } @@ -433,11 +433,7 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl new scrollPlugin(), // Add "today" button - // @ts-ignore TypeScript can't find ShortcutButtonsPlugin, but rollup does - ShortcutButtonsPlugin({ - button: [{label: this.egw().lang("Today")}], - onClick: this._handleShortcutButtonClick - }) + this._buttonPlugin() ]; // Listen for flatpickr change so we can update internal value, needed for validation @@ -477,6 +473,19 @@ export class Et2Date extends Et2InputWidget(FormControlMixin(ValidateMixin(LitFl }; } + /** + * Add "today" button below calendar + * @protected + */ + protected _buttonPlugin() + { + // @ts-ignore TypeScript can't find ShortcutButtonsPlugin, but rollup does + return ShortcutButtonsPlugin({ + button: [{label: this.egw().lang("Today")}], + onClick: this._handleShortcutButtonClick + }) + } + set value(value) { if(!value || value == 0 || value == "0") diff --git a/api/js/etemplate/Et2Date/Et2DateTime.ts b/api/js/etemplate/Et2Date/Et2DateTime.ts index ad29be936f..935683e2dc 100644 --- a/api/js/etemplate/Et2Date/Et2DateTime.ts +++ b/api/js/etemplate/Et2Date/Et2DateTime.ts @@ -66,6 +66,19 @@ export class Et2DateTime extends Et2Date return options; } + + /** + * Add "today" button below calendar + * @protected + */ + protected _buttonPlugin() + { + // @ts-ignore TypeScript can't find ShortcutButtonsPlugin, but rollup does + return ShortcutButtonsPlugin({ + button: [{label: this.egw().lang("Now")}], + onClick: this._handleShortcutButtonClick + }) + } } // @ts-ignore TypeScript is not recognizing that Et2DateTime is a LitElement