1: <?php
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: class Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Checkbox
35: extends Mage_Adminhtml_Block_Widget_Grid_Column_Renderer_Abstract
36: {
37: protected $_defaultWidth = 55;
38: protected $_values;
39:
40: 41: 42: 43: 44:
45: public function getValues()
46: {
47: if (is_null($this->_values)) {
48: $this->_values = $this->getColumn()->getData('values') ? $this->getColumn()->getData('values') : array();
49: }
50: return $this->_values;
51: }
52: 53: 54: 55: 56: 57:
58: public function render(Varien_Object $row)
59: {
60: $values = $this->getColumn()->getValues();
61: $value = $row->getData($this->getColumn()->getIndex());
62: if (is_array($values)) {
63: $checked = in_array($value, $values) ? ' checked="checked"' : '';
64: }
65: else {
66: $checked = ($value === $this->getColumn()->getValue()) ? ' checked="checked"' : '';
67: }
68:
69: $disabledValues = $this->getColumn()->getDisabledValues();
70: if (is_array($disabledValues)) {
71: $disabled = in_array($value, $disabledValues) ? ' disabled="disabled"' : '';
72: }
73: else {
74: $disabled = ($value === $this->getColumn()->getDisabledValue()) ? ' disabled="disabled"' : '';
75: }
76:
77: $this->setDisabled($disabled);
78:
79: if ($this->getNoObjectId() || $this->getColumn()->getUseIndex()){
80: $v = $value;
81: } else {
82: $v = ($row->getId() != "") ? $row->getId():$value;
83: }
84:
85: return $this->_getCheckboxHtml($v, $checked);
86: }
87:
88: 89: 90: 91: 92:
93: protected function _getCheckboxHtml($value, $checked)
94: {
95: $html = '<input type="checkbox" ';
96: $html .= 'name="' . $this->getColumn()->getFieldName() . '" ';
97: $html .= 'value="' . $this->escapeHtml($value) . '" ';
98: $html .= 'class="'. ($this->getColumn()->getInlineCss() ? $this->getColumn()->getInlineCss() : 'checkbox') .'"';
99: $html .= $checked . $this->getDisabled() . '/>';
100: return $html;
101: }
102:
103: 104: 105: 106: 107:
108: public function ()
109: {
110: if($this->getColumn()->getHeader()) {
111: return parent::renderHeader();
112: }
113:
114: $checked = '';
115: if ($filter = $this->getColumn()->getFilter()) {
116: $checked = $filter->getValue() ? ' checked="checked"' : '';
117: }
118:
119: $disabled = '';
120: if ($this->getColumn()->getDisabled()) {
121: $disabled = ' disabled="disabled"';
122: }
123: $html = '<input type="checkbox" ';
124: $html .= 'name="' . $this->getColumn()->getFieldName() . '" ';
125: $html .= 'onclick="' . $this->getColumn()->getGrid()->getJsObjectName() . '.checkCheckboxes(this)" ';
126: $html .= 'class="checkbox"' . $checked . $disabled . ' ';
127: $html .= 'title="'.Mage::helper('adminhtml')->__('Select All') . '"/>';
128: return $html;
129: }
130: }
131: