All Data Structures Functions Variables Pages
AddressElement.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 
43  {
44  public $breakLines = true;
45 
52  protected function renderControlNonEditable()
53  {
54  assert('$this->model->{$this->attribute} instanceof Address');
55  $addressModel = $this->model->{$this->attribute};
56  $id = $addressModel->id;
57  $street1 = $addressModel->street1;
58  $street2 = $addressModel->street2;
59  $city = $addressModel->city;
60  $state = $addressModel->state;
61  $postalCode = $addressModel->postalCode;
62  $country = $addressModel->country;
63  $latitude = $addressModel->latitude;
64  $longitude = $addressModel->longitude;
65  $invalid = $addressModel->invalid;
66  $content = null;
67  if (!empty($street1))
68  {
69  $content .= Yii::app()->format->text($street1);
70  $content .= $this->resolveHtmlAndTextBreakLine();
71  }
72  if (!empty($street2))
73  {
74  $content .= Yii::app()->format->text($street2);
75  $content .= $this->resolveHtmlAndTextBreakLine();
76  }
77  if (!empty($city))
78  {
79  $content .= Yii::app()->format->text($city) . ' ';
80  }
81  if (!empty($state))
82  {
83  $content .= Yii::app()->format->text($state);
84  }
85  if (!empty($state) && !empty($postalCode))
86  {
87  $content .= ',&#160;';
88  }
89  if (!empty($postalCode))
90  {
91  $content .= Yii::app()->format->text($postalCode);
92  }
93  if (!empty($country))
94  {
95  $content .= $this->resolveHtmlAndTextBreakLine() . Yii::app()->format->text($country);
96  }
97  if (!$invalid && $addressModel->makeAddress() != '')
98  {
99  $content = $this->renderMapLink($addressModel, $content);
100  }
101  return $content;
102  }
103 
110  protected function renderControlEditable()
111  {
112  assert('$this->model->{$this->attribute} instanceof Address');
113  $addressModel = $this->model->{$this->attribute};
114  $content = $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'street1') .
115  $this->resolveTextBreakLine();
116  $content .= $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'street2') .
117  $this->resolveTextBreakLine();
118  $content .= $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'city') .
119  $this->resolveTextBreakLine();
120  $content .= '<div class="hasHalfs">';
121  $content .= $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'state', true) .
122  $this->resolveTextBreakLine();;
123  $content .= $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'postalCode', true) .
124  $this->resolveTextBreakLine();
125  $content .= '</div>';
126  $content .= $this->renderEditableAddressTextField($addressModel, $this->form, $this->attribute, 'country') .
127  $this->resolveTextBreakLine();
128  return '<div class="address-fields">' . $content . '</div>';
129  }
130 
131  protected function renderEditableAddressTextField($model, $form, $inputNameIdPrefix, $attribute,
132  $renderAsHalfSize = false)
133  {
134  $id = $this->getEditableInputId($inputNameIdPrefix, $attribute);
135  $htmlOptions = array(
136  'name' => $this->getEditableInputName($inputNameIdPrefix, $attribute),
137  'id' => $id,
138  'encode' => false,
139  );
140  $label = $form->labelEx ($model, $attribute, array('for' => $id));
141  $textField = $form->textField($model, $attribute, $htmlOptions);
142  $error = $form->error ($model, $attribute, array('inputID' => $id), true, true,
143  $this->renderScopedErrorId($inputNameIdPrefix, $attribute));
144  if ($model->$attribute != null)
145  {
146  $label = null;
147  }
148  $halfClassString = null;
149  if ($renderAsHalfSize)
150  {
151  $halfClassString = ' half';
152  }
153  return ZurmoHtml::tag('div', array('class' => 'overlay-label-field' . $halfClassString), $label . $textField . $error);
154  }
155 
161  protected function renderMapLink($addressModel, $addressLine)
162  {
163  assert('$addressModel instanceof Address');
164  Yii::app()->getClientScript()->registerScriptFile(
165  Yii::app()->getAssetManager()->publish(
166  Yii::getPathOfAlias('application.core.elements.assets')
167  ) . '/Modal.js',
168  CClientScript::POS_END
169  );
170  $mapRenderUrl = Yii::app()->mappingHelper->resolveMappingLinkUrl(array(
171  'addressString' => $addressModel->makeAddress(),
172  'latitude' => $addressModel->latitude,
173  'longitude' => $addressModel->longitude));
174  $id = $this->getEditableInputId($this->attribute, 'MapLink');
175  $content = ZurmoHtml::ajaxLink($addressLine, $mapRenderUrl,
176  $this->resolveAjaxOptionsForMapLink(),
177  array('id' => $id, 'class' => 'icon-map')
178  );
179  return $content;
180  }
181 
182  protected function resolveAjaxOptionsForMapLink()
183  {
184  return ModalView::getAjaxOptionsForModalLink(strval($this->model));
185  }
186 
187  protected function renderError()
188  {
189  }
190 
191  protected function renderLabel()
192  {
193  return $this->resolveNonActiveFormFormattedLabel($this->getFormattedAttributeLabel());
194  }
195 
196  protected function resolveHtmlAndTextBreakLine()
197  {
198  if ($this->breakLines)
199  {
200  return "<br/>\n";
201  }
202  return ' ';
203  }
204 
205  protected function resolveTextBreakLine()
206  {
207  if ($this->breakLines)
208  {
209  return "\n";
210  }
211  return ' ';
212  }
213 
218  public static function getModelAttributeNames()
219  {
220  return array('street1',
221  'street2',
222  'city',
223  'state',
224  'postalCode',
225  'country',
226  'latitude',
227  'longitude');
228  }
229  }
230 ?>
static ajaxLink($text, $url, $ajaxOptions=array(), $htmlOptions=array())
Definition: ZurmoHtml.php:328
static getModelAttributeNames()
renderMapLink($addressModel, $addressLine)
Generated on Sat Feb 22 2020 07:10:34