Add label option, implement et2_IDetachedDOM interface

This commit is contained in:
Nathan Gray 2012-06-12 18:38:21 +00:00
parent 851918e5b3
commit ad83103362

View File

@ -18,8 +18,18 @@
et2_core_baseWidget;
*/
var et2_html = et2_valueWidget.extend({
var et2_html = et2_valueWidget.extend([et2_IDetachedDOM], {
attributes: {
'label': {
default: "",
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,
type: "string",
}
},
init: function() {
this._super.apply(this, arguments);
@ -27,6 +37,10 @@ var et2_html = et2_valueWidget.extend({
this.supportedWidgetClasses = [];
this.htmlNode = $j(document.createElement("span"));
if(this.options.label)
{
this.htmlNode.append('<span class="et2_label">'+this.options.label+'</span>');
}
this.setDOMNode(this.htmlNode[0]);
},
@ -39,6 +53,10 @@ var et2_html = et2_valueWidget.extend({
egw_seperateJavaScript(html);
// Append the html to the parent element
if(this.options.label)
{
this.htmlNode.append('<span class="et2_label">'+this.options.label+'</span>');
}
this.htmlNode.append(html.html);
this.htmlNode.append(html.js);
},
@ -46,6 +64,28 @@ var et2_html = et2_valueWidget.extend({
set_value: function(_value) {
this.htmlNode.empty();
this.loadContent(_value);
},
/**
* Code for implementing et2_IDetachedDOM
*/
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']);
}
}
});