All Data Structures Functions Variables Pages
CampaignEditView.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 
38  {
39  public static function getDefaultMetadata()
40  {
41  $metadata = array(
42  'global' => array(
43  'toolbar' => array(
44  'elements' => array(
45  array('type' => 'SaveButton', 'label' => 'eval:static::renderLabelForSaveButton()',
46  'htmlOptions' => 'eval:static::resolveHtmlOptionsForSaveButton()'),
47  array('type' => 'CancelLink'),
48  array('type' => 'SendTestEmailLink'),
49  array('type' => 'CampaignDeleteLink'),
50  ),
51  ),
52  'panels' => array(
53  array(
54  'rows' => array(
55  array('cells' =>
56  array(
57  array(
58  'elements' => array(
59  array('attributeName' => 'name', 'type' => 'Text'),
60  ),
61  ),
62  )
63  ),
64  array('cells' =>
65  array(
66  array(
67  'elements' => array(
68  array('attributeName' => 'marketingList', 'type' => 'MarketingList'),
69  ),
70  ),
71  )
72  ),
73  array('cells' =>
74  array(
75  array(
76  'elements' => array(
77  array('attributeName' => 'fromName', 'type' => 'Text'),
78  ),
79  ),
80  )
81  ),
82  array('cells' =>
83  array(
84  array(
85  'elements' => array(
86  array('attributeName' => 'fromAddress', 'type' => 'Email'),
87  ),
88  ),
89  )
90  ),
91  array('cells' =>
92  array(
93  array(
94  'elements' => array(
95  array('attributeName' => 'sendOnDateTime', 'type' => 'DateTime'),
96  ),
97  ),
98  )
99  ),
100  array('cells' =>
101  array(
102  array(
103  'elements' => array(
104  array('attributeName' => 'subject', 'type' => 'Text'),
105  ),
106  ),
107  )
108  ),
109  array('cells' =>
110  array(
111  array(
112  'elements' => array(
113  array('attributeName' => 'enableTracking',
114  'type' => 'EnableTrackingCheckBox'),
115  ),
116  ),
117  )
118  ),
119  array('cells' =>
120  array(
121  array(
122  'elements' => array(
123  array('attributeName' => 'supportsRichText',
124  'type' => 'SupportsRichTextCheckBox'),
125  ),
126  ),
127  )
128  ),
129  array('cells' =>
130  array(
131  array(
132  'elements' => array(
133  array('attributeName' => 'null', 'type' => 'EmailTemplate')
134  ),
135  ),
136  )
137  ),
138  array('cells' =>
139  array(
140  array(
141  'elements' => array(
142  array('attributeName' => 'null', 'type' => 'Files'),
143  ),
144  ),
145  )
146  ),
147  ),
148  ),
149  ),
150  ),
151  );
152  return $metadata;
153  }
154 
155  protected function renderContent()
156  {
157  $this->registerCopyInfoFromMarketingListScript();
158  $this->registerRedactorHeightScript();
159  $this->registerSendTestEmailScriptsForEditView();
160  return parent::renderContent();
161  }
162 
163  protected function renderAfterFormLayout($form)
164  {
165  $content = $this->renderHtmlAndTextContentElement($this->model, null, $form);
166  return ZurmoHtml::tag('div', array('class' => 'email-template-combined-content left-column strong-right clearfix'), $content);
167  }
168 
169  protected function renderHtmlAndTextContentElement($model, $attribute, $form)
170  {
171  $content = null;
172  if (!$this->isCampaignEditable())
173  {
174  $element = new EmailTemplateHtmlAndTextContentElement($model, $attribute);
175  }
176  else
177  {
178  $content .= ZurmoHtml::tag('div', array('class' => 'left-column'), $this->renderMergeTagsContent());
179  $element = new EmailTemplateHtmlAndTextContentElement($model, $attribute , $form);
180  $element->plugins = array('fontfamily', 'fontsize', 'fontcolor');
181  }
182  if ($form !== null)
183  {
184  $this->resolveElementDuringFormLayoutRender($element);
185  }
186  $content .= ZurmoHtml::tag('div', array('class' => 'email-template-combined-content right-column'), $element->render());
187  return $content;
188  }
189 
190  protected function renderMergeTagsContent()
191  {
192  $title = ZurmoHtml::tag('h3', array(), Zurmo::t('Default', 'Merge Tags'));
193  $view = new MergeTagsView('Campaign',
194  Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'textContent')),
195  Element::resolveInputIdPrefixIntoString(array(get_class($this->model), 'htmlContent')),
196  false);
197  $content = $view->render();
198  return $title . $content;
199  }
200 
204  protected function resolveElementInformationDuringFormLayoutRender(& $elementInformation)
205  {
206  if (!$this->isCampaignEditable() && $elementInformation['attributeName'] != 'name')
207  {
208  $elementInformation['disabled'] = true;
209  }
210  }
211 
212  protected function resolveElementDuringFormLayoutRender(& $element)
213  {
214  if ($this->alwaysShowErrorSummary())
215  {
216  $element->editableTemplate = str_replace('{error}', '', $element->editableTemplate);
217  }
218  }
219 
220  protected function alwaysShowErrorSummary()
221  {
222  return true;
223  }
224 
225  protected function getNewModelTitleLabel()
226  {
227  return Zurmo::t('Default', 'Create AutorespondersModuleSingularLabel',
229  }
230 
231  protected function registerCopyInfoFromMarketingListScript()
232  {
233  $url = Yii::app()->createUrl('marketingLists/default/getInfoToCopyToCampaign');
234  // Begin Not Coding Standard
235  Yii::app()->clientScript->registerScript('copyInfoFromMarketingListScript', "
236  $('#Campaign_marketingList_id').live('change', function()
237  {
238  if ($('#Campaign_marketingList_id').val())
239  {
240  $.ajax(
241  {
242  url : '" . $url . "?id=' + $('#Campaign_marketingList_id').val(),
243  type : 'GET',
244  dataType: 'json',
245  success : function(data)
246  {
247  $('#Campaign_fromName').val(data.fromName);
248  $('#Campaign_fromAddress').val(data.fromAddress)
249  },
250  error : function()
251  {
252  //todo: error call
253  }
254  }
255  );
256  }
257  }
258  );
259  ");
260  // End Not Coding Standard
261  }
262 
263  protected function registerRedactorHeightScript()
264  {
265  /*Yii::app()->clientScript->registerScript('redactorHeightScript', '
266  var contentHeight = $(".redactor_box iframe").contents().find("html").outerHeight();
267  $(".redactor_box iframe").height(contentHeight + 50);');*/
268  }
269 
270  protected function isCampaignEditable()
271  {
272  return ($this->model->status == Campaign::STATUS_ACTIVE);
273  }
274 
275  protected function renderLabelForSaveButton()
276  {
277  if ($this->model->isAttributeEditable('sendOnDateTime'))
278  {
279  return Zurmo::t("CampaignsModule", "Save and Schedule");
280  }
281  else
282  {
283  Zurmo::t('Core', 'Save');
284  }
285  }
286 
292  protected function resolveHtmlOptionsForSaveButton()
293  {
294  if ($this->model->status == Campaign::STATUS_ACTIVE)
295  {
296  return null;
297  }
298  else
299  {
300  return array('style' => 'display: none');
301  }
302  }
303 
304  protected function renderRightSideFormLayoutForEdit($form)
305  {
306  assert('$form instanceof ZurmoActiveForm');
307  $content = "<h3>".Zurmo::t('ZurmoModule', 'Rights and Permissions') . '</h3><div id="owner-box">';
308  if($this->model->isAttributeEditable('owner'))
309  {
310  $element = new UserElement($this->getModel(), 'owner', $form);
311  }
312  else
313  {
314  $element = new UserElement($this->getModel(), 'owner', $form, array('disabled' => true));
315  }
316  $element->editableTemplate = '{label}{content}{error}';
317  $content .= $element->render().'</div>';
318  $element = new CampaignDerivedExplicitReadWriteModelPermissionsElement($this->getModel(), 'null', $form);
319  $element->editableTemplate = '{label}{content}{error}';
320  $content .= $element->render();
321  return $content;
322  }
323 
324  protected function registerSendTestEmailScriptsForEditView()
325  {
326  $scriptName = $this->modelClassName. '-compile-send-test-email-data-for-campaign-edit-view';
327  if (Yii::app()->clientScript->isScriptRegistered($scriptName))
328  {
329  return;
330  }
331  else
332  {
333  $functionName = SendTestEmailModalEditView::COMPILE_SEND_TEST_EMAIL_DATA_JS_FUNCTION_NAME;
334  // Begin Not Coding Standard
335  Yii::app()->clientScript->registerScript($scriptName, "
336  window.{$functionName} = function ()
337  {
338  var textContent, htmlContent;
339  if ($('#" . ZurmoHtml::activeId($this->model, 'textContent') . "').length > 0) {
340  textContent = $('#" . ZurmoHtml::activeId($this->model, 'textContent') . "').val();
341  }
342  else
343  {
344  textContent = $('.email-template-textContent').text();
345  }
346 
347  if ($('#" . ZurmoHtml::activeId($this->model, 'htmlContent') . "').length > 0) {
348  htmlContent = $('#" . ZurmoHtml::activeId($this->model, 'htmlContent') . "').val();
349  }
350  else
351  {
352  htmlContent = $('.email-template-htmlContent iframe').contents().find('html').html()
353  }
354 
355  var testData = {
356  fromName : $('#" . ZurmoHtml::activeId($this->model, 'fromName') . "').val(),
357  fromAddress : $('#" . ZurmoHtml::activeId($this->model, 'fromAddress') . "').val(),
358  subject : $('#" . ZurmoHtml::activeId($this->model, 'subject') . "').val(),
359  textContent : textContent,
360  htmlContent : htmlContent,
361  marketingListId : $('#" . ZurmoHtml::activeId($this->model, '_marketingList_id') . "').val(),
362  enableTracking : $('input:checkbox[name*=enableTracking]').prop('checked') ? 1 : 0,
363  supportsRichText : $('input:checkbox[name*=supportsRichText]').prop('checked') ? 1 : 0,
364  attachmentIds : new Array()
365  };
366  $(':input[name*=filesIds]').each(function()
367  {
368  testData.attachmentIds.push($(this).val());
369  });
370  return testData;
371  }
372  ");
373  // End Not Coding Standard
374  }
375  }
376  }
377 ?>
static getTranslationParamsForAllModules()
Definition: LabelUtil.php:75
resolveElementInformationDuringFormLayoutRender(&$elementInformation)
Generated on Tue Jan 28 2020 07:10:15