From e9a5f7e09c5819f9cef4d8ea86eee8ac8ef143c9 Mon Sep 17 00:00:00 2001 From: Nathan Gray Date: Fri, 10 May 2013 20:39:12 +0000 Subject: [PATCH] Add values for tabs, and make sure dynamic tab values are passed --- .../inc/class.etemplate_widget_tabbox.inc.php | 60 +++++++++++++++++++ etemplate/js/et2_widget_tabs.js | 32 ++++++++-- 2 files changed, 88 insertions(+), 4 deletions(-) create mode 100644 etemplate/inc/class.etemplate_widget_tabbox.inc.php diff --git a/etemplate/inc/class.etemplate_widget_tabbox.inc.php b/etemplate/inc/class.etemplate_widget_tabbox.inc.php new file mode 100644 index 0000000000..f9b2cba623 --- /dev/null +++ b/etemplate/inc/class.etemplate_widget_tabbox.inc.php @@ -0,0 +1,60 @@ +id, $expand); + + if (!$this->is_readonly($cname, $form_name)) + { + $value = self::get_array($content, $form_name); + $valid =& self::get_array($validated, $form_name, true); + $valid = $value; + + if(!$this->attrs['tabs']) + { + return; + } + + // Make sure additional tabs are processed + foreach($this->attrs['tabs'] as $tab) + { + if($tab['id'] && $content[$tab['id']]) + { + /* This doesn't work for some reason + $template = etemplate_widget_template::instance($tab['template']); + $template->run('validate', array($tab['id'], $expand, $content, &$validated), true); + */ + $tab_valid =& self::get_array($validated, $tab['id'], true); + $tab_valid = $content[$tab['id']]; + } + } + $valid = $value; + } + } +} +etemplate_widget::registerWidget('etemplate_widget_tabbox', array('tabbox')); diff --git a/etemplate/js/et2_widget_tabs.js b/etemplate/js/et2_widget_tabs.js index d8cdb12852..933cedf778 100644 --- a/etemplate/js/et2_widget_tabs.js +++ b/etemplate/js/et2_widget_tabs.js @@ -23,7 +23,7 @@ * * @augments et2_DOMWidget */ -var et2_tabbox = et2_DOMWidget.extend( +var et2_tabbox = et2_valueWidget.extend([et2_IInput], { attributes: { 'tabs': { @@ -108,6 +108,7 @@ var et2_tabbox = et2_DOMWidget.extend( } } tabData.push({ + "id": index_name, "label": this.egw().lang(et2_readAttrWithDefault(node, "label", "Tab")), "widget": null, "contentDiv": null, @@ -168,6 +169,7 @@ var et2_tabbox = et2_DOMWidget.extend( tab_options.content = tab.id; } tabData.push({ + "id": tab.id, "label": this.egw().lang(tab.label), "widget": et2_createWidget('template',tab_options,this), "contentDiv": null, @@ -221,8 +223,8 @@ var et2_tabbox = et2_DOMWidget.extend( var entry = this.tabData[i]; entry.flagDiv = $j(document.createElement("span")) .addClass("et2_tabflag") - .text(entry.label) - .appendTo(this.flagContainer); + .appendTo(this.flagContainer) + entry.flagDiv.text(entry.label || "Tab"); if(entry.hidden) { entry.flagDiv.hide(); @@ -279,7 +281,29 @@ var et2_tabbox = et2_DOMWidget.extend( this.height = _value; this.tabContainer.css("height", _value); - } + }, + /** + * getValue has to return the value of the input widget + */ + getValue: function() { + return this.tabData[this.selected_index].id; + }, + + /** + * Is dirty returns true if the value of the widget has changed since it + * was loaded. + */ + isDirty: function() { + return this.selected_index != this.value; + }, + + /** + * Causes the dirty flag to be reseted. + */ + resetDirty: function() + { + this.value = this.selected_index; + } }); et2_register_widget(et2_tabbox, ["tabbox"]);