2011-08-16 15:12:39 +02:00
/ * *
2013-04-13 21:00:13 +02:00
* EGroupware eTemplate2 - JS widget class containing raw HTML
2011-08-16 15:12:39 +02:00
*
* @ license http : //opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @ package etemplate
* @ subpackage api
* @ link http : //www.egroupware.org
* @ author Andreas Stöckel
* @ copyright Stylite 2011
* @ version $Id$
* /
"use strict" ;
/ * e g w : u s e s
jsapi . jsapi ; // Needed for egw_seperateJavaScript
jquery . jquery ;
2011-08-24 12:18:07 +02:00
et2 _core _baseWidget ;
2011-08-16 15:12:39 +02:00
* /
2013-04-13 21:00:13 +02:00
/ * *
* @ augments et2 _valueWidget
* /
2014-02-14 11:14:28 +01:00
var et2 _html = et2 _valueWidget . extend ( [ et2 _IDetachedDOM ] ,
2013-04-13 21:00:13 +02:00
{
2012-06-12 20:38:21 +02:00
attributes : {
'label' : {
2013-04-13 21:00:13 +02:00
'default' : "" ,
2012-06-12 20:38:21 +02:00
description : "The label is displayed by default in front (for radiobuttons behind) each widget (if not empty). If you want to specify a different position, use a '%s' in the label, which gets replaced by the widget itself. Eg. '%s Name' to have the label Name behind a checkbox. The label can contain variables, as descript for name. If the label starts with a '@' it is replaced by the value of the content-array at this index (with the '@'-removed and after expanding the variables)." ,
ignore : false ,
name : "Label" ,
translate : true ,
2014-02-14 11:14:28 +01:00
type : "string"
2012-07-24 01:54:16 +02:00
} ,
"needed" : {
"ignore" : true
2014-02-14 11:14:28 +01:00
} ,
value : {
name : "Value" ,
description : "The value of the widget" ,
type : "html" , // "string" would remove html tags by running html_entity_decode
default : et2 _no _init
2012-06-12 20:38:21 +02:00
}
} ,
2014-02-14 11:14:28 +01:00
2013-04-13 21:00:13 +02:00
/ * *
* Constructor
2014-02-14 11:14:28 +01:00
*
2013-04-13 21:00:13 +02:00
* @ memberOf et2 _html
* /
2011-08-16 15:12:39 +02:00
init : function ( ) {
this . _super . apply ( this , arguments ) ;
// Allow no child widgets
this . supportedWidgetClasses = [ ] ;
this . htmlNode = $j ( document . createElement ( "span" ) ) ;
2013-06-26 21:34:14 +02:00
if ( this . _type == 'htmlarea' )
{
this . htmlNode . addClass ( 'et2_textbox_ro' ) ;
}
2012-06-12 20:38:21 +02:00
if ( this . options . label )
{
this . htmlNode . append ( '<span class="et2_label">' + this . options . label + '</span>' ) ;
}
2011-08-16 15:12:39 +02:00
this . setDOMNode ( this . htmlNode [ 0 ] ) ;
} ,
loadContent : function ( _data ) {
// Create an object containg the given value and an empty js string
2012-04-25 19:26:34 +02:00
var html = { html : _data ? _data : '' , js : '' } ;
2011-08-16 15:12:39 +02:00
// Seperate the javascript from the given html. The js code will be
// written to the previously created empty js string
egw _seperateJavaScript ( html ) ;
// Append the html to the parent element
2012-06-12 20:38:21 +02:00
if ( this . options . label )
{
this . htmlNode . append ( '<span class="et2_label">' + this . options . label + '</span>' ) ;
}
2011-08-16 15:12:39 +02:00
this . htmlNode . append ( html . html ) ;
this . htmlNode . append ( html . js ) ;
2012-04-25 19:26:34 +02:00
} ,
set _value : function ( _value ) {
this . htmlNode . empty ( ) ;
this . loadContent ( _value ) ;
2012-06-12 20:38:21 +02:00
} ,
/ * *
* Code for implementing et2 _IDetachedDOM
2014-02-14 11:14:28 +01:00
*
* @ param { array } _attrs
2012-06-12 20:38:21 +02:00
* /
getDetachedAttributes : function ( _attrs )
{
_attrs . push ( "value" , "class" ) ;
} ,
getDetachedNodes : function ( )
{
return [ this . htmlNode [ 0 ] ] ;
} ,
setDetachedAttributes : function ( _nodes , _values )
{
this . htmlNode = jQuery ( _nodes [ 0 ] ) ;
if ( typeof _values [ 'value' ] !== 'undefined' )
{
this . set _value ( _values [ 'value' ] ) ;
}
2011-08-16 15:12:39 +02:00
}
} ) ;
2012-03-23 00:21:35 +01:00
et2 _register _widget ( et2 _html , [ "html" , "htmlarea_ro" ] ) ;
2011-08-16 15:12:39 +02:00