Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
EmailTemplateElement.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 
45  {
46  const DISABLE_DROPDOWN_WHEN_AJAX_IN_PROGRESS = true;
47 
48  const DISABLE_TEXTBOX_WHEN_AJAX_IN_PROGRESS = true;
49 
50  const NOTIFICATION_BAR_ID = 'FlashMessageBar';
51 
52  public $editableTemplate = '<th>{label}</th><td colspan="{colspan}"><div class="has-model-select">{content}</div>{error}</td>';
53 
54  protected static $moduleId = 'emailTemplates';
55 
56  protected $name;
57 
58  protected $id;
59 
60  public function __construct($model, $attribute, $form = null, array $params = array())
61  {
62  parent::__construct($model, $attribute, $form, $params);
63  if ($this->attribute == 'null')
64  {
65  $this->attribute = 'contactEmailTemplateNames';
66  $this->name = '';
67  $this->id = '';
68  }
69  else
70  {
71  $this->name = parent::getName();
72  $this->id = parent::getId();
73  }
74  }
75 
82  protected function renderControlEditable()
83  {
84  $this->registerScripts();
85  return $this->renderEditableContent();
86  }
87 
88  protected function wrapHasModelSelectInput(& $content)
89  {
90  }
91 
92  protected function getName()
93  {
94  return $this->name;
95  }
96 
97  protected function getId()
98  {
99  return $this->id;
100  }
101 
102  protected function registerScripts()
103  {
104  $this->registerUpdateFlashBarScript();
105  $this->registerChangeHandlerScript();
106  }
107 
108  protected function registerChangeHandlerScript()
109  {
110  $hiddenId = $this->getIdForHiddenField();
111  $scriptName = $hiddenId . '_changeHandler';
112  if (Yii::app()->clientScript->isScriptRegistered($scriptName))
113  {
114  return;
115  }
116  else
117  {
118  // Begin Not Coding Standard
119  Yii::app()->clientScript->registerScript($scriptName, '
120  function updateContentElementsWithData(textContentElement, htmlContentElement, subjectElement, data)
121  {
122  if ($(".tabs-nav > a:first").hasClass("active-tab"))
123  {
124  $(".tabs-nav > a:eq(1)").click();
125  }
126  updateElementWithData(textContentElement, data.textContent);
127  $(subjectElement).parent().children("label").css("display", "none");
128  updateElementWithData(subjectElement, data.subject);
129  $(htmlContentElement).redactor("set", data.htmlContent);
130  $(htmlContentElement).redactor("toggle");
131  $(htmlContentElement).redactor("toggle");
132  var contentHeight = $(".redactor_box iframe").contents().find("html").outerHeight();
133  $(".redactor_box iframe").height(contentHeight + 50);
134  }
135 
136  function updateElementWithData(element, data)
137  {
138  if ($(element).attr("type") == "text")
139  {
140  $(element).val(data);
141  }
142  else
143  {
144  $(element).html(data);
145  }
146  }
147 
148  function deleteExistingAttachments()
149  {
150  $("div.attributesContainer div.panel .form-fields div.fileupload-content table.files tr.template-download td.name span.upload-actions.delete button.icon-delete:first")
151  .click();
152  $("div.attributesContainer div.panel .form-fields div.fileupload-content table.files tr.template-download")
153  .remove();
154  }
155 
156  function updateAddFilesWithDataFromAjax(filesIds, notificationBarId)
157  {
158  if (filesIds != "")
159  {
160  var url = "' . $this->getCloneExitingFilesUrl() . '";
161  var templateId = "#' . FileUpload::DOWNLOAD_TEMPLATE_ID .'";
162  var targetClass = ".files";
163  var filesIdsString = filesIds.join();
164  $.ajax(
165  {
166  url: url,
167  dataType: "json",
168  data:
169  {
170  commaSeparatedExistingModelIds: filesIdsString
171  },
172  success: function(data, status, request)
173  {
174  $(templateId).tmpl(data).appendTo(targetClass);
175  },
176  error: function(request, status, error)
177  {
178  var data = {' . // Not Coding Standard
179  ' "message" : "' . Zurmo::t('Core',
180  'There was an error processing your request') .
181  '",
182  "type" : "error"
183  };
184  updateFlashBar(data, notificationBarId);
185  },
186  }
187  );
188  }
189  }
190  $("#' . $hiddenId . '").unbind("change.action").bind("change.action", function(event, ui)
191  {
192  selectedOptionValue = $(this).val();
193  if (selectedOptionValue)
194  {
195  var dropDown = $(this);
196  var notificationBarId = "' . static::NOTIFICATION_BAR_ID . '";
197  var url = "' . $this->getEmailTemplateDetailsJsonUrl() . '";
198  var disableDropDown = "' . static::DISABLE_DROPDOWN_WHEN_AJAX_IN_PROGRESS . '";
199  var disableTextBox = "' . static::DISABLE_TEXTBOX_WHEN_AJAX_IN_PROGRESS. '";
200  var textContentId = "' . $this->getTextContentId() . '";
201  var htmlContentId = "' . $this->getHtmlContentId() . '";
202  var subjectId = "' . $this->getSubjectId() . '";
203  var subjectElement = $("#" + subjectId);
204  var textContentElement = $("#" + textContentId);
205  var htmlContentElement = $("#" + htmlContentId);
206  var contactId = ' . $this->getContactId() . ';
207  var redActorElement = $("#" + htmlContentId).parent().find(".redactor_editor");
208  $.ajax(
209  {
210  url: url,
211  dataType: "json",
212  data:
213  {
214  id: selectedOptionValue,
215  renderJson: true,
216  includeFilesInJson: true,
217  contactId: contactId
218  },
219  beforeSend: function(request, settings)
220  {
221  $(this).makeLargeLoadingSpinner(true, ".email-template-content");
222  if (disableDropDown == true)
223  {
224  $(dropDown).attr("disabled", "disabled");
225  }
226  if (disableTextBox == true)
227  {
228  $(textContentElement).attr("disabled", "disabled");
229  $(htmlContentElement).attr("disabled", "disabled");
230  $(subjectElement).attr("disabled", "disabled");
231  $(redActorElement).hide();
232  }
233  deleteExistingAttachments();
234  },
235  success: function(data, status, request)
236  {
237  $(this).makeLargeLoadingSpinner(false, ".email-template-content");
238  $(".email-template-content .big-spinner").remove();
239  updateContentElementsWithData(textContentElement,
240  htmlContentElement,
241  subjectElement,
242  data);
243  subjectElement.focus();
244  updateAddFilesWithDataFromAjax(data.filesIds, notificationBarId);
245  },
246  error: function(request, status, error)
247  {
248  var data = {' . // Not Coding Standard
249  ' "message" : "' . Zurmo::t('Core',
250  'There was an error processing your request') .
251  '",
252  "type" : "error"
253  };
254  updateFlashBar(data, notificationBarId);
255  },
256  complete: function(request, status)
257  {
258  $(dropDown).removeAttr("disabled");
259  $(dropDown).val("");
260  $(textContentElement).removeAttr("disabled");
261  $(htmlContentElement).removeAttr("disabled");
262  $(subjectElement).removeAttr("disabled");
263  $(redActorElement).show();
264  event.preventDefault();
265  return false;
266  }
267  }
268  );
269  }
270  }
271  );
272  ');
273  // End Not Coding Standard
274  }
275  }
276 
277  protected function registerUpdateFlashBarScript()
278  {
279  if (Yii::app()->clientScript->isScriptRegistered('handleUpdateFlashBar'))
280  {
281  return;
282  }
283  else
284  {
285  Yii::app()->clientScript->registerScript('handleUpdateFlashBar', '
286  function updateFlashBar(data, flashBarId)
287  {
288  $("#" + flashBarId).jnotifyAddMessage(
289  {
290  text: data.message,
291  permanent: false,
292  showIcon: true,
293  type: data.type
294  });
295  }
296  ');
297  }
298  }
299 
300  protected function renderLabel()
301  {
302  $label = Zurmo::t('EmailTemplatesModule', 'Select a template');
303  if ($this->form === null)
304  {
305  return $label;
306  }
307  $id = $this->getIdForTextField();
308  return ZurmoHtml::tag('label',
309  array('for' => $id),
310  $label);
311  }
312 
313  protected function renderError()
314  {
315  return null;
316  }
317 
318  protected function getEditableHtmlOptions()
319  {
320  $prompt = array('prompt' => Zurmo::t('EmailTemplatesModule', 'Select a template'));
321  $parentHtmlOptions = parent::getEditableHtmlOptions();
322  $htmlOptions = CMap::mergeArray($parentHtmlOptions, $prompt);
323  return $htmlOptions;
324  }
325 
326  protected function getEmailTemplateDetailsJsonUrl()
327  {
328  return Yii::app()->createUrl('/emailTemplates/default/detailsJson');
329  }
330 
331  protected function getTextContentId()
332  {
333  return $this->getEditableInputId(EmailTemplateHtmlAndTextContentElement::TEXT_CONTENT_INPUT_NAME);
334  }
335 
336  protected function getSubjectId()
337  {
338  return $this->getEditableInputId('subject');
339  }
340 
341  protected function getHtmlContentId()
342  {
343  return $this->getEditableInputId(EmailTemplateHtmlAndTextContentElement::HTML_CONTENT_INPUT_NAME);
344  }
345 
346  protected function getCloneExitingFilesUrl()
347  {
348  return Yii::app()->createUrl('/zurmo/fileModel/cloneExistingFiles');
349  }
350 
351  protected function getContactId()
352  {
353  return 'null';
354  }
355 
356  protected function getAutoCompleteUrlParams()
357  {
358  return array('type' => EmailTemplate::TYPE_CONTACT);
359  }
360 
361  protected function getSelectLinkUrlParams()
362  {
363  return array_merge(parent::getSelectLinkUrlParams(),
364  array('stateMetadataAdapterClassName' => 'EmailTemplatesForMarketingStateMetadataAdapter'));
365  }
366 
367  protected function getNameForHiddenField()
368  {
369  return '';
370  }
371 
372  protected function getNameForTextField()
373  {
374  return '';
375  }
376  }
377 ?>
getEditableInputId($attributeName=null, $relationAttributeName=null)
Definition: Element.php:277
Generated on Sun Oct 25 2020 07:10:29
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.