summaryrefslogtreecommitdiff
path: root/framework/Web/UI/ActiveControls/TActiveTemplateColumn.php
blob: c0a49b63a85c4f73e5debcdabc27356a3c6f89a6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
<?php
/**
 * TActiveDataGrid class file
 *
 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
 * @link http://www.landwehr-software.de/
 * @copyright Copyright &copy; 2009 LANDWEHR Computer und Software GmbH
 * @license http://www.pradosoft.com/license/
 * @package Prado\Web\UI\ActiveControls
 */

namespace Prado\Web\UI\ActiveControls;
use Prado\Prado;
use Prado\Web\UI\WebControls\IItemDataRenderer;
use Prado\Web\UI\WebControls\TDataGrid;
use Prado\Web\UI\WebControls\TTemplateColumn;

/**
 * TActiveTemplateColumn class
 *
 * TActiveTemplateColumn customizes the layout of controls in the column with templates.
 * In particular, you can specify {@link setItemTemplate ItemTemplate},
 * {@link setEditItemTemplate EditItemTemplate}, {@link setHeaderTemplate HeaderTemplate}
 * and {@link setFooterTemplate FooterTemplate} to customize specific
 * type of cells in the column.
 *
 * This is the active counterpart to the {@link TTemplateColumn} control. For that purpose,
 * if sorting is allowed, the header links/buttons are replaced by active controls.
 *
 * Please refer to the original documentation of the {@link TTemplateColumn} for usage.
 *
 * @author LANDWEHR Computer und Software GmbH <programmierung@landwehr-software.de>
 * @package Prado\Web\UI\ActiveControls
 * @since 3.1.9
 */
class TActiveTemplateColumn extends TTemplateColumn {
	protected function initializeHeaderCell($cell,$columnIndex) {
		$text=$this->getHeaderText();

		if(($classPath=$this->getHeaderRenderer())!=='') {
			$control=Prado::createComponent($classPath);
			if($control instanceof \Prado\IDataRenderer) {
				if($control instanceof IItemDataRenderer) {
					$item=$cell->getParent();
					$control->setItemIndex($item->getItemIndex());
					$control->setItemType($item->getItemType());
				}
				$control->setData($text);
			}
			$cell->getControls()->add($control);
		}
		else if($this->getAllowSorting()) {
				$sortExpression=$this->getSortExpression();
				if(($url=$this->getHeaderImageUrl())!=='') {
					$button=Prado::createComponent('System.Web.UI.WebControls.TActiveImageButton');
					$button->setImageUrl($url);
					$button->setCommandName(TDataGrid::CMD_SORT);
					$button->setCommandParameter($sortExpression);
					if($text!=='')
						$button->setAlternateText($text);
					$button->setCausesValidation(false);
					$cell->getControls()->add($button);
				}
				else if($text!=='') {
						$button=Prado::createComponent('System.Web.UI.WebControls.TActiveLinkButton');
						$button->setText($text);
						$button->setCommandName(TDataGrid::CMD_SORT);
						$button->setCommandParameter($sortExpression);
						$button->setCausesValidation(false);
						$cell->getControls()->add($button);
					}
					else
						$cell->setText('&nbsp;');
			}
			else {
				if(($url=$this->getHeaderImageUrl())!=='') {
					$image=Prado::createComponent('System.Web.UI.WebControls.TActiveImage');
					$image->setImageUrl($url);
					if($text!=='')
						$image->setAlternateText($text);
					$cell->getControls()->add($image);
				}
				else if($text!=='')
						$cell->setText($text);
					else
						$cell->setText('&nbsp;');
			}
	}
}