2016-10-21 18:01:30 +00:00
|
|
|
/* global $, APP */
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Base class for overlay components - the components which are displayed on
|
|
|
|
* top of the application with semi-transparent background covering the whole
|
|
|
|
* screen.
|
|
|
|
*/
|
|
|
|
export default class Overlay{
|
|
|
|
/**
|
|
|
|
* Creates new <tt>Overlay</tt> instance.
|
|
|
|
*/
|
|
|
|
constructor() {
|
|
|
|
/**
|
|
|
|
*
|
|
|
|
* @type {jQuery}
|
|
|
|
*/
|
|
|
|
this.$overlay = null;
|
2016-12-06 23:05:32 +00:00
|
|
|
|
|
|
|
/**
|
|
|
|
* Indicates if this overlay should use the light look & feel or the
|
|
|
|
* standard one.
|
|
|
|
* @type {boolean}
|
|
|
|
*/
|
|
|
|
this.isLightOverlay = false;
|
2016-10-21 18:01:30 +00:00
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Template method which should be used by subclasses to provide the overlay
|
|
|
|
* content. The contents provided by this method are later subject to
|
|
|
|
* the translation using {@link APP.translation.translateElement}.
|
|
|
|
* @return {string} HTML representation of the overlay dialog contents.
|
2016-12-06 23:05:32 +00:00
|
|
|
* @protected
|
2016-10-21 18:01:30 +00:00
|
|
|
*/
|
|
|
|
_buildOverlayContent() {
|
|
|
|
return '';
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Constructs the HTML body of the overlay dialog.
|
2016-12-06 05:38:09 +00:00
|
|
|
*
|
2016-12-06 23:05:32 +00:00
|
|
|
* @private
|
2016-10-21 18:01:30 +00:00
|
|
|
*/
|
2016-12-07 16:24:37 +00:00
|
|
|
_buildOverlayHtml() {
|
2016-10-21 18:01:30 +00:00
|
|
|
|
|
|
|
let overlayContent = this._buildOverlayContent();
|
|
|
|
|
2016-12-07 16:24:37 +00:00
|
|
|
let containerClass = this.isLightOverlay ? "overlay__container-light"
|
|
|
|
: "overlay__container";
|
2016-12-06 05:38:09 +00:00
|
|
|
|
2016-10-21 18:01:30 +00:00
|
|
|
this.$overlay = $(`
|
2016-12-06 05:38:09 +00:00
|
|
|
<div class=${containerClass}>
|
2016-10-31 15:35:22 +00:00
|
|
|
<div class='overlay__content'>
|
2016-10-21 18:01:30 +00:00
|
|
|
${overlayContent}
|
|
|
|
</div>
|
|
|
|
</div>`);
|
|
|
|
|
|
|
|
APP.translation.translateElement(this.$overlay);
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Checks whether the page reload overlay has been displayed.
|
|
|
|
* @return {boolean} <tt>true</tt> if the page reload overlay is currently
|
|
|
|
* visible or <tt>false</tt> otherwise.
|
|
|
|
*/
|
|
|
|
isVisible() {
|
|
|
|
return this.$overlay && this.$overlay.parents('body').length > 0;
|
|
|
|
}
|
|
|
|
/**
|
|
|
|
* Template method called just after the overlay is displayed for the first
|
|
|
|
* time.
|
2016-12-06 23:05:32 +00:00
|
|
|
* @protected
|
2016-10-21 18:01:30 +00:00
|
|
|
*/
|
|
|
|
_onShow() {
|
|
|
|
// To be overridden by subclasses.
|
|
|
|
}
|
|
|
|
/**
|
2016-12-06 23:05:32 +00:00
|
|
|
* Shows the overlay dialog and attaches the underlying HTML representation
|
2016-10-21 18:01:30 +00:00
|
|
|
* to the DOM.
|
|
|
|
*/
|
2016-12-06 23:05:32 +00:00
|
|
|
show() {
|
2016-10-21 18:01:30 +00:00
|
|
|
|
2016-12-07 16:24:37 +00:00
|
|
|
!this.$overlay && this._buildOverlayHtml();
|
2016-10-21 18:01:30 +00:00
|
|
|
|
|
|
|
if (!this.isVisible()) {
|
|
|
|
this.$overlay.appendTo('body');
|
|
|
|
this._onShow();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Hides the overlay dialog and detaches it's HTML representation from
|
|
|
|
* the DOM.
|
|
|
|
*/
|
|
|
|
hide() {
|
|
|
|
this.$overlay && this.$overlay.detach();
|
|
|
|
}
|
|
|
|
}
|