Non puoi selezionare più di 25 argomenti
Gli argomenti devono iniziare con una lettera o un numero, possono includere trattini ('-') e possono essere lunghi fino a 35 caratteri.
153 righe
3.3 KiB
153 righe
3.3 KiB
5 anni fa
|
AUI.add(
|
||
|
'maintenance-alert',
|
||
|
function(A) {
|
||
|
|
||
|
var Lang = A.Lang;
|
||
|
|
||
|
var BUFFER_TIME = [];
|
||
|
|
||
|
var MaintenanceAlert = A.Component.create(
|
||
|
{
|
||
|
ATTRS: {
|
||
|
remainingTime:{
|
||
|
value: 0
|
||
|
},
|
||
|
onExpired:{
|
||
|
value: undefined
|
||
|
}
|
||
|
},
|
||
|
EXTENDS: A.Base,
|
||
|
NAME: 'maintenancealert',
|
||
|
prototype: {
|
||
|
initializer: function(config) {
|
||
|
var instance = this;
|
||
|
|
||
|
instance._expiredText = Liferay.Language.get('warning-the-portal-is-in-maintenance-mode');
|
||
|
|
||
|
instance._warningText = Liferay.Language.get('warning-the-portal-will-go-to-maintenance-mode');
|
||
|
instance._warningText = Lang.sub(instance._warningText, ['<span class="countdown-timer">{0}</span>']);
|
||
|
|
||
|
instance._remainingTime = instance.get('remainingTime');
|
||
|
instance._onExpired = instance.get('onExpired');
|
||
|
|
||
|
instance._timer = A.setInterval(function(){
|
||
|
|
||
|
if(instance._remainingTime > 0){
|
||
|
instance._remainingTime -= 1000;
|
||
|
instance._uiSetRemainingTime(instance._remainingTime);
|
||
|
}else{
|
||
|
|
||
|
if(instance._onExpired){
|
||
|
instance._onExpired();
|
||
|
}
|
||
|
instance._uiSetExpired();
|
||
|
}
|
||
|
|
||
|
}, 1000);
|
||
|
|
||
|
instance._banner = instance._getBanner();
|
||
|
instance._banner.show();
|
||
|
},
|
||
|
|
||
|
_uiSetExpired: function() {
|
||
|
var instance = this;
|
||
|
|
||
|
A.clearInterval(instance._timer);
|
||
|
|
||
|
var banner = instance._getBanner();
|
||
|
|
||
|
banner.html(instance._expiredText);
|
||
|
|
||
|
banner.replaceClass('popup-alert-notice', 'popup-alert-warning');
|
||
|
|
||
|
banner.addClass('alert-error');
|
||
|
|
||
|
banner.show();
|
||
|
|
||
|
},
|
||
|
|
||
|
_getBanner: function() {
|
||
|
var instance = this;
|
||
|
|
||
|
var banner = instance._banner;
|
||
|
|
||
|
if (!banner) {
|
||
|
banner = new Liferay.Notice(
|
||
|
{
|
||
|
closeText: false,
|
||
|
toggleText: false,
|
||
|
content: instance._warningText,
|
||
|
noticeClass: 'popup-alert-notice'
|
||
|
}
|
||
|
);
|
||
|
|
||
|
instance._banner = banner;
|
||
|
}
|
||
|
|
||
|
return banner;
|
||
|
},
|
||
|
|
||
|
_uiSetRemainingTime: function(remainingTime) {
|
||
|
var instance = this;
|
||
|
counterTextNode = instance._banner.one('.countdown-timer');
|
||
|
counterTextNode.text(instance._formatTime(remainingTime));
|
||
|
|
||
|
},
|
||
|
|
||
|
_formatNumber: function(value) {
|
||
|
var instance = this;
|
||
|
|
||
|
var floor = Math.floor;
|
||
|
var padNumber = Lang.String.padNumber;
|
||
|
|
||
|
return Lang.String.padNumber(Math.floor(value), 2);
|
||
|
},
|
||
|
|
||
|
|
||
|
_formatTime: function(time) {
|
||
|
var instance = this;
|
||
|
|
||
|
time = Number(time);
|
||
|
|
||
|
if (Lang.isNumber(time) && time > 0) {
|
||
|
time /= 1000;
|
||
|
|
||
|
BUFFER_TIME[0] = instance._formatNumber(time / 3600);
|
||
|
|
||
|
time %= 3600;
|
||
|
|
||
|
BUFFER_TIME[1] = instance._formatNumber(time / 60);
|
||
|
|
||
|
time %= 60;
|
||
|
|
||
|
BUFFER_TIME[2] = instance._formatNumber(time);
|
||
|
|
||
|
time = BUFFER_TIME.join(':');
|
||
|
}
|
||
|
else {
|
||
|
time = 0;
|
||
|
}
|
||
|
|
||
|
return time;
|
||
|
},
|
||
|
cancel: function(){
|
||
|
var instance = this;
|
||
|
var banner = instance._getBanner();
|
||
|
|
||
|
if (banner) {
|
||
|
banner.hide();
|
||
|
}
|
||
|
|
||
|
A.clearInterval(instance._timer);
|
||
|
}
|
||
|
}
|
||
|
}
|
||
|
);
|
||
|
|
||
|
Liferay.MaintenanceAlert = MaintenanceAlert;
|
||
|
},
|
||
|
'',
|
||
|
{
|
||
|
requires: ['aui-io-request', 'aui-timer', 'cookie', 'liferay-notice']
|
||
|
}
|
||
|
);
|