Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.
 All Data Structures Functions Variables Pages
MarketingListMemberSelectAutoCompleteBaseElement.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  const DISABLE_TEXT_BOX_WHEN_AJAX_IN_PROGRESS = true;
40 
41  const DISABLE_RADIO_BUTTON_WHEN_AJAX_IN_PROGRESS = true;
42 
43  const NOTIFICATION_BAR_ID = 'FlashMessageBar';
44 
45  public $editableTemplate = '<td colspan="{colspan}">{content}</td>';
46 
47  abstract protected function getSelectType();
48 
49  protected function getSubscribeUrl()
50  {
51  return Yii::app()->createUrl('/' . Yii::app()->getController()->getModule()->getId() . '/' .
52  'defaultPortlet/subscribeContacts/');
53  }
54 
55  protected function getWidgetValue()
56  {
57  return null;
58  }
59 
60  protected function getHtmlOptions()
61  {
62  return CMap::mergeArray(parent::getHtmlOptions(), array('onfocus' => '$(this).val("");'));
63  }
64 
69  protected function renderControlNonEditable()
70  {
71  throw new NotSupportedException();
72  }
73 
74  protected function renderControlEditable()
75  {
76  $this->registerScripts();
77  return parent::renderControlEditable();
78  }
79 
80  protected function getOptions()
81  {
82  return array(
83  'autoFill' => false,
84  'select' => $this->getWidgetSelectActionJS(),
85  'search' => 'js:function(event, ui) { $(this).makeOrRemoveTogglableSpinner(true, $(this).parent()) }',
86  'open' => 'js:function(event, ui) { $(this).makeOrRemoveTogglableSpinner(false, $(this).parent()) }',
87  'close' => 'js:function(event, ui) { $(this).makeOrRemoveTogglableSpinner(false, $(this).parent()) }',
88  'response' => 'js:function(event, ui)
89  {
90  if (ui.content.length < 1)
91  {
92  $(this).makeOrRemoveTogglableSpinner(false, $(this).parent());
93  }
94  }'
95  );
96  }
97 
98  protected function getWidgetSelectActionJS()
99  {
100  // Begin Not Coding Standard
101  return 'js: function(event, ui)
102  {
103  subscribeContactsToMarketingList' . $this->getSelectType() . ' ($(this), event, ui.item.id, 1, 0, 0)
104  }';
105  // End Not Coding Standard
106  }
107 
108  protected function registerScripts()
109  {
110  $this->registerSubscribeContactsAjaxScript();
111  $scriptName = $this->getListViewGridId() . '-updateFlashBar';
112  if (Yii::app()->clientScript->isScriptRegistered($scriptName))
113  {
114  return;
115  }
116  else
117  {
118  Yii::app()->clientScript->registerScript($scriptName, '
119  function updateFlashBar(data, flashBarId)
120  {
121  $("#" + flashBarId).jnotifyAddMessage(
122  {
123  text: data.message,
124  permanent: true,
125  showIcon: true,
126  type: data.type,
127  removeExisting: true
128  });
129  }
130  ');
131  }
132  }
133 
134  protected function registerSubscribeContactsAjaxScript()
135  {
136  // Begin Not Coding Standard
137  $script = 'function subscribeContactsToMarketingList' . $this->getSelectType() . ' (object, event, itemId, page, subscribedCount, skippedCount) {
138  var searchBox = object;
139  var listGridViewId = "' . $this->getListViewGridId() .'";
140  var notificationBarId = "' . static::NOTIFICATION_BAR_ID . '";
141  var radioButtonClass = "' . $this->getRadioButtonClass() . '";
142  var url = "' . $this->getSubscribeUrl() . '";
143  var modelId = "' . $this->getModelId() . '";
144  var selectType = "' . $this->getSelectType() . '";
145  var disableTextBox = "' . static::DISABLE_TEXT_BOX_WHEN_AJAX_IN_PROGRESS . '";
146  var disableRadioButton = "' . static::DISABLE_RADIO_BUTTON_WHEN_AJAX_IN_PROGRESS . '";
147  var event = event;
148  var itemId = itemId;
149  var page = page;
150  var subscribedCount = subscribedCount;
151  var skippedCount = skippedCount;
152  $.ajax(
153  {
154  url: url,
155  dataType: "json",
156  data: {
157  marketingListId: modelId,
158  id: itemId,
159  type: selectType,
160  page: page,
161  subscribedCount: subscribedCount,
162  skippedCount: skippedCount
163  },
164  beforeSend: function(request, settings)
165  {
166  $(searchBox).makeSmallLoadingSpinner(listGridViewId);
167 - $("#" + listGridViewId).addClass("loading");
168  if (disableTextBox == true)
169  {
170  $(searchBox).attr("disabled", "disabled");
171  }
172  if (disableRadioButton == true)
173  {
174  $("." + radioButtonClass).attr("disabled", "disabled");
175  }
176  },
177  success: function(data, status, request)
178  {
179  refreshMembersListGridView("' . $this->getListViewGridId() . '");
180  updateFlashBar(data, notificationBarId);
181  //todo: this is only a check if reporting.
182  if (data.nextPage)
183  {
184  subscribeContactsToMarketingList' . $this->getSelectType() . '
185  (object, event, itemId, data.nextPage, data.subscribedCount, data.skippedCount);
186  }
187  },
188  error: function(request, status, error)
189  {
190  var data = {' . // Not Coding Standard
191  ' "message" : "' .
192  Zurmo::t('Core',
193  'There was an error processing your request'). '",
194  "type" : "error"
195  };
196  updateFlashBar(data, notificationBarId);
197  },
198  complete: function(request, status)
199  {
200  $(searchBox).removeAttr("disabled");
201  $(searchBox).val("");
202  $("." + radioButtonClass).removeAttr("disabled");
203  $("#" + listGridViewId).removeClass("loading");
204  event.preventDefault();
205  return false;
206  }
207  }
208  );
209  }';
210  // End Not Coding Standard
211  Yii::app()->clientScript->registerScript('SubscribeContactsToMarketingListAjaxScript' . $this->getSelectType(), $script);
212  }
213 
214  protected function getModelId()
215  {
216  $marketingListId = ArrayUtil::getArrayValue($this->params, 'marketingListId');
217  if (!isset($marketingListId))
218  {
219  if (!isset($this->model))
220  {
221  throw new NotSupportedException();
222  }
223  else
224  {
225  $marketingListId = $this->model->id;
226  }
227  }
228  return $marketingListId;
229  }
230 
231  protected function getRadioButtonClass()
232  {
233  return ArrayUtil::getArrayValueWithExceptionIfNotFound($this->params, 'radioButtonClass');
234  }
235 
236  protected function getAfterChangeSelectIdScript()
237  {
238  return "subscribeContactsToMarketingList{$this->getSelectType()} ($(this), event, $(this).val(), 1, 0, 0);";
239  }
240 
241  protected function shouldRenderSelectLinkDefault()
242  {
243  return true;
244  }
245  }
246 ?>
static getArrayValue($array, $element, $defaultValue=null)
Definition: ArrayUtil.php:45
static getArrayValueWithExceptionIfNotFound($array, $element)
Definition: ArrayUtil.php:72
Generated on Sun Nov 29 2020 07:10:26
Account Suspended
Account Suspended
This Account has been suspended.
Contact your hosting provider for more information.