PageRenderTime 82ms CodeModel.GetById 23ms RepoModel.GetById 1ms app.codeStats 0ms

/app/protected/core/components/CheckBoxColumn.php

https://bitbucket.org/zurmo/zurmo/
PHP | 184 lines | 120 code | 9 blank | 55 comment | 12 complexity | 0c3d2de279ce23500c5fc3c4ff2f5ae9 MD5 | raw file
Possible License(s): AGPL-3.0, BSD-3-Clause, GPL-2.0, LGPL-3.0, LGPL-2.1, BSD-2-Clause
  1. <?php
  2. /*********************************************************************************
  3. * Zurmo is a customer relationship management program developed by
  4. * Zurmo, Inc. Copyright (C) 2015 Zurmo Inc.
  5. *
  6. * Zurmo is free software; you can redistribute it and/or modify it under
  7. * the terms of the GNU Affero General Public License version 3 as published by the
  8. * Free Software Foundation with the addition of the following permission added
  9. * to Section 15 as permitted in Section 7(a): FOR ANY PART OF THE COVERED WORK
  10. * IN WHICH THE COPYRIGHT IS OWNED BY ZURMO, ZURMO DISCLAIMS THE WARRANTY
  11. * OF NON INFRINGEMENT OF THIRD PARTY RIGHTS.
  12. *
  13. * Zurmo is distributed in the hope that it will be useful, but WITHOUT
  14. * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
  15. * FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for more
  16. * details.
  17. *
  18. * You should have received a copy of the GNU Affero General Public License along with
  19. * this program; if not, see http://www.gnu.org/licenses or write to the Free
  20. * Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
  21. * 02110-1301 USA.
  22. *
  23. * You can contact Zurmo, Inc. with a mailing address at 27 North Wacker Drive
  24. * Suite 370 Chicago, IL 60606. or at email address contact@zurmo.com.
  25. *
  26. * The interactive user interfaces in original and modified versions
  27. * of this program must display Appropriate Legal Notices, as required under
  28. * Section 5 of the GNU Affero General Public License version 3.
  29. *
  30. * In accordance with Section 7(b) of the GNU Affero General Public License version 3,
  31. * these Appropriate Legal Notices must retain the display of the Zurmo
  32. * logo and Zurmo copyright notice. If the display of the logo is not reasonably
  33. * feasible for technical reasons, the Appropriate Legal Notices must display the words
  34. * "Copyright Zurmo Inc. 2015. All rights reserved".
  35. ********************************************************************************/
  36. /**
  37. * Override class for CCheckBoxColumn utilized by
  38. * yii CGridView extension. Adds functionality
  39. * for checking/unchecking entire results of a list.
  40. * @see CGridView class
  41. */
  42. class CheckBoxColumn extends CCheckBoxColumn
  43. {
  44. public function init()
  45. {
  46. if (isset($this->checkBoxHtmlOptions['name']))
  47. {
  48. $name = $this->checkBoxHtmlOptions['name'];
  49. }
  50. else
  51. {
  52. $name = $this->id;
  53. if (substr($name, -2) !== '[]')
  54. {
  55. $name .= '[]';
  56. }
  57. $this->checkBoxHtmlOptions['name'] = $name;
  58. }
  59. $name = strtr($name, array('[' => "\\[", ']' => "\\]"));
  60. if ($this->grid->selectableRows == 1)
  61. {
  62. $one = "\n\tjQuery(\"input:not(#\"+$(this).attr('id')+\")[name = '$name']\").attr('checked', false);"; // Not Coding Standard
  63. }
  64. else
  65. {
  66. $one = '';
  67. }
  68. // Begin Not Coding Standard
  69. $js = <<<END
  70. jQuery('#{$this->id}_all').live('click', function()
  71. {
  72. var checked = this.checked;
  73. //custom checkbox style
  74. if (this.checked){
  75. jQuery(this).parent().addClass('c_on');
  76. }
  77. else
  78. {
  79. jQuery(this).parent().removeClass('c_on');
  80. }
  81. jQuery("input[name='$name']").each(function()
  82. {
  83. this.checked = checked;
  84. updateListViewSelectedIds('{$this->grid->id}', $(this).val(), checked);
  85. //custom checkbox style
  86. if (this.checked){
  87. jQuery(this).parent().addClass('c_on');
  88. }
  89. else
  90. {
  91. jQuery(this).parent().removeClass('c_on');
  92. }
  93. });
  94. });
  95. jQuery("input[name='$name']").live('click', function()
  96. {
  97. jQuery('#{$this->id}_all').attr( 'checked', jQuery("input[name='$name']").length == jQuery("input[name='$name']:checked").length);{$one}
  98. updateListViewSelectedIds('{$this->grid->id}', $(this).val(), $(this).attr('checked'));
  99. //custom checkbox style
  100. if ( jQuery('#{$this->id}_all').attr( 'checked') === 'checked' ){
  101. jQuery('#{$this->id}_all').parent().addClass('c_on');
  102. }
  103. else
  104. {
  105. jQuery('#{$this->id}_all').parent().removeClass('c_on');
  106. }
  107. if ( this.checked )
  108. {
  109. jQuery(this).parent().addClass('c_on');
  110. }
  111. else
  112. {
  113. jQuery(this).parent().removeClass('c_on');
  114. }
  115. });
  116. END;
  117. // End Not Coding Standard
  118. Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $this->id, $js);
  119. }
  120. /**
  121. * Renders the header cell content.
  122. * Override in order to allow for disabled and checked by default
  123. * in the scenario where selectAll is selected.
  124. */
  125. protected function renderHeaderCellContent()
  126. {
  127. if ($this->grid->selectableRows>1)
  128. {
  129. $checked = false;
  130. $disabled = '';
  131. $htmlOptions = array('disabled' => $disabled);
  132. echo ZurmoHtml::checkBox($this->id . '_all', $checked, $htmlOptions);
  133. }
  134. else
  135. {
  136. parent::renderHeaderCellContent();
  137. }
  138. }
  139. public function renderDataCellContentFromOutsideClass($row, $data)
  140. {
  141. $this->renderDataCellContent($row, $data);
  142. }
  143. /**
  144. * Override to support adding the label wrapper on the checkbox
  145. * (non-PHPdoc)
  146. * @see CCheckBoxColumn::renderDataCellContent()
  147. */
  148. protected function renderDataCellContent($row, $data)
  149. {
  150. if ($this->value !== null)
  151. {
  152. $value = $this->evaluateExpression($this->value, array('data' => $data, 'row' => $row));
  153. }
  154. elseif ($this->name !== null)
  155. {
  156. $value = ZurmoHtml::value($data, $this->name);
  157. }
  158. else
  159. {
  160. $value = $this->grid->dataProvider->keys[$row];
  161. }
  162. $checked = false;
  163. if ($this->checked !== null)
  164. {
  165. $checked = $this->evaluateExpression($this->checked, array('data' => $data, 'row' => $row));
  166. }
  167. $options = $this->checkBoxHtmlOptions;
  168. $name = $options['name'];
  169. unset($options['name']);
  170. $options['value'] = $value;
  171. $options['id'] = $this->id . '_' . $row;
  172. echo ZurmoHtml::checkBox($name, $checked, $options);
  173. }
  174. }
  175. ?>