_dataObj) {
$idSlide = (int) $_REQUEST['idSlide'];
if (!$idSlide) {
$this->_dataObj = null;
} else {
$this->_dataObj->setIdSlide($idSlide);
}
}
return $this->_dataObj;
}
protected function _doEdit()
{
if ('image' != $this->dataObj->getSlideData('type')) {
$this->doc->displayError(
'Only "Image" type slides support "hot spots" function.'
. '
« Back to list'
);
return false;
}
$item = array();
$this->dataObj->initData();
$item['tpl'] = 'Slide/spot_form.tpl';
$item['slide'] = $this->dataObj->getSlideData();
$item['pages'] = App_Cms_Obj::getInstance()->getParent4Select(0);
$options = array();
$options['cancelUrl'] = $this->_getBackUrl(PARENT_PAGE);
$options['spotsList'] = $this->dataObj->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/jquery-ui.css')
->addStylesheet('css/admin-slide.css')
->addScript('js/app/admin-slide.js')
->addInitFunction('initAppSlideSpotForm', array($options));
return $this;
}
public function _doSave()
{
return $this->_doSaveAjax();
}
protected function _doSaveAjax()
{
$data = $_REQUEST;
if (true === ($errors = $this->_isValid($data))) {
$this->dataObj->save($data);
$data = array('status' => 'ok');
} 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['idPage'][$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)) ? true : $errors;
}
}