Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
EmailTemplateWizardView.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 
37  abstract class EmailTemplateWizardView extends WizardView
38  {
39  protected $containingViews;
40 
44  public static function getModuleId()
45  {
46  return 'emailTemplates';
47  }
48 
49  protected static function resolveContainingViewClassNames()
50  {
51  throw new NotImplementedException();
52  }
53 
57  public function getTitle()
58  {
59  return Zurmo::t('EmailTemplatesModule', 'Email Template Wizard');
60  }
61 
62  protected function resolveContainingViews(WizardActiveForm $form)
63  {
64  if (!isset($this->containingViews))
65  {
66  $this->initContainingViews($form);
67  }
68  return $this->containingViews;
69  }
70 
71  protected function initContainingViews(WizardActiveForm $form)
72  {
73  $viewClassNames = static::resolveContainingViewClassNames();
74  $views = array();
75  foreach ($viewClassNames as $id => $view)
76  {
77  $views[] = new $view($this->model, $form, (bool)$id);
78  }
79  $this->containingViews = $views;
80  }
81 
82  protected function renderAfterFormContent()
83  {
84  $content = parent::renderAfterFormContent();
85  return $content . $this->renderElementEditContainerAndContent();
86  }
87 
88  protected function renderElementEditContainerAndContent()
89  {
90  $editFormContent = $this->resolveEditFormContent();
91  $content = ZurmoHtml::tag('div', array('id' => BuilderCanvasWizardView::ELEMENT_EDIT_CONTAINER_ID,
92  'style' => 'display:none'),
93  $editFormContent);
94  return $content;
95  }
96 
97  protected function resolveEditFormContent()
98  {
99  $content = ZurmoHtml::tag('div', array('id' => BuilderCanvasWizardView::ELEMENT_EDIT_FORM_OVERLAY_CONTAINER_ID), '');
100  return $content;
101  }
102 
106  protected static function getStartingValidationScenario()
107  {
108  return EmailTemplateWizardForm::GENERAL_DATA_VALIDATION_SCENARIO;
109  }
110 
111  protected function renderContainingViews(WizardActiveForm $form)
112  {
113  $views = $this->resolveContainingViews($form);
114  $rows = count($views);
115  $gridView = new GridView($rows, 1);
116  foreach ($views as $row => $view)
117  {
118  $gridView->setView($view, $row, 0);
119  }
120  $content = $gridView->render();
121  return $content;
122  }
123 
124  protected function renderConfigSaveAjax($formName)
125  {
126  assert('is_string($formName)');
127  $script = "linkId = $('#" . $formName . "').find('.attachLoadingTarget').attr('id');";
128  $script .= $this->renderTreeViewAjaxScriptContentForMergeTagsView();
129  $viewClassNames = static::resolveContainingViewClassNames();
130  $progressPerStep = $this->resolveProgressPerStep();
131  $validationInputId = static::getValidationScenarioInputId();
132  foreach ($viewClassNames as $id => $viewClassName)
133  {
134  $script .= $this->resolveNextPageScript($formName, $viewClassName,
135  $validationInputId, $progressPerStep, $id);
136  $this->registerPreviousPageScript($viewClassName, $validationInputId, $progressPerStep, $id);
137  }
138  return $script;
139  }
140 
141  protected function resolveSaveRedirectToListUrl()
142  {
143  $action = $this->resolveListActionByEmailTemplateType();
144  return Yii::app()->createUrl(static::getModuleId() . '/' . static::getControllerId() . '/' . $action);
145  }
146 
147  protected function getFormActionUrl()
148  {
149  return Yii::app()->createUrl(static::getModuleId() . '/' . static::getControllerId() . '/save',
150  array('builtType' => $this->model->builtType));
151  }
152 
153  protected function resolveListActionByEmailTemplateType()
154  {
155  $action = 'ListForMarketing';
156  if (Yii::app()->request->getQuery('type') == EmailTemplate::TYPE_WORKFLOW)
157  {
158  $action = 'ListForWorkflow';
159  }
160  return $action;
161  }
162 
163  protected function renderTreeViewAjaxScriptContentForMergeTagsView()
164  {
165  if ($this->model->isWorkflowTemplate())
166  {
167  $view = new MergeTagsView('EmailTemplate',
168  get_class($this->model) . '_textContent',
169  get_class($this->model) . '_htmlContent', false); //todo: get these last 2 values dynamically
170  $view->modelClassNameSelector = GeneralDataForEmailTemplateWizardView::
171  resolveModelClassNameHiddenInputJQuerySelector();
172  return $view->renderTreeViewAjaxScriptContent();
173  }
174  }
175 
176  protected function resolveNextPageScript($formName, $viewClassName, $validationInputId, $progressPerStep, $stepCount)
177  {
178  $scriptPrefix = 'if';
179  if ($stepCount)
180  {
181  $scriptPrefix = 'else if'; // Not Coding Standard
182  }
183  $ajaxOptions = $this->resolveAdditionalAjaxOptions($formName, $viewClassName, $validationInputId,
184  $progressPerStep, $stepCount);
185  $nextPageLinkId = $viewClassName::getNextPageLinkId();
186  $redirectAfterSave = $viewClassName::redirectAfterSave();
187  $script = $this->getSaveAjaxString($formName, $redirectAfterSave, $ajaxOptions);
188  // Begin Not Coding Standard
189  $script = $scriptPrefix . " (linkId == '" . $nextPageLinkId . "')
190  {
191  " . $script . "
192  }";
193  // End Not Coding Standard
194  return $script;
195  }
196 
197  protected function resolveAdditionalAjaxOptions($formName, $viewClassName, $validationInputId,
198  $progressPerStep, $stepCount)
199  {
200  $nextPageClassName = static::resolveNextPageClassName($stepCount);
201  $ajaxOptions = $viewClassName::resolveAdditionalAjaxOptions($formName, $validationInputId,
202  $progressPerStep, $stepCount, $nextPageClassName, $this->model);
203  return $ajaxOptions;
204  }
205 
206  protected function registerPreviousPageScript($viewClassName, $validationInput, $progressPerStep, $stepCount)
207  {
208  $previousPageLinkId = $viewClassName::getPreviousPageLinkId();
209  $scriptName = "clickflow." . $previousPageLinkId;
210  $eventName = "click." . $previousPageLinkId;
211  $previousPageClassName = static::resolvePreviousPageClassName($stepCount);
212  if (!isset($previousPageClassName))
213  {
214  $script = $this->resolvePreviousPageScriptForFirstStep($previousPageLinkId);
215  }
216  else
217  {
218  $script = $this->resolvePreviousPageScriptForStep($viewClassName, $previousPageClassName, $validationInput, $progressPerStep, $stepCount);
219  }
220 
221  $script = "
222  $('#" . $previousPageLinkId . "').unbind('" . $eventName . "').bind('" . $eventName . "', function()
223  {
224  " . $script . "
225  });";
226  Yii::app()->clientScript->registerScript($scriptName, $script);
227  }
228 
229  protected function resolvePreviousPageScriptForFirstStep()
230  {
231  $script = "
232  url = '" . $this->resolveSaveRedirectToListUrl() . "';
233  window.location.href = url;
234  return false;";
235  return $script;
236  }
237 
238  protected function resolvePreviousPageScriptForStep($viewClassName, $previousPageClassName, $validationInputId,
239  $progressPerStep, $stepCount)
240  {
241  $validationScenario = $previousPageClassName::resolveValidationScenario();
242  $progress = $stepCount * $progressPerStep;
243  $script = "
244  $('#" . $validationInputId . "').val('" . $validationScenario . "');
245  $('#" . $previousPageClassName . "').show();
246  $('#" . $viewClassName . "').hide();
247  $('.StepsAndProgressBarForWizardView').find('.progress-bar').width('" . $progress ."%');
248  $('.StepsAndProgressBarForWizardView').find('.current-step').removeClass('current-step')
249  .prev().addClass('current-step');
250  return false;
251  ";
252  $viewClassName::resolvePreviousPageScript($script);
253  return $script;
254  }
255 
256  protected function resolveProgressPerStep()
257  {
258  return (100 / (count(static::resolveContainingViewClassNames())));
259  }
260 
261  protected function registerClickFlowScript()
262  {
263  // this is here just because its abstract in parent.
264  }
265 
266  protected function resolveNextPageClassName($currentId)
267  {
268  return ArrayUtil::getArrayValue(static::resolveContainingViewClassNames(), $currentId + 1 );
269  }
270 
271  protected function resolvePreviousPageClassName($currentId)
272  {
273  return ArrayUtil::getArrayValue(static::resolveContainingViewClassNames(), $currentId - 1 );
274  }
275 
276  protected function wrapContentInDiv(& $content, $htmlOptions = array())
277  {
278  $content = ZurmoHtml::tag('div', $htmlOptions, $content);
279  }
280  }
281 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
getSaveAjaxString($formName, $redirectAfterSave=true, array $additionalAjaxOptions=array())
Definition: WizardView.php:281
Generated on Sat Aug 15 2020 07:10:30
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.