Fix et2_dialog TS errors

This commit is contained in:
Hadi Nategh 2020-01-22 11:45:20 +01:00
parent da9072f769
commit 1ef0353728
3 changed files with 76 additions and 73 deletions

View File

@ -142,29 +142,11 @@ var et2_dialog = /** @class */ (function (_super) {
{ "button_id": 0, "text": 'cancel', id: 'dialog[cancel]', image: 'cancel' } { "button_id": 0, "text": 'cancel', id: 'dialog[cancel]', image: 'cancel' }
] ]
]; ];
/**
* Types
* @constant
*/
_this.PLAIN_MESSAGE = 0;
_this.INFORMATION_MESSAGE = 1;
_this.QUESTION_MESSAGE = 2;
_this.WARNING_MESSAGE = 3;
_this.ERROR_MESSAGE = 4;
/* Pre-defined Button combos */
_this.BUTTONS_OK = 0;
_this.BUTTONS_OK_CANCEL = 1;
_this.BUTTONS_YES_NO = 2;
_this.BUTTONS_YES_NO_CANCEL = 3;
/* Button constants */
_this.CANCEL_BUTTON = 0;
_this.OK_BUTTON = 1;
_this.YES_BUTTON = 2;
_this.NO_BUTTON = 3;
_this.div = null; _this.div = null;
_this.template = null; _this.template = null;
// Define this as null to avoid breaking any hierarchies (eg: destroy()) // Define this as null to avoid breaking any hierarchies (eg: destroy())
_this._parent = null; if (_this.getParent() != null)
_this.getParent().removeChild(_this);
// Button callbacks need a reference to this // Button callbacks need a reference to this
var self = _this; var self = _this;
for (var i = 0; i < _this._buttons.length; i++) { for (var i = 0; i < _this._buttons.length; i++) {
@ -360,7 +342,6 @@ var et2_dialog = /** @class */ (function (_super) {
this.set_dialog_type(this.options.dialog_type); this.set_dialog_type(this.options.dialog_type);
} }
this.set_buttons(typeof this.options.buttons == "number" ? this._buttons[this.options.buttons] : this.options.buttons); this.set_buttons(typeof this.options.buttons == "number" ? this._buttons[this.options.buttons] : this.options.buttons);
var self = this;
var options = { var options = {
// Pass the internal object, not the option // Pass the internal object, not the option
buttons: this.options.buttons, buttons: this.options.buttons,
@ -391,7 +372,7 @@ var et2_dialog = /** @class */ (function (_super) {
}; };
// Leaving width unset lets it size itself according to contents // Leaving width unset lets it size itself according to contents
if (this.options.width) { if (this.options.width) {
options.width = this.options.width; options['width'] = this.options.width;
} }
this.div.dialog(options); this.div.dialog(options);
// Make sure dialog is wide enough for the title // Make sure dialog is wide enough for the title
@ -405,22 +386,23 @@ var et2_dialog = /** @class */ (function (_super) {
/** /**
* Create a parent to inject application specific egw object with loaded translations into et2_dialog * Create a parent to inject application specific egw object with loaded translations into et2_dialog
* *
* @param {string|egw} _egw_or_appname egw object with already laoded translations or application name to load translations for * @param {string|egw} _egw_or_appname egw object with already loaded translations or application name to load translations for
*/ */
et2_dialog._create_parent = function (_egw_or_appname) { et2_dialog._create_parent = function (_egw_or_appname) {
if (typeof _egw_or_appname == 'undefined') { if (typeof _egw_or_appname == 'undefined') {
// @ts-ignore
_egw_or_appname = egw_appName; _egw_or_appname = egw_appName;
} }
// create a dummy parent with a correct reference to an application specific egw object // create a dummy parent with a correct reference to an application specific egw object
var parent = new et2_core_widget_1.et2_widget(); var parent = new et2_core_widget_1.et2_widget();
// if egw object is passed in because called from et2, just use it // if egw object is passed in because called from et2, just use it
if (typeof _egw_or_appname != 'string') { if (typeof _egw_or_appname != 'string') {
parent._egw = _egw_or_appname; parent.setApiInstance(_egw_or_appname);
} }
// otherwise use given appname to create app-specific egw instance and load default translations // otherwise use given appname to create app-specific egw instance and load default translations
else { else {
parent._egw = egw(_egw_or_appname); parent.setApiInstance(egw(_egw_or_appname));
parent._egw.langRequireApp(parent._egw.window, _egw_or_appname); parent.egw().langRequireApp(parent.egw().window, _egw_or_appname);
} }
return parent; return parent;
}; };
@ -443,7 +425,7 @@ var et2_dialog = /** @class */ (function (_super) {
callback: _callback || function () { callback: _callback || function () {
}, },
message: _message, message: _message,
title: _title || parent._egw.lang('Confirmation required'), title: _title || parent.egw().lang('Confirmation required'),
buttons: typeof _buttons != 'undefined' ? _buttons : et2_dialog.BUTTONS_YES_NO, buttons: typeof _buttons != 'undefined' ? _buttons : et2_dialog.BUTTONS_YES_NO,
dialog_type: typeof _type != 'undefined' ? _type : et2_dialog.QUESTION_MESSAGE, dialog_type: typeof _type != 'undefined' ? _type : et2_dialog.QUESTION_MESSAGE,
icon: _icon, icon: _icon,
@ -460,7 +442,7 @@ var et2_dialog = /** @class */ (function (_super) {
* @param {integer} _type One of the message constants. This defines the style of the message. * @param {integer} _type One of the message constants. This defines the style of the message.
*/ */
et2_dialog.alert = function (_message, _title, _type) { et2_dialog.alert = function (_message, _title, _type) {
var parent = et2_dialog._create_parent(et2_dialog._create_parent()._egw); var parent = et2_dialog._create_parent(et2_dialog._create_parent().egw());
et2_createWidget("dialog", { et2_createWidget("dialog", {
callback: function () { callback: function () {
}, },
@ -517,7 +499,7 @@ var et2_dialog = /** @class */ (function (_super) {
var buttonId = _senders.id; var buttonId = _senders.id;
var dialogMsg = (typeof _dialogMsg != "undefined") ? _dialogMsg : ''; var dialogMsg = (typeof _dialogMsg != "undefined") ? _dialogMsg : '';
var titleMsg = (typeof _titleMsg != "undefined") ? _titleMsg : ''; var titleMsg = (typeof _titleMsg != "undefined") ? _titleMsg : '';
var egw = _senders instanceof et2_core_widget_1.et2_widget ? _senders.egw() : et2_dialog._create_parent()._egw; var egw = _senders instanceof et2_core_widget_1.et2_widget ? _senders.egw() : et2_dialog._create_parent().egw();
var callbackDialog = function (button_id) { var callbackDialog = function (button_id) {
if (button_id == et2_dialog.YES_BUTTON) { if (button_id == et2_dialog.YES_BUTTON) {
if (_postSubmit) { if (_postSubmit) {
@ -528,7 +510,7 @@ var et2_dialog = /** @class */ (function (_super) {
} }
} }
}; };
et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {}, et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw); et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {}, et2_dialog.BUTTONS_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw);
}; };
; ;
/** /**
@ -560,7 +542,7 @@ var et2_dialog = /** @class */ (function (_super) {
*/ */
et2_dialog.long_task = function (_callback, _message, _title, _menuaction, _list, _egw_or_appname) { et2_dialog.long_task = function (_callback, _message, _title, _menuaction, _list, _egw_or_appname) {
var parent = et2_dialog._create_parent(_egw_or_appname); var parent = et2_dialog._create_parent(_egw_or_appname);
var egw = parent._egw; var egw = parent.egw();
// Special action for cancel // Special action for cancel
var buttons = [ var buttons = [
{ "button_id": et2_dialog.OK_BUTTON, "text": egw.lang('ok'), "default": true, "disabled": true }, { "button_id": et2_dialog.OK_BUTTON, "text": egw.lang('ok'), "default": true, "disabled": true },
@ -790,5 +772,25 @@ var et2_dialog = /** @class */ (function (_super) {
default: "center" default: "center"
} }
}; };
/**
* Types
* @constant
*/
et2_dialog.PLAIN_MESSAGE = 0;
et2_dialog.INFORMATION_MESSAGE = 1;
et2_dialog.QUESTION_MESSAGE = 2;
et2_dialog.WARNING_MESSAGE = 3;
et2_dialog.ERROR_MESSAGE = 4;
/* Pre-defined Button combos */
et2_dialog.BUTTONS_OK = 0;
et2_dialog.BUTTONS_OK_CANCEL = 1;
et2_dialog.BUTTONS_YES_NO = 2;
et2_dialog.BUTTONS_YES_NO_CANCEL = 3;
/* Button constants */
et2_dialog.CANCEL_BUTTON = 0;
et2_dialog.OK_BUTTON = 1;
et2_dialog.YES_BUTTON = 2;
et2_dialog.NO_BUTTON = 3;
return et2_dialog; return et2_dialog;
}(et2_core_widget_1.et2_widget)); }(et2_core_widget_1.et2_widget));
//# sourceMappingURL=et2_widget_dialog.js.map

File diff suppressed because one or more lines are too long

View File

@ -240,23 +240,23 @@ class et2_dialog extends et2_widget {
* Types * Types
* @constant * @constant
*/ */
readonly PLAIN_MESSAGE: number = 0; public static PLAIN_MESSAGE: number = 0;
readonly INFORMATION_MESSAGE: number = 1; public static INFORMATION_MESSAGE: number = 1;
readonly QUESTION_MESSAGE: number = 2; public static QUESTION_MESSAGE: number = 2;
readonly WARNING_MESSAGE: number = 3; public static WARNING_MESSAGE: number = 3;
readonly ERROR_MESSAGE: number = 4; public static ERROR_MESSAGE: number = 4;
/* Pre-defined Button combos */ /* Pre-defined Button combos */
readonly BUTTONS_OK: number = 0; public static BUTTONS_OK: number = 0;
readonly BUTTONS_OK_CANCEL: number = 1; public static BUTTONS_OK_CANCEL: number = 1;
readonly BUTTONS_YES_NO: number = 2; public static BUTTONS_YES_NO: number = 2;
readonly BUTTONS_YES_NO_CANCEL: number = 3; public static BUTTONS_YES_NO_CANCEL: number = 3;
/* Button constants */ /* Button constants */
readonly CANCEL_BUTTON: number = 0; public static CANCEL_BUTTON: number = 0;
readonly OK_BUTTON: number = 1; public static OK_BUTTON: number = 1;
readonly YES_BUTTON: number = 2; public static YES_BUTTON: number = 2;
readonly NO_BUTTON: number = 3; public static NO_BUTTON: number = 3;
div: JQuery = null; div: JQuery = null;
template: any = null; template: any = null;
@ -265,7 +265,7 @@ class et2_dialog extends et2_widget {
super(); super();
// Define this as null to avoid breaking any hierarchies (eg: destroy()) // Define this as null to avoid breaking any hierarchies (eg: destroy())
this._parent = null; if (this.getParent() != null) this.getParent().removeChild(this);
// Button callbacks need a reference to this // Button callbacks need a reference to this
let self = this; let self = this;
@ -477,9 +477,8 @@ class et2_dialog extends et2_widget {
this.set_dialog_type(this.options.dialog_type); this.set_dialog_type(this.options.dialog_type);
} }
this.set_buttons(typeof this.options.buttons == "number" ? this._buttons[this.options.buttons] : this.options.buttons); this.set_buttons(typeof this.options.buttons == "number" ? this._buttons[this.options.buttons] : this.options.buttons);
var self = this;
var options = { let options = {
// Pass the internal object, not the option // Pass the internal object, not the option
buttons: this.options.buttons, buttons: this.options.buttons,
modal: this.options.modal, modal: this.options.modal,
@ -509,7 +508,7 @@ class et2_dialog extends et2_widget {
}; };
// Leaving width unset lets it size itself according to contents // Leaving width unset lets it size itself according to contents
if (this.options.width) { if (this.options.width) {
options.width = this.options.width; options['width'] = this.options.width;
} }
this.div.dialog(options); this.div.dialog(options);
@ -526,22 +525,23 @@ class et2_dialog extends et2_widget {
/** /**
* Create a parent to inject application specific egw object with loaded translations into et2_dialog * Create a parent to inject application specific egw object with loaded translations into et2_dialog
* *
* @param {string|egw} _egw_or_appname egw object with already laoded translations or application name to load translations for * @param {string|egw} _egw_or_appname egw object with already loaded translations or application name to load translations for
*/ */
static _create_parent(_egw_or_appname) { static _create_parent(_egw_or_appname? : string) {
if (typeof _egw_or_appname == 'undefined') { if (typeof _egw_or_appname == 'undefined') {
// @ts-ignore
_egw_or_appname = egw_appName; _egw_or_appname = egw_appName;
} }
// create a dummy parent with a correct reference to an application specific egw object // create a dummy parent with a correct reference to an application specific egw object
var parent = new et2_widget(); let parent = new et2_widget();
// if egw object is passed in because called from et2, just use it // if egw object is passed in because called from et2, just use it
if (typeof _egw_or_appname != 'string') { if (typeof _egw_or_appname != 'string') {
parent._egw = _egw_or_appname; parent.setApiInstance(_egw_or_appname);
} }
// otherwise use given appname to create app-specific egw instance and load default translations // otherwise use given appname to create app-specific egw instance and load default translations
else { else {
parent._egw = egw(_egw_or_appname); parent.setApiInstance(egw(_egw_or_appname));
parent._egw.langRequireApp(parent._egw.window, _egw_or_appname); parent.egw().langRequireApp(parent.egw().window, _egw_or_appname);
} }
return parent; return parent;
} }
@ -566,7 +566,7 @@ class et2_dialog extends et2_widget {
callback: _callback || function () { callback: _callback || function () {
}, },
message: _message, message: _message,
title: _title || parent._egw.lang('Confirmation required'), title: _title || parent.egw().lang('Confirmation required'),
buttons: typeof _buttons != 'undefined' ? _buttons : et2_dialog.BUTTONS_YES_NO, buttons: typeof _buttons != 'undefined' ? _buttons : et2_dialog.BUTTONS_YES_NO,
dialog_type: typeof _type != 'undefined' ? _type : et2_dialog.QUESTION_MESSAGE, dialog_type: typeof _type != 'undefined' ? _type : et2_dialog.QUESTION_MESSAGE,
icon: _icon, icon: _icon,
@ -582,8 +582,8 @@ class et2_dialog extends et2_widget {
* @param {string} _title Text in the top bar of the dialog. * @param {string} _title Text in the top bar of the dialog.
* @param {integer} _type One of the message constants. This defines the style of the message. * @param {integer} _type One of the message constants. This defines the style of the message.
*/ */
static alert(_message, _title, _type) { static alert(_message? : string, _title? : string, _type?) {
var parent = et2_dialog._create_parent(et2_dialog._create_parent()._egw); let parent = et2_dialog._create_parent(et2_dialog._create_parent().egw());
et2_createWidget("dialog", { et2_createWidget("dialog", {
callback: function () { callback: function () {
}, },
@ -642,7 +642,7 @@ class et2_dialog extends et2_widget {
var buttonId = _senders.id; var buttonId = _senders.id;
var dialogMsg = (typeof _dialogMsg != "undefined") ? _dialogMsg : ''; var dialogMsg = (typeof _dialogMsg != "undefined") ? _dialogMsg : '';
var titleMsg = (typeof _titleMsg != "undefined") ? _titleMsg : ''; var titleMsg = (typeof _titleMsg != "undefined") ? _titleMsg : '';
var egw = _senders instanceof et2_widget ? _senders.egw() : et2_dialog._create_parent()._egw; var egw = _senders instanceof et2_widget ? _senders.egw() : et2_dialog._create_parent().egw();
var callbackDialog = function (button_id) { var callbackDialog = function (button_id) {
if (button_id == et2_dialog.YES_BUTTON) { if (button_id == et2_dialog.YES_BUTTON) {
if (_postSubmit) { if (_postSubmit) {
@ -653,7 +653,7 @@ class et2_dialog extends et2_widget {
} }
}; };
et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {}, et2_dialog.show_dialog(callbackDialog, egw.lang(dialogMsg), egw.lang(titleMsg), {},
et2_dialog.BUTTON_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw); et2_dialog.BUTTONS_YES_NO, et2_dialog.WARNING_MESSAGE, undefined, egw);
}; };
@ -684,12 +684,13 @@ class et2_dialog extends et2_widget {
* *
* @return {et2_dialog} * @return {et2_dialog}
*/ */
static long_task(_callback, _message, _title, _menuaction, _list, _egw_or_appname) { static long_task(_callback, _message, _title, _menuaction, _list, _egw_or_appname)
var parent = et2_dialog._create_parent(_egw_or_appname); {
var egw = parent._egw; let parent = et2_dialog._create_parent(_egw_or_appname);
let egw = parent.egw();
// Special action for cancel // Special action for cancel
var buttons = [ let buttons = [
{"button_id": et2_dialog.OK_BUTTON, "text": egw.lang('ok'), "default": true, "disabled": true}, {"button_id": et2_dialog.OK_BUTTON, "text": egw.lang('ok'), "default": true, "disabled": true},
{ {
"button_id": et2_dialog.CANCEL_BUTTON, "text": egw.lang('cancel'), click: function () { "button_id": et2_dialog.CANCEL_BUTTON, "text": egw.lang('cancel'), click: function () {
@ -700,7 +701,7 @@ class et2_dialog extends et2_widget {
} }
} }
]; ];
var dialog = et2_createWidget("dialog", { let dialog = et2_createWidget("dialog", {
template: egw.webserverUrl + '/api/templates/default/long_task.xet', template: egw.webserverUrl + '/api/templates/default/long_task.xet',
value: { value: {
content: { content: {
@ -722,10 +723,10 @@ class et2_dialog extends et2_widget {
// OK starts disabled // OK starts disabled
jQuery("button[button_id=" + et2_dialog.OK_BUTTON + "]", dialog.div.parent()).button("disable"); jQuery("button[button_id=" + et2_dialog.OK_BUTTON + "]", dialog.div.parent()).button("disable");
var log = null; let log = null;
var progressbar = null; let progressbar = null;
var cancel = false; let cancel = false;
var totals = { let totals = {
success: 0, success: 0,
skipped: 0, skipped: 0,
failed: 0, failed: 0,
@ -733,9 +734,9 @@ class et2_dialog extends et2_widget {
}; };
// Updates progressbar & log, calls next step // Updates progressbar & log, calls next step
var update = function (response) { let update = function (response) {
// context is index // context is index
var index = this || 0; let index = this || 0;
progressbar.set_value(100 * (index / _list.length)); progressbar.set_value(100 * (index / _list.length));
progressbar.set_label(index + ' / ' + _list.length); progressbar.set_label(index + ' / ' + _list.length);
@ -787,7 +788,7 @@ class et2_dialog extends et2_widget {
} }
} }
// Scroll to bottom // Scroll to bottom
var height = log[0].scrollHeight; let height = log[0].scrollHeight;
log.scrollTop(height); log.scrollTop(height);
// Update totals // Update totals