Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
BorderPositionElement.php
1 <?php
2  /*********************************************************************************
3  * Zurmo is a customer relationship management program developed by
4  * Zurmo, Inc. Copyright (C) 2017 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. 2017. All rights reserved".
35  ********************************************************************************/
36 
38  {
39  protected function renderControlEditable()
40  {
41  $this->registerScripts();
42  // TODO: @Shoaibi: High: Enable all and none once we figure out following:
43  // what to do if none is unchecked?
44  // what to do is all is unchecked?
45  //$content = $this->renderAllCheckbox();
46  $content = $this->renderDirectionalCheckboxes();
47  //$content .= "<br />";
48  //$content .= $this->renderNoneCheckbox();
49  return $content;
50  }
51 
52  protected function renderControlNonEditable()
53  {
54  throw new NotSupportedException();
55  }
56 
57  protected function renderAllCheckbox()
58  {
59  $attribute = 'border-all';
60  $label = Zurmo::t('Core', 'All');
61  $all = $this->renderCheckboxWithHiddenInput($label, $attribute);
62  return $all;
63  }
64 
65  protected function renderNoneCheckbox()
66  {
67  $attribute = 'border-none';
68  $label = Zurmo::t('Core', 'None');
69  $none = $this->renderCheckboxWithHiddenInput($label, $attribute);
70  return $none;
71  }
72 
73  protected function renderDirectionalCheckboxes()
74  {
75  $checkboxConfigurations = array(
76  'border-top' => Zurmo::t('Core', 'Top'),
77  'border-bottom' => Zurmo::t('Core', 'Bottom'),
78  'border-left' => Zurmo::t('Core', 'Left'),
79  'border-right' => Zurmo::t('Core', 'Right')
80  );
81  $content = null;
82  foreach ($checkboxConfigurations as $attribute => $label)
83  {
84  $content .= ZurmoHtml::tag('span', array('class' => 'builder-position-checkbox'),
85  $this->renderCheckboxWithHiddenInput($label, $attribute, true));
86  }
87  return $content;
88  }
89 
90  protected function renderCheckboxWithHiddenInput($label, $attribute, $renderHidden = false)
91  {
92  $checkboxLabelFor = $attribute;
93  if ($renderHidden)
94  {
95  $attribute = $this->resolveCheckboxInputAttributeName($attribute);
96  $checkboxLabelFor = ZurmoHtml::activeId($this->model, $attribute);
97  }
98  $checkboxLabelHtmlOptions = array();
99  $checkboxLabel = ZurmoHtml::label($label, $checkboxLabelFor, $checkboxLabelHtmlOptions);
100  $checkboxHtmlOptions = $this->resolveCheckBoxHtmlOptions($renderHidden);
101  $content = null;
102  if ($renderHidden)
103  {
104  $content .= $this->form->checkBox($this->model, $attribute, $checkboxHtmlOptions);
105  }
106  else
107  {
108  $content .= ZurmoHtml::checkBox($attribute, false, $checkboxHtmlOptions);
109  }
110  $content .= $checkboxLabel;
111  return $content;
112  }
113 
114  protected function resolveCheckboxInputAttributeName($attribute)
115  {
116  return $this->params['checkboxInputPrefix'] . "[${attribute}]";
117  }
118 
119  protected function resolveCheckBoxHtmlOptions($renderUncheckValue)
120  {
121  $options = array('value' => 1);
122  $options['class'] = 'border-checkbox';
123  if ($renderUncheckValue)
124  {
125  $options['class'] = 'directional-border-checkbox';
126  $options['uncheckValue'] = 'none';
127  }
128  return $options;
129  }
130 
131  protected function registerScripts()
132  {
133  $this->registerDirectionalCheckboxScript();
134  $this->registerAllOrNoneCheckboxScript();
135  }
136 
137  protected function registerDirectionalCheckboxScript()
138  {
139  $script = '
140  var directionalCheckBoxSelector = ".directional-border-checkbox:checkbox";
141  var noneCheckboxSelector = ".border-checkbox#border-none:checkbox";
142  var allCheckboxSelector = ".border-checkbox#border-all:checkbox";
143  function toggleCheckBoxState(checkboxSelector, state)
144  {
145  if ($(checkboxSelector).prop("checked") != state)
146  {
147  $(checkboxSelector).trigger("click");
148  $(checkboxSelector).parent().addClass("c_on");
149  }
150  }
151 
152  function areAllDirectionalCheckboxesChecked()
153  {
154  allCount = $(directionalCheckBoxSelector).length;
155  checkedCount = $(directionalCheckBoxSelector + ":checked").length;
156  return (allCount == checkedCount);
157  }
158 
159  function areAllDirectionalCheckboxesUnchecked()
160  {
161  checkedCount = $(directionalCheckBoxSelector + ":checked").length;
162  return (checkedCount == 0);
163  }
164 
165  function checkAllIfAllDirectionalCheckboxesChecked()
166  {
167  if (areAllDirectionalCheckboxesChecked())
168  {
169  toggleCheckBoxState(allCheckboxSelector, true);
170  return true;
171  }
172  }
173 
174  function checkNoneIfAllDirectionalCheckboxesUnchecked()
175  {
176  if (areAllDirectionalCheckboxesUnchecked())
177  {
178  toggleCheckBoxState(noneCheckboxSelector, true);
179  return true;
180  }
181  }
182 
183  $(directionalCheckBoxSelector).unbind("change").bind("change", function()
184  {
185  if ($(this).is(":checked"))
186  {
187  //toggleCheckBoxState(noneCheckboxSelector, false);
188  //checkAllIfAllDirectionalCheckboxesChecked();
189  }
190  else
191  {
192  //toggleCheckBoxState(allCheckboxSelector, false);
193  //checkNoneIfAllDirectionalCheckboxesUnchecked();
194  }
195  });
196  //checkNoneIfAllDirectionalCheckboxesUnchecked() || checkAllIfAllDirectionalCheckboxesChecked();
197  ';
198  Yii::app()->clientScript->registerScript('directionalCheckboxClickScript', $script);
199  }
200 
201  protected function registerAllOrNoneCheckboxScript()
202  {
203  // Begin Not Coding Standard
204  $script = '
205  function changeAllDirectionalCheckboxesAndRaiseEvents(checked)
206  {
207  $(directionalCheckBoxSelector)
208  .each(function(){
209  toggleCheckBoxState(this, "checked");
210  });
211  }
212  function checkAllDirectionalCheckboxesAndRaiseEvents()
213  {
214  changeAllDirectionalCheckboxesAndRaiseEvents(true);
215  }
216 
217  function uncheckAllDirectionalCheckboxesAndRaiseEvents()
218  {
219  changeAllDirectionalCheckboxesAndRaiseEvents(false);
220  }
221 
222  $(".border-checkbox:checkbox").unbind("change").bind("change", function()
223  {
224  if ($(this).is(":checked"))
225  {
226  if ($(this).attr("id") == "border-all")
227  {
228  checkAllDirectionalCheckboxesAndRaiseEvents();
229  }
230  else
231  {
232  uncheckAllDirectionalCheckboxesAndRaiseEvents();
233  }
234  }
235  else
236  {
237  }
238  });';
239  Yii::app()->clientScript->registerScript('allOrNoneChangeCheckboxScript', $script);
240  // End Not Coding Standard
241  }
242  }
243 ?>
static checkBox($name, $checked=false, $htmlOptions=array())
Definition: ZurmoHtml.php:267
Generated on Sun Oct 25 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.