Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
SearchView.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 
40  abstract class SearchView extends ModelView
41  {
42  protected $gridIdSuffix;
43 
44  protected $hideAllSearchPanelsToStart;
45 
46  protected $showAdvancedSearch = true;
47 
52  public function __construct($model,
53  $listModelClassName,
54  $gridIdSuffix = null,
55  $hideAllSearchPanelsToStart = false
56  )
57  {
58  assert('$model != null');
59  assert('is_string($listModelClassName)');
60  assert('is_bool($hideAllSearchPanelsToStart)');
61  $this->model = $model;
62  $this->listModelClassName = $listModelClassName;
63  $this->gridIdSuffix = $gridIdSuffix;
64  $this->gridId = 'list-view';
65  $this->hideAllSearchPanelsToStart = $hideAllSearchPanelsToStart;
66  }
67 
75  protected function renderContent()
76  {
77  $content = '<div class="wide form">';
78  $clipWidget = new ClipWidget();
79  list($form, $formStart) = $clipWidget->renderBeginWidget(
80  'NoRequiredsActiveForm',
81  array('id' => $this->getSearchFormId(),
82  'action' => $this->getFormActionUrl(),
83  'enableAjaxValidation' => $this->getEnableAjaxValidationValue(),
84  'clientOptions' => $this->getClientOptions(),
85 
86  )
87  );
88  $content .= $formStart;
89  $content .= $this->renderFormLayout($form);
90  $content .= $this->renderAfterFormLayout($form);
91  $formEnd = $clipWidget->renderEndWidget();
92  $content .= $formEnd;
93  $content .= $this->renderModalContainer();
94  $content .= '</div>';
95  return $content;
96  }
97 
98  protected function getEnableAjaxValidationValue()
99  {
100  return false;
101  }
102 
103  protected function getClientOptions()
104  {
105  return array();
106  }
107 
108  protected function getFormActionUrl()
109  {
110  return null;
111  }
112 
113  protected function renderAfterFormLayout($form)
114  {
115  $this->registerScripts();
116  }
117 
124  protected function renderFormBottomPanel()
125  {
126  $moreSearchOptionsLink = $this->resolveMoreSearchOptionsLinkContent();
127  $selectListAttributesLink = $this->getSelectListAttributesLinkContent();
128  $kanbanBoardOptionsLink = $this->getKanbanBoardOptionsLinkContent();
129  $clearSearchLabelPrefix = $this->getClearSearchLabelPrefixContent();
130  $clearSearchLabel = $this->getClearSearchLabelContent();
131  $clearSearchLinkStartingStyle = $this->getClearSearchLinkStartingStyle();
132  $clearSearchLink = ZurmoHtml::link($clearSearchLabelPrefix . $clearSearchLabel, '#',
133  array('id' => 'clear-search-link' . $this->gridIdSuffix,
134  'style' => $clearSearchLinkStartingStyle));
135  $startingDivStyle = null;
136  if ($this->hideAllSearchPanelsToStart)
137  {
138  $startingDivStyle = "style='display:none;'";
139  }
140  $content = '<div class="search-form-tools">';
141  $content .= $moreSearchOptionsLink;
142  $content .= $selectListAttributesLink;
143  $content .= $kanbanBoardOptionsLink;
144  $content .= $clearSearchLink;
145  $content .= $this->renderFormBottomPanelExtraLinks();
146  $content .= $this->renderClearingSearchInputContent();
147  $content .= '</div>';
148  return $content;
149  }
150 
151  protected function resolveMoreSearchOptionsLinkContent()
152  {
153  if ($this->showAdvancedSearch)
154  {
155  return ZurmoHtml::link(Zurmo::t('Core', 'Advanced'), '#', array('id' => 'more-search-link' . $this->gridIdSuffix));
156  }
157  }
158 
159  protected function getClearSearchLabelPrefixContent()
160  {
161  }
162 
163  protected function getClearSearchLabelContent()
164  {
165  return Zurmo::t('Core', 'Clear');
166  }
167 
168  protected function getClearSearchLinkStartingStyle()
169  {
170  if ($this->model->anyMixedAttributes == null)
171  {
172  return "display:none;";
173  }
174  }
175 
176  protected function getExtraRenderForClearSearchLinkScript()
177  {
178  }
179 
180  protected function renderClearingSearchInputContent()
181  {
182  $idInputHtmlOptions = array('id' => $this->getClearingSearchInputId());
183  $hiddenInputName = 'clearingSearch';
184  return ZurmoHtml::hiddenField($hiddenInputName, null, $idInputHtmlOptions);
185  }
186 
187  protected function getClearingSearchInputId()
188  {
189  return 'clearingSearch-' . $this->getSearchFormId();
190  }
191 
192  protected function registerScripts()
193  {
194  DropDownUtil::registerScripts();
195  // Begin Not Coding Standard
196  Yii::app()->clientScript->registerScript('search' . $this->getSearchFormId(), "
197  $('#clear-search-link" . $this->gridIdSuffix . "').removeAttr('clearForm');
198  $('#clear-search-link" . $this->gridIdSuffix . "').clearform({
199  form: '#" . $this->getSearchFormId() . "'
200  }
201  );
202  $('#clear-search-link" . $this->gridIdSuffix . "').unbind('click.clear');
203  $('#clear-search-link" . $this->gridIdSuffix . "').bind('click.clear', function(){
204  $('#" . $this->getClearingSearchInputId() . "').val('1');
205  $('#clear-search-link" . $this->gridIdSuffix . "').hide();
206  " . $this->getExtraRenderForClearSearchLinkScript() . "
207  $(this).closest('form').submit();
208  $('#" . $this->getClearingSearchInputId() . "').val('');
209  return false;
210  }
211  );
212  $('#more-search-link" . $this->gridIdSuffix . "').unbind('click.more');
213  $('#more-search-link" . $this->gridIdSuffix . "').bind('click.more', function(event){
214  $('.select-list-attributes-view').hide();
215  $('.kanban-board-options-view').hide();
216  $(this).closest('form').find('.search-view-1').toggle();
217  return false;
218  }
219  );
220  $('#cancel-advanced-search').unbind('click');
221  $('#cancel-advanced-search').live('click', function(event){
222  $(this).closest('form').find('.search-view-1').hide();
223  });
225  $this->renderAdvancedSearchScripts();
226  // End Not Coding Standard
227  }
228 
229  protected function renderAdvancedSearchScripts()
230  {
231  Yii::app()->clientScript->registerScript('advancedSearch' . $this->getSearchFormId(), "
232  $('#" . $this->getSearchFormId() . "').unbind('submit');
233  $('#" . $this->getSearchFormId() . "').bind('submit', function(event)
234  {
235  $(this).closest('form').find('.search-view-1').hide();
236  " . $this->getHideOrShowClearSearchLinkScript() . "
237  $('.select-list-attributes-view').hide();
238  $('.kanban-board-options-view').hide();
239  $('#" . $this->gridId . $this->gridIdSuffix . "-selectedIds').val(null);
240  $.fn.yiiGridView.update('" . $this->gridId . $this->gridIdSuffix . "',
241  {
242  data: $(this).serialize() + '&" . $this->listModelClassName . "_page=&" . // Not Coding Standard
243  $this->listModelClassName . "_sort=" .
244  $this->getExtraQueryPartForSearchFormScriptSubmitFunction() ."' // Not Coding Standard
245  }
246  );
247  return false;
248  }
249  );");
250  }
251 
258  {
259  $script = "
260  var empty = $('#" . $this->getSearchFormId(). "').find('.anyMixedAttributes-input').val() == '';
261  $(this).closest('form').find('.search-view-1').find(':input').each(function()
262  {
263  if ($(this).val() != '')
264  {
265  empty = false;
266  }
267  });
268  if (!empty)
269  {
270  $('#clear-search-link" . $this->gridIdSuffix . "').show();
271  }
272  else
273  {
274  $('#clear-search-link" . $this->gridIdSuffix . "').hide();
275  }
276  ";
277  return $script;
278  }
279 
283  protected function renderFormBottomPanelExtraLinks()
284  {
285  return null;
286  }
287 
292  {
293  return null;
294  }
295 
300  {
301  $script = "
302  $('#" . $this->getSearchFormId(). "').find('.anyMixedAttributes-input').unbind('input.clear propertychange.clear keyup.clear');
303  $('#" . $this->getSearchFormId(). "').find('.anyMixedAttributes-input').bind('input.clear propertychange.clear keyup.clear', function(event)
304  {
305  $('#clear-search-link" . $this->gridIdSuffix . "').show();
306  });
307  ";
308  return $script;
309  }
310 
316  protected function renderFormLayout(ZurmoActiveForm $form)
317  {
318  $metadata = self::getMetadata();
319  $maxCellsPerRow = $this->getMaxCellsPerRow();
320  $content = "";
321  $content .= $this->renderSummaryCloneContent();
322  assert('count($metadata["global"]["panels"]) == 2 || count($metadata["global"]["panels"]) == 1');
323  foreach ($metadata['global']['panels'] as $key => $panel)
324  {
325  $startingDivStyle = "";
326  if ($key == 1 || $this->hideAllSearchPanelsToStart)
327  {
328  $startingDivStyle = "style='display:none;'";
329  }
330  $content .= '<div class="search-view-' . $key . '" ' . $startingDivStyle . '>';
331  if ($key == 1)
332  {
333  $content .= $this->renderAdvancedSearchForFormLayout($panel, $maxCellsPerRow, $form);
334  }
335  else
336  {
337  $content .= $this->renderStaticSearchRows($panel, $maxCellsPerRow, $form);
338  $content .= $this->renderStarredFilterHidenField($form);
339  }
340  if ($key == 1)
341  {
342  $content .= $this->renderViewToolBarContainerForAdvancedSearch($form);
343  }
344  $content .= '</div>';
345  }
346  $content .= $this->renderListAttributesSelectionContent($form);
347  $content .= $this->renderKanbanBoardOptionsContent($form);
348  $content .= $this->renderFiltersContent($form);
349  $content .= $this->renderFormBottomPanel();
350 
351  return $content;
352  }
353 
354  protected function renderSummaryCloneContent()
355  {
356  return ZurmoHtml::tag('div',
357  array(
358  'id' => $this->getListViewId() . '-summary-clone',
359  'class' => ExtendedGridView::CLONE_SUMMARY_CLASS,
360  ),
361  '');
362  }
363 
364  protected function getSelectListAttributesLinkContent()
365  {
366  if ($this->model->getListAttributesSelector() != null &&
367  ($this->model->getKanbanBoard() == null || !$this->model->getKanbanBoard()->getIsActive()))
368  {
369  return ZurmoHtml::link(Zurmo::t('Core', 'Columns'), '#', array('id' => 'select-list-attributes-link' . $this->gridIdSuffix));
370  }
371  }
372 
373  protected function renderListAttributesSelectionContent(ZurmoActiveForm $form)
374  {
375  if ($this->model->getListAttributesSelector() == null)
376  {
377  return;
378  }
379  Yii::app()->clientScript->registerScript('listAttributes' . $this->getSearchFormId(), "
380  $('#select-list-attributes-link" . $this->gridIdSuffix . "').unbind('click.more');
381  $('#select-list-attributes-link" . $this->gridIdSuffix . "').bind('click.more', function(event)
382  {
383  $(this).closest('form').find('.search-view-1').hide();
384  $(this).closest('form').find('.kanban-board-options-view').hide();
385  $('.select-list-attributes-view').toggle();
386  return false;
387  }
388  );
389  $('#list-attributes-reset').unbind('click.close');
390  $('#list-attributes-reset').bind('click.close', function()
391  {
392  $('.select-list-attributes-view').hide();
393  }
394  );
395  $('#list-attributes-apply').unbind('click.close');
396  $('#list-attributes-apply').bind('click.close', function()
397  {
398  $('.select-list-attributes-view').hide();
399  }
400  );
401  ");
402  $element = new ListAttributesSelectionElement($this->model, null, $form, array());
403  $element->editableTemplate = '{content}';
404  $content = $element->render();
405  return ZurmoHtml::tag('div', array('class' => 'select-list-attributes-view',
406  'style' => 'display:none'), $content);
407  }
408 
412  protected function getKanbanBoardOptionsLinkContent()
413  {
414  if ($this->model->getKanbanBoard() != null && $this->model->getKanbanBoard()->getIsActive())
415  {
416  return ZurmoHtml::link(Zurmo::t('Core', 'Options'), '#', array('id' => 'kanban-board-options-link' . $this->gridIdSuffix));
417  }
418  }
419 
425  {
426  if ($this->model->getKanbanBoard() == null || !$this->model->getKanbanBoard()->getIsActive())
427  {
428  return;
429  }
430  Yii::app()->clientScript->registerScript('kanbanBoardOptions' . $this->getSearchFormId(), "
431  $('#kanban-board-options-link" . $this->gridIdSuffix . "').unbind('click.more');
432  $('#kanban-board-options-link" . $this->gridIdSuffix . "').bind('click.more', function(event)
433  {
434  $(this).closest('form').find('.search-view-1').hide();
435  $('.select-list-attributes-view').hide();
436  $('.kanban-board-options-view').toggle();
437  return false;
438  }
439  );
440  $('#kanban-board-options-reset').unbind('click.close');
441  $('#kanban-board-options-reset').bind('click.close', function()
442  {
443  $('.kanban-board-options-view').hide();
444  }
445  );
446  $('#kanban-board-options-apply').unbind('click.close');
447  $('#kanban-board-options-apply').bind('click.close', function()
448  {
449  $('.kanban-board-options-view').hide();
450  }
451  );
452  ");
453  $element = new KanbanBoardOptionsElement($this->model, null, $form, array());
454  $element->editableTemplate = '{content}';
455  $content = $element->render();
456  return ZurmoHtml::tag('div', array('class' => 'kanban-board-options-view', 'style' => 'display:none'), $content);
457  }
458 
459  protected function renderViewToolBarContainerForAdvancedSearch($form)
460  {
461  $content = '<div class="view-toolbar-container clearfix">';
462  $content .= '<div class="form-toolbar">';
463  $content .= $this->renderViewToolBarLinksForAdvancedSearch($form);
464  $content .= '</div></div>';
465  return $content;
466  }
467 
468  protected function renderViewToolBarLinksForAdvancedSearch($form)
469  {
470  $params = array();
471  $params['label'] = Zurmo::t('Core', 'Search');
472  $params['htmlOptions'] = array('id' => 'search-advanced-search', 'onclick' => 'js:$(this).addClass("attachLoadingTarget");');
473  $searchElement = new SaveButtonActionElement(null, null, null, $params);
474  $content = $searchElement->render();
475  $closeButton = ZurmoHtml::link(ZurmoHtml::wrapLabel(Zurmo::t('Core', 'Close')),
476  '#', array('id' => 'cancel-advanced-search', 'class' => 'cancel-button'));
477  return $content . $closeButton;
478  }
479 
480  protected function renderSaveInputAndSaveButtonContentForAdvancedSearch($form)
481  {
482  }
483 
484  protected function renderAdvancedSearchForFormLayout($panel, $maxCellsPerRow, $form)
485  {
486  return $this->renderStaticSearchRows($panel, $maxCellsPerRow, $form);
487  }
488 
489  protected function renderStaticSearchRows($panel, $maxCellsPerRow, $form = null)
490  {
491  $content = null;
492  foreach ($panel['rows'] as $row)
493  {
494  $innerContent = null;
495  foreach ($row['cells'] as $cell)
496  {
497  if (!empty($cell['elements']))
498  {
499  foreach ($cell['elements'] as $elementInformation)
500  {
501  if (count($row['cells']) == 1 && count($row['cells']) < $maxCellsPerRow)
502  {
503  $elementInformation['wide'] = true;
504  }
505  $elementclassname = $elementInformation['type'] . 'Element';
506  $element = new $elementclassname($this->model, $elementInformation['attributeName'], $form, array_slice($elementInformation, 2));
507  $innerContent .= $element->render();
508  }
509  }
510  $content .= ZurmoHtml::tag('tr', array(), $innerContent);
511  }
512  }
513  return ZurmoHtml::tag('table', array(), $content);
514  }
515 
584  public static function getDefaultMetadata()
585  {
586  return array();
587  }
588 
589  protected function getColumnCount($metadata)
590  {
591  $columnCount = 1;
592  foreach ($metadata['panels'] as $panel)
593  {
594  foreach ($panel['rows'] as $row)
595  {
596  $tempCount = 0;
597  foreach ($row['cells'] as $cell)
598  {
599  $tempCount++;
600  }
601  if ($tempCount > $columnCount)
602  {
603  $columnCount = $tempCount;
604  }
605  }
606  }
607  return $columnCount;
608  }
609 
610  public static function getDesignerRulesType()
611  {
612  return 'SearchView';
613  }
614 
615  protected function getSearchFormId()
616  {
617  return 'search-form' . $this->gridIdSuffix;
618  }
619 
620  protected function getListViewId()
621  {
622  return $this->gridId . $this->gridIdSuffix;
623  }
624 
625  protected function getMaxCellsPerRow()
626  {
627  $designerRulesType = static::getDesignerRulesType();
628  $designerRulesClassName = $designerRulesType . 'DesignerRules';
629  $designerRules = new $designerRulesClassName();
630  return $designerRules->maxCellsPerRow();
631  }
632 
633  protected function renderModalContainer()
634  {
635  return ZurmoHtml::tag('div', array(
636  'id' => ModelElement::MODAL_CONTAINER_PREFIX . '-' . $this->getSearchFormId()
637  ), '');
638  }
639 
645  protected function renderStarredFilterHidenField($form)
646  {
647  $content = null;
648  if (StarredUtil::modelHasStarredInterface($this->model->getModel()))
649  {
650  $content .= $form->hiddenField($this->model, 'filterByStarred',
651  array('class' => $form->id . '_filterByStarred'));
652  }
653  return $content;
654  }
655 
661  protected function renderFiltersContent($form)
662  {
663  return null;
664  }
665  }
666 ?>
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
renderFormLayout(ZurmoActiveForm $form)
Definition: SearchView.php:316
static getDefaultMetadata()
Definition: SearchView.php:584
renderStarredFilterHidenField($form)
Definition: SearchView.php:645
renderFormBottomPanel()
Definition: SearchView.php:124
__construct($model, $listModelClassName, $gridIdSuffix=null, $hideAllSearchPanelsToStart=false)
Definition: SearchView.php:52
getExtraQueryPartForSearchFormScriptSubmitFunction()
Definition: SearchView.php:291
renderFiltersContent($form)
Definition: SearchView.php:661
getHideOrShowClearSearchLinkScript()
Definition: SearchView.php:257
getKanbanBoardOptionsLinkContent()
Definition: SearchView.php:412
renderFormBottomPanelExtraLinks()
Definition: SearchView.php:283
renderKanbanBoardOptionsContent(ZurmoActiveForm $form)
Definition: SearchView.php:424
getExtraRenderFormBottomPanelScriptPart()
Definition: SearchView.php:299
Generated on Wed Jul 1 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.