From e1d24055c2db5bb56bd10d324effdcb25e9f3121 Mon Sep 17 00:00:00 2001 From: Hadi Nategh Date: Thu, 13 Feb 2020 10:25:00 +0100 Subject: [PATCH] Convert et2_widget_script to TS --- api/js/etemplate/et2_widget_script.js | 84 ++++++++++++++------------- api/js/etemplate/et2_widget_script.ts | 63 ++++++++++++++++++++ 2 files changed, 108 insertions(+), 39 deletions(-) create mode 100644 api/js/etemplate/et2_widget_script.ts diff --git a/api/js/etemplate/et2_widget_script.js b/api/js/etemplate/et2_widget_script.js index 9633b8262b..bc9368486d 100644 --- a/api/js/etemplate/et2_widget_script.js +++ b/api/js/etemplate/et2_widget_script.js @@ -1,3 +1,4 @@ +"use strict"; /** * EGroupware eTemplate2 - JS widget class containing javascript * @@ -6,14 +7,26 @@ * @subpackage api * @link http://www.egroupware.org * @author Ralf Becker - * @copyright Stylite 2015 - * @version $Id$ */ - +var __extends = (this && this.__extends) || (function () { + var extendStatics = function (d, b) { + extendStatics = Object.setPrototypeOf || + ({ __proto__: [] } instanceof Array && function (d, b) { d.__proto__ = b; }) || + function (d, b) { for (var p in b) if (b.hasOwnProperty(p)) d[p] = b[p]; }; + return extendStatics(d, b); + }; + return function (d, b) { + extendStatics(d, b); + function __() { this.constructor = d; } + d.prototype = b === null ? Object.create(b) : (__.prototype = b.prototype, new __()); + }; +})(); +Object.defineProperty(exports, "__esModule", { value: true }); /*egw:uses - et2_core_widget; + et2_core_widget; */ - +var et2_core_widget_1 = require("./et2_core_widget"); +var et2_core_widget_2 = require("./et2_core_widget"); /** * Function which executes the encapsulated script data. * @@ -31,37 +44,30 @@ * * @augments et2_widget */ -var et2_script = (function(){ "use strict"; return et2_widget.extend( -{ - /** - * Constructor - * - * @memberOf et2_script - */ - init: function() - { - this._super.apply(this, arguments); - - // Allow no child widgets - this.supportedWidgetClasses = []; - }, - - /** - * We can NOT create a script tag containing the content, as this violoates our CSP policy! - * - * @param {string} _content - */ - loadContent: function(_content) - { - try - { - var func = new Function(_content); - func.call(window); - } - catch (e) - { - this.egw.debug('error', 'Error while executing script: ',_content,e); - } - } -});}).call(this); -et2_register_widget(et2_script, ["script"]); +var et2_script = /** @class */ (function (_super) { + __extends(et2_script, _super); + function et2_script(_parent, _attrs, _child) { + var _this = _super.call(this) || this; + // Allow no child widgets + _this.supportedWidgetClasses = []; + return _this; + } + ; + /** + * We can NOT create a script tag containing the content, as this violoates our CSP policy! + * + * @param {string} _content + */ + et2_script.prototype.loadContent = function (_content) { + try { + var func = new Function(_content); + func.call(window); + } + catch (e) { + this.egw.debug('error', 'Error while executing script: ', _content, e); + } + }; + return et2_script; +}(et2_core_widget_2.et2_widget)); +et2_core_widget_1.et2_register_widget(et2_script, ["script"]); +//# sourceMappingURL=et2_widget_script.js.map \ No newline at end of file diff --git a/api/js/etemplate/et2_widget_script.ts b/api/js/etemplate/et2_widget_script.ts new file mode 100644 index 0000000000..90bde25622 --- /dev/null +++ b/api/js/etemplate/et2_widget_script.ts @@ -0,0 +1,63 @@ +/** + * EGroupware eTemplate2 - JS widget class containing javascript + * + * @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License + * @package etemplate + * @subpackage api + * @link http://www.egroupware.org + * @author Ralf Becker + */ + +/*egw:uses + et2_core_widget; +*/ + +import {et2_register_widget, WidgetConfig} from "./et2_core_widget"; +import {et2_widget} from "./et2_core_widget"; + +/** + * Function which executes the encapsulated script data. + * + * This should only be used for customization and NOT for regular EGroupware code! + * + * We can NOT create a script tag containing the content, as this violoates our CSP policy! + * + * We use new Function(_content) instead. Therefore you have to use window to address global context: + * + * window.some_func = function() {...} + * + * instead of not working + * + * function some_funct() {...} + * + * @augments et2_widget + */ +class et2_script extends et2_widget +{ + constructor(_parent?, _attrs? : WidgetConfig, _child? : object) + { + super(); + // Allow no child widgets + this.supportedWidgetClasses = []; + }; + + /** + * We can NOT create a script tag containing the content, as this violoates our CSP policy! + * + * @param {string} _content + */ + loadContent(_content) + { + try + { + var func = new Function(_content); + func.call(window); + } + catch (e) + { + this.egw.debug('error', 'Error while executing script: ',_content,e); + } + } +} +et2_register_widget(et2_script, ["script"]); +