Fix some typescript bugs

- Don't default dialog width so the automatic calculations run
- Setting etemplate_exec_id after load doesn't work, moved to passing it in.  Fixes several file select issues
This commit is contained in:
nathangray 2020-04-09 14:26:57 -06:00
parent 0eb65b9efe
commit eda34d67b3
4 changed files with 139 additions and 136 deletions

View File

@ -769,7 +769,7 @@ var et2_dialog = /** @class */ (function (_super) {
name: "width", name: "width",
type: "string", type: "string",
description: "Define width of dialog, the default is auto", description: "Define width of dialog, the default is auto",
"default": 'auto' "default": et2_no_init
}, },
height: { height: {
name: "height", name: "height",

View File

@ -95,106 +95,106 @@ import {et2_DOMWidget} from "./et2_core_DOMWidget";
*/ */
export class et2_dialog extends et2_widget { export class et2_dialog extends et2_widget {
static readonly _attributes: any = { static readonly _attributes: any = {
callback: { callback: {
name: "Callback", name: "Callback",
type: "js", type: "js",
description: "Callback function is called with the value when the dialog is closed", description: "Callback function is called with the value when the dialog is closed",
"default": function (button_id) { "default": function (button_id) {
egw.debug("log", "Button ID: %d", button_id); egw.debug("log", "Button ID: %d", button_id);
} }
}, },
beforeClose: { beforeClose: {
name: "before close callback", name: "before close callback",
type: "js", type: "js",
description: "Callback function before dialog is closed, return false to prevent that", description: "Callback function before dialog is closed, return false to prevent that",
"default": function () { "default": function () {
} }
}, },
message: { message: {
name: "Message", name: "Message",
type: "string", type: "string",
description: "Dialog message (plain text, no html)", description: "Dialog message (plain text, no html)",
"default": "Somebody forgot to set this..." "default": "Somebody forgot to set this..."
}, },
dialog_type: { dialog_type: {
name: "Dialog type", name: "Dialog type",
type: "integer", type: "integer",
description: "To use a pre-defined dialog style, use et2_dialog.ERROR_MESSAGE, INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE,PLAIN_MESSAGE constants. Default is et2_dialog.PLAIN_MESSAGE", description: "To use a pre-defined dialog style, use et2_dialog.ERROR_MESSAGE, INFORMATION_MESSAGE,WARNING_MESSAGE,QUESTION_MESSAGE,PLAIN_MESSAGE constants. Default is et2_dialog.PLAIN_MESSAGE",
"default": 0 //this.PLAIN_MESSAGE "default": 0 //this.PLAIN_MESSAGE
}, },
buttons: { buttons: {
name: "Buttons", name: "Buttons",
type: "any", type: "any",
"default": 0, //this.BUTTONS_OK, "default": 0, //this.BUTTONS_OK,
description: "Buttons that appear at the bottom of the dialog. You can use the constants et2_dialog.BUTTONS_OK, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_OK_CANCEL, or pass in an array for full control" description: "Buttons that appear at the bottom of the dialog. You can use the constants et2_dialog.BUTTONS_OK, BUTTONS_YES_NO, BUTTONS_YES_NO_CANCEL, BUTTONS_OK_CANCEL, or pass in an array for full control"
}, },
icon: { icon: {
name: "Icon", name: "Icon",
type: "string", type: "string",
description: "URL of an icon for the dialog. If omitted, an icon based on dialog_type will be used.", description: "URL of an icon for the dialog. If omitted, an icon based on dialog_type will be used.",
"default": "" "default": ""
}, },
title: { title: {
name: "Title", name: "Title",
type: "string", type: "string",
description: "Title for the dialog box (plain text, no html)", description: "Title for the dialog box (plain text, no html)",
"default": "" "default": ""
}, },
modal: { modal: {
name: "Modal", name: "Modal",
type: "boolean", type: "boolean",
description: "Prevent the user from interacting with the page", description: "Prevent the user from interacting with the page",
"default": true "default": true
}, },
resizable: { resizable: {
name: "Resizable", name: "Resizable",
type: "boolean", type: "boolean",
description: "Allow the user to resize the dialog", description: "Allow the user to resize the dialog",
"default": true "default": true
}, },
value: { value: {
"name": "Value", "name": "Value",
"description": "The (default) value of the dialog. Use with template.", "description": "The (default) value of the dialog. Use with template.",
"type": "any", "type": "any",
"default": et2_no_init "default": et2_no_init
}, },
template: { template: {
"name": "Template", "name": "Template",
"description": "Instead of displaying a simple message, a full template can be loaded instead. Set defaults with value.", "description": "Instead of displaying a simple message, a full template can be loaded instead. Set defaults with value.",
"type": "string", "type": "string",
"default": et2_no_init "default": et2_no_init
}, },
minWidth: { minWidth: {
name: "minimum width", name: "minimum width",
type: "integer", type: "integer",
description: "Define minimum width of dialog", description: "Define minimum width of dialog",
"default": 0 "default": 0
}, },
minHeight: { minHeight: {
name: "minimum height", name: "minimum height",
type: "integer", type: "integer",
description: "Define minimum height of dialog", description: "Define minimum height of dialog",
"default": 0 "default": 0
}, },
width: { width: {
name: "width", name: "width",
type: "string", type: "string",
description: "Define width of dialog, the default is auto", description: "Define width of dialog, the default is auto",
"default": 'auto' "default": et2_no_init
}, },
height: { height: {
name: "height", name: "height",
type: "string", type: "string",
description: "Define width of dialog, the default is auto", description: "Define width of dialog, the default is auto",
"default": 'auto' "default": 'auto'
}, },
position: { position: {
name: "position", name: "position",
type: "string", type: "string",
description: "Define position of dialog in the main window", description: "Define position of dialog in the main window",
default: "center" default: "center"
} }
}; };
/** /**
* Details for dialog type options * Details for dialog type options

View File

@ -1072,7 +1072,18 @@ var et2_vfsSelect = /** @class */ (function (_super) {
} }
} }
buttons.push({ text: egw.lang("Close"), id: "close", image: "cancel" }); buttons.push({ text: egw.lang("Close"), id: "close", image: "cancel" });
var data = jQuery.extend(_data, { 'currentapp': egw(window).app_name() }); // Don't rely only on app_name to fetch et2 object as app_name may not
// always represent current app of the window, e.g.: mail admin account.
// Try to fetch et2 from its template name.
var etemplate = jQuery('form').data('etemplate');
var et2;
if (etemplate && etemplate.name && !app[egw(window).app_name()]) {
et2 = etemplate2.getByTemplate(etemplate.name)[0];
}
else {
et2 = etemplate2.getByApplication(egw(window).app_name())[0];
}
var data = jQuery.extend(_data, { 'currentapp': egw(window).app_name(), etemplate_exec_id: et2.etemplate_exec_id });
// define a mini app object for vfs select UI // define a mini app object for vfs select UI
app.vfsSelectUI = new app.classes.vfsSelectUI; app.vfsSelectUI = new app.classes.vfsSelectUI;
// callback for dialog // callback for dialog
@ -1146,26 +1157,15 @@ var et2_vfsSelect = /** @class */ (function (_super) {
this.dialog.template.uniqueId = 'api.vfsSelectUI'; this.dialog.template.uniqueId = 'api.vfsSelectUI';
app.vfsSelectUI.et2 = this.dialog.template.widgetContainer; app.vfsSelectUI.et2 = this.dialog.template.widgetContainer;
app.vfsSelectUI.vfsSelectWidget = this; app.vfsSelectUI.vfsSelectWidget = this;
// Don't rely only on app_name to fetch et2 object as app_name may not
// always represent current app of the window, e.g.: mail admin account.
// Try to fetch et2 from its template name.
var etemplate = jQuery('form').data('etemplate');
var et2;
if (etemplate && etemplate.name && !app[egw(window).app_name()]) {
et2 = etemplate2.getByTemplate(etemplate.name)[0];
}
else {
et2 = etemplate2.getByApplication(egw(window).app_name())[0];
}
// we need an etemplate_exec_id for better handling serverside parts of
// widgets and since we can not have a etemplate_exec_id specifically
// for dialog template our best shot is to inherit its parent etemplate_exec_id.
this.dialog.template.etemplate_exec_id = et2.etemplate_exec_id;
// Keep the dialog always at the top // Keep the dialog always at the top
this.dialog.div.parent().css({ "z-index": 100000 }); this.dialog.div.parent().css({ "z-index": 100000 });
this.dialog.div.on('load', function (e) { this.dialog.div.on('load', function (e) {
app.vfsSelectUI.et2_ready(app.vfsSelectUI.et2, 'api.vfsSelectUI'); app.vfsSelectUI.et2_ready(app.vfsSelectUI.et2, 'api.vfsSelectUI');
}); });
// we need an etemplate_exec_id for better handling serverside parts of
// widgets and since we can not have a etemplate_exec_id specifically
// for dialog template our best shot is to inherit its parent etemplate_exec_id.
this.dialog.template.etemplate_exec_id = et2.etemplate_exec_id;
}; };
/** /**
* Set recent path into sessionStorage * Set recent path into sessionStorage

View File

@ -1304,7 +1304,23 @@ export class et2_vfsSelect extends et2_inputWidget
} }
buttons.push({text: egw.lang("Close"), id:"close", image:"cancel"}); buttons.push({text: egw.lang("Close"), id:"close", image:"cancel"});
let data = jQuery.extend(_data, {'currentapp': egw(window).app_name()});
// Don't rely only on app_name to fetch et2 object as app_name may not
// always represent current app of the window, e.g.: mail admin account.
// Try to fetch et2 from its template name.
let etemplate = jQuery('form').data('etemplate');
let et2;
if (etemplate && etemplate.name && !app[egw(window).app_name()])
{
et2 = etemplate2.getByTemplate(etemplate.name)[0];
}
else
{
et2 = etemplate2.getByApplication(egw(window).app_name())[0];
}
let data = jQuery.extend(_data, {'currentapp': egw(window).app_name(), etemplate_exec_id: et2.etemplate_exec_id});
// define a mini app object for vfs select UI // define a mini app object for vfs select UI
app.vfsSelectUI = new app.classes.vfsSelectUI; app.vfsSelectUI = new app.classes.vfsSelectUI;
@ -1401,29 +1417,16 @@ export class et2_vfsSelect extends et2_inputWidget
app.vfsSelectUI.et2 = this.dialog.template.widgetContainer; app.vfsSelectUI.et2 = this.dialog.template.widgetContainer;
app.vfsSelectUI.vfsSelectWidget = this; app.vfsSelectUI.vfsSelectWidget = this;
// Don't rely only on app_name to fetch et2 object as app_name may not
// always represent current app of the window, e.g.: mail admin account.
// Try to fetch et2 from its template name.
let etemplate = jQuery('form').data('etemplate');
let et2;
if (etemplate && etemplate.name && !app[egw(window).app_name()])
{
et2 = etemplate2.getByTemplate(etemplate.name)[0];
}
else
{
et2 = etemplate2.getByApplication(egw(window).app_name())[0];
}
// we need an etemplate_exec_id for better handling serverside parts of
// widgets and since we can not have a etemplate_exec_id specifically
// for dialog template our best shot is to inherit its parent etemplate_exec_id.
this.dialog.template.etemplate_exec_id = et2.etemplate_exec_id;
// Keep the dialog always at the top // Keep the dialog always at the top
this.dialog.div.parent().css({"z-index": 100000}); this.dialog.div.parent().css({"z-index": 100000});
this.dialog.div.on('load', function(e) { this.dialog.div.on('load', function(e) {
app.vfsSelectUI.et2_ready(app.vfsSelectUI.et2, 'api.vfsSelectUI'); app.vfsSelectUI.et2_ready(app.vfsSelectUI.et2, 'api.vfsSelectUI');
}); });
// we need an etemplate_exec_id for better handling serverside parts of
// widgets and since we can not have a etemplate_exec_id specifically
// for dialog template our best shot is to inherit its parent etemplate_exec_id.
this.dialog.template.etemplate_exec_id = et2.etemplate_exec_id;
} }
/** /**