Add values for tabs, and make sure dynamic tab values are passed

This commit is contained in:
Nathan Gray 2013-05-10 20:39:12 +00:00
parent 6b113a159d
commit e9a5f7e09c
2 changed files with 88 additions and 4 deletions

View File

@ -0,0 +1,60 @@
<?php
/**
* EGroupware - eTemplate serverside Tabs widget
*
* @license http://opensource.org/licenses/gpl-license.php GPL - GNU General Public License
* @package etemplate
* @subpackage api
* @link http://www.egroupware.org
* @author Nathan Gray
* @copyright 2013 Nathan Gray
* @version $Id$
*/
/**
* eTemplate Tabs widget stacks multiple sub-templates and lets you switch between them
*/
class etemplate_widget_tabbox extends etemplate_widget
{
/**
* Validate input - just pass through, tabs doesn't care
*
* @param string $cname current namespace
* @param array $expand values for keys 'c', 'row', 'c_', 'row_', 'cont'
* @param array $content
* @param array &$validated=array() validated content
* @param array $expand=array values for keys 'c', 'row', 'c_', 'row_', 'cont'
*/
public function validate($cname, array $expand, array $content, &$validated=array())
{
$form_name = self::form_name($cname, $this->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'));

View File

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