_setMessage($message, static::MSG_LOCKED);
$this->_setMessage('Hot spots have been updated', static::MSG_UPDATED);
$this->_getDataObj()->setSlideId(Qs_Request::getRequestValue('slideId'));
$this->_pageHeaderTemplates['headerEdit'] = 'Edit Slide\'s Hot Spots';
$this->_getDataObj()->setResourceName($this->_getDataObj()->getResourceName() . 'HotSpot');
return $this;
}
public function exec()
{
$this->_initBackUrl();
if (true !== $this->getConfig('hasHotSpots')) {
$this->_setBackAttention('Hot Sports are disabled');
parent::_doCancel();
}
return parent::exec();
}
protected function _doEdit()
{
if (!$this->_lock()) {
$this->_setBackUrl($this->_getBackUrl(PARENT_PAGE));
$this->_setBackAttention($this->_createMessage(static::MSG_LOCKED, $this->_getLocker()));
$this->_doBack();
}
if ('image' != $this->_getDataObj()->getSlideData('type')) {
$this->_doc->displayError(
'Only "Image" type slides support "hot spots" function.'
. '
« Back to list'
);
return false;
}
$item = array();
$this->_getDataObj()->initData();
$item['tpl'] = 'Slide/spot_form.tpl';
$item['slide'] = $this->_getDataObj()->getSlideData();
$item['pages'] = App_Cms_Obj::getInstance()->getPages4Select();
$options = array();
$options['cancelUrl'] = $this->url(array('action' => 'cancel', 'slideId' => $this->_getDataObj()->getSlideId()));
$options['spotsList'] = $this->_getDataObj()->getData();
$options['containerWidth'] = $item['slide']['width'];
$options['containerHeight'] = $item['slide']['height'];
$options['slideId'] = $item['slide']['id'];
$this->_addItem($item);
$this->_doc->addScript('js/jquery-ui.js')
->addStylesheet('css/thirdpart/jquery-ui.css')
->addScript('js/app/admin-slide.js')
->addInitFunction('initAppSlideSpotForm', array($options));
$this->_log();
return $this;
}
public function _doSave()
{
$this->_doSaveAjax();
}
protected function _doSaveAjax()
{
if ($this->_isLocked()) {
$data = array('isLocked' => true, 'error' => $this->_createMessage(static::MSG_LOCKED, $this->_getLocker()));
} else {
$data = $_REQUEST;
if (true === ($errors = $this->_isValid($data))) {
$this->_getDataObj()->save($data);
$data = array('status' => 'ok', 'backUrl' => $this->_getBackUrl());
$this->_log();
$this->_setBackMessage(static::MSG_UPDATED);
} else {
$data = array('status' => 'fail', 'errors' => $errors);
}
}
$this->_displayJson($data);
}
protected function _isValid($data)
{
$errors = array();
if (is_array($data['urlType']) && !empty($data['urlType'])) {
foreach ($data['urlType'] as $index => $urlType) {
if ($urlType == 'page' && intval($data['pageId'][$index]) == 0) {
$errors[$index] = 'Please select page.';
break;
}
if ($urlType == 'url') {
if ($data['url'][$index] == '') {
$errors[$index] = 'Url is required.';
break;
} else if (!preg_match('/^(http|ftp)s?:\/\/.+$/', $data['url'][$index])) {
$errors[$index] = 'Url is in wrong format.';
break;
}
}
}
}
return empty($errors) ?: $errors;
}
protected function _initBackUrl()
{
$this->_setBackUrl($this->_getBackUrl(PARENT_PAGE));
return $this;
}
}