diff --git a/admin-dev/themes/default/template/controllers/products/attachments.tpl b/admin-dev/themes/default/template/controllers/products/attachments.tpl index 1bda72673..7388a17ef 100644 --- a/admin-dev/themes/default/template/controllers/products/attachments.tpl +++ b/admin-dev/themes/default/template/controllers/products/attachments.tpl @@ -65,92 +65,9 @@ {l s='File:'} -
- - - - -
+ {$attachment_uploader} - -
diff --git a/admin-dev/themes/default/template/controllers/products/helpers/uploader/attachment_ajax.tpl b/admin-dev/themes/default/template/controllers/products/helpers/uploader/attachment_ajax.tpl new file mode 100644 index 000000000..84d386e86 --- /dev/null +++ b/admin-dev/themes/default/template/controllers/products/helpers/uploader/attachment_ajax.tpl @@ -0,0 +1,116 @@ +{* +* 2007-2013 PrestaShop +* +* NOTICE OF LICENSE +* +* This source file is subject to the Academic Free License (AFL 3.0) +* that is bundled with this package in the file LICENSE.txt. +* It is also available through the world-wide-web at this URL: +* http://opensource.org/licenses/afl-3.0.php +* If you did not receive a copy of the license and are unable to +* obtain it through the world-wide-web, please send an email +* to license@prestashop.com so we can send you a copy immediately. +* +* DISCLAIMER +* +* Do not edit or add to this file if you wish to upgrade PrestaShop to newer +* versions in the future. If you wish to customize PrestaShop for your +* needs please refer to http://www.prestashop.com for more information. +* +* @author PrestaShop SA +* @copyright 2007-2013 PrestaShop SA +* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0) +* International Registered Trademark & Property of PrestaShop SA +*} +
+ + + + +
+ + \ No newline at end of file diff --git a/classes/helper/HelperUploader.php b/classes/helper/HelperUploader.php index e5dc03b7b..dcdc02e31 100644 --- a/classes/helper/HelperUploader.php +++ b/classes/helper/HelperUploader.php @@ -40,6 +40,7 @@ class HelperUploaderCore extends Uploader private $_name; private $_max_files; private $_multiple; + private $_post_max_size; protected $_template; private $_template_directory; private $_title; @@ -119,12 +120,6 @@ class HelperUploaderCore extends Uploader return $this; } - public function setTemplate($value) - { - $this->_template = $value; - return $this; - } - public function setName($value) { $this->_name = (string)$value; @@ -136,6 +131,26 @@ class HelperUploaderCore extends Uploader return $this->_name; } + public function setPostMaxSize($value) + { + $this->_post_max_size = $value; + return $this; + } + + public function getPostMaxSize() + { + if (!isset($this->_post_max_size)) + $this->_post_max_size = parent::getPostMaxSize(); + + return $this->_post_max_size; + } + + public function setTemplate($value) + { + $this->_template = $value; + return $this; + } + public function getTemplate() { if (!isset($this->_template)) @@ -240,37 +255,20 @@ class HelperUploaderCore extends Uploader .'template')) $bo_theme = 'default'; - if ($this->getContext()->controller->ajax) - { - $html = ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - } - else - { - $html = ''; - $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath - .'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.'js/vendor/spin.js'); - $this->getContext()->controller->addJs(__PS_BASE_URI__.'js/vendor/ladda.js'); - } + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath + .'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.'js/vendor/spin.js'); + $this->getContext()->controller->addJs(__PS_BASE_URI__.'js/vendor/ladda.js'); - if ($this->useAjax()) + if ($this->useAjax() && !isset($this->_template)) $this->setTemplate(self::DEFAULT_AJAX_TEMPLATE); $template = $this->getContext()->smarty->createTemplate( @@ -289,8 +287,7 @@ class HelperUploaderCore extends Uploader 'drop_zone' => $this->getDropZone() )); - $html .= $template->fetch(); - return $html; + return $template->fetch(); } public function useAjax() diff --git a/controllers/admin/AdminProductsController.php b/controllers/admin/AdminProductsController.php index c65f0ce85..9f3d0b37f 100644 --- a/controllers/admin/AdminProductsController.php +++ b/controllers/admin/AdminProductsController.php @@ -267,6 +267,28 @@ class AdminProductsControllerCore extends AdminController 'position' => 'position' ); } + + public function setMedia() + { + $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); + $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); + $bo_theme = ((Validate::isLoadedObject($this->context->employee) + && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default'); + + if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR + .'template')) + $bo_theme = 'default'; + + $this->addJs(__PS_BASE_URI__.$admin_webpath.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js'); + $this->addJs(__PS_BASE_URI__.$admin_webpath.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js'); + $this->addJs(__PS_BASE_URI__.$admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload.js'); + $this->addJs(__PS_BASE_URI__.$admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-process.js'); + $this->addJs(__PS_BASE_URI__.$admin_webpath.'/themes/'.$bo_theme.'/js/jquery.fileupload-validate.js'); + $this->addJs(__PS_BASE_URI__.'js/vendor/spin.js'); + $this->addJs(__PS_BASE_URI__.'js/vendor/ladda.js'); + + return parent::setMedia(); + } protected function _cleanMetaKeywords($keywords) { @@ -3573,6 +3595,12 @@ class AdminProductsControllerCore extends AdminController $iso_tiny_mce = $this->context->language->iso_code; $iso_tiny_mce = (file_exists(_PS_JS_DIR_.'tiny_mce/langs/'.$iso_tiny_mce.'.js') ? $iso_tiny_mce : 'en'); + $attachment_uploader = new HelperUploader('attachment_file'); + $attachment_uploader->setMultiple(false)->setUseAjax(true)->setUrl( + Context::getContext()->link->getAdminLink('AdminProducts').'&ajax=1&id_product='.(int)$obj->id + .'&action=AddAttachment')->setPostMaxSize((Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024)) + ->setTemplate('attachment_ajax.tpl'); + $data->assign(array( 'obj' => $obj, 'table' => $this->table, @@ -3587,7 +3615,7 @@ class AdminProductsControllerCore extends AdminController 'attachment_name' => $attachment_name, 'attachment_description' => $attachment_description, 'PS_ATTACHMENT_MAXIMUM_SIZE' => Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE'), - 'post_max_size' => (Configuration::get('PS_ATTACHMENT_MAXIMUM_SIZE') * 1024 * 1024) + 'attachment_uploader' => $attachment_uploader->render() )); } else @@ -3596,27 +3624,7 @@ class AdminProductsControllerCore extends AdminController else $this->displayWarning($this->l('You must save this product before adding attachements.')); - $admin_webpath = str_ireplace(_PS_ROOT_DIR_, '', _PS_ADMIN_DIR_); - $admin_webpath = preg_replace('/^'.preg_quote(DIRECTORY_SEPARATOR, '/').'/', '', $admin_webpath); - $bo_theme = ((Validate::isLoadedObject($this->context->employee) - && $this->context->employee->bo_theme) ? $this->context->employee->bo_theme : 'default'); - - if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR - .'template')) - $bo_theme = 'default'; - - $html = ''; - $html .= ''; - $html .= ''; - $html .= ''; - $html .= ''; - - $this->tpl_form_vars['custom_form'] = $html.$data->fetch(); + $this->tpl_form_vars['custom_form'] = $data->fetch(); } public function initFormInformations($product)