From 2b561021234120898fe4f8b935b7c9b8809fb1f3 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Wed, 2 Dec 2020 16:54:50 +0100 Subject: [PATCH] Implement an alarm callback for countdown widget --- api/js/etemplate/et2_widget_countdown.js | 15 +++++++++++++++ api/js/etemplate/et2_widget_countdown.ts | 18 +++++++++++++++++- 2 files changed, 32 insertions(+), 1 deletion(-) diff --git a/api/js/etemplate/et2_widget_countdown.js b/api/js/etemplate/et2_widget_countdown.js index 5a5a6fb1e4..d451073b2f 100644 --- a/api/js/etemplate/et2_widget_countdown.js +++ b/api/js/etemplate/et2_widget_countdown.js @@ -84,6 +84,9 @@ var et2_countdown = /** @class */ (function (_super) { var distance = time.getTime() - now.getTime(); if (distance < 0) return 0; + if (this.options.alarm > 0 && this.options.alarm == distance / 1000 && typeof this.onAlarm == 'function') { + this.onAlarm(); + } var values = { days: Math.floor(distance / (1000 * 60 * 60 * 24)), hours: Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)), @@ -136,6 +139,18 @@ var et2_countdown = /** @class */ (function (_super) { type: "string", default: true, description: "Only displays none empty values." + }, + alarm: { + name: "alarm", + type: "any", + default: "", + description: "Defines an alarm set before the countdown is finished, it should be in seconds" + }, + onAlarm: { + name: "alarm callback", + type: "js", + default: "", + description: "Defines a callback to gets called at alarm - timer. This only will work if there's an alarm set." } }; return et2_countdown; diff --git a/api/js/etemplate/et2_widget_countdown.ts b/api/js/etemplate/et2_widget_countdown.ts index af46cf7ab2..34c74f35b3 100644 --- a/api/js/etemplate/et2_widget_countdown.ts +++ b/api/js/etemplate/et2_widget_countdown.ts @@ -47,7 +47,20 @@ export class et2_countdown extends et2_baseWidget { type: "string", default: true, description: "Only displays none empty values." + }, + alarm: { + name: "alarm", + type: "any", + default: "", + description: "Defines an alarm set before the countdown is finished, it should be in seconds" + }, + onAlarm: { + name: "alarm callback", + type: "js", + default: "", + description: "Defines a callback to gets called at alarm - timer. This only will work if there's an alarm set." } + }; private time : et2_date; @@ -113,7 +126,10 @@ export class et2_countdown extends et2_baseWidget { let distance = time.getTime() - now.getTime(); if (distance < 0) return 0; - + if (this.options.alarm > 0 && this.options.alarm == distance/1000 && typeof this.onAlarm == 'function') + { + this.onAlarm(); + } let values = { days: Math.floor(distance / (1000 * 60 * 60 * 24)), hours: Math.floor((distance % (1000 * 60 * 60 * 24)) / (1000 * 60 * 60)),