X-Git-Url: http://wagnertech.de/gitweb/gitweb.cgi/timetracker.git/blobdiff_plain/098a79f0819ebb89b7d48df4a6b154af4560f68e..9a23a8c0a51b7ec38a96f525484134f3cb85dc7e:/WEB-INF/lib/form/Table.class.php diff --git a/WEB-INF/lib/form/Table.class.php b/WEB-INF/lib/form/Table.class.php new file mode 100644 index 00000000..89f6543f --- /dev/null +++ b/WEB-INF/lib/form/Table.class.php @@ -0,0 +1,226 @@ +mName = $name; + $this->mValue = $value; + } + + function setKeyField($value) { + $this->mKeyField = $value; + } + + function setData($data) { + if (is_array($data) && isset($data[0]) && is_array($data[0])) + $this->mData = &$data; + } + + function addColumn($column) { + if ($column != null) $column->setTable($this); + $this->mColumns[] = &$column; + } + + function setInteractive($value) { $this->mInteractive = $value; } + function isInteractive() { return $this->mInteractive; } + + function setIAScript($value) { $this->mIAScript = $value; } + function getIAScript() { return $this->mIAScript; } + + function setWidth($value) { $this->mWidth = $value; } + function getWidth() { return $this->mWidth; } + + function setTableOptions($value) { $this->mTableOptions = $value; } + function getTableOptions() { return $this->mTableOptions; } + + function setRowOptions($value) { $this->mRowOptions = $value; } + function getRowOptions() { return $this->mRowOptions; } + + function setHeaderOptions($value) { $this->mHeaderOptions = $value; } + function getHeaderOptions() { return $this->mHeaderOptions; } + + function getValueAt($rowindex, $colindex) { + if (!$this->mProccessed) $this->_process(); + return @$this->mData[$rowindex][$this->mColumnFields[$colindex]]; + } + + function getValueAtName($rowindex,$fieldname) { + if (!$this->mProccessed) $this->_process(); + return @$this->mData[$rowindex][$fieldname]; + } + + function _process() { + $this->mProccessed = true; + + if ($this->mInteractive) { + // Add a column of clickable checkboxes. + $column = new TableColumn("","getName()."_all\" onclick=\"setAll(this.checked)\">"); + import('form.CheckboxCellRenderer'); + $cb = new CheckboxCellRenderer(); + if ($this->getIAScript()) $cb->setOnChangeAdd($this->getIAScript()."(this)"); + $column->setRenderer($cb); + $column->setTable($this); + array_unshift($this->mColumns, $column); + } + + foreach ($this->mColumns as $column) { + $this->mColumnFields[] = $column->getField(); + $this->mHeaders[] = $column->getHeader(); + } + } + + function toStringControl() { + if (!$this->isRenderable()) return ""; + if (!$this->mProccessed) $this->_process(); + + $html = ""; + if ($this->mInteractive) $html .= $this->_addJavaScript(); + + $html .= "
| mHeaderOptions) > 0) { + foreach ($this->mHeaderOptions as $k=>$v) { + $html .= " $k=\"$v\""; + } + } + $html .= ">$header | \n"; + } + $html .= "
|---|