All Data Structures Functions Variables Pages
MarketingListResolveSubscribersFromCampaignView.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  const NOTIFICATION_BAR_ID = 'FlashMessageBar';
43 
44  public static function getDefaultMetadata()
45  {
46  $metadata = array(
47  'global' => array(
48  'toolbar' => array(
49  'elements' => array(
50  array('type' => 'SaveButton', 'label' => 'Retarget'),
51  ),
52  ),
53  'panelsDisplayType' => FormLayout::PANELS_DISPLAY_TYPE_ALL,
54  'panels' => array(
55  array(
56  'rows' => array(
57  array('cells' =>
58  array(
59  array(
60  'elements' => array(
61  array('attributeName' => 'marketingList', 'type' => 'MarketingList'),
62  ),
63  ),
64  )
65  ),
66  array('cells' =>
67  array(
68  array(
69  'elements' => array(
70  array('attributeName' => 'newMarketingListName', 'type' => 'Text'),
71  ),
72  ),
73  )
74  ),
75  array('cells' =>
76  array(
77  array(
78  'elements' => array(
79  array('attributeName' => 'retargetOpenedEmailRecipients', 'type' => 'CheckBox'),
80  ),
81  ),
82  )
83  ),
84  array('cells' =>
85  array(
86  array(
87  'elements' => array(
88  array('attributeName' => 'retargetClickedEmailRecipients', 'type' => 'CheckBox'),
89  ),
90  ),
91  )
92  ),
93  array('cells' =>
94  array(
95  array(
96  'elements' => array(
97  array('attributeName' => 'retargetNotViewedEmailRecipients', 'type' => 'CheckBox'),
98  ),
99  ),
100  )
101  ),
102  array('cells' =>
103  array(
104  array(
105  'elements' => array(
106  array('attributeName' => 'retargetNotClickedEmailRecipients', 'type' => 'CheckBox'),
107  ),
108  ),
109  )
110  ),
111  ),
112  ),
113  ),
114  ),
115  );
116  return $metadata;
117  }
118 
119  protected function renderAfterFormLayout($form)
120  {
121  parent::renderAfterFormLayout($form);
122  $this->registerSubscribeCampaignItemsToMarketingListScript($form);
123  $this->registerUpdateFlashBarScript($form);
124  }
125 
126  protected function resolveActiveFormAjaxValidationOptions()
127  {
128  $ajaxValidationOptions = array('enableAjaxValidation' => true,
129  'clientOptions' => array(
130  'validateOnSubmit' => true,
131  'validateOnChange' => false,
132  'beforeValidate' => 'js:$(this).beforeValidateAction',
133  'afterValidate' => 'js:$(this).afterValidateAjaxAction',
134  'afterValidateAjax' => '',
135  'inputContainer' => 'td',
136  ));
137  return array_merge($ajaxValidationOptions,
138  array('action' => $this->getSubscribeUrl()));
139  }
140 
141  protected function getValidateAndSaveUrl()
142  {
143  return Yii::app()->createUrl('/marketingLists/default/attemptToValidateAjaxSubscriberFormFromPost', $_GET);
144  }
145 
146  protected function registerSubscribeCampaignItemsToMarketingListScript($form)
147  {
148  // Begin Not Coding Standard
149  $unloadWindowMessage = Zurmo::t('MarketingListsModule',
150  'Are you sure you want to leave this page, remaining contacts will not be retargeted.');
151  $script = '$("#' . $form->getId() . '").submit(function(event){
152  event.preventDefault();
153  subscribeCampaignItemsToMarketingList(event, 0, 0, 0);
154  return false;
155  });
156 
157  function subscribeCampaignItemsToMarketingList(event, page, subscribedCount, skippedCount, marketingListId) {
158  marketingListId = marketingListId || null; // set default value
159  var notificationBarId = "' . static::NOTIFICATION_BAR_ID . '";
160  var url = "' . $this->getSubscribeUrl() . '&page=" + page + "&subscribedCount=" + subscribedCount + "&skippedCount=" + skippedCount;
161  if (marketingListId)
162  {
163  url = url + "&marketingListId=" + marketingListId;
164  }
165  var event = event;
166  var page = page;
167  var subscribedCount = subscribedCount;
168  var skippedCount = skippedCount;
169  var formId = "' . $form->getId() . '";
170  $.ajax(
171  {
172  url: url,
173  dataType: "json",
174  type: "post",
175  data: $("#" + formId).serialize(),
176  beforeSend: function(request, settings)
177  {
178  $(window).off("beforeunload");
179  $(window).on("beforeunload", function(){
180  return "' . $unloadWindowMessage . '";
181  });
182  event.preventDefault();
183  $(this).makeLargeLoadingSpinner(true, $("#' . $form->getId() . '").parent());
184  },
185  success: function(data, status, request)
186  {
187  updateFlashBar(data, notificationBarId);
188  if (data.nextPage)
189  {
190  subscribeCampaignItemsToMarketingList(event, data.nextPage, data.subscribedCount, data.skippedCount, data.marketingListId);
191  }
192  else if (data.redirectUrl)
193  {
194  $(window).off("beforeunload")
195  window.location = data.redirectUrl;
196  }
197  },
198  error: function(request, status, error)
199  {
200  var data = {' .
201  ' "message" : "' .
202  Zurmo::t('Core',
203  'There was an error processing your request'). '",
204  "type" : "error"
205  };
206  updateFlashBar(data, notificationBarId);
207  $(window).off("beforeunload");
208  },
209  complete: function(request, status)
210  {
211  $(this).makeLargeLoadingSpinner(false, $("#' . $form->getId() . '").parent());
212  $("#' . $form->getId() . ' span.z-spinner").text("");
213  return false;
214  }
215  }
216  );
217  }';
218  // End Not Coding Standard
219  Yii::app()->clientScript->registerScript('SubscribeCampaignItemsToMarketingList', $script);
220  }
221 
222  protected function registerUpdateFlashBarScript()
223  {
224  $scriptName = $this->getId() . '-updateFlashBar';
225  if (Yii::app()->clientScript->isScriptRegistered($scriptName))
226  {
227  return;
228  }
229  else
230  {
231  Yii::app()->clientScript->registerScript($scriptName, '
232  function updateFlashBar(data, flashBarId)
233  {
234  $("#" + flashBarId).jnotifyAddMessage(
235  {
236  text: data.message,
237  permanent: true,
238  showIcon: true,
239  type: data.type,
240  removeExisting: true
241  });
242  }
243  ');
244  }
245  }
246 
247  protected function getSubscribeUrl()
248  {
249  return Yii::app()->createUrl('/marketingLists/default/saveSubscribersFromCampaign', $_GET);
250  }
251 
252  protected function getAfterClickSubmitButtonScript()
253  {
254  return "subscribeCampaignItemsToMarketingList(event, 0, 0, 0);";
255  }
256 
257  protected function resolveElementDuringFormLayoutRender(& $element)
258  {
259  if ($element->getAttribute() == 'marketingList')
260  {
261  $title = Zurmo::t('MarketingListsModule', 'Add subscribers to existing marketing list. Please select either existing marketing list or enter name for new one, but not both!');
262  $content = '<span id="existing-marketing-list-tooltip" class="tooltip" title="' . $title . '">?</span>';
263  $qtip = new ZurmoTip();
264  $qtip->addQTip("#existing-marketing-list-tooltip");
265  $element->editableTemplate = '<th>{label}' . $content . '</th>' .
266  '<td colspan="{colspan}">{content}{error}</td>';
267  }
268  elseif ($element->getAttribute() == 'newMarketingListName')
269  {
270  $title = Zurmo::t('MarketingListsModule', 'Create new marketing list and add subscribers to it. Please select either existing marketing list or enter name for new one, but not both!');
271  $content = '<span id="new-marketing-list-tooltip" class="tooltip" title="' . $title . '">?</span>';
272  $qtip = new ZurmoTip();
273  $qtip->addQTip("#new-marketing-list-tooltip");
274  $element->editableTemplate = '<th>{label}' . $content . '</th>' .
275  '<td colspan="{colspan}">{content}{error}</td>';
276  }
277  }
278  }
279 ?>
getId()
Definition: View.php:155
Generated on Tue Jun 2 2020 07:10:33