All Data Structures Functions Variables Pages
GlobalSearchView.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  class GlobalSearchView extends View
41  {
42  protected $moduleNamesAndLabelsAndAll;
43 
44  protected $sourceUrl;
45 
50  public function __construct($moduleNamesAndLabelsAndAll, $sourceUrl)
51  {
52  assert('is_array($moduleNamesAndLabelsAndAll)');
53  assert('is_string($sourceUrl)');
54  $this->moduleNamesAndLabelsAndAll = $moduleNamesAndLabelsAndAll;
55  $this->sourceUrl = $sourceUrl;
56  }
57 
61  public function render()
62  {
63  return $this->renderContent();
64  }
65 
66  protected function renderContent()
67  {
68  $searchBoxId = $this->getSearchBoxId();
69  $contentPrefix = $this->getContentPrefix();
70  return $this->renderSearchView($searchBoxId, $contentPrefix);
71  }
72 
73  protected function getContentPrefix()
74  {
75  return null;
76  }
77 
78  protected function getSearchBoxId()
79  {
80  return 'app-search';
81  }
82 
83  protected function renderSearchView($searchBoxId, $contentPrefix = null)
84  {
85  $globalSearchContent = $this->renderGlobalSearchContent();
86  $spinner = ZurmoHtml::tag('span', array('class' => 'z-spinner'), '');
87  $searchBox = ZurmoHtml::tag('div', array('id' => $searchBoxId, 'class' => 'clearfix'),
88  $globalSearchContent . $spinner);
89  $content = $contentPrefix . $searchBox;
90  return $content;
91  }
92 
93  protected function renderGlobalSearchContent()
94  {
95  if (count($this->moduleNamesAndLabelsAndAll) == 1)
96  {
97  return null;
98  }
99  $content = $this->renderGlobalSearchScopingInputContent();
100  $hintMessage = Zurmo::t('ZurmoModule', 'Search by name, phone, or e-mail');
101  $htmlOptions = array('class' => 'global-search global-search-hint',
102  'onfocus' => '$(this).removeClass("global-search-hint"); $(this).val("");',
103  'onblur' => '$(this).val("")');
104  $cClipWidget = new CClipWidget();
105  $cClipWidget->beginClip('GlobalSearchElement');
106  $cClipWidget->widget('zii.widgets.jui.CJuiAutoComplete', array(
107  'name' => 'globalSearchInput',
108  'id' => 'globalSearchInput',
109  'value' => $hintMessage,
110  'source' => $this->sourceUrl,
111  'htmlOptions' => $htmlOptions,
112  'options' => array('select' => 'js: function(event, ui) {if (ui.item.href.length > 0)' .
113  '{window.location = ui.item.href;} return false;}',
114  'search' => 'js: function(event, ui) { $(this).makeOrRemoveTogglableSpinner(true, "#app-search") }',
115  'open' => 'js: function(event, ui) { $(this).makeOrRemoveTogglableSpinner(false, "#app-search") }',
116  'position' => array('my' => 'right top', 'at' => 'right bottom')
117  )));
118  $cClipWidget->endClip();
119  $content .= $cClipWidget->getController()->clips['GlobalSearchElement'];
120  // Begin Not Coding Standard
121  $script = ' $("#globalSearchInput").data( "ui-autocomplete" )._renderItem = function( ul, item ) {
122  return $( "<li></li>" ).data( "item.autocomplete", item )
123  .append( "<a><span class=" + item.iconClass + "></span><span>" + item.label + "</span></a>" )
124  .appendTo( ul );
125  };';
127  Yii::app()->clientScript->registerScript('GlobalSearchElementPosition', $script);
128  return $content;
129  }
130 
132  {
133  $cClipWidget = new CClipWidget();
134  $cClipWidget->beginClip("ScopedJuiMultiSelect");
135  $cClipWidget->widget('application.core.widgets.ScopedSearchJuiMultiSelect', array(
136  'dataAndLabels' => $this->moduleNamesAndLabelsAndAll,
137  'selectedValue' => 'All',
138  'inputId' => 'globalSearchScope',
139  'inputName' => 'globalSearchScope',
140  'options' => array(
141  'selectedText' => '',
142  'noneSelectedText' => '', 'header' => false,
143  'position' => array('my' => 'right top', 'at' => 'right bottom')),
144  'htmlOptions' => array('class' => 'ignore-style')
145  ));
146  $cClipWidget->endClip();
147  $content = $cClipWidget->getController()->clips['ScopedJuiMultiSelect'];
148  // Begin Not Coding Standard
149  $script = '$("#globalSearchInput").bind("focus", function(event, ui){
150  $("#globalSearchInput").autocomplete("option", "source", "' . $this->sourceUrl . '?" + $.param($("#globalSearchScope").serializeArray()));
151  });
152  ';
154  Yii::app()->clientScript->registerScript('GlobalSearchScopeChanges', $script);
155  return $content;
156  }
157  }
158 ?>
__construct($moduleNamesAndLabelsAndAll, $sourceUrl)
Definition: View.php:43
Generated on Thu Apr 2 2020 07:10:47