X-Git-Url: http://wagnertech.de/git?a=blobdiff_plain;f=WEB-INF%2Flib%2Fform%2FTable.class.php;h=7bcd78be89e717c60c932e7020eed4e0d04e4d32;hb=97bc3daf3d32a73d2b614eecacfe1abc0639a271;hp=833bffac98a6873b8da27eceb210b70942371a3e;hpb=6e59f47d1baf9e3d420b4a368dcc005d54b6e599;p=timetracker.git diff --git a/WEB-INF/lib/form/Table.class.php b/WEB-INF/lib/form/Table.class.php index 833bffac..7bcd78be 100644 --- a/WEB-INF/lib/form/Table.class.php +++ b/WEB-INF/lib/form/Table.class.php @@ -34,6 +34,7 @@ class Table extends FormElement { var $mColumns = array(); // array of columns in table var $mData = null; // array of rows with data for column cells var $mHeaders = array(); // column headers + var $mFooters = array(); // column footers var $mInteractive = true; // adds a clickable checkbox column to table var $mIAScript = null; // sctipt to execute when a checkbox is clicked var $mKeyField = ''; // identifies a column used as key to access row data @@ -41,23 +42,23 @@ class Table extends FormElement { var $mBgColor = '#ffffff'; var $mBgColorOver = '#eeeeff'; var $mWidth = ''; - var $cClassName = 'Table'; var $mTableOptions = array(); var $mRowOptions = array(); var $mHeaderOptions = array(); var $mProccessed = false; - function __construct($name, $value='') { + function __construct($name, $cssClass = null) { + $this->class = 'Table'; $this->name = $name; - $this->mValue = $value; + $this->cssClass = $cssClass; } function setKeyField($value) { - $this->mKeyField = $value; + $this->mKeyField = $value; } function setData($data) { - if (is_array($data) && isset($data[0]) && is_array($data[0])) + if (is_array($data) && isset($data[0]) && is_array($data[0])) $this->mData = &$data; } @@ -89,17 +90,17 @@ class Table extends FormElement { return @$this->mData[$rowindex][$this->mColumnFields[$colindex]]; } - function getValueAtName($rowindex,$fieldname) { + function getValueAtName($rowindex, $fieldname) { if (!$this->mProccessed) $this->_process(); return @$this->mData[$rowindex][$fieldname]; } function _process() { - $this->mProccessed = true; + $this->mProccessed = true; - if ($this->mInteractive) { + if ($this->mInteractive) { // Add a column of clickable checkboxes. - $column = new TableColumn("","getName()."_all\" onclick=\"setAll(this.checked)\">"); + $column = new TableColumn("","name."_all\" onclick=\"setAll(this.checked)\">"); import('form.CheckboxCellRenderer'); $cb = new CheckboxCellRenderer(); if ($this->getIAScript()) $cb->setOnChangeAdd($this->getIAScript()."(this)"); @@ -111,17 +112,20 @@ class Table extends FormElement { foreach ($this->mColumns as $column) { $this->mColumnFields[] = $column->getField(); $this->mHeaders[] = $column->getHeader(); + $this->mFooters[] = $column->getFooter(); } } - function toStringControl() { - if (!$this->isRenderable()) return ""; + function getHtml() { if (!$this->mProccessed) $this->_process(); $html = ""; if ($this->mInteractive) $html .= $this->_addJavaScript(); $html .= "cssClass) { + $html .= " class=\"".$this->cssClass."\""; + } if (count($this->mTableOptions) > 0) { foreach ($this->mTableOptions as $k=>$v) { $html .= " $k=\"$v\""; @@ -133,7 +137,7 @@ class Table extends FormElement { $html .= ">\n"; // Print headers. - if (($this->mInteractive && (count($this->mHeaders) > 1)) || (!$this->mInteractive && (count($this->mHeaders) > 0))) { + if (($this->mInteractive && (count($this->mHeaders) > 1)) || (!$this->mInteractive && (count($this->mHeaders) > 0))) { $html .= "mRowOptions) > 0) { foreach ($this->mRowOptions as $k=>$v) { @@ -160,8 +164,8 @@ class Table extends FormElement { if (0 == $col && strtolower(get_class($this->mColumns[$col]->getRenderer())) == 'checkboxcellrenderer') { // Checkbox for the row. Determine if selected. $selected = false; - if (is_array($this->mValue)) { - foreach ($this->mValue as $p) { + if (is_array($this->value)) { + foreach ($this->value as $p) { if ($p == $this->mData[$row][$this->mKeyField]) { $selected = true; break; @@ -178,6 +182,27 @@ class Table extends FormElement { $html .= "\n"; } + // Print footers. + if (($this->mInteractive && (count($this->mFooters) > 1)) || (!$this->mInteractive && (count($this->mFooters) > 0))) { + $html .= "mRowOptions) > 0) { + foreach ($this->mRowOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } + $html .= ">\n"; + foreach ($this->mFooters as $footer) { + $html .= "mHeaderOptions) > 0) { + foreach ($this->mHeaderOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } + $html .= ">$footer\n"; + } + $html .= "\n"; + } + $html .= ""; return $html; } @@ -191,7 +216,7 @@ class Table extends FormElement { // setAll - checks / unchecks all checkboxes in the table. $html .= "function setAll(value) {\n"; $html .= "\tfor (var i = 0; i < ".$this->getFormName().".elements.length; i++) {\n"; - $html .= "\t\tif ((".$this->getFormName().".elements[i].type=='checkbox') && (".$this->getFormName().".elements[i].name=='".$this->getName()."[]')) {\n"; + $html .= "\t\tif ((".$this->getFormName().".elements[i].type=='checkbox') && (".$this->getFormName().".elements[i].name=='".$this->name."[]')) {\n"; $html .= "\t\t\t".$this->getFormName().".elements[i].checked=value;\n"; if ($this->getIAScript()) { $html .= "\t\t\t".$this->getIAScript()."(".$this->getFormName().".elements[i]);\n";