From 63e900aeac4c2434301cfcfec992175e858cc951 Mon Sep 17 00:00:00 2001 From: mMarinetti Date: Tue, 15 Nov 2011 16:47:18 +0000 Subject: [PATCH] [+] BO : #PSFV-94 - AdminScenes is now an AdminController // improvement of form.tpl (shop) --- admin-dev/tabs/AdminScenes.php | 246 ---------------- .../themes/template/helper/form/form.tpl | 90 +++--- controllers/admin/AdminScenesController.php | 263 ++++++++++++++++++ 3 files changed, 309 insertions(+), 290 deletions(-) delete mode 100644 admin-dev/tabs/AdminScenes.php create mode 100644 controllers/admin/AdminScenesController.php diff --git a/admin-dev/tabs/AdminScenes.php b/admin-dev/tabs/AdminScenes.php deleted file mode 100644 index a258bfa59..000000000 --- a/admin-dev/tabs/AdminScenes.php +++ /dev/null @@ -1,246 +0,0 @@ - -* @copyright 2007-2011 PrestaShop SA -* @version Release: $Revision: 7040 $ -* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) -* International Registered Trademark & Property of PrestaShop SA -*/ - -class AdminScenes extends AdminTab -{ - public function __construct() - { - $this->table = 'scene'; - $this->className = 'Scene'; - $this->lang = true; - $this->edit = true; - $this->delete = true; - - $this->fieldImageSettings = array( - array('name' => 'image', 'dir' => 'scenes'), - array('name' => 'thumb', 'dir' => 'scenes/thumbs') - ); - - $this->fieldsDisplay = array( - 'id_scene' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), - 'name' => array('title' => $this->l('Image Maps'), 'width' => 150, 'filter_key' => 'b!name'), - 'active' => array('title' => $this->l('Activated'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) - ); - - parent::__construct(); - } - - public function afterImageUpload() - { - /* Generate image with differents size */ - if (!($obj = $this->loadObject(true))) - return; - if ($obj->id AND (isset($_FILES['image']) OR isset($_FILES['thumb']))) - { - $imagesTypes = ImageType::getImagesTypes('scenes'); - foreach ($imagesTypes AS $k => $imageType) - { - if ($imageType['name'] == 'large_scene' AND isset($_FILES['image'])) - imageResize($_FILES['image']['tmp_name'], _PS_SCENE_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); - elseif ($imageType['name'] == 'thumb_scene') - { - if (isset($_FILES['thumb']) AND !$_FILES['thumb']['error']) - $tmpName = $_FILES['thumb']['tmp_name']; - else - $tmpName = $_FILES['image']['tmp_name']; - imageResize($tmpName, _PS_SCENE_THUMB_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); - } - } - } - return true; - } - - public function displayForm($isMainTab = true) - { - parent::displayForm(); - - if (!($obj = $this->loadObject(true))) - return; - - $langtags = 'name'; - $active = $this->getFieldValue($obj, 'active'); - - echo ' - -
- '.($obj->id ? '' : '').' -
'.$this->l('Image Maps').''; - echo ' - -
- '.$this->l('When a customer hovers over the image with the mouse, a pop-up appears displaying a brief description of the product. The customer can then click to open the product\'s full product page. To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up. Left-click with your mouse to draw the four-sided mapping zone, then release. Then, begin typing the name of the associated product. A list of products appears. Click the appropriate product, then click OK. Repeat these steps for each mapping zone you wish to create. When you have finished mapping zones, click Save Image Map.').' -
- '; - - echo ' -
'; - foreach ($this->_languages as $language) - echo ' -
- * -
'; - $this->displayFlags($this->_languages, $this->_defaultFormLanguage, $langtags, 'name'); - echo '
-
'; - - - echo ' -
- id OR Tools::getValue('active', $obj->active)) ? 'checked="checked" ' : '').'/> - - active) AND $obj->id) ? 'checked="checked" ' : '').'/> - -

'.$this->l('Activate or deactivate the image map').'

-
'; - - - $sceneImageTypes = ImageType::getImagesTypes('scenes'); - $largeSceneImageType = NULL; - $thumbSceneImageType = NULL; - foreach ($sceneImageTypes as $sceneImageType) - { - if ($sceneImageType['name'] == 'large_scene') - $largeSceneImageType = $sceneImageType; - if ($sceneImageType['name'] == 'thumb_scene') - $thumbSceneImageType = $sceneImageType; - } - - - echo ' -
- -
-

'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('File size:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('KB max.').' '.$this->l('If larger than the image size setting, the image will be reduced to ').' '.$largeSceneImageType['width'].'x'.$largeSceneImageType['height'].'px '.$this->l('(width x height). If smaller than the image-size setting, a white background will be added in order to achieve the correct image size.').'.
'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

'; - - if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg')) - { - echo '
'; - - echo ' - - '; - - echo ' - - - - - - '; - - echo '
'; - - - echo ' -
-   '.$this->l('(optional)').' -

'.$this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.').'
'.$this->l('Format:').' JPG, GIF, PNG. '.$this->l('Filesize:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('Kb max.').' '.$this->l('Automatically resized to').' '.$thumbSceneImageType['width'].'x'.$thumbSceneImageType['height'].'px '.$this->l('(width x height)').'.
'.$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).').'

- '; - if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg')) - echo '
'; - echo '
- '; - - $selectedCat = array(); - if (Tools::isSubmit('categories')) - foreach (Tools::getValue('categories') as $k => $row) - $selectedCat[] = $row; - else if ($obj->id) - foreach (Scene::getIndexedCategories($obj->id) as $k => $row) - $selectedCat[] = $row['id_category']; - - $trads = array( - 'Home' => $this->l('Home'), - 'selected' => $this->l('selected'), - 'Collapse All' => $this->l('Collapse All'), - 'Expand All' => $this->l('Expand All'), - 'Check All' => $this->l('Check All'), - 'Uncheck All' => $this->l('Uncheck All') - ); - - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop(); - echo '
'; - } - echo ' - -
- '; - echo Helper::renderAdminCategorieTree($trads, $selectedCat, 'categories'); - echo ' -
-
id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg')) ? '' : 'style="display:none;"') .'> - -
- '; - } - else - { - echo '
'.$this->l('Please add a picture to continue mapping the image...').'

'; - echo ''; - if (Shop::isFeatureActive()) - { - echo '
'; - $this->displayAssoShop(); - echo '
'; - } - - } - echo ' -
* '.$this->l('Required field').'
-
-
- '; - } - - public function postProcess() - { - if (Tools::isSubmit('save_image_map')) - { - if (!Tools::isSubmit('categories') || !sizeof(Tools::getValue('categories'))) - $this->_errors[] = Tools::displayError('You should select at least one category'); - if (!Tools::isSubmit('zones') || !sizeof(Tools::getValue('zones'))) - $this->_errors[] = Tools::displayError('You should make at least one zone'); - } - parent::postProcess(); - } -} - - diff --git a/admin-dev/themes/template/helper/form/form.tpl b/admin-dev/themes/template/helper/form/form.tpl index 82a3433b2..f0e98d29e 100644 --- a/admin-dev/themes/template/helper/form/form.tpl +++ b/admin-dev/themes/template/helper/form/form.tpl @@ -24,48 +24,6 @@ * International Registered Trademark & Property of PrestaShop SA *} -{if $firstCall} - -{/if} {if $show_toolbar}
@@ -97,6 +55,8 @@ {if isset($field.image)}{$field.title}{/if} {$field.title} + {elseif $key == 'description'} +

{$field}

{elseif $key == 'input'} {foreach $field as $input} {if $input.name == 'id_state'} @@ -268,7 +228,7 @@ {assign var=groups value=$input.values} {include file='helper/form/form_group.tpl'} {elseif $input.type == 'shop' OR $input.type == 'group_shop'} - {include file='helper/form/form_shop.tpl'} + {include file='helper/form/form_shop.tpl' input=$input fields_value=$fields_value} {elseif $input.type == 'categories'} {include file='helper/form/form_category.tpl' categories=$input.values} {elseif $input.type == 'asso_shop' && isset($asso_shop) && $asso_shop} @@ -350,7 +310,7 @@ {/foreach} {/block} - +{block name="after"}{/block} {if isset($tinymce) && $tinymce} {/if} +{if $firstCall} + +{/if} diff --git a/controllers/admin/AdminScenesController.php b/controllers/admin/AdminScenesController.php new file mode 100644 index 000000000..f6c910e92 --- /dev/null +++ b/controllers/admin/AdminScenesController.php @@ -0,0 +1,263 @@ + +* @copyright 2007-2011 PrestaShop SA +* @version Release: $Revision: 7040 $ +* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*/ + +class AdminScenesControllerCore extends AdminController +{ + public function __construct() + { + $this->table = 'scene'; + $this->className = 'Scene'; + $this->lang = true; + $this->edit = true; + $this->delete = true; + + $this->identifier = 'id_scene'; + $this->fieldImageSettings = array( + array('name' => 'image', 'dir' => 'scenes'), + array('name' => 'thumb', 'dir' => 'scenes/thumbs') + ); + + $this->fieldsDisplay = array( + 'id_scene' => array('title' => $this->l('ID'), 'align' => 'center', 'width' => 25), + 'name' => array('title' => $this->l('Image Maps'), 'width' => 150, 'filter_key' => 'b!name'), + 'active' => array('title' => $this->l('Activated'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false) + ); + + parent::__construct(); + } + + public function afterImageUpload() + { + /* Generate image with differents size */ + if (!($obj = $this->loadObject(true))) + return; + if ($obj->id AND (isset($_FILES['image']) OR isset($_FILES['thumb']))) + { + $imagesTypes = ImageType::getImagesTypes('scenes'); + foreach ($imagesTypes AS $k => $imageType) + { + if ($imageType['name'] == 'large_scene' AND isset($_FILES['image'])) + imageResize($_FILES['image']['tmp_name'], _PS_SCENE_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); + elseif ($imageType['name'] == 'thumb_scene') + { + if (isset($_FILES['thumb']) AND !$_FILES['thumb']['error']) + $tmpName = $_FILES['thumb']['tmp_name']; + else + $tmpName = $_FILES['image']['tmp_name']; + imageResize($tmpName, _PS_SCENE_THUMB_IMG_DIR_.$obj->id.'-'.stripslashes($imageType['name']).'.jpg', (int)($imageType['width']), (int)($imageType['height'])); + } + } + } + return true; + } + + public function initForm() + { + $this->initFieldsForm(); + $content = ''; + + if (!($obj = $this->loadObject(true))) + return; + + $langtags = 'name'; + $active = $this->getFieldValue($obj, 'active'); + + $products = $obj->getProducts(true, $this->context->language->id, false, $this->context); + $this->tpl_form_vars['products'] = $obj->getProducts(true, $this->context->language->id, false, $this->context); + + + return parent::initForm(); + } + + public function initFieldsForm() + { + $obj = $this->loadObject(true); + $sceneImageTypes = ImageType::getImagesTypes('scenes'); + $largeSceneImageType = NULL; + $thumbSceneImageType = NULL; + foreach ($sceneImageTypes as $sceneImageType) + { + if ($sceneImageType['name'] == 'large_scene') + $largeSceneImageType = $sceneImageType; + if ($sceneImageType['name'] == 'thumb_scene') + $thumbSceneImageType = $sceneImageType; + } + $fields_form = array( + 'legend' => array( + 'title' => $this->l('Image Maps'), + 'image' => '../img/admin/photo.gif', + ), + 'description' => $this->l('When a customer hovers over the image with the mouse, a pop-up appears displaying a brief description of the product. The customer can then click to open the product\'s full product page. To achieve this, please define the \'mapping zone\' that, when hovered over, will display the pop-up. Left-click with your mouse to draw the four-sided mapping zone, then release. Then, begin typing the name of the associated product. A list of products appears. Click the appropriate product, then click OK. Repeat these steps for each mapping zone you wish to create. When you have finished mapping zones, click Save Image Map.'), + 'submit' => array( + 'title' => $this->l(' Save '), + 'class' => 'button' + ), + 'input' => array( + array( + 'type' => 'text', + 'label' => $this->l('Image map name:'), + 'name' => 'name', + 'lang' => true, + 'size' => 48, + 'required' => true, + 'hint' => $this->l('Invalid characters:').' <>;=#{}' + ), + array( + 'type' => 'radio', + 'label' => $this->l('Status:'), + 'name' => 'active', + 'required' => false, + 'class' => 't', + 'is_bool' => true, + 'values' => array( + array( + 'id' => 'active_on', + 'value' => 1, + 'label' => $this->l('Enabled') + ), + array( + 'id' => 'active_off', + 'value' => 0, + 'label' => $this->l('Disabled') + ) + ) + ), + ), + ); + $this->fields_form = $fields_form; + + $image_to_map_desc = ''; + $image_to_map_desc = $this->l('Format:').' JPG, GIF, PNG. '.$this->l('File size:').' ' + .(Tools::getMaxUploadSize() / 1024).''.$this->l('KB max.').' ' + .$this->l('If larger than the image size setting, the image will be reduced to ') + .' '.$largeSceneImageType['width'].'x'.$largeSceneImageType['height'].'px ' + .$this->l('(width x height). If smaller than the image-size setting, a white background will be added in order to achieve the correct image size.').'.
'.$this->l('Note: To change image dimensions, please change the \'large_scene\' image type settings to the desired size (in Back Office > Preferences > Images).'); + if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.$obj->id.'-large_scene.jpg')) + { + $this->addJqueryPlugin('autocomplete'); + $this->addJqueryPlugin('imgareaselect'); + $this->addJs(_PS_JS_DIR_.'admin-scene-cropping.js' ); + $image_to_map_desc .= '

'; + + $image_to_map_desc .= ' + + '; + + + if ($obj->id && file_exists(_PS_SCENE_IMG_DIR_.'thumbs/'.$obj->id.'-thumb_scene.jpg')) + $image_to_map_desc .= '

'; + + $img_alt_desc = ''; + $img_alt_desc .= $this->l('If you want to use a thumbnail other than one generated from simply reducing the mapped image, please upload it here.') + .'
'.$this->l('Format:').' JPG, GIF, PNG. ' + .$this->l('Filesize:').' '.(Tools::getMaxUploadSize() / 1024).''.$this->l('Kb max.').' ' + .$this->l('Automatically resized to') + .' '.$thumbSceneImageType['width'].'x'.$thumbSceneImageType['height'].'px '.$this->l('(width x height)').'.
' + .$this->l('Note: To change image dimensions, please change the \'thumb_scene\' image type settings to the desired size (in Back Office > Preferences > Images).'); + + $input_img_alt = array( + 'type' => 'file', + 'label' => $this->l('Alternative thumbnail:'), + 'name' => 'thumb', + 'p' => $img_alt_desc + ); + + $selectedCat = array(); + if (Tools::isSubmit('categories')) + foreach (Tools::getValue('categories') as $k => $row) + $selectedCat[] = $row; + else if ($obj->id) + foreach (Scene::getIndexedCategories($obj->id) as $k => $row) + $selectedCat[] = $row['id_category']; + + $trads = array( + 'Home' => $this->l('Home'), + 'selected' => $this->l('selected'), + 'Check all' => $this->l('Check all'), + 'Check All' => $this->l('Check All'), + 'Uncheck All' => $this->l('Uncheck All'), + 'Collapse All' => $this->l('Collapse All'), + 'Expand All' => $this->l('Expand All'), + 'search' => $this->l('Search a category') + + ); + $this->fields_form['input'][] = array( + 'type' => 'categories', + 'label' => $this->l('Categories:'), + 'name' => 'categories', + 'values' => array('trads' => $trads, + 'selected_cat' => $selectedCat, + 'input_name' => 'categories[]', + 'use_radio' => false, + 'use_search' => true, + 'disabled_categories' => array(4), + ) + ); + } + else + { + $image_to_map_desc .= '
'.$this->l('Please add a picture to continue mapping the image...').'

'; + $image_to_map_desc .= '
'; + } + if (Shop::isFeatureActive()) + { + $this->fields_form['input'][] = array( + 'type' => 'shop', + 'label' => $this->l('Shop association:'), + 'name' => 'checkBoxShopAsso', + 'values' => Shop::getTree() + ); + } + + $this->fields_form['input'][] = array( + 'type' => 'file', + 'label' => $this->l('Image to be mapped:'), + 'name' => 'image', + 'display_image' => true, + 'p' => $image_to_map_desc, + ); + + if(isset($input_img_alt)) + $this->fields_form['input'][] = $input_img_alt; + } + + public function postProcess() + { + if (Tools::isSubmit('save_image_map')) + { + if (!Tools::isSubmit('categories') || !sizeof(Tools::getValue('categories'))) + $this->_errors[] = Tools::displayError('You should select at least one category'); + if (!Tools::isSubmit('zones') || !sizeof(Tools::getValue('zones'))) + $this->_errors[] = Tools::displayError('You should make at least one zone'); + } + parent::postProcess(); + } +} + +