All Data Structures Functions Variables Pages
AnyContactSelectForEmailMatchingView.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 
41  {
42  protected $controllerId;
43 
44  protected $moduleId;
45 
46  protected $model;
47 
48  protected $uniqueId;
49 
54  protected $saveActionId;
55 
60  protected $urlParameters;
61 
65  public function __construct($controllerId, $moduleId, $model, $uniqueId, $saveActionId, $urlParameters)
66  {
67  assert('$model != null');
68  assert('$model instanceof AnyContactSelectForm || $model instanceof ContactSelectForm || $model instanceof LeadSelectForm');
69  assert('is_string($uniqueId) || is_int($uniqueId)');
70  assert('is_string($saveActionId)');
71  assert('is_array($urlParameters)');
72  $this->controllerId = $controllerId;
73  $this->moduleId = $moduleId;
74  $this->model = $model;
75  $this->uniqueId = $uniqueId;
76  $this->saveActionId = $saveActionId;
77  $this->urlParameters = $urlParameters;
78  }
79 
84  protected function renderContent()
85  {
86  $this->renderScriptsContent();
87  $content = '<div class="wide form">';
88  $clipWidget = new ClipWidget();
89  $afterValidateAjax = $this->renderConfigSaveAjax($this->getFormId());
90  list($form, $formStart) = $clipWidget->renderBeginWidget(
91  'ZurmoActiveForm',
92  array(
93  'id' => $this->getFormId(),
94  'action' => $this->getValidateAndSaveUrl(),
95  'enableAjaxValidation' => true,
96  'clientOptions' => array(
97  'validateOnSubmit' => true,
98  'validateOnChange' => false,
99  'beforeValidate' => 'js:$(this).beforeValidateAction',
100  'afterValidate' => 'js:$(this).afterValidateAjaxAction',
101  'afterValidateAjax' => $afterValidateAjax,
102  ),
103  )
104  );
105  $content .= $formStart;
106  $content .= $this->renderFormLayout($form);
107  $formEnd = $clipWidget->renderEndWidget();
108  $content .= $formEnd;
109  $content .= $this->renderModalContainer();
110  $content .= '</div>';
111  return $content;
112  }
113 
114  protected function renderFormLayout($form = null)
115  {
116  $content = '<table>';
117  $content .= TableUtil::getColGroupContent(1);
118  $content .= '<tbody>';
119  $content .= '<tr>';
120  if ($this->model instanceof AnyContactSelectForm)
121  {
122  $elementClassName = 'AnyContactNameIdElement';
123  }
124  elseif ($this->model instanceof ContactSelectForm)
125  {
126  $elementClassName = 'ContactNameIdElement';
127  }
128  else
129  {
130  $elementClassName = 'LeadNameIdElement';
131  }
132  $params = array();
133  $params['inputPrefix'] = array(get_class($this->model), $this->uniqueId);
134  $element = new $elementClassName($this->model, 'null', $form, $params);
135  $content .= $element->render();
136  $content .= '</tr>';
137  $content .= '</tbody>';
138  $content .= '</table>';
139  $content .= '<div class="view-toolbar-container clearfix"><div class="form-toolbar">';
140  $cancelElement = new CancelLinkForEmailsMatchingListActionElement($this->controllerId, $this->moduleId,
141  null,
142  array('htmlOptions' =>
143  array('name' => 'anyContactCancel-' . $this->uniqueId,
144  'id' => 'anyContactCancel-' . $this->uniqueId,
145  'class' => 'anyContactCancel')));
146  $content .= $cancelElement->render();
147  $element = new SaveButtonActionElement($this->controllerId, $this->moduleId,
148  null,
149  array('htmlOptions' =>
150  array('name' => 'ContactSelect-' . $this->uniqueId,
151  'id' => 'ContactSelect-' . $this->uniqueId)));
152  $content .= $element->render();
153  $content .= '</div></div>';
154  return $content;
155  }
156 
157  protected function renderScriptsContent()
158  {
159  Yii::app()->clientScript->registerScript('anyContactSelectFormCollapseActions', "
160  $('.anyContactCancel').each(function()
161  {
162  $('.anyContactCancel').live('click', function()
163  {
164  $(this).parentsUntil('.email-archive-item').find('.AnyContactSelectForEmailMatchingView').hide();
165  $(this).closest('.email-archive-item').closest('td').removeClass('active-panel')
166  .find('.z-action-link-active').removeClass('z-action-link-active');
167  });
168  });");
169  }
170 
171  protected function getFormId()
172  {
173  return 'select-contact-form-' . $this->uniqueId;
174  }
175 
176  protected function getValidateAndSaveUrl()
177  {
178  return Yii::app()->createUrl($this->moduleId . '/' . $this->controllerId . '/' . $this->saveActionId, $this->urlParameters);
179  }
180 
181  protected function renderConfigSaveAjax($formName)
182  {
183  // Begin Not Coding Standard
184  return ZurmoHtml::ajax(array(
185  'type' => 'POST',
186  'data' => 'js:$("#' . $formName . '").serialize()',
187  'url' => $this->getValidateAndSaveUrl(),
188  'complete' => "function(XMLHttpRequest, textStatus){
189  $('#wrapper-" . $this->uniqueId . "').parent().parent().parent().remove();
190  $('#" . self::getNotificationBarId() . "').jnotifyAddMessage(
191  {
192  text: '" . Zurmo::t('ContactsModule', 'Selected successfully') . "',
193  permanent: false,
194  showIcon: true,
195  });
196  if ($('.email-archive-item').length==0)
197  {
198  window.location.reload();
199  }
200  }",
201  ));
202  // End Not Coding Standard
203  }
204 
205  public function isUniqueToAPage()
206  {
207  return false;
208  }
209 
210  protected function getViewStyle()
211  {
212  return " style=' display:none;'";
213  }
214 
215  protected static function getNotificationBarId()
216  {
217  return 'FlashMessageBar';
218  }
219 
220  protected function renderModalContainer()
221  {
222  return ZurmoHtml::tag('div', array(
223  'id' => ModelElement::MODAL_CONTAINER_PREFIX . '-' . static::getFormId()
224  ), '');
225  }
226  }
227 ?>
__construct($controllerId, $moduleId, $model, $uniqueId, $saveActionId, $urlParameters)
Generated on Fri Jun 5 2020 07:10:30