Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SortableCompareLists.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 
42  class SortableCompareLists extends CWidget
43  {
44  public $model;
45 
46  public $form;
47 
48  public $leftSideAttributeName;
49 
50  public $leftSideDisplayLabel;
51 
52  public $rightSideAttributeName;
53 
54  public $rightSideDisplayLabel;
55 
56  public $leftSideId;
57 
58  public $leftSideName;
59 
60  public $leftSideValue;
61 
62  public $leftSideData;
63 
64  public $rightSideId;
65 
66  public $rightSideName;
67 
68  public $rightSideValue;
69 
70  public $rightSideData;
71 
72  public $formId;
73 
74  public $allowSorting = false;
75 
76  public $multiselectNavigationClasses;
77 
78  public $hasLeftSideBox = true;
79 
80  public $hasRightSideBox = true;
81 
82  public function init()
83  {
84  assert('($this->model instanceof CModel && $this->form instanceof ZurmoActiveForm) ||
85  ( $this->model == null && $this->form == null)');
86  assert('is_bool($this->allowSorting)');
87  if ($this->hasRightSideBox === true)
88  {
89  if ($this->rightSideId == null)
90  {
91  $this->rightSideId = $this->form->id . '_' . $this->rightSideAttributeName;
92  }
93  if ($this->rightSideName == null)
94  {
95  $this->rightSideName = $this->rightSideAttributeName;
96  }
97  if ($this->rightSideValue === null)
98  {
99  $this->rightSideValue = $this->model->{$this->rightSideAttributeName};
100  }
101  }
102  if ($this->hasLeftSideBox === true)
103  {
104  if ($this->leftSideId == null)
105  {
106  $this->leftSideId = $this->form->id . '_' . $this->leftSideAttributeName;
107  }
108  if ($this->leftSideName == null)
109  {
110  $this->leftSideName = $this->leftSideAttributeName;
111  }
112  if ($this->leftSideValue === null)
113  {
114  $this->leftSideValue = $this->model->{$this->leftSideAttributeName};
115  }
116  }
117  if ($this->formId === null)
118  {
119  $this->formId = $this->form->id;
120  }
121  $this->registerCoreScripts();
122  parent::init();
123  }
124 
125  public function run()
126  {
127  $id = $this->getId();
128  $content = '<td>';
129  $content .= '<div class="multiselect-holder">';
130  if ($this->hasLeftSideBox === true)
131  {
132  $leftListContent = $this->resolveLeftSideListBox();
133 
134  $content .= '<div class="multiselect-left">';
135  $content .= '<label>' . $this->leftSideDisplayLabel . '</label>';
136  $content .= $leftListContent;
137  $content .= '</div>';
138 
139  $content .= '<div class="multiselect-nav">';
140  $content .= ZurmoHtml::button( '7', array( 'id' => $id . 'moveRight', 'class' => 'white-button icon-right-arrow' ) ); //used 7, 8 becuase those are rendered as icons with symbly, other option is to make it an A with a SPAN inside it
141  $content .= ZurmoHtml::button( '8', array( 'id' => $id . 'moveLeft', 'class' => 'white-button icon-left-arrow' ) );
142  $content .= '</div>';
143  }
144  if ($this->hasRightSideBox === true)
145  {
146  $rightListContent = $this->resolveRightSideListBox();
147  $content .= '<div class="multiselect-right">';
148  $content .= '<label>' . $this->rightSideDisplayLabel . '</label>';
149  $content .= $rightListContent;
150  $content .= '</div>';
151 
152  if ($this->allowSorting)
153  {
154  $content .= '<div class="multiselect-nav' . $this->resolveMultiselectNavigationClassesContent() . '">';
155  $content .= ZurmoHtml::button( '5', array( 'id' => $id . 'moveUp', 'class' => 'white-button icon-up-arrow' ) ); // value "up" in icon font
156  $content .= ZurmoHtml::button( '6', array( 'id' => $id . 'moveDown', 'class' => 'white-button icon-down-arrow' ) ); // value "down" in icon font
157  $content .= '</div>';
158  }
159  }
160  $content .= '</div>';
161  $content .= '</td>';
162  echo $content;
163  }
164 
165  protected function resolveLeftSideListBox()
166  {
167  $htmlOptions = array('size' => '10', 'multiple' => true, 'class' => 'ignore-style multiple',
168  'id' => $this->leftSideId);
169  if ($this->model != null)
170  {
171  return $this->form->dropDownList(
172  $this->model,
173  $this->leftSideName,
174  $this->leftSideValue,
175  $htmlOptions
176  );
177  }
178  else
179  {
180  return ZurmoHtml::listBox($this->leftSideName, $this->leftSideValue, $this->leftSideData, $htmlOptions);
181  }
182  }
183 
184  protected function resolveRightSideListBox()
185  {
186  $htmlOptions = array('size' => '10', 'multiple' => true, 'class' => 'ignore-style multiple',
187  'id' => $this->rightSideId);
188  if ($this->model != null)
189  {
190  return $this->form->dropDownList(
191  $this->model,
192  $this->rightSideName,
193  $this->rightSideValue,
194  $htmlOptions
195  );
196  }
197  else
198  {
199  return ZurmoHtml::listBox($this->rightSideName, $this->rightSideValue, $this->rightSideData, $htmlOptions);
200  }
201  }
202 
206  protected function registerCoreScripts()
207  {
208  $id = $this->getId();
209  $script = "";
210  if ($this -> hasLeftSideBox === true && $this->hasRightSideBox === true)
211  {
212  $script .= "$('#" . $id . "moveRight').click(function()
213  {
214  return !$('#" . $this->leftSideId . " option:selected')
215  .remove().appendTo('#" . $this->rightSideId . "');
216  });
217  $('#" . $id . "moveLeft').click(function()
218  {
219  return !$('#" . $this->rightSideId . " option:selected')
220  .remove().appendTo('#" . $this->leftSideId . "');
221  });";
222  }
223  if ($this->hasLeftSideBox === true)
224  {
225  $script .= "$('#" . $this->formId . "').submit(function()
226  {
227  $('#" . $this->leftSideId . " option').each(function(i)
228  {
229  $(this).attr('selected', 'selected');
230  });
231  });";
232  }
233  if ($this->hasRightSideBox === true)
234  {
235  $script .= "$('#" . $this->formId . "').submit(function()
236  {
237  $('#" . $this->rightSideId . " option').each(function(i)
238  {
239  $(this).attr('selected', 'selected');
240  });
241  });";
242  $script .= "$('#" . $id . "moveUp').click(function()
243  {
244  if ($('#" . $this->rightSideId . " option:selected').first().index() > 0)
245  {
246  $('#" . $this->rightSideId . " option:selected').each(function()
247  {
248  $(this).insertBefore($(this).prev());
249  });
250  }
251  });
252  $('#" . $id . "moveDown').click(function()
253  {
254  if ($('#" . $this->rightSideId . " option:selected').last().index() < ($('#" . $this->rightSideId . " option').length - 1))
255  {
256  $($('#" . $this->rightSideId . " option:selected').get().reverse()).each(function(i, selected)
257  {
258  if (!$(this).next().length) return false;
259  $(this).insertAfter($(this).next());
260  });
261  }
262  });";
263  }
264  Yii::app()->getClientScript()->registerScript(__CLASS__ . '#' . $id, $script);
265  }
266 
267  protected function resolveMultiselectNavigationClassesContent()
268  {
269  if ($this->multiselectNavigationClasses != null)
270  {
271  return ' ' . $this->multiselectNavigationClasses;
272  }
273  }
274  }
275 ?>
Generated on Fri Jul 10 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.