]> git.sur5r.net Git - bacula/bacula/blob - gui/baculum/framework/Web/UI/WebControls/TCheckBoxColumn.php
baculum: New Baculum API and Baculum Web
[bacula/bacula] / gui / baculum / framework / Web / UI / WebControls / TCheckBoxColumn.php
1 <?php
2 /**
3  * TCheckBoxColumn class file
4  *
5  * @author Qiang Xue <qiang.xue@gmail.com>
6  * @link https://github.com/pradosoft/prado
7  * @copyright Copyright &copy; 2005-2016 The PRADO Group
8  * @license https://github.com/pradosoft/prado/blob/master/COPYRIGHT
9  * @package System.Web.UI.WebControls
10  */
11
12 /**
13  * TDataGridColumn class file
14  */
15 Prado::using('System.Web.UI.WebControls.TDataGridColumn');
16 /**
17  * TCheckBox class file
18  */
19 Prado::using('System.Web.UI.WebControls.TCheckBox');
20
21 /**
22  * TCheckBoxColumn class
23  *
24  * TCheckBoxColumn represents a checkbox column that is bound to a field in a data source.
25  * The checked state of the checkboxes are determiend by the bound data at
26  * {@link setDataField DataField}. If {@link setReadOnly ReadOnly} is false,
27  * TCheckBoxColumn will display an enabled checkbox provided the cells are
28  * in edit mode. Otherwise, the checkboxes will be disabled to prevent from editting.
29  *
30  * The checkbox control in the TCheckBoxColumn can be accessed by one of
31  * the following two methods:
32  * <code>
33  * $datagridItem->CheckBoxColumnID->CheckBox
34  * $datagridItem->CheckBoxColumnID->Controls[0]
35  * </code>
36  * The second method is possible because the checkbox control created within the
37  * datagrid cell is the first child.
38  *
39  * @author Qiang Xue <qiang.xue@gmail.com>
40  * @package System.Web.UI.WebControls
41  * @since 3.0
42  */
43 class TCheckBoxColumn extends TDataGridColumn
44 {
45         /**
46          * @return string the field name from the data source to bind to the column
47          */
48         public function getDataField()
49         {
50                 return $this->getViewState('DataField','');
51         }
52
53         /**
54          * @param string the field name from the data source to bind to the column
55          */
56         public function setDataField($value)
57         {
58                 $this->setViewState('DataField',$value,'');
59         }
60
61         /**
62          * @return boolean whether the items in the column can be edited. Defaults to false.
63          */
64         public function getReadOnly()
65         {
66                 return $this->getViewState('ReadOnly',false);
67         }
68
69         /**
70          * @param boolean whether the items in the column can be edited
71          */
72         public function setReadOnly($value)
73         {
74                 $this->setViewState('ReadOnly',TPropertyValue::ensureBoolean($value),false);
75         }
76
77         /**
78          * Initializes the specified cell to its initial values.
79          * This method overrides the parent implementation.
80          * It creates a checkbox inside the cell.
81          * If the column is read-only or if the item is not in edit mode,
82          * the checkbox will be set disabled.
83          * @param TTableCell the cell to be initialized.
84          * @param integer the index to the Columns property that the cell resides in.
85          * @param string the type of cell (Header,Footer,Item,AlternatingItem,EditItem,SelectedItem)
86          */
87         public function initializeCell($cell,$columnIndex,$itemType)
88         {
89                 if($itemType===TListItemType::Item || $itemType===TListItemType::AlternatingItem || $itemType===TListItemType::SelectedItem || $itemType===TListItemType::EditItem)
90                 {
91                         $checkBox=new TCheckBox;
92                         if($this->getReadOnly() || $itemType!==TListItemType::EditItem)
93                                 $checkBox->setEnabled(false);
94                         $cell->setHorizontalAlign('Center');
95                         $cell->getControls()->add($checkBox);
96                         $cell->registerObject('CheckBox',$checkBox);
97                         if($this->getDataField()!=='')
98                                 $checkBox->attachEventHandler('OnDataBinding',array($this,'dataBindColumn'));
99                 }
100                 else
101                         parent::initializeCell($cell,$columnIndex,$itemType);
102         }
103
104         /**
105          * Databinds a cell in the column.
106          * This method is invoked when datagrid performs databinding.
107          * It populates the content of the cell with the relevant data from data source.
108          */
109         public function dataBindColumn($sender,$param)
110         {
111                 $item=$sender->getNamingContainer();
112                 $data=$item->getData();
113                 if(($field=$this->getDataField())!=='')
114                         $value=TPropertyValue::ensureBoolean($this->getDataFieldValue($data,$field));
115                 else
116                         $value=TPropertyValue::ensureBoolean($data);
117                 if($sender instanceof TCheckBox)
118                         $sender->setChecked($value);
119         }
120 }
121