2020-02-24 23:16:40 +01:00
|
|
|
/**
|
|
|
|
* EGroupware eTemplate2 - JS file which contains the complete et2 module
|
|
|
|
*
|
|
|
|
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
|
|
|
|
* @package etemplate
|
|
|
|
* @subpackage api
|
2021-06-07 17:33:53 +02:00
|
|
|
* @link https://www.egroupware.org
|
2020-02-24 23:16:40 +01:00
|
|
|
* @author Andreas Stöckel
|
2021-06-07 17:33:53 +02:00
|
|
|
* @copyright EGroupware GmbH 2011-2021
|
|
|
|
*/
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
|
|
|
|
import {et2_widget} from "./et2_core_widget";
|
|
|
|
import {et2_baseWidget, et2_container} from "./et2_core_baseWidget";
|
|
|
|
import {EgwApp} from "../jsapi/egw_app";
|
2021-06-07 17:33:53 +02:00
|
|
|
import {et2_IInput, et2_IPrint, et2_IResizeable, et2_ISubmitListener} from "./et2_core_interfaces";
|
|
|
|
import {egw} from "../jsapi/egw_global";
|
|
|
|
import {et2_arrayMgr, et2_readonlysArrayMgr} from "./et2_core_arrayMgr";
|
|
|
|
import {et2_checkType} from "./et2_core_common";
|
|
|
|
import {et2_compileLegacyJS} from "./et2_core_legacyJSFunctions";
|
|
|
|
import {et2_loadXMLFromURL} from "./et2_core_xml";
|
|
|
|
import {et2_nextmatch, et2_nextmatch_header_bar} from "./et2_extension_nextmatch";
|
|
|
|
import '../jsapi/egw_json.js';
|
2023-07-10 16:02:30 +02:00
|
|
|
import {egwIsMobile} from "../egw_action/egw_action_common";
|
2022-05-06 19:57:53 +02:00
|
|
|
import './Layout/Et2Box/Et2Box';
|
2022-07-28 15:01:05 +02:00
|
|
|
import './Layout/Et2Details/Et2Details';
|
2022-08-02 18:30:40 +02:00
|
|
|
import './Layout/Et2Tabs/Et2Tab';
|
|
|
|
import './Layout/Et2Tabs/Et2Tabs';
|
|
|
|
import './Layout/Et2Tabs/Et2TabPanel';
|
2023-02-21 18:31:38 +01:00
|
|
|
import './Layout/Et2Tabs/Et2TabsMobile';
|
2022-07-12 17:14:44 +02:00
|
|
|
import './Et2Avatar/Et2Avatar';
|
2022-08-15 23:16:23 +02:00
|
|
|
import './Et2Avatar/Et2AvatarGroup';
|
2021-08-25 19:32:15 +02:00
|
|
|
import './Et2Button/Et2Button';
|
2022-08-22 21:45:06 +02:00
|
|
|
import './Et2Button/Et2ButtonIcon';
|
2023-03-22 17:59:05 +01:00
|
|
|
import './Et2Button/Et2ButtonScroll';
|
2022-08-03 15:48:23 +02:00
|
|
|
import './Et2Button/Et2ButtonTimestamper';
|
2022-07-27 23:51:32 +02:00
|
|
|
import './Et2Checkbox/Et2Checkbox';
|
2022-07-28 18:28:22 +02:00
|
|
|
import './Et2Checkbox/Et2CheckboxReadonly';
|
2021-12-17 22:47:19 +01:00
|
|
|
import './Et2Date/Et2Date';
|
2022-01-21 21:45:12 +01:00
|
|
|
import './Et2Date/Et2DateDuration';
|
|
|
|
import './Et2Date/Et2DateDurationReadonly';
|
2022-12-20 22:04:45 +01:00
|
|
|
import './Et2Date/Et2DateRange';
|
2022-01-21 21:45:12 +01:00
|
|
|
import './Et2Date/Et2DateReadonly';
|
|
|
|
import './Et2Date/Et2DateSinceReadonly';
|
2021-11-03 16:05:16 +01:00
|
|
|
import './Et2Date/Et2DateTime';
|
2022-02-16 18:43:15 +01:00
|
|
|
import './Et2Date/Et2DateTimeOnly';
|
2022-02-24 18:44:30 +01:00
|
|
|
import './Et2Date/Et2DateTimeOnlyReadonly';
|
2021-12-15 00:55:02 +01:00
|
|
|
import './Et2Date/Et2DateTimeReadonly';
|
2022-02-03 22:58:56 +01:00
|
|
|
import './Et2Date/Et2DateTimeToday';
|
2021-12-17 22:47:19 +01:00
|
|
|
import './Et2Description/Et2Description';
|
2022-03-15 00:06:42 +01:00
|
|
|
import './Et2Dialog/Et2Dialog';
|
2022-05-12 23:22:49 +02:00
|
|
|
import './Et2DropdownButton/Et2DropdownButton';
|
2022-05-05 01:31:42 +02:00
|
|
|
import './Expose/Et2ImageExpose';
|
2022-05-05 21:48:39 +02:00
|
|
|
import './Expose/Et2DescriptionExpose';
|
2022-05-18 19:01:27 +02:00
|
|
|
import './Et2Favorites/Et2Favorites';
|
2022-04-08 21:03:20 +02:00
|
|
|
import './Et2Image/Et2Image';
|
2022-08-07 11:55:02 +02:00
|
|
|
import './Et2Image/Et2AppIcon';
|
2022-07-12 17:14:44 +02:00
|
|
|
import './Et2Avatar/Et2LAvatar';
|
2022-05-11 00:02:33 +02:00
|
|
|
import './Et2Link/Et2Link';
|
2022-07-19 00:34:58 +02:00
|
|
|
import './Et2Link/Et2LinkAdd';
|
2022-05-26 22:47:52 +02:00
|
|
|
import './Et2Link/Et2LinkAppSelect';
|
2022-05-31 21:40:31 +02:00
|
|
|
import './Et2Link/Et2LinkEntry';
|
2022-05-11 00:02:33 +02:00
|
|
|
import './Et2Link/Et2LinkList';
|
2022-05-31 21:40:31 +02:00
|
|
|
import './Et2Link/Et2LinkSearch';
|
2022-05-11 00:02:33 +02:00
|
|
|
import './Et2Link/Et2LinkString';
|
2022-06-06 21:31:33 +02:00
|
|
|
import './Et2Link/Et2LinkTo';
|
2022-08-18 22:46:44 +02:00
|
|
|
import './Et2Nextmatch/ColumnSelection';
|
2022-07-07 21:18:42 +02:00
|
|
|
import './Et2Nextmatch/Headers/AccountFilterHeader';
|
|
|
|
import './Et2Nextmatch/Headers/CustomFilterHeader';
|
|
|
|
import './Et2Nextmatch/Headers/EntryHeader';
|
|
|
|
import './Et2Nextmatch/Headers/FilterHeader';
|
2022-10-05 18:50:54 +02:00
|
|
|
import './Et2Select/Et2Listbox';
|
2022-01-04 23:38:10 +01:00
|
|
|
import './Et2Select/Et2Select';
|
2022-01-19 21:17:07 +01:00
|
|
|
import './Et2Select/Et2SelectAccount';
|
2022-06-20 17:35:38 +02:00
|
|
|
import './Et2Select/Et2SelectCategory';
|
2022-06-22 23:47:28 +02:00
|
|
|
import './Et2Select/Et2SelectCountry';
|
2022-06-10 18:11:34 +02:00
|
|
|
import './Et2Select/Et2SelectEmail';
|
2022-01-04 23:38:10 +01:00
|
|
|
import './Et2Select/Et2SelectReadonly';
|
2022-06-17 21:07:33 +02:00
|
|
|
import './Et2Select/Et2SelectThumbnail'
|
2022-06-10 18:11:34 +02:00
|
|
|
import './Et2Select/Tag/Et2Tag';
|
2022-06-17 21:07:33 +02:00
|
|
|
import './Et2Select/Tag/Et2CategoryTag';
|
2022-06-24 20:10:10 +02:00
|
|
|
import './Et2Select/Tag/Et2EmailTag';
|
2022-06-17 21:07:33 +02:00
|
|
|
import './Et2Select/Tag/Et2ThumbnailTag';
|
2022-09-02 13:50:38 +02:00
|
|
|
import './Et2Spinner/Et2Spinner';
|
2022-08-03 13:41:08 +02:00
|
|
|
import './Et2Switch/Et2Switch';
|
2021-08-25 23:35:06 +02:00
|
|
|
import './Et2Textarea/Et2Textarea';
|
2022-09-19 21:28:20 +02:00
|
|
|
import './Et2Textarea/Et2TextareaReadonly';
|
2021-08-25 23:35:06 +02:00
|
|
|
import './Et2Textbox/Et2Textbox';
|
2022-01-13 23:31:01 +01:00
|
|
|
import './Et2Textbox/Et2TextboxReadonly';
|
2022-03-06 19:14:53 +01:00
|
|
|
import './Et2Textbox/Et2Number';
|
|
|
|
import './Et2Textbox/Et2NumberReadonly';
|
2021-09-02 16:47:49 +02:00
|
|
|
import './Et2Colorpicker/Et2Colorpicker';
|
2022-03-10 09:15:59 +01:00
|
|
|
import './Et2Url/Et2Url';
|
|
|
|
import './Et2Url/Et2UrlReadonly';
|
2022-03-08 19:19:33 +01:00
|
|
|
import './Et2Url/Et2UrlEmail';
|
2022-03-10 09:15:59 +01:00
|
|
|
import './Et2Url/Et2UrlEmailReadonly';
|
2022-03-08 19:19:33 +01:00
|
|
|
import './Et2Url/Et2UrlPhone';
|
2022-03-10 09:15:59 +01:00
|
|
|
import './Et2Url/Et2UrlPhoneReadonly';
|
|
|
|
import './Et2Url/Et2UrlFax';
|
|
|
|
import './Et2Url/Et2UrlFaxReadonly';
|
2022-04-19 17:36:44 +02:00
|
|
|
import "./Layout/Et2Split/Et2Split";
|
2022-07-12 01:27:17 +02:00
|
|
|
import "./Layout/RowLimitedMixin";
|
2022-05-13 11:59:13 +02:00
|
|
|
import "./Et2Vfs/Et2VfsMime";
|
|
|
|
import "./Et2Vfs/Et2VfsUid";
|
2022-07-22 15:21:27 +02:00
|
|
|
import "./Et2Textbox/Et2Password";
|
2022-07-22 20:43:09 +02:00
|
|
|
import './Et2Textbox/Et2Searchbox';
|
2022-03-02 16:28:45 +01:00
|
|
|
|
2021-06-25 22:49:24 +02:00
|
|
|
/* Include all widget classes here, we only care about them registering, not importing anything*/
|
|
|
|
import './et2_widget_vfs'; // Vfs must be first (before et2_widget_file) due to import cycle
|
2021-06-07 17:33:53 +02:00
|
|
|
import './et2_widget_template';
|
|
|
|
import './et2_widget_grid';
|
|
|
|
import './et2_widget_box';
|
|
|
|
import './et2_widget_hbox';
|
|
|
|
import './et2_widget_groupbox';
|
|
|
|
import './et2_widget_button';
|
|
|
|
import './et2_widget_entry';
|
|
|
|
import './et2_widget_textbox';
|
|
|
|
import './et2_widget_number';
|
|
|
|
import './et2_widget_selectbox';
|
|
|
|
import './et2_widget_radiobox';
|
|
|
|
import './et2_widget_date';
|
|
|
|
import './et2_widget_dialog';
|
|
|
|
import './et2_widget_diff';
|
|
|
|
import './et2_widget_styles';
|
|
|
|
import './et2_widget_html';
|
|
|
|
import './et2_widget_htmlarea';
|
|
|
|
import './et2_widget_taglist';
|
|
|
|
import './et2_widget_toolbar';
|
|
|
|
import './et2_widget_tree';
|
|
|
|
import './et2_widget_historylog';
|
|
|
|
import './et2_widget_hrule';
|
|
|
|
import './et2_widget_iframe';
|
|
|
|
import './et2_widget_file';
|
2021-09-20 22:58:02 +02:00
|
|
|
import './et2_widget_placeholder';
|
2021-06-07 17:33:53 +02:00
|
|
|
import './et2_widget_progress';
|
|
|
|
import './et2_widget_portlet';
|
|
|
|
import './et2_widget_selectAccount';
|
|
|
|
import './et2_widget_ajaxSelect';
|
|
|
|
import './et2_widget_video';
|
|
|
|
import './et2_widget_audio';
|
|
|
|
import './et2_widget_barcode';
|
|
|
|
import './et2_widget_itempicker';
|
|
|
|
import './et2_widget_script';
|
|
|
|
import './et2_widget_countdown';
|
|
|
|
import './et2_extension_nextmatch';
|
|
|
|
import './et2_extension_customfields';
|
2021-07-06 15:50:49 +02:00
|
|
|
import './vfsSelectUI';
|
2022-08-05 20:33:29 +02:00
|
|
|
import {Et2Tabs} from "./Layout/Et2Tabs/Et2Tabs";
|
2023-07-14 00:18:11 +02:00
|
|
|
import {Et2Dialog} from "./Et2Dialog/Et2Dialog";
|
2021-06-25 22:49:24 +02:00
|
|
|
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
/**
|
|
|
|
* The etemplate2 class manages a certain etemplate2 instance.
|
|
|
|
*
|
|
|
|
* @param _container is the DOM-Node into which the DOM-Nodes of this instance
|
|
|
|
* should be inserted
|
|
|
|
* @param _menuaction is the URL to which the form data should be submitted.
|
|
|
|
*/
|
|
|
|
export class etemplate2
|
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* List of loaded templates
|
|
|
|
*/
|
|
|
|
public static templates = {};
|
|
|
|
/**
|
|
|
|
* List of etemplates by loaded template
|
|
|
|
*/
|
|
|
|
private static _byTemplate = {};
|
|
|
|
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
private _etemplate_exec_id : string;
|
|
|
|
private readonly menuaction : string;
|
|
|
|
name : string;
|
|
|
|
private uniqueId : void | string;
|
|
|
|
private template_base_url : string;
|
2021-08-13 23:26:18 +02:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
private _widgetContainer : et2_container;
|
|
|
|
private _DOMContainer : HTMLElement;
|
2021-08-13 23:26:18 +02:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
private resize_timeout : number | boolean;
|
|
|
|
private destroy_session : any;
|
|
|
|
private close_prompt : any;
|
|
|
|
private _skip_close_prompt : boolean;
|
|
|
|
private app_obj : EgwApp;
|
|
|
|
app : string;
|
2021-08-13 23:26:18 +02:00
|
|
|
|
2023-02-27 23:31:07 +01:00
|
|
|
/**
|
|
|
|
* Flag indicating that all loading is done, and the etemplate is ready to be used by app.js
|
|
|
|
*
|
|
|
|
* onChange handler checks this to ignore change events before the etemplate is ready
|
|
|
|
*/
|
|
|
|
private ready : boolean = false;
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
constructor(_container : HTMLElement, _menuaction? : string, _uniqueId? : string)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _menuaction == "undefined")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
_menuaction = "EGroupware\\Api\\Etemplate::ajax_process_content";
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Copy the given parameters
|
|
|
|
this._DOMContainer = _container;
|
|
|
|
this.menuaction = _menuaction;
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Unique ID to prevent DOM collisions across multiple templates
|
|
|
|
this.uniqueId = _uniqueId ? _uniqueId : (_container.getAttribute("id") ? _container.getAttribute("id").replace('.', '-') : '');
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* Preset the object variable
|
|
|
|
* @type {et2_container}
|
|
|
|
*/
|
|
|
|
this._widgetContainer = null;
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// List of templates (XML) that are known, not always used. Indexed by id.
|
|
|
|
// We share list of templates with iframes and popups
|
|
|
|
try
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(opener && opener.etemplate2)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
etemplate2.templates = opener.etemplate2.templates;
|
|
|
|
}
|
|
|
|
// @ts-ignore
|
2021-12-15 00:55:02 +01:00
|
|
|
else if(top.etemplate2)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// @ts-ignore
|
|
|
|
etemplate2.templates = top.etemplate2.templates;
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
catch(e)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// catch security exception if opener is from a different domain
|
|
|
|
console.log('Security exception accessing etemplate2.prototype of opener or top!');
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof etemplate2.templates == "undefined")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
etemplate2.templates = {};
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Calls the resize event of all widgets
|
|
|
|
*
|
|
|
|
* @param {jQuery.event} e
|
|
|
|
*/
|
|
|
|
public resize(e)
|
|
|
|
{
|
|
|
|
const event = e;
|
|
|
|
const self = this;
|
2021-12-15 00:55:02 +01:00
|
|
|
let excess_height : number | boolean = false;
|
2021-08-13 23:26:18 +02:00
|
|
|
|
|
|
|
// Check if the framework has an specific excess height calculation
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof window.framework != 'undefined' && typeof window.framework.get_wExcessHeight != 'undefined')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
excess_height = window.framework.get_wExcessHeight(window);
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
//@TODO implement getaccess height for other framework and remove
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof event != 'undefined' && event.type == 'resize')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this.resize_timeout)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
clearTimeout(<number>this.resize_timeout);
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
this.resize_timeout = setTimeout(function()
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
self.resize_timeout = false;
|
2021-12-15 00:55:02 +01:00
|
|
|
if(self._widgetContainer)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
const appHeader = jQuery('#divAppboxHeader');
|
|
|
|
|
|
|
|
//Calculate the excess height
|
|
|
|
excess_height = egw(window).is_popup() ? jQuery(window).height() - jQuery(self._DOMContainer).height() - appHeader.outerHeight() + 11 : 0;
|
|
|
|
// Recalculate excess height if the appheader is shown
|
2021-12-15 00:55:02 +01:00
|
|
|
if(appHeader.length > 0 && appHeader.is(':visible'))
|
|
|
|
{
|
|
|
|
excess_height -= appHeader.outerHeight() - 9;
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
|
|
|
|
// Do not resize if the template height is bigger than screen available height
|
|
|
|
// For templates which have sub templates and they are bigger than screenHeight
|
2021-12-15 00:55:02 +01:00
|
|
|
if(screen.availHeight < jQuery(self._DOMContainer).height())
|
|
|
|
{
|
|
|
|
excess_height = 0;
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
|
|
|
|
// If we're visible, call the "resize" event of all functions which implement the
|
|
|
|
// "IResizeable" interface
|
2021-12-15 00:55:02 +01:00
|
|
|
if(jQuery(self.DOMContainer).is(":visible"))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
self._widgetContainer.iterateOver(function(_widget)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2022-07-29 14:56:03 +02:00
|
|
|
if (typeof _widget.resize === 'function')
|
|
|
|
{
|
|
|
|
_widget.resize(excess_height);
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}, self, et2_IResizeable);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}, 100);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
// Initial resize needs to be resized immediately (for instance for nextmatch resize)
|
2021-12-15 00:55:02 +01:00
|
|
|
else if(this._widgetContainer)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Call the "resize" event of all functions which implement the
|
|
|
|
// "IResizeable" interface
|
2021-12-15 00:55:02 +01:00
|
|
|
this._widgetContainer.iterateOver(function(_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
_widget.resize(excess_height);
|
|
|
|
}, this, et2_IResizeable);
|
|
|
|
}
|
|
|
|
};
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Clears the current instance.
|
|
|
|
* @param _keep_app_object keep app object
|
|
|
|
* @param _keep_session keep server-side et2 session eg. for vfs-select
|
|
|
|
*/
|
2021-12-15 00:55:02 +01:00
|
|
|
public clear(_keep_app_object? : boolean, _keep_session? : boolean)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
this.DOMContainer.dispatchEvent(new Event("clear", {bubbles: true}));
|
2021-08-13 23:26:18 +02:00
|
|
|
|
|
|
|
// Remove any handlers on window (resize)
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this.uniqueId)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
jQuery(window).off("." + this.uniqueId);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// call our destroy_session handler, if it is not already unbind, and unbind it after
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this.destroy_session)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!_keep_session)
|
|
|
|
{
|
|
|
|
this.destroy_session();
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
this.unbind_unload();
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this._widgetContainer != null)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Un-register handler
|
|
|
|
this._widgetContainer.egw().unregisterJSONPlugin(this.handle_assign, this, 'assign');
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
this._widgetContainer.destroy();
|
|
|
|
this._widgetContainer = null;
|
|
|
|
}
|
|
|
|
jQuery(this._DOMContainer).empty();
|
2020-04-21 23:36:17 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Remove self from the index
|
2021-12-15 00:55:02 +01:00
|
|
|
for(const name in etemplate2.templates)
|
2020-04-21 23:36:17 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof etemplate2._byTemplate[name] == "undefined")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
for(let i = 0; i < etemplate2._byTemplate[name].length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(etemplate2._byTemplate[name][i] === this)
|
2020-04-21 23:36:17 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
etemplate2._byTemplate[name].splice(i, 1);
|
2020-04-21 23:36:17 +02:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// If using a private app object, remove all of them
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!_keep_app_object && this.app_obj !== window.app)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
for(const app_name in this.app_obj)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this.app_obj[app_name] instanceof EgwApp)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2022-10-19 18:54:11 +02:00
|
|
|
this.app_obj[app_name].destroy(this.app_obj);
|
2021-08-12 18:32:05 +02:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
get widgetContainer() : et2_container
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return this._widgetContainer;
|
|
|
|
}
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
get DOMContainer() : HTMLElement
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return this._DOMContainer;
|
|
|
|
}
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
get etemplate_exec_id() : string
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return this._etemplate_exec_id;
|
|
|
|
}
|
|
|
|
|
2023-02-27 23:31:07 +01:00
|
|
|
get isReady() : boolean
|
|
|
|
{
|
|
|
|
return this.ready;
|
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* Creates an associative array containing the data array managers for each part
|
|
|
|
* of the associative data array. A part is something like "content", "readonlys"
|
|
|
|
* or "sel_options".
|
|
|
|
*
|
|
|
|
* @param {object} _data object with values for attributes content, sel_options, readonlys, modifications
|
|
|
|
*/
|
|
|
|
private _createArrayManagers(_data)
|
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _data == "undefined")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
_data = {};
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Create all neccessary _data entries
|
|
|
|
const neededEntries = ["content", "sel_options", "readonlys", "modifications",
|
|
|
|
"validation_errors"];
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let i = 0; i < neededEntries.length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _data[neededEntries[i]] == "undefined" || !_data[neededEntries[i]])
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.debug("log", "Created not passed entry '" + neededEntries[i] +
|
|
|
|
"' in data array.");
|
|
|
|
_data[neededEntries[i]] = {};
|
|
|
|
}
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const result = {};
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Create an array manager object for each part of the _data array.
|
2021-12-15 00:55:02 +01:00
|
|
|
for(const key in _data)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
switch(key)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
case "etemplate_exec_id": // already processed
|
|
|
|
case "app_header":
|
|
|
|
break;
|
|
|
|
case "readonlys":
|
|
|
|
result[key] = new et2_readonlysArrayMgr(_data[key]);
|
|
|
|
result[key].perspectiveData.owner = this._widgetContainer;
|
|
|
|
break;
|
|
|
|
default:
|
|
|
|
result[key] = new et2_arrayMgr(_data[key]);
|
|
|
|
result[key].perspectiveData.owner = this._widgetContainer;
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Bind our unload handler to notify server that eT session/request no longer needed
|
|
|
|
*
|
|
|
|
* We only bind, if we have an etemplate_exec_id: not the case for pure client-side
|
|
|
|
* calls, eg. via et2_dialog.
|
|
|
|
*/
|
|
|
|
bind_unload()
|
|
|
|
{
|
|
|
|
// Prompt user to save for dirty popups
|
2021-12-15 00:55:02 +01:00
|
|
|
if(window !== egw_topWindow() && !this.close_prompt)
|
2020-06-19 21:27:41 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
this.close_prompt = this._close_changed_prompt.bind(this);
|
|
|
|
window.addEventListener("beforeunload", this.close_prompt);
|
2020-06-19 21:27:41 +02:00
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this._etemplate_exec_id)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
this.destroy_session = jQuery.proxy(function(ev)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// need to use async === "keepalive" to run via beforeunload
|
|
|
|
egw.json("EGroupware\\Api\\Etemplate::ajax_destroy_session",
|
|
|
|
[this._etemplate_exec_id], null, null, "keepalive").sendRequest();
|
|
|
|
}, this);
|
|
|
|
|
2023-08-16 18:23:58 +02:00
|
|
|
window.addEventListener("unload", this.destroy_session);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
private _close_changed_prompt(e : BeforeUnloadEvent)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this._skip_close_prompt || !this.isDirty())
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
return;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Cancel the event
|
|
|
|
e.preventDefault(); // If you prevent default behavior in Mozilla Firefox prompt will always be shown
|
|
|
|
|
|
|
|
// Chrome requires returnValue to be set
|
|
|
|
e.returnValue = '';
|
2023-08-16 18:23:58 +02:00
|
|
|
return "";
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
public skip_close_prompt(skip = true)
|
|
|
|
{
|
|
|
|
this._skip_close_prompt = skip;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Unbind our unload handler
|
|
|
|
*/
|
|
|
|
unbind_unload()
|
|
|
|
{
|
|
|
|
window.removeEventListener("beforeunload", this.destroy_session);
|
|
|
|
window.removeEventListener("beforeunload", this.close_prompt);
|
2021-12-15 00:55:02 +01:00
|
|
|
if(window.onbeforeunload === this.destroy_session)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
window.onbeforeunload = null;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
else
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
const onbeforeunload = window.onbeforeunload;
|
|
|
|
window.onbeforeunload = null;
|
|
|
|
// bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!)
|
2021-12-15 00:55:02 +01:00
|
|
|
window.setTimeout(function()
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
window.onbeforeunload = onbeforeunload;
|
|
|
|
}, 100);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
delete this.destroy_session;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Download a URL not triggering our unload handler and therefore destroying our et2 request
|
|
|
|
*
|
|
|
|
* We use a new anchor element to avoid not destroying other etemplates as well, which
|
|
|
|
* is what happens if we use window.location
|
|
|
|
*
|
|
|
|
* @param {string} _url
|
|
|
|
*/
|
|
|
|
download(_url)
|
|
|
|
{
|
|
|
|
const a = document.createElement('a');
|
|
|
|
a.href = _url;
|
|
|
|
a.download = 'download';
|
|
|
|
|
|
|
|
// Programmatically trigger a click on the anchor element
|
|
|
|
a.click();
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Loads the template from the given URL and sets the data object
|
|
|
|
*
|
|
|
|
* @param {string} _name name of template
|
|
|
|
* @param {string} _url url to load template
|
|
|
|
* @param {object} _data object with attributes content, langRequire, etemplate_exec_id, ...
|
|
|
|
* @param {function} _callback called after template is loaded
|
|
|
|
* @param {object} _app local app object
|
|
|
|
* @param {boolean} _no_et2_ready true: do not send et2_ready, used by et2_dialog to not overwrite app.js et2 object
|
|
|
|
* @param {string} _open_target flag of string to distinguish between tab target and normal app object
|
|
|
|
* @return Promise
|
|
|
|
*/
|
|
|
|
async load(_name, _url, _data, _callback?, _app?, _no_et2_ready?, _open_target?)
|
|
|
|
{
|
2023-02-27 23:31:07 +01:00
|
|
|
this.ready = false;
|
2021-08-13 23:26:18 +02:00
|
|
|
let app = _app || window.app;
|
|
|
|
this.name = _name; // store top-level template name to have it available in widgets
|
|
|
|
// store template base url, in case initial template is loaded via webdav, to use that for further loads too
|
|
|
|
// need to split off domain first, as it could contain app-name part of template eg. stylite.report.xet and https://my.stylite.de/egw/...
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_url && _url[0] != '/')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
this.template_base_url = _url.match(/https?:\/\/[^/]+/).shift();
|
|
|
|
_url = _url.split(this.template_base_url)[1];
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
else
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
this.template_base_url = '';
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
this.template_base_url += _url.split(_name.split('.').shift())[0];
|
|
|
|
|
|
|
|
egw().debug("info", "Loaded data", _data);
|
|
|
|
const currentapp = this.app = _data.currentapp || egw().app_name();
|
|
|
|
const appname = _name.split('.')[0];
|
|
|
|
// if no app object provided and template app is not currentapp (eg. infolog CRM view)
|
|
|
|
// create private app object / closure with just classes / prototypes
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!_app && appname && appname != currentapp || _open_target)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
app = {classes: window.app.classes};
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
// remember used app object, to eg. use: onchange="widget.getInstanceMgr().app_object[app].callback()"
|
|
|
|
this.app_obj = app;
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// extract $content['msg'] and call egw.message() with it
|
|
|
|
const msg = _data.content.msg;
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof msg != 'undefined')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
egw(window).message(msg);
|
|
|
|
delete _data.content.msg;
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Register a handler for AJAX responses
|
|
|
|
egw(currentapp, window).registerJSONPlugin(this.handle_assign, this, 'assign');
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(egw.debug_level() >= 3)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(console.groupCollapsed)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.window.console.groupCollapsed("Loading %s into ", _name, '#' + this._DOMContainer.id);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Timing & profiling on debug level 'log' (4)
|
2021-12-15 00:55:02 +01:00
|
|
|
if(egw.debug_level() >= 4)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(console.time)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
console.time(_name);
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(console.profile)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
console.profile(_name);
|
|
|
|
}
|
|
|
|
var start_time = (new Date).getTime();
|
2021-06-10 14:54:16 +02:00
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// require necessary translations from server AND the app.js file, if not already loaded
|
|
|
|
let promisses = [window.egw_ready]; // to wait for legacy-loaded JS
|
2021-12-15 00:55:02 +01:00
|
|
|
if(Array.isArray(_data.langRequire))
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
promisses.push(egw(currentapp, window).langRequire(window, _data.langRequire));
|
|
|
|
}
|
2022-04-26 23:27:49 +02:00
|
|
|
if(appname && typeof app[appname] !== "object")
|
|
|
|
{
|
|
|
|
/*
|
|
|
|
Don't have the app.ts code - load it here and delay load until its ready
|
|
|
|
promisses.push(import(egw.webserverUrl + "/" + appname + "/js/app.min.js?" + ((new Date).valueOf() / 86400 | 0).toString())
|
|
|
|
.then(() =>
|
|
|
|
{
|
|
|
|
if(typeof app.classes[appname] === "undefined")
|
|
|
|
{
|
|
|
|
throw new Error("app.classes." + appname + " not found!");
|
|
|
|
}
|
|
|
|
}));
|
|
|
|
*/
|
|
|
|
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
return Promise.all(promisses).catch((err) =>
|
|
|
|
{
|
|
|
|
console.log("et2.load(): error loading lang-files and app.js: " + err.message);
|
|
|
|
}).then(() =>
|
|
|
|
{
|
|
|
|
this.clear();
|
|
|
|
|
|
|
|
// Initialize application js
|
|
|
|
let app_callback = null;
|
|
|
|
// Only initialize once
|
|
|
|
// new app class with constructor function in app.classes[appname]
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof app[appname] !== 'object' && typeof app.classes[appname] == 'function')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
app[appname] = new app.classes[appname]();
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
else if(appname && typeof app[appname] !== "object")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.debug("warn", "Did not load '%s' JS object", appname);
|
|
|
|
}
|
|
|
|
// If etemplate current app does not match app owning the template,
|
|
|
|
// initialize the current app too
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof app[this.app] !== 'object' && typeof app.classes[this.app] == 'function')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
app[this.app] = new app.classes[this.app]();
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof app[appname] == "object")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
app_callback = function(_et2, _name)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
app[appname].et2_ready(_et2, _name);
|
|
|
|
};
|
|
|
|
}
|
|
|
|
|
|
|
|
// Create the basic widget container and attach it to the DOM
|
|
|
|
this._widgetContainer = new et2_container(null);
|
|
|
|
this._widgetContainer.setApiInstance(egw(currentapp, egw.elemWindow(this._DOMContainer)));
|
|
|
|
this._widgetContainer.setInstanceManager(this);
|
|
|
|
this._widgetContainer.setParentDOMNode(this._DOMContainer);
|
|
|
|
|
|
|
|
// store the id to submit it back to server
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_data)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
this._etemplate_exec_id = _data.etemplate_exec_id;
|
|
|
|
// set app_header
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _data.app_header == 'string')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
// @ts-ignore
|
|
|
|
window.egw_app_header(_data.app_header);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
// bind our unload handler
|
|
|
|
this.bind_unload();
|
|
|
|
}
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
const _load = function()
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.debug("log", "Loading template...");
|
2021-12-15 00:55:02 +01:00
|
|
|
if(egw.debug_level() >= 4 && console.timeStamp)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
console.timeStamp("Begin rendering template");
|
2022-08-02 18:30:40 +02:00
|
|
|
console.time("Template load");
|
|
|
|
console.time("loadFromXML");
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Add into indexed list - do this before, so anything looking can find it,
|
|
|
|
// even if it's not loaded
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof etemplate2._byTemplate[_name] == "undefined")
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
etemplate2._byTemplate[_name] = [];
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
etemplate2._byTemplate[_name].push(this);
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Read the XML structure of the requested template
|
|
|
|
this._widgetContainer.loadFromXML(etemplate2.templates[this.name]);
|
2022-08-02 18:30:40 +02:00
|
|
|
console.timeEnd("loadFromXML");
|
|
|
|
console.time("deferred");
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// List of Promises from widgets that are not quite fully loaded
|
|
|
|
const deferred = [];
|
|
|
|
|
|
|
|
// Inform the widget tree that it has been successfully loaded.
|
|
|
|
this._widgetContainer.loadingFinished(deferred);
|
|
|
|
|
|
|
|
// Connect to the window resize event
|
2021-12-15 00:55:02 +01:00
|
|
|
jQuery(window).on("resize." + this.uniqueId, this, function(e)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
e.data.resize(e);
|
|
|
|
});
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(egw.debug_level() >= 3 && console.groupEnd)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2022-08-02 18:30:40 +02:00
|
|
|
if(console.timeStamp)
|
|
|
|
{
|
|
|
|
console.timeStamp("loading finished, waiting for deferred");
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.window.console.groupEnd();
|
2021-08-12 18:32:05 +02:00
|
|
|
}
|
2021-06-11 09:05:57 +02:00
|
|
|
|
2022-03-29 17:16:19 +02:00
|
|
|
// Wait for everything to be loaded, then finish it up. Use timeout to give anything else a chance
|
|
|
|
// to run.
|
|
|
|
setTimeout(() =>
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2022-03-29 17:16:19 +02:00
|
|
|
Promise.all(deferred).then(() =>
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2022-08-02 18:30:40 +02:00
|
|
|
|
|
|
|
console.timeEnd("deferred");
|
|
|
|
console.timeStamp("Deferred done");
|
2022-06-21 17:03:15 +02:00
|
|
|
// Clear dirty now that it's all loaded
|
|
|
|
this.widgetContainer.iterateOver((_widget) =>
|
|
|
|
{
|
|
|
|
_widget.resetDirty();
|
|
|
|
}, this, et2_IInput);
|
2022-03-29 17:16:19 +02:00
|
|
|
egw.debug("log", "Finished loading %s, triggering load event", _name);
|
2021-08-13 23:26:18 +02:00
|
|
|
|
2022-03-29 17:16:19 +02:00
|
|
|
if(typeof window.framework != 'undefined' && typeof window.framework.et2_loadingFinished != 'undefined')
|
2021-12-15 00:55:02 +01:00
|
|
|
{
|
2022-03-29 17:16:19 +02:00
|
|
|
//Call loading finished method of the framework with local window
|
|
|
|
window.framework.et2_loadingFinished(egw(window).window);
|
2021-12-15 00:55:02 +01:00
|
|
|
}
|
2022-03-29 17:16:19 +02:00
|
|
|
// Trigger the "resize" event
|
|
|
|
this.resize();
|
2021-08-13 23:26:18 +02:00
|
|
|
|
2022-03-29 17:16:19 +02:00
|
|
|
// Automatically set focus to first visible input for popups
|
|
|
|
if(this._widgetContainer._egw.is_popup() && jQuery('[autofocus]', this._DOMContainer).focus().length == 0)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2022-05-04 14:14:48 +02:00
|
|
|
this.focusOnFirstInput();
|
2021-08-12 18:32:05 +02:00
|
|
|
}
|
2022-03-30 09:21:22 +02:00
|
|
|
|
2023-02-27 23:31:07 +01:00
|
|
|
// Now etemplate is ready for others to interact with (eg: app.js)
|
|
|
|
this.ready = true;
|
|
|
|
|
2022-03-29 17:16:19 +02:00
|
|
|
// Tell others about it
|
|
|
|
if(typeof _callback == "function")
|
2021-12-15 00:55:02 +01:00
|
|
|
{
|
2022-03-29 17:16:19 +02:00
|
|
|
_callback.call(window, this, _name);
|
2021-12-15 00:55:02 +01:00
|
|
|
}
|
2022-03-29 17:16:19 +02:00
|
|
|
if(app_callback && _callback != app_callback && !_no_et2_ready)
|
2022-03-29 17:16:19 +02:00
|
|
|
{
|
2022-03-29 17:16:19 +02:00
|
|
|
app_callback.call(window, this, _name);
|
2022-03-29 17:16:19 +02:00
|
|
|
}
|
2022-03-29 17:16:19 +02:00
|
|
|
if(appname && appname != this.app && typeof app[this.app] == "object" && !_no_et2_ready)
|
2022-03-29 17:16:19 +02:00
|
|
|
{
|
2022-03-29 17:16:19 +02:00
|
|
|
// Loaded a template from a different application?
|
|
|
|
// Let the application that loaded it know too
|
|
|
|
app[this.app].et2_ready(this, this.name);
|
2022-03-29 17:16:19 +02:00
|
|
|
}
|
2022-03-29 17:16:19 +02:00
|
|
|
|
|
|
|
// Dispatch an event that will bubble through shadow DOM boundary (pass through custom elements)
|
|
|
|
this._DOMContainer.dispatchEvent(new CustomEvent('load', {
|
|
|
|
bubbles: true,
|
|
|
|
composed: true,
|
|
|
|
detail: this
|
|
|
|
}));
|
|
|
|
|
|
|
|
if(etemplate2.templates[this.name].attributes.onload)
|
|
|
|
{
|
|
|
|
let onload = et2_checkType(etemplate2.templates[this.name].attributes.onload.value, 'js', 'onload', {});
|
|
|
|
if(typeof onload === 'string')
|
|
|
|
{
|
|
|
|
onload = et2_compileLegacyJS(onload, this, this._widgetContainer);
|
|
|
|
}
|
|
|
|
onload.call(this._widgetContainer);
|
|
|
|
}
|
|
|
|
|
|
|
|
// Profiling
|
|
|
|
if(egw.debug_level() >= 4)
|
|
|
|
{
|
|
|
|
if(console.timeEnd)
|
|
|
|
{
|
|
|
|
console.timeEnd(_name);
|
|
|
|
}
|
|
|
|
if(console.profileEnd)
|
|
|
|
{
|
|
|
|
console.profileEnd(_name);
|
|
|
|
}
|
|
|
|
const end_time = (new Date).getTime();
|
|
|
|
let gen_time_div = jQuery('#divGenTime_' + appname);
|
|
|
|
if(!gen_time_div.length)
|
|
|
|
{
|
|
|
|
gen_time_div = jQuery('.pageGenTime');
|
|
|
|
}
|
|
|
|
gen_time_div.find('.et2RenderTime').remove();
|
|
|
|
gen_time_div.append('<span class="et2RenderTime">' + egw.lang('eT2 rendering took %1s', '' + ((end_time - start_time) / 1000)) + '</span>');
|
|
|
|
}
|
|
|
|
});
|
2022-03-08 23:11:32 +01:00
|
|
|
});
|
2021-08-13 23:26:18 +02:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
// Load & process
|
|
|
|
try
|
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(etemplate2.templates[_name])
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Set array managers first, or errors will happen
|
|
|
|
this._widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Already have it
|
|
|
|
_load.apply(this, []);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
catch(e)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// weird security exception in IE denying access to template cache in opener
|
2021-12-15 00:55:02 +01:00
|
|
|
if(e.message == 'Permission denied')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
etemplate2.templates = {};
|
|
|
|
}
|
|
|
|
// other error eg. in app.js et2_ready or event handlers --> rethrow it
|
|
|
|
else
|
|
|
|
{
|
|
|
|
throw e;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
// Split the given data into array manager objects and pass those to the
|
|
|
|
// widget container - do this here because file is loaded async
|
|
|
|
this._widgetContainer.setArrayMgrs(this._createArrayManagers(_data));
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Asynchronously load the XET file
|
2021-12-15 00:55:02 +01:00
|
|
|
return et2_loadXMLFromURL(_url, function(_xmldoc)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Scan for templates and store them
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let i = 0; i < _xmldoc.childNodes.length; i++)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
const template = _xmldoc.childNodes[i];
|
2021-12-15 00:55:02 +01:00
|
|
|
if(template.nodeName.toLowerCase() != "template")
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
etemplate2.templates[template.getAttribute("id")] = template;
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!_name)
|
|
|
|
{
|
|
|
|
this.name = template.getAttribute("id");
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
_load.apply(this, []);
|
|
|
|
}, this);
|
|
|
|
});
|
|
|
|
}
|
|
|
|
|
2022-05-04 14:14:48 +02:00
|
|
|
public focusOnFirstInput()
|
|
|
|
{
|
2022-08-17 00:49:42 +02:00
|
|
|
const $input = jQuery('input:visible,et2-textbox:visible,et2-select-email:visible', this.DOMContainer)
|
2022-05-04 14:14:48 +02:00
|
|
|
// Date fields open the calendar popup on focus
|
|
|
|
.not('.et2_date')
|
|
|
|
.filter(function()
|
|
|
|
{
|
|
|
|
// Skip inputs that are out of tab ordering
|
|
|
|
const $this = jQuery(this);
|
|
|
|
return !$this.attr('tabindex') || parseInt($this.attr('tabIndex')) >= 0;
|
|
|
|
}).first();
|
|
|
|
|
|
|
|
// mobile device, focus only if the field is empty (usually means new entry)
|
|
|
|
// should focus always for non-mobile one
|
|
|
|
if(egwIsMobile() && $input.val() == "" || !egwIsMobile())
|
|
|
|
{
|
|
|
|
$input.focus();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* Check if template contains any dirty (unsaved) content
|
|
|
|
*
|
|
|
|
* @returns {Boolean}
|
|
|
|
*/
|
|
|
|
public isDirty()
|
|
|
|
{
|
|
|
|
let dirty = false;
|
2022-05-13 15:32:36 +02:00
|
|
|
this._widgetContainer?.iterateOver(function(_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_widget.isDirty && _widget.isDirty())
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
console.info(_widget.id + " is dirty", _widget);
|
|
|
|
dirty = true;
|
|
|
|
}
|
|
|
|
}, this);
|
|
|
|
|
|
|
|
return dirty;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Submit the et2_container form to a blank iframe in order to activate browser autocomplete
|
|
|
|
*/
|
|
|
|
autocomplete_fixer()
|
|
|
|
{
|
|
|
|
const self = this;
|
|
|
|
const form = self._DOMContainer;
|
|
|
|
|
|
|
|
// Safari always do the autofill for password field regardless of autocomplete = off
|
|
|
|
// and since there's no other way to switch the autocomplete of, we should switch the
|
|
|
|
// form autocomplete off (e.g. compose dialog, attachment password field)
|
2021-12-15 00:55:02 +01:00
|
|
|
if(navigator.userAgent.match(/safari/i) && !navigator.userAgent.match(/chrome/i)
|
2021-08-13 23:26:18 +02:00
|
|
|
&& jQuery('input[type="password"]').length > 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(form)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Stop submit propagation in order to not fire other possible submit events
|
2021-12-15 00:55:02 +01:00
|
|
|
form.onsubmit = function(e)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
e.stopPropagation();
|
|
|
|
};
|
|
|
|
|
|
|
|
// Firefox give a security warning when transmitting to "about:blank" from a https site
|
|
|
|
// we work around that by giving existing etemplate/empty.html url
|
|
|
|
// Safari shows same warning, thought Chrome userAgent also includes Safari
|
2021-12-15 00:55:02 +01:00
|
|
|
if(navigator.userAgent.match(/(firefox|safari|iceweasel)/i) && !navigator.userAgent.match(/chrome/i))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
jQuery(form).attr({action: egw.webserverUrl + '/api/templates/default/empty.html', method: 'post'});
|
|
|
|
}
|
|
|
|
// need to trigger submit because submit() would not trigger onsubmit event
|
|
|
|
// since the submit does not get fired directly via user interaction.
|
|
|
|
jQuery(form).trigger('submit');
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
private _set_button(button, values)
|
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof button == 'string')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
button = this._widgetContainer.getWidgetById(button);
|
|
|
|
}
|
|
|
|
// Button parameter used for submit buttons in datagrid
|
|
|
|
// TODO: This should probably go in nextmatch's getValues(), along with selected rows somehow.
|
|
|
|
// I'm just not sure how.
|
2021-12-15 00:55:02 +01:00
|
|
|
if(button && !values.button)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
let i;
|
|
|
|
values.button = {};
|
|
|
|
const path = button.getPath();
|
|
|
|
let target = values;
|
2021-12-15 00:55:02 +01:00
|
|
|
for(i = 0; i < path.length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!values[path[i]])
|
|
|
|
{
|
|
|
|
values[path[i]] = {};
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
target = values[path[i]];
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(target != values || button.id.indexOf('[') != -1 && path.length == 0)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
let indexes = button.id.split('[');
|
2021-12-15 00:55:02 +01:00
|
|
|
if(indexes.length > 1)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
indexes = [indexes.shift(), indexes.join('[')];
|
|
|
|
indexes[1] = indexes[1].substring(0, indexes[1].length - 1);
|
|
|
|
const children = indexes[1].split('][');
|
2021-12-15 00:55:02 +01:00
|
|
|
if(children.length)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
indexes = jQuery.merge([indexes[0]], children);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
let idx = '';
|
2021-12-15 00:55:02 +01:00
|
|
|
for(i = 0; i < indexes.length; i++)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
idx = indexes[i];
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!target[idx] || target[idx]['$row_cont'])
|
|
|
|
{
|
|
|
|
target[idx] = i < indexes.length - 1 ? {} : true;
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
target = target[idx];
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
else if(typeof values.button == 'undefined' || jQuery.isEmptyObject(values.button))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
delete values.button;
|
|
|
|
values[button.id] = true;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2021-09-30 09:26:36 +02:00
|
|
|
/**
|
|
|
|
* Check if there is an invalid widget / all widgets are valid
|
|
|
|
*
|
|
|
|
* @param container
|
|
|
|
* @param values
|
2022-02-24 23:52:45 +01:00
|
|
|
* @return Promise<et2_widget>|Promise<Et2Widget>|null
|
2021-09-30 09:26:36 +02:00
|
|
|
*/
|
2022-02-24 23:52:45 +01:00
|
|
|
async isInvalid(container : et2_container | undefined, values : object | undefined) : Promise<et2_ISubmitListener> | null
|
2021-09-30 09:26:36 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof container === 'undefined')
|
2021-09-30 09:26:36 +02:00
|
|
|
{
|
|
|
|
container = this._widgetContainer;
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof values === 'undefined')
|
2021-09-30 09:26:36 +02:00
|
|
|
{
|
|
|
|
values = this.getValues(container);
|
|
|
|
}
|
2022-02-24 23:52:45 +01:00
|
|
|
let invalid = [];
|
2021-12-15 00:55:02 +01:00
|
|
|
container.iterateOver(function(_widget)
|
2021-09-30 09:26:36 +02:00
|
|
|
{
|
2022-02-24 23:52:45 +01:00
|
|
|
let submit = _widget.submit(values);
|
|
|
|
if(submit === false)
|
2021-09-30 09:26:36 +02:00
|
|
|
{
|
2022-04-27 19:56:03 +02:00
|
|
|
invalid.push(_widget);
|
2021-09-30 09:26:36 +02:00
|
|
|
}
|
2022-02-24 23:52:45 +01:00
|
|
|
else if(submit instanceof Promise)
|
|
|
|
{
|
2022-02-25 18:21:16 +01:00
|
|
|
invalid.push(submit.then(function(ok)
|
2022-02-24 23:52:45 +01:00
|
|
|
{
|
2022-02-25 18:21:16 +01:00
|
|
|
return ok ? false : this;
|
2022-02-24 23:52:45 +01:00
|
|
|
}.bind(_widget)));
|
|
|
|
}
|
2021-09-30 09:26:36 +02:00
|
|
|
}, this, et2_ISubmitListener);
|
|
|
|
|
2022-02-24 23:52:45 +01:00
|
|
|
return Promise.all(invalid);
|
2021-09-30 09:26:36 +02:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* Submit form via ajax
|
|
|
|
*
|
|
|
|
* @param {(et2_button|string)} button button widget or string with id
|
|
|
|
* @param {boolean|string} async true: do an asynchronious submit, string: spinner message (please wait...)
|
|
|
|
* default is asynchronoush with message
|
|
|
|
* @param {boolean} no_validation - Do not do individual widget validation, just submit their current values
|
|
|
|
* @param {et2_widget|undefined} _container container to submit, default whole template
|
|
|
|
* @return {boolean} true if submit was send, false if eg. validation stoped submit
|
|
|
|
*/
|
|
|
|
submit(button, async, no_validation, _container)
|
|
|
|
{
|
|
|
|
const api = this._widgetContainer.egw();
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof no_validation == 'undefined')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
no_validation = false;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
const container = _container || this._widgetContainer;
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Get the form values
|
|
|
|
const values = this.getValues(container);
|
|
|
|
|
2022-04-01 20:28:25 +02:00
|
|
|
const doSubmit = () =>
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof async == 'undefined' || typeof async == 'string')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
api.loading_prompt('et2_submit_spinner', true, api.lang(typeof async == 'string' ? async : 'Please wait...'));
|
|
|
|
async = true;
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(button)
|
|
|
|
{
|
|
|
|
this._set_button(button, values);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Create the request object
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this.menuaction)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
//Autocomplete
|
|
|
|
this.autocomplete_fixer();
|
|
|
|
|
|
|
|
// unbind our session-destroy handler, as we are submitting
|
|
|
|
this.unbind_unload();
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
const request = api.json(this.menuaction, [this._etemplate_exec_id, values, no_validation], function()
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
api.loading_prompt('et2_submit_spinner', false);
|
|
|
|
}, this, async);
|
2023-07-10 17:06:41 +02:00
|
|
|
const request_promise = request.sendRequest();
|
|
|
|
|
|
|
|
// Set up timeout for 30 seconds
|
|
|
|
let warning_message = null;
|
|
|
|
const timeout_id = window.setTimeout(() =>
|
|
|
|
{
|
|
|
|
// Do not abort request, it might still come
|
|
|
|
api.debug("warn", "Request '" + this.menuaction + "' timeout")
|
|
|
|
warning_message = api.message(api.lang("No response from server: your data is probably NOT saved"), "warning");
|
|
|
|
api.loading_prompt('et2_submit_spinner', false);
|
|
|
|
}, 30000);
|
|
|
|
|
|
|
|
// Cancel timeout
|
|
|
|
request_promise.then(() =>
|
|
|
|
{
|
|
|
|
// Responded * and response processed *
|
|
|
|
clearTimeout(timeout_id);
|
|
|
|
if(warning_message)
|
|
|
|
{
|
|
|
|
warning_message.close();
|
|
|
|
}
|
|
|
|
});
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
this._widgetContainer.egw().debug("warn", "Missing menuaction for submit. Values: ", values);
|
|
|
|
}
|
2022-04-01 20:28:25 +02:00
|
|
|
}
|
2022-02-24 23:52:45 +01:00
|
|
|
|
2022-04-01 20:28:25 +02:00
|
|
|
// Trigger the submit event
|
|
|
|
let canSubmit = true;
|
|
|
|
let invalid = null;
|
|
|
|
if(!no_validation)
|
|
|
|
{
|
|
|
|
canSubmit = !(invalid = this.isInvalid(container, values));
|
|
|
|
|
|
|
|
invalid?.then((widgets) =>
|
|
|
|
{
|
|
|
|
let invalid_widgets = widgets.filter((widget) => widget);
|
2022-02-24 23:52:45 +01:00
|
|
|
|
2022-09-21 17:56:15 +02:00
|
|
|
if(invalid_widgets.length && !(invalid_widgets[0] instanceof et2_widget))
|
2022-04-01 20:28:25 +02:00
|
|
|
{
|
2022-09-21 17:56:15 +02:00
|
|
|
// Handle validation_error (messages coming back from server as a response) if widget is children of a tabbox
|
|
|
|
let tmpWidget = invalid_widgets[0];
|
|
|
|
while(tmpWidget.getParent() && tmpWidget.getType() !== 'ET2-TABBOX')
|
2022-04-01 20:28:25 +02:00
|
|
|
{
|
2022-09-21 17:56:15 +02:00
|
|
|
tmpWidget = tmpWidget.getParent();
|
|
|
|
}
|
|
|
|
//Activate the tab where the widget with validation error is located
|
|
|
|
if(tmpWidget.getType() === 'ET2-TABBOX')
|
|
|
|
{
|
|
|
|
(<Et2Tabs><unknown>tmpWidget).activateTab(invalid_widgets[0]);
|
2022-04-01 20:28:25 +02:00
|
|
|
}
|
2022-09-22 17:20:50 +02:00
|
|
|
// scroll the widget into view
|
2022-09-22 19:43:29 +02:00
|
|
|
if(typeof tmpWidget.scrollIntoView === 'function')
|
2022-09-22 17:20:50 +02:00
|
|
|
{
|
2022-09-22 19:43:29 +02:00
|
|
|
tmpWidget.scrollIntoView();
|
2022-09-22 17:20:50 +02:00
|
|
|
}
|
2022-04-01 20:28:25 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doSubmit();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
doSubmit();
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
return canSubmit;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Does a full form post submit necessary for downloads
|
|
|
|
*
|
|
|
|
* Only use this one if you need it, use the ajax submit() instead.
|
|
|
|
* It ensures eT2 session continues to exist on server by unbinding unload handler and rebinding it.
|
|
|
|
*
|
|
|
|
* @param {(et2_button|string)} button button widget or string with id
|
|
|
|
*/
|
|
|
|
postSubmit(button)
|
|
|
|
{
|
|
|
|
// Get the form values
|
|
|
|
const values = this.getValues(this._widgetContainer);
|
|
|
|
|
|
|
|
// Trigger the submit event
|
|
|
|
let canSubmit = true;
|
2021-12-15 00:55:02 +01:00
|
|
|
this._widgetContainer.iterateOver(function(_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_widget.submit(values) === false)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
canSubmit = false;
|
|
|
|
}
|
|
|
|
}, this, et2_ISubmitListener);
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(canSubmit)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(button)
|
|
|
|
{
|
|
|
|
this._set_button(button, values);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// unbind our session-destroy handler, as we are submitting
|
|
|
|
this.unbind_unload();
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const form = jQuery("<form id='form' action='" + egw().webserverUrl +
|
|
|
|
"/index.php?menuaction=" + this._widgetContainer.egw().getAppName() + ".EGroupware\\Api\\Etemplate.process_exec&ajax=true' method='POST'>");
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const etemplate_id = jQuery(document.createElement("input"))
|
|
|
|
.attr("name", 'etemplate_exec_id')
|
|
|
|
.attr("type", 'hidden')
|
|
|
|
.val(this._etemplate_exec_id)
|
|
|
|
.appendTo(form);
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const input = document.createElement("input");
|
|
|
|
input.type = "hidden";
|
|
|
|
input.name = 'value';
|
|
|
|
input.value = egw().jsonEncode(values);
|
|
|
|
form.append(input);
|
|
|
|
form.appendTo(jQuery('body')).submit();
|
|
|
|
|
|
|
|
// bind unload handler again (can NOT do it direct, as this would be quick enough to be still triggered!)
|
|
|
|
window.setTimeout(jQuery.proxy(this.bind_unload, this), 100);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Fetches all input element values and returns them in an associative
|
|
|
|
* array. Widgets which introduce namespacing can use the internal _target
|
|
|
|
* parameter to add another layer.
|
|
|
|
*
|
|
|
|
* @param {et2_widget} _root widget to start iterating
|
|
|
|
*/
|
2021-12-15 00:55:02 +01:00
|
|
|
getValues(_root : et2_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
const result = {};
|
|
|
|
|
|
|
|
// Iterate over the widget tree
|
2021-12-15 00:55:02 +01:00
|
|
|
_root.iterateOver(function(_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// The widget must have an id to be included in the values array
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_widget.id === undefined || _widget.id === "")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
// Get the path to the node we have to store the value at
|
|
|
|
let path = _widget.getPath();
|
|
|
|
|
|
|
|
// check if id contains a hierachical name, eg. "button[save]"
|
2022-08-03 19:45:45 +02:00
|
|
|
let id = _widget.id || "";
|
2021-12-16 11:39:43 +01:00
|
|
|
let indexes = id?.split('[');
|
|
|
|
if(indexes?.length > 1)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
indexes = [indexes.shift(), indexes.join('[')];
|
|
|
|
indexes[1] = indexes[1].substring(0, indexes[1].length - 1);
|
|
|
|
const children = indexes[1].split('][');
|
2021-12-15 00:55:02 +01:00
|
|
|
if(children.length)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
indexes = jQuery.merge([indexes[0]], children);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
path = path.concat(indexes);
|
|
|
|
// Take the last one as the ID
|
|
|
|
id = path.pop();
|
|
|
|
}
|
|
|
|
|
|
|
|
// Set the _target variable to that node
|
|
|
|
let _target = result;
|
2021-12-15 00:55:02 +01:00
|
|
|
for(var i = 0; i < path.length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Create a new object for not-existing path nodes
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _target[path[i]] === 'undefined')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
_target[path[i]] = {};
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Check whether the path node is really an object
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _target[path[i]] === 'object')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
_target = _target[path[i]];
|
|
|
|
}
|
|
|
|
else
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.debug("error", "ID collision while writing at path " +
|
|
|
|
"node '" + path[i] + "'");
|
|
|
|
}
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Handle arrays, eg radio[]
|
2021-12-15 00:55:02 +01:00
|
|
|
if(id === "")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
id = typeof _target == "undefined" ? 0 : Object.keys(_target).length;
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const value = _widget.getValue();
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Check whether the entry is really undefined
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _target[id] != "undefined" && (typeof _target[id] != 'object' || typeof value != 'object'))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Don't warn about children of nextmatch header - they're part of nm value
|
2021-12-15 00:55:02 +01:00
|
|
|
if(!_widget.getParent().instanceOf(et2_nextmatch_header_bar))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.debug("warn", _widget, "Overwriting value of '" + _widget.id +
|
|
|
|
"', id exists twice!");
|
2020-10-22 13:52:17 +02:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Store the value of the widget and reset its dirty flag
|
2021-12-15 00:55:02 +01:00
|
|
|
if(value !== null)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Merge, if possible (link widget)
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof _target[id] == 'object' && typeof value == 'object')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
_target[id] = jQuery.extend({}, _target[id], value);
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
_target[id] = value;
|
|
|
|
}
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
else if(jQuery.isEmptyObject(_target))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Avoid sending back empty sub-arrays
|
|
|
|
_target = result;
|
2021-12-15 00:55:02 +01:00
|
|
|
for(var i = 0; i < path.length - 1; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
_target = _target[path[i]];
|
|
|
|
}
|
|
|
|
delete _target[path[path.length - 1]];
|
|
|
|
}
|
|
|
|
_widget.resetDirty();
|
|
|
|
|
|
|
|
}, this, et2_IInput);
|
|
|
|
|
|
|
|
egw().debug("info", "Value", result);
|
|
|
|
return result;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Intelligently" refresh the template based on the given ID
|
|
|
|
*
|
|
|
|
* Rather than blindly re-load the entire template, we try to be a little smarter about it.
|
|
|
|
* If there's a message provided, we try to find where it goes and set it directly. Then
|
|
|
|
* we look for a nextmatch widget, and tell it to refresh its data based on that ID.
|
|
|
|
*
|
|
|
|
* @see egw_message.refresh()
|
|
|
|
*
|
|
|
|
* @param {string} msg message to try to display. eg: "Entry added" (not used anymore, handeled by egw_refresh and egw_message)
|
|
|
|
* @param {string} app app-name
|
|
|
|
* @param {(string|null)} id application specific entry ID to try to refresh
|
|
|
|
* @param {(string|null)} type type of change. One of 'update','edit', 'delete', 'add' or null
|
|
|
|
* @return {boolean} true if nextmatch found and refreshed, false if not
|
|
|
|
*/
|
|
|
|
refresh(msg, app, id, type)
|
|
|
|
{
|
|
|
|
// msg, app; // unused but required by function signature
|
|
|
|
let refresh_done = false;
|
|
|
|
|
|
|
|
// Refresh nextmatches
|
2021-12-15 00:55:02 +01:00
|
|
|
this._widgetContainer.iterateOver(function(_widget)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
// Trigger refresh
|
|
|
|
_widget.refresh(id, type);
|
|
|
|
refresh_done = true;
|
|
|
|
}, this, et2_nextmatch);
|
|
|
|
|
|
|
|
return refresh_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Intelligently" refresh a given app
|
|
|
|
*
|
|
|
|
* @see egw_message.refresh()
|
|
|
|
*
|
|
|
|
* @param {string} _msg message to try to display. eg: "Entry added" (not used anymore, handeled by egw_refresh and egw_message)
|
|
|
|
* @param {string} _app app-name
|
|
|
|
* @param {(string|null)} _id application specific entry ID to try to refresh
|
|
|
|
* @param {(string|null)} _type type of change. One of 'update','edit', 'delete', 'add' or null
|
|
|
|
* @return {boolean} true if nextmatch found and refreshed, false if not
|
|
|
|
*/
|
|
|
|
static app_refresh(_msg, _app, _id, _type)
|
|
|
|
{
|
|
|
|
let refresh_done = false;
|
|
|
|
let app = _app.split('-');
|
|
|
|
const et2 = etemplate2.getByApplication(app[0]);
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let i = 0; i < et2.length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(app[1])
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(et2[i]['uniqueId'].match(_app))
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
refresh_done = et2[i].refresh(_msg, app[0], _id, _type) || refresh_done;
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
refresh_done = et2[i].refresh(_msg, app[0], _id, _type) || refresh_done;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
return refresh_done;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* "Intelligently" print a given etemplate
|
|
|
|
*
|
|
|
|
* Mostly, we let the nextmatch change how many rows it's showing, so you don't
|
|
|
|
* get just one printed page.
|
|
|
|
*
|
|
|
|
* @return {Deferred[]} A list of Deferred objects that must complete before
|
|
|
|
* actual printing can begin.
|
|
|
|
*/
|
|
|
|
public print()
|
|
|
|
{
|
|
|
|
// Sometimes changes take time
|
|
|
|
const deferred = [];
|
|
|
|
|
|
|
|
// Skip hidden etemplates
|
2021-12-15 00:55:02 +01:00
|
|
|
if(jQuery(this._DOMContainer).filter(':visible').length === 0)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return [];
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Allow any widget to change for printing
|
2021-12-15 00:55:02 +01:00
|
|
|
this._widgetContainer.iterateOver(function(_widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Skip widgets from a different etemplate (home)
|
2021-12-15 00:55:02 +01:00
|
|
|
if(_widget.getInstanceManager() != this)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Skip hidden widgets
|
2021-12-15 00:55:02 +01:00
|
|
|
if(jQuery(_widget.getDOMNode()).filter(':visible').length === 0)
|
|
|
|
{
|
|
|
|
return;
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
const result = _widget.beforePrint();
|
2022-10-06 23:39:35 +02:00
|
|
|
if(typeof result == "object")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
deferred.push(result);
|
|
|
|
}
|
|
|
|
}, this, et2_IPrint);
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
return deferred;
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// Some static things to make getting into widget context a little easier //
|
2020-02-24 23:16:40 +01:00
|
|
|
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
/**
|
|
|
|
* Get a list of etemplate2 objects that loaded the given template name
|
|
|
|
*
|
|
|
|
* @param template String Name of the template that was loaded
|
|
|
|
*
|
|
|
|
* @return Array list of etemplate2 that have that template
|
|
|
|
*/
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2022-09-08 11:30:20 +02:00
|
|
|
public static getByTemplate(template) : etemplate2[]
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof etemplate2._byTemplate[template] != "undefined")
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
return etemplate2._byTemplate[template];
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
else
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
// Return empty array so you can always iterate over results
|
|
|
|
return [];
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a list of etemplate2 objects that are associated with the given application
|
|
|
|
*
|
|
|
|
* "Associated" is determined by the first part of the template
|
|
|
|
*
|
|
|
|
* @param {string} app app-name
|
2022-09-08 11:30:20 +02:00
|
|
|
* @return {etemplate2[]} list of etemplate2 that have that app as the first part of their loaded template
|
2021-08-13 23:26:18 +02:00
|
|
|
*/
|
2022-09-08 11:30:20 +02:00
|
|
|
public static getByApplication(app) : etemplate2[]
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
let list = [];
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let name in etemplate2._byTemplate)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(name.indexOf(app + ".") == 0)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
list = list.concat(etemplate2._byTemplate[name]);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
return list;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Get a etemplate2 object from the given DOM ID
|
|
|
|
*
|
|
|
|
* @param {string} id DOM ID of the container node
|
|
|
|
* @returns {etemplate2|null}
|
|
|
|
*/
|
2022-09-08 11:30:20 +02:00
|
|
|
public static getById(id) : etemplate2|null
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let name in etemplate2._byTemplate)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let i = 0; i < etemplate2._byTemplate[name].length; i++)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
const et = etemplate2._byTemplate[name][i];
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-12-15 00:55:02 +01:00
|
|
|
if(et._DOMContainer.getAttribute("id") == id)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
return et;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
return null;
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin for egw.json type "et2_load"
|
|
|
|
*
|
|
|
|
* @param _type
|
|
|
|
* @param _response
|
|
|
|
* @returns Promise
|
|
|
|
*/
|
|
|
|
public static async handle_load(_type, _response)
|
|
|
|
{
|
|
|
|
// Check the parameters
|
|
|
|
const data = _response.data;
|
2023-07-11 22:45:33 +02:00
|
|
|
// window-close does NOT send data.DOMNodeID!
|
2023-07-14 00:18:11 +02:00
|
|
|
const dialog = <any>document.querySelector('et2-dialog > form' + (data.DOMNodeID ? '#' + data.DOMNodeID : '.dialog_content'))?.parentNode ??
|
|
|
|
// Reloaded into same container
|
|
|
|
(this?.DOMContainer?.parentNode instanceof Et2Dialog ? this.DOMContainer.parentNode : undefined);
|
2023-07-13 18:41:07 +02:00
|
|
|
|
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
// stop dialogs from being closed on button click
|
|
|
|
dialog.callback = () => false;
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
|
|
|
|
// handle Api\Framework::refresh_opener()
|
2021-12-15 00:55:02 +01:00
|
|
|
if(Array.isArray(data['refresh-opener']))
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
if(window.opener || dialog)// && typeof window.opener.egw_refresh == 'function')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2023-07-11 22:45:33 +02:00
|
|
|
const egw = window.egw(dialog ? window : opener);
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.refresh.apply(egw, data['refresh-opener']);
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2023-07-11 22:45:33 +02:00
|
|
|
const egw = window.egw(window);
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// need to set app_header before message, as message temp. replaces app_header
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof data.data == 'object' && typeof data.data.app_header == 'string')
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2023-07-11 22:45:33 +02:00
|
|
|
if (dialog)
|
|
|
|
{
|
|
|
|
dialog.title = data.data.app_header;
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
egw.app_header(data.data.app_header, data.data.currentapp || null);
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
delete data.data.app_header;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// handle Api\Framework::message()
|
2023-07-11 22:45:33 +02:00
|
|
|
if(Array.isArray(data.message))
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.message.apply(egw, data.message);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// handle Api\Framework::window_close(), this will terminate execution
|
2021-12-15 00:55:02 +01:00
|
|
|
if(data['window-close'])
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof data['window-close'] == 'string' && data['window-close'] !== 'true')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
alert(data['window-close']);
|
|
|
|
}
|
2023-07-11 22:45:33 +02:00
|
|
|
if (dialog)
|
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
return dialog.close();
|
2023-07-11 22:45:33 +02:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.close();
|
|
|
|
return true;
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// handle Api\Framework::window_focus()
|
2021-12-15 00:55:02 +01:00
|
|
|
if(data['window-focus'])
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
window.focus();
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// handle framework.setSidebox calls
|
2023-07-13 15:22:21 +02:00
|
|
|
if(!dialog && window.framework && Array.isArray(data.setSidebox))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(data['fw-target'])
|
|
|
|
{
|
|
|
|
data.setSidebox[0] = data['fw-target'];
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
window.framework.setSidebox.apply(window.framework, data.setSidebox);
|
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// regular et2 re-load
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof data.url == "string" && typeof data.data === 'object')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2023-07-14 00:18:11 +02:00
|
|
|
let load : Promise<any>;
|
2021-08-13 23:26:18 +02:00
|
|
|
// @ts-ignore
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this && typeof this.load == 'function')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Called from etemplate
|
|
|
|
// set id in case serverside returned a different template
|
|
|
|
this._DOMContainer.id = this.uniqueId = data.DOMNodeID;
|
2023-07-14 00:18:11 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
// @ts-ignore
|
2023-07-14 00:18:11 +02:00
|
|
|
load = this.load(data.name, data.url, data.data);
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
// Not etemplate
|
|
|
|
const node = document.getElementById(data.DOMNodeID);
|
|
|
|
let uniqueId = data.DOMNodeID;
|
2021-12-15 00:55:02 +01:00
|
|
|
if(node)
|
2020-02-24 23:16:40 +01:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(node.children.length)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Node has children already? Check for loading over an
|
|
|
|
// existing etemplate
|
|
|
|
const old = etemplate2.getById(node.id);
|
2021-12-15 00:55:02 +01:00
|
|
|
if(old)
|
|
|
|
{
|
|
|
|
old.clear();
|
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(data['open_target'] && !uniqueId.match(data['open_target']))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
uniqueId = data.DOMNodeID.replace('.', '-') + '-' + data['open_target'];
|
|
|
|
}
|
2022-01-09 15:38:14 +01:00
|
|
|
const et2 = new etemplate2(node, data.data.menuaction, uniqueId);
|
2023-07-14 00:18:11 +02:00
|
|
|
load = et2.load(data.name, data.url, data.data, null, null, null, data['fw-target']);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
else
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.debug("error", "Could not find target node %s", data.DOMNodeId);
|
2021-08-12 18:32:05 +02:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2023-07-14 00:18:11 +02:00
|
|
|
|
|
|
|
// Extra handling for being loaded into a Et2Dialog
|
|
|
|
if(dialog)
|
|
|
|
{
|
|
|
|
load.then(() =>
|
|
|
|
{
|
|
|
|
// Move footer type buttons into dialog footer
|
|
|
|
const buttons = dialog._adoptTemplateButtons();
|
|
|
|
|
|
|
|
// Make sure adopted buttons are removed on clear
|
|
|
|
dialog.addEventListener("clear", () =>
|
|
|
|
{
|
|
|
|
buttons.forEach(n => n.remove());
|
|
|
|
});
|
|
|
|
});
|
|
|
|
}
|
|
|
|
return load;
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2021-08-12 18:32:05 +02:00
|
|
|
|
2021-08-13 23:26:18 +02:00
|
|
|
throw("Error while parsing et2_load response");
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Plugin for egw.json type "et2_validation_error"
|
|
|
|
*
|
|
|
|
* @param _type
|
|
|
|
* @param _response
|
|
|
|
*/
|
|
|
|
public static handle_validation_error(_type, _response)
|
|
|
|
{
|
|
|
|
// Display validation errors
|
2021-12-15 00:55:02 +01:00
|
|
|
for(let id in _response.data)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// @ts-ignore
|
|
|
|
const widget = this._widgetContainer.getWidgetById(id);
|
2021-12-15 00:55:02 +01:00
|
|
|
if(widget && widget.instanceOf(et2_baseWidget))
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
(<et2_baseWidget>widget).showMessage(_response.data[id], 'validation_error');
|
|
|
|
|
2022-06-30 16:38:48 +02:00
|
|
|
}
|
|
|
|
else if(typeof widget.set_validation_error == "function")
|
|
|
|
{
|
|
|
|
widget.set_validation_error(_response.data[id]);
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
2022-07-14 19:37:29 +02:00
|
|
|
// Handle validation_error (messages coming back from server as a response) if widget is children of a tabbox
|
|
|
|
let tmpWidget = widget;
|
2022-08-05 20:33:29 +02:00
|
|
|
while(tmpWidget.getParent() && tmpWidget.getType() !== 'ET2-TABBOX')
|
2022-07-14 19:37:29 +02:00
|
|
|
{
|
|
|
|
tmpWidget = tmpWidget.getParent();
|
|
|
|
}
|
2022-08-05 20:33:29 +02:00
|
|
|
//Activate the tab where the widget with validation error is located
|
|
|
|
if(tmpWidget.getType() === 'ET2-TABBOX')
|
2022-07-14 19:37:29 +02:00
|
|
|
{
|
2022-08-05 20:33:29 +02:00
|
|
|
(<Et2Tabs><unknown>tmpWidget).activateTab(widget);
|
|
|
|
}
|
|
|
|
// scroll the widget into view
|
|
|
|
if (typeof widget.getDOMNode().scrollIntoView === 'function')
|
|
|
|
{
|
|
|
|
widget.scrollIntoView();
|
2022-07-14 19:37:29 +02:00
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
egw().debug("warn", "Validation errors", _response.data);
|
|
|
|
}
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Handle assign for attributes on etemplate2 widgets
|
|
|
|
*
|
|
|
|
* @param {string} type "assign"
|
|
|
|
* @param {object} res Response
|
|
|
|
* res.data.id {String} Widget ID
|
|
|
|
* res.data.key {String} Attribute name
|
|
|
|
* res.data.value New value for widget
|
|
|
|
* res.data.etemplate_exec_id
|
|
|
|
* @param {object} req
|
|
|
|
* @returns {Boolean} Handled by this plugin
|
|
|
|
* @throws Invalid parameters if the required res.data parameters are missing
|
|
|
|
*/
|
|
|
|
public handle_assign(type, res, req)
|
|
|
|
{
|
|
|
|
//type, req; // unused, but required by plugin signature
|
|
|
|
|
|
|
|
//Check whether all needed parameters have been passed and call the alertHandler function
|
2021-12-15 00:55:02 +01:00
|
|
|
if((typeof res.data.id != 'undefined') &&
|
2021-08-13 23:26:18 +02:00
|
|
|
(typeof res.data.key != 'undefined') &&
|
|
|
|
(typeof res.data.value != 'undefined')
|
|
|
|
)
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof res.data.etemplate_exec_id == 'undefined' ||
|
2021-08-13 23:26:18 +02:00
|
|
|
res.data.etemplate_exec_id != this._etemplate_exec_id)
|
|
|
|
{
|
|
|
|
// Not for this etemplate, but not an error
|
|
|
|
return false;
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(res.data.key == 'etemplate_exec_id')
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
this._etemplate_exec_id = res.data.value;
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
if(this._widgetContainer == null)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
// Right etemplate, but it's already been cleared.
|
|
|
|
egw.debug('warn', "Tried to call assign on an un-loaded etemplate", res.data);
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
const widget = this._widgetContainer.getWidgetById(res.data.id);
|
2021-12-15 00:55:02 +01:00
|
|
|
if(widget)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof widget['set_' + res.data.key] != 'function')
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
egw.debug('warn', "Cannot set %s attribute %s via JSON assign, no set_%s()", res.data.id, res.data.key, res.data.key);
|
|
|
|
return false;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
try
|
2021-08-12 18:32:05 +02:00
|
|
|
{
|
2021-08-13 23:26:18 +02:00
|
|
|
widget['set_' + res.data.key].call(widget, res.data.value);
|
|
|
|
return true;
|
|
|
|
}
|
2021-12-15 00:55:02 +01:00
|
|
|
catch(e)
|
2021-08-13 23:26:18 +02:00
|
|
|
{
|
|
|
|
egw.debug("error", "When assigning %s on %s via AJAX, \n" + (e.message || e + ""), res.data.key, res.data.id, widget);
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
}
|
|
|
|
return false;
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-08-13 23:26:18 +02:00
|
|
|
throw 'Invalid parameters';
|
|
|
|
}
|
2020-02-24 23:16:40 +01:00
|
|
|
}
|
2021-07-06 15:59:51 +02:00
|
|
|
|
|
|
|
// make etemplate2 global, as we need it to check an app uses it and then call methods on it
|
2021-12-15 00:55:02 +01:00
|
|
|
if(typeof window.etemplate2 === 'undefined')
|
|
|
|
{
|
|
|
|
window['etemplate2'] = etemplate2;
|
|
|
|
}
|
2021-07-06 15:59:51 +02:00
|
|
|
|
2020-02-24 23:16:40 +01:00
|
|
|
// Calls etemplate2_handle_response in the context of the object which
|
|
|
|
// requested the response from the server
|
|
|
|
egw(window).registerJSONPlugin(etemplate2.handle_load, null, 'et2_load');
|
2022-02-24 18:44:30 +01:00
|
|
|
egw(window).registerJSONPlugin(etemplate2.handle_validation_error, null, 'et2_validation_error');
|