new script widget to allow to include javascript in (customizied) templates, also adding an id to style widget

This commit is contained in:
Ralf Becker 2015-01-23 19:32:51 +00:00
commit d100187584
3 changed files with 97 additions and 3 deletions

View File

@ -0,0 +1,69 @@
/**
* 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
* @copyright Stylite 2015
* @version $Id$
*/
"use strict";
/*egw:uses
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
*/
var et2_script = 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);
}
}
});
et2_register_widget(et2_script, ["script"]);

View File

@ -64,8 +64,32 @@ var et2_styles = et2_widget.extend(
{
this.styleNode.appendChild(document.createTextNode(_content));
}
}
},
/**
* Sets the id of the DOM-Node.
*
* DOM id's have dots "." replaced with dashes "-"
*
* @param {string} _value id to set
*/
set_id: function(_value) {
this.id = _value;
this.dom_id = _value ? this.getInstanceManager().uniqueId+'_'+_value.replace(/\./g, '-') : _value;
if (this.styleNode)
{
if (_value != "")
{
this.styleNode.setAttribute("id", this.dom_id);
}
else
{
this.styleNode.removeAttribute("id");
}
}
}
});
et2_register_widget(et2_styles, ["styles"]);

View File

@ -54,6 +54,7 @@
et2_widget_vfs;
et2_widget_video;
et2_widget_itempicker;
et2_widget_script;
et2_extension_nextmatch;
et2_extension_customfields;