39 const DISABLE_TEXT_BOX_WHEN_AJAX_IN_PROGRESS =
true;
41 const DISABLE_RADIO_BUTTON_WHEN_AJAX_IN_PROGRESS =
true;
43 const NOTIFICATION_BAR_ID =
'FlashMessageBar';
45 public $editableTemplate =
'<td colspan="{colspan}">{content}</td>';
47 abstract protected function getSelectType();
49 protected function getSubscribeUrl()
51 return Yii::app()->createUrl(
'/' . Yii::app()->getController()->getModule()->getId() .
'/' .
52 'defaultPortlet/subscribeContacts/');
55 protected function getWidgetValue()
60 protected function getHtmlOptions()
62 return CMap::mergeArray(parent::getHtmlOptions(), array(
'onfocus' =>
'$(this).val("");'));
74 protected function renderControlEditable()
76 $this->registerScripts();
77 return parent::renderControlEditable();
80 protected function getOptions()
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)
90 if (ui.content.length < 1)
92 $(this).makeOrRemoveTogglableSpinner(false, $(this).parent());
98 protected function getWidgetSelectActionJS()
101 return 'js: function(event, ui)
103 subscribeContactsToMarketingList' . $this->getSelectType() .
' ($(this), event, ui.item.id, 1, 0, 0)
108 protected function registerScripts()
110 $this->registerSubscribeContactsAjaxScript();
111 $scriptName = $this->getListViewGridId() .
'-updateFlashBar';
112 if (Yii::app()->clientScript->isScriptRegistered($scriptName))
118 Yii::app()->clientScript->registerScript($scriptName,
'
119 function updateFlashBar(data, flashBarId)
121 $("#" + flashBarId).jnotifyAddMessage(
134 protected function registerSubscribeContactsAjaxScript()
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 .
'";
150 var subscribedCount = subscribedCount;
151 var skippedCount = skippedCount;
157 marketingListId: modelId,
161 subscribedCount: subscribedCount,
162 skippedCount: skippedCount
164 beforeSend: function(request, settings)
166 $(searchBox).makeSmallLoadingSpinner(listGridViewId);
167 - $("#" + listGridViewId).addClass("loading");
168 if (disableTextBox == true)
170 $(searchBox).attr("disabled", "disabled");
172 if (disableRadioButton == true)
174 $("." + radioButtonClass).attr("disabled", "disabled");
177 success: function(data, status, request)
179 refreshMembersListGridView("' . $this->getListViewGridId() .
'");
180 updateFlashBar(data, notificationBarId);
181 //todo: this is only a check if reporting.
184 subscribeContactsToMarketingList' . $this->getSelectType() .
'
185 (object, event, itemId, data.nextPage, data.subscribedCount, data.skippedCount);
188 error: function(request, status, error)
193 'There was an error processing your request').
'",
196 updateFlashBar(data, notificationBarId);
198 complete: function(request, status)
200 $(searchBox).removeAttr("disabled");
201 $(searchBox).val("");
202 $("." + radioButtonClass).removeAttr("disabled");
203 $("#" + listGridViewId).removeClass("loading");
204 event.preventDefault();
211 Yii::app()->clientScript->registerScript(
'SubscribeContactsToMarketingListAjaxScript' . $this->getSelectType(), $script);
214 protected function getModelId()
217 if (!isset($marketingListId))
219 if (!isset($this->model))
225 $marketingListId = $this->model->id;
228 return $marketingListId;
231 protected function getRadioButtonClass()
236 protected function getAfterChangeSelectIdScript()
238 return "subscribeContactsToMarketingList{$this->getSelectType()} ($(this), event, $(this).val(), 1, 0, 0);";
241 protected function shouldRenderSelectLinkDefault()
static getArrayValue($array, $element, $defaultValue=null)
renderControlNonEditable()
static getArrayValueWithExceptionIfNotFound($array, $element)