Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
DropDownDependencyElement.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  {
47  protected $dropDownDependencyDerivedAttributeMetadata;
48 
49  protected function makeMetadata()
50  {
51  assert('$this->attribute != null');
52  assert('$this->model instanceof RedBeanModel');
53  $this->dropDownDependencyDerivedAttributeMetadata = DropDownDependencyDerivedAttributeMetadata::
54  getByNameAndModelClassName($this->attribute,
55  get_class($this->model));
56  }
57 
62  protected function renderEditable()
63  {
64  $this->makeMetadata();
65  return parent::renderEditable();
66  }
67 
72  protected function renderControlEditable()
73  {
74  $unserializedMetadata = unserialize($this->dropDownDependencyDerivedAttributeMetadata->serializedMetadata);
75  $onChangeScript = null;
76  $dependencyData = array();
77  $attributes = $this->dropDownDependencyDerivedAttributeMetadata->getUsedAttributeNames();
78  $content = "<table> \n";
79  $parentInputId = null;
80  $parentAttributeLabel = null;
81  foreach ($attributes as $position => $attribute)
82  {
83  $element = new DropDownElement($this->model,
84  $attribute,
85  $this->form,
86  array('addBlank' => true));
87 
88  $element->editableTemplate = $this->getEditableTemplate();
89  $content .= $element->render();
90  $inputId = $element->getIdForSelectInput();
91  $onChangeScript .= "$('#" . $inputId . "').bind('change', function()
92  {
93  " . $this->getDependencyManagerResolveScriptCall() . "
94  }
95  );";
96  $dependencyData[] = $this->resolveDependencyData($inputId,
97  $parentInputId,
98  $unserializedMetadata['mappingData'],
99  $position,
100  null,
101  $parentAttributeLabel);
102  $parentInputId = $inputId;
103  $parentAttributeLabel = $this->model->getAttributeLabel($attribute);
104  }
105  $content .= "</table> \n";
106  $this->resolveScriptContent($onChangeScript, $dependencyData);
107  return $content;
108  }
109 
110  protected static function resolveDependencyData($inputId, $parentInputId, $mappingData, $position,
111  $existingValue, $parentAttributeLabel)
112  {
113  assert('is_string($inputId)');
114  assert('$parentInputId == null || is_string($parentInputId)');
115  assert('is_array($mappingData)');
116  assert('is_int($position)');
117  assert('$existingValue == null || is_string($existingValue)');
118  assert('is_string($parentAttributeLabel) || $parentAttributeLabel == null');
119  $dependencyData = array();
120  $dependencyData['inputId'] = $inputId;
121  $dependencyData['parentInputId'] = $parentInputId;
122  $dependencyData['valueToAlwaysShow'] = $existingValue;
123  if ($parentAttributeLabel != null)
124  {
125  $dependencyData['notReadyToSelectText'] = ZurmoHtml::encode(Zurmo::t('Core', 'First select the {attributeLabel}',
126  array('{attributeLabel}' => $parentAttributeLabel)));
127  }
128  else
129  {
130  $dependencyData['notReadyToSelectText'] = null;
131  }
132  if (isset($mappingData[$position]['valuesToParentValues']))
133  {
134  $dependencyData['valuesToParentValues'] = $mappingData[$position]['valuesToParentValues'];
135  }
136  else
137  {
138  $dependencyData['valuesToParentValues'] = null;
139  }
140  return $dependencyData;
141  }
142 
143  protected function resolveScriptContent($onChangeScript, $dependencyData)
144  {
145  assert('is_string($onChangeScript)');
146  assert('is_array($dependencyData)');
147  Yii::app()->clientScript->registerScriptFile(
148  Yii::app()->getAssetManager()->publish(
149  Yii::getPathOfAlias('application.core.elements.assets')
150  ) . '/DropDownDependencyManager.js',
151  CClientScript::POS_END
152  );
153  $managerObjectName = $this->getDependencyManagerScriptObjectName();
154  $suffix = $this->getDependencyManagerScriptSuffix();
155  $script = "
156  var " . $managerObjectName . " = new DropDownDependencyManager('" . CJSON::encode($dependencyData) . "');
157  " . $this->getDependencyManagerResolveScriptCall() . ";";
158  Yii::app()->clientScript->registerScript(
159  'dropDownDependencyManager' . $suffix,
160  $script,
161  CClientScript::POS_END
162  );
163  Yii::app()->clientScript->registerScript(
164  'dropDownDependencyOnChange' . $suffix,
165  $onChangeScript,
166  CClientScript::POS_END
167  );
168  }
169 
170  protected function getDependencyManagerScriptObjectName()
171  {
172  return 'DependencyManager' . $this->getDependencyManagerScriptSuffix();
173  }
174 
175  protected function getDependencyManagerScriptSuffix()
176  {
177  return $this->dropDownDependencyDerivedAttributeMetadata->name;
178  }
179 
180  protected function getDependencyManagerResolveScriptCall()
181  {
182  return $this->getDependencyManagerScriptObjectName() . ".resolveOptions()";
183  }
184 
189  protected function renderNonEditable()
190  {
191  $this->makeMetadata();
192  return parent::renderNonEditable();
193  }
194 
199  protected function renderControlNonEditable()
200  {
201  $attributes = $this->dropDownDependencyDerivedAttributeMetadata->getUsedAttributeNames();
202  $content = null;
203  foreach ($attributes as $attribute)
204  {
205  $element = new DropDownElement($this->model,
206  $attribute,
207  $this->form);
208  $element->nonEditableTemplate = $this->getNonEditableTemplate();
209  if ($content != null)
210  {
211  $content .= ' &rarr; ';
212  }
213  $content .= $element->render();
214  }
215  return $content;
216  }
217 
222  protected function renderLabel()
223  {
224  $content = $this->dropDownDependencyDerivedAttributeMetadata->getLabelByLanguage(Yii::app()->language);
225  if ($this->form === null)
226  {
227  return Yii::app()->format->text($content);
228  }
229  return ZurmoHtml::tag('label', array(), $content);
230  }
231 
236  protected function renderError()
237  {
238  return null;
239  }
240 
241  protected function getEditableTemplate()
242  {
243  $template = "<tr><td style='border:0px;' nowrap='nowrap'>\n";
244  $template .= "{label}";
245  $template .= "</td><td width='100%' style='border:0px;'>\n";
246  $template .= '&#160;{content}{error}';
247  $template .= "</td></tr>\n";
248  return $template;
249  }
250 
251  protected function getNonEditableTemplate()
252  {
253  return "{content}";
254  }
255  }
256 ?>
static encode($text)
Definition: ZurmoHtml.php:47
static getByNameAndModelClassName($name, $modelClassName)
Generated on Wed Jul 8 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.