Convert et2_widget_script to TS

This commit is contained in:
Hadi Nategh 2020-02-13 10:25:00 +01:00
parent 216ba980a9
commit e1d24055c2
2 changed files with 108 additions and 39 deletions

View File

@ -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

View File

@ -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"]);