Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DynamicSearchRowView.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 DynamicSearchRowView extends View
41  {
42  protected $searchableAttributeIndicesAndDerivedTypes;
43 
44  protected $rowNumber;
45 
46  protected $suffix;
47 
48  protected $formModelClassName;
49 
50  protected $ajaxOnChangeUrl;
51 
52  protected $selectedAttribute;
53 
54  protected $inputContent;
55 
65  public function __construct($searchableAttributeIndicesAndDerivedTypes, $rowNumber,
66  $suffix, $formModelClassName, $ajaxOnChangeUrl, $selectedAttribute = null, $inputContent = null)
67  {
68  assert('is_array($searchableAttributeIndicesAndDerivedTypes)');
69  assert('is_int($rowNumber)');
70  assert('is_string($suffix) || $suffix == null');
71  assert('is_string($formModelClassName)');
72  assert('is_string($ajaxOnChangeUrl)');
73  assert('is_string($selectedAttribute) || $selectedAttribute == null');
74  assert('is_string($inputContent) || $inputContent == null');
75  $this->searchableAttributeIndicesAndDerivedTypes = $searchableAttributeIndicesAndDerivedTypes;
76  $this->rowNumber = $rowNumber;
77  $this->suffix = $suffix;
78  $this->formModelClassName = $formModelClassName;
79  $this->ajaxOnChangeUrl = $ajaxOnChangeUrl;
80  $this->selectedAttribute = $selectedAttribute;
81  $this->inputContent = $inputContent;
82  }
83 
84  public function render()
85  {
86  return $this->renderContent();
87  }
88 
89  protected function renderContent()
90  {
91  $this->renderScripts();
92  $hiddenInputName = $this->formModelClassName . '[' . DynamicSearchForm::DYNAMIC_NAME . '][' . $this->rowNumber . '][structurePosition]';
93  $hiddenInputId = $this->formModelClassName . '_' . DynamicSearchForm::DYNAMIC_NAME . '_' . $this->rowNumber . '_structurePosition';
94  $idInputHtmlOptions = array('id' => $hiddenInputId, 'class' => 'structure-position');
95 
96  $content = '<div>';
97  $content .= ZurmoHtml::wrapLabel(($this->rowNumber + 1) . '.', 'dynamic-search-row-number-label');
98  $content .= $this->renderAttributeDropDownContent();
99  $content .= ZurmoHtml::hiddenField($hiddenInputName, ($this->rowNumber + 1), $idInputHtmlOptions);
100  $content .= ZurmoHtml::tag('div', array('id' => $this->getInputsDivId(), 'class' => 'criteria-value-container'), $this->inputContent);
101  $content .= '</div>';
102  $content .= ZurmoHtml::link('—', '#', array('class' => 'remove-extra-dynamic-search-row-link'));
103  return $content;
104  }
105 
109  protected function renderScripts()
110  {
111  DropDownUtil::registerScripts(CClientScript::POS_END);
112  }
113 
114  protected function renderAttributeDropDownContent()
115  {
116  $name = $this->formModelClassName . '[' . DynamicSearchForm::DYNAMIC_NAME . '][' . $this->rowNumber . '][attributeIndexOrDerivedType]';
117  $id = $this->formModelClassName . '_' . DynamicSearchForm::DYNAMIC_NAME . '_' . $this->rowNumber . '_attributeIndexOrDerivedType';
118  $htmlOptions = array('id' => $id, 'class' => 'attribute-dropdown',
119  'empty' => Zurmo::t('ZurmoModule', 'Select a field')
120  );
121  Yii::app()->clientScript->registerScript('AttributeDropDown' . $id,
122  $this->renderAttributeDropDownOnChangeScript($id,
123  $this->getInputsDivId(),
124  $this->ajaxOnChangeUrl));
125  $content = ZurmoHtml::dropDownList($name,
126  $this->selectedAttribute,
127  $this->searchableAttributeIndicesAndDerivedTypes,
128  $htmlOptions);
129  Yii::app()->clientScript->registerScript('mappingExtraColumnRemoveLink', "
130  $('.remove-extra-dynamic-search-row-link').unbind('click');
131  $('.remove-extra-dynamic-search-row-link').bind('click', function()
132  {
133  formId = $(this).closest('form').attr('id');
134  $(this).parent().remove();
135  rebuildDynamicSearchRowNumbersAndStructureInput(formId);
136  resolveClearLinkPrefixLabelAndVisibility(formId);
137  }
138  );");
139  return $content;
140  }
141 
142  protected function renderAttributeDropDownOnChangeScript($id, $inputDivId, $ajaxOnChangeUrl)
143  {
144  // Begin Not Coding Standard
145  $ajaxSubmitScript = ZurmoHtml::ajax(array(
146  'type' => 'GET',
147  'data' => 'js:\'suffix=' . $this->suffix .
148  '&attributeIndexOrDerivedType=\' + $(this).val()',
149  'url' => $ajaxOnChangeUrl,
150  'beforeSend' => 'js:function(){
151  $("#' . $inputDivId . '").html("<span class=\"loading z-spinner\"></span>");
152  $(this).makeOrRemoveLoadingSpinner(true, "#' . $inputDivId . '", "dark");
153  }',
154  'success' => 'js:function(data){ $("#' . $inputDivId . '").html(data); }',
155  ));
156  return "$('#" . $id . "').unbind('change'); $('#" . $id . "').bind('change', function()
157  {
158  $ajaxSubmitScript
159  }
160  );";
161  // End Not Coding Standard
162  }
163 
164  protected function getInputsDivId()
165  {
166  return $this->formModelClassName . '-dynamic-search-inputs-for-' . $this->rowNumber . '-' . $this->suffix;
167  }
168  }
169 ?>
static wrapLabel($label, $class= 'z-label')
Definition: ZurmoHtml.php:656
__construct($searchableAttributeIndicesAndDerivedTypes, $rowNumber, $suffix, $formModelClassName, $ajaxOnChangeUrl, $selectedAttribute=null, $inputContent=null)
static dropDownList($name, $select, $data, $htmlOptions=array())
Definition: ZurmoHtml.php:627
Definition: View.php:43
Generated on Thu Aug 6 2020 07:10:36
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.