Add onFinish callback to countdown widget and style it

This commit is contained in:
Hadi Nategh 2020-11-24 13:46:05 +01:00
parent 65b24440a0
commit 54eb66fd30
3 changed files with 32 additions and 3 deletions

View File

@ -70,8 +70,11 @@ var et2_countdown = /** @class */ (function (_super) {
this.time.set_value(_time); this.time.set_value(_time);
var self = this; var self = this;
this.timer = setInterval(function () { this.timer = setInterval(function () {
if (self._updateTimer() <= 0) if (self._updateTimer() <= 0) {
clearInterval(this.timer); clearInterval(self.timer);
if (typeof self.onFinish == "function")
self.onFinish();
}
}, 1000); }, 1000);
}; };
et2_countdown.prototype._updateTimer = function () { et2_countdown.prototype._updateTimer = function () {
@ -102,6 +105,12 @@ var et2_countdown = /** @class */ (function (_super) {
type: "string", type: "string",
default: "s", default: "s",
description: "Defines display format; s (Initial letter) or l (Complete word) display, default is s." description: "Defines display format; s (Initial letter) or l (Complete word) display, default is s."
},
onFinish: {
name: "on finish countdown",
type: "js",
default: et2_no_init,
description: "Callback function to call when the countdown is finished."
} }
}; };
return et2_countdown; return et2_countdown;

View File

@ -35,6 +35,12 @@ export class et2_countdown extends et2_baseWidget {
type: "string", type: "string",
default: "s", // s or l default: "s", // s or l
description: "Defines display format; s (Initial letter) or l (Complete word) display, default is s." description: "Defines display format; s (Initial letter) or l (Complete word) display, default is s."
},
onFinish: {
name: "on finish countdown",
type: "js",
default: et2_no_init,
description: "Callback function to call when the countdown is finished."
} }
}; };
@ -76,7 +82,11 @@ export class et2_countdown extends et2_baseWidget {
this.time.set_value(_time); this.time.set_value(_time);
let self = this; let self = this;
this.timer = setInterval(function(){ this.timer = setInterval(function(){
if (self._updateTimer() <= 0) clearInterval(this.timer); if (self._updateTimer() <= 0)
{
clearInterval(self.timer);
if (typeof self.onFinish == "function") self.onFinish();
}
}, 1000); }, 1000);
} }

View File

@ -3283,3 +3283,13 @@ tr.disableIfNoEPL {
.colselection.ui-widget-content .et2_selectbox .ui-multiselect-checkboxes { .colselection.ui-widget-content .et2_selectbox .ui-multiselect-checkboxes {
height: calc(100% - 68px) !important; height: calc(100% - 68px) !important;
} }
.et2_countdown {
margin-left: 10px;
background: #f1f1f1;
}
.et2_countdown > span {
margin-right: 10px;
}
span.et2_countdown_seconds {
margin-right: 0px;
}