//Starting Uploader helper

This commit is contained in:
Jerome Nadaud committed 2013-10-25 14:19:51 +02:00
1 parent 139ee8f62d
commit 52795495bd
15 files changed
+3521 -58

No files matched your search

+18
View File
@@ -76,6 +76,7 @@ class HelperFormCore extends Helper
$date = true;
$tinymce = true;
$textarea_autosize = true;
$file = true;
foreach ($this->fields_form as $fieldset_key => &$fieldset)
if (isset($fieldset['form']['input']))
foreach ($fieldset['form']['input'] as $key => &$params)
@@ -110,6 +111,23 @@ class HelperFormCore extends Helper
}
break;
case 'file':
$uploader = new HelperUploader();
$uploader->setId(isset($params['id'])?$params['id']:null);
$uploader->setName($params['name']);
$uploader->setUrl(isset($params['url'])?$params['url']:null);
$uploader->setMultiple(isset($params['multiple'])?$params['multiple']:false);
$uploader->setUseAjax(isset($params['ajax'])?$params['ajax']:false);
$uploader->setDisplayImage(isset($params['display_image'])?$params['display_image']:false);
$uploader->setImage(isset($params['image'])?$params['image']:null);
$uploader->setThumb(isset($params['thumb'])?$params['thumb']:null);
$uploader->setSize(isset($params['size'])?$params['size']:null);
$uploader->setTitle(isset($params['title'])?$params['title']:null);
$uploader->setDeleteUrl(isset($params['delete_url'])?$params['delete_url']:null);
$params['file'] = $uploader->render();
break;
case 'color':
if ($color)
{
+18
View File
@@ -95,6 +95,24 @@ class HelperOptionsCore extends Helper
if ($field['type'] == 'texarea' || $field['type'] == 'textareaLang')
$this->context->controller->addJS(_PS_JS_DIR_.'jquery/plugins/jquery.autosize.min.js');
if ($field['type'] == 'file')
{
$uploader = new HelperUploader();
$uploader->setId(isset($field['id'])?$field['id']:null);
$uploader->setName($field['name']);
$uploader->setUrl(isset($field['url'])?$field['url']:null);
$uploader->setMultiple(isset($field['multiple'])?$field['multiple']:false);
$uploader->setUseAjax(isset($field['ajax'])?$field['ajax']:false);
$uploader->setDisplayImage(isset($field['display_image'])?$field['display_image']:false);
$uploader->setImage(isset($field['image'])?$field['image']:null);
$uploader->setThumb(isset($field['thumb'])?$field['thumb']:null);
$uploader->setSize(isset($field['size'])?$field['size']:null);
$uploader->setTitle(isset($field['title'])?$field['title']:null);
$uploader->setDeleteUrl(isset($field['delete_url'])?$field['delete_url']:null);
$field['file'] = $uploader->render();
}
// Cast options values if specified
if ($field['type'] == 'select' && isset($field['cast']))
+319
View File
@@ -0,0 +1,319 @@
<?php
/*
* 2007-2013 PrestaShop
*
* NOTICE OF LICENSE
*
* This source file is subject to the Open Software License (OSL 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/osl-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 <contact@prestashop.com>
* @copyright 2007-2013 PrestaShop SA
* @license http://opensource.org/licenses/osl-3.0.php Open Software License (OSL 3.0)
* International Registered Trademark & Property of PrestaShop SA
*/
class HelperUploaderCore extends Uploader
{
const DEFAULT_TEMPLATE_DIRECTORY = 'helpers/uploader';
const DEFAULT_TEMPLATE = 'simple.tpl';
const DEFAULT_AJAX_TEMPLATE = 'ajax.tpl';
private $_context;
private $_delete_url;
private $_display_image;
private $_id;
private $_image;
private $_name;
private $_multiple;
private $_size;
protected $_template;
private $_template_directory;
private $_title;
private $_thumb;
private $_url;
private $_use_ajax;
public function setContext($value)
{
$this->_context = $value;
return $this;
}
public function getContext()
{
if (!isset($this->_context))
$this->_context = Context::getContext();
return $this->_context;
}
public function setDeleteUrl($value)
{
$this->_delete_url = $value;
return $this;
}
public function getDeleteUrl()
{
return $this->_delete_url;
}
public function setDisplayImage($value)
{
$this->_display_image = $value;
return $this;
}
public function setId($value)
{
$this->_id = (string)$value;
return $this;
}
public function getId()
{
if (!isset($this->_id) || trim($this->_id) === '')
$this->_id = $this->getName();
return $this->_id;
}
public function setImage($value)
{
$this->_image = $value;
return $this;
}
public function getImage()
{
return $this->_image;
}
public function setName($value)
{
$this->_name = (string)$value;
return $this;
}
public function getName()
{
return $this->_name;
}
public function setMultiple($value)
{
$this->_multiple = (bool)$value;
return $this;
}
public function setSize($value)
{
$this->_size = $value;
return $this;
}
public function getSize()
{
return $this->_size;
}
public function setTemplate($value)
{
$this->_template = $value;
return $this;
}
public function getTemplate()
{
if (!isset($this->_template))
$this->setTemplate(self::DEFAULT_TEMPLATE);
return $this->_template;
}
public function setTemplateDirectory($value)
{
$this->_template_directory = $value;
return $this;
}
public function getTemplateDirectory()
{
if (!isset($this->_template_directory))
$this->_template_directory = self::DEFAULT_TEMPLATE_DIRECTORY;
return $this->_normalizeDirectory($this->_template_directory);
}
public function getTemplateFile($template)
{
if (preg_match_all('/((?:^|[A-Z])[a-z]+)/', get_class($this->getContext()->controller), $matches) !== FALSE)
$controllerName = strtolower($matches[0][1]);
if ($this->getContext()->controller instanceof ModuleAdminController)
return $this->_normalizeDirectory(
$this->getContext()->controller->getTemplatePath())
.$this->getTemplateDirectory().$template;
else if ($this->getContext()->controller instanceof AdminController
&& isset($controllerName) && file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0)).'controllers'
.DIRECTORY_SEPARATOR
.$controllerName
.DIRECTORY_SEPARATOR
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0)).'controllers'
.DIRECTORY_SEPARATOR
.$controllerName
.DIRECTORY_SEPARATOR
.$this->getTemplateDirectory().$template;
else if (file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(1))
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(1))
.$this->getTemplateDirectory().$template;
else if (file_exists($this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0))
.$this->getTemplateDirectory().$template))
return $this->_normalizeDirectory(
$this->getContext()->smarty->getTemplateDir(0))
.$this->getTemplateDirectory().$template;
else
return $this->getTemplateDirectory().$template;
}
public function setTitle($value)
{
$this->_title = $value;
return $this;
}
public function getTitle()
{
return $this->_title;
}
public function setThumb($value)
{
$this->_thumb = $value;
return $this;
}
public function getThumb()
{
return $this->_thumb;
}
public function setUrl($value)
{
$this->_url = (string)$value;
return $this;
}
public function getUrl()
{
return $this->_url;
}
public function setUseAjax($value)
{
$this->_use_ajax = (bool)$value;
return $this;
}
public function displayImage()
{
return (isset($this->_display_image) && $this->_display_image);
}
public function isMultiple()
{
return (isset($this->_multiple) && $this->_multiple);
}
public function process()
{
$files = parent::process();
die(Tools::jsonEncode(array($this->getName() => $files)));
}
public function render()
{
$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->getContext()->employee)
&& $this->getContext()->employee->bo_theme) ? $this->getContext()->employee->bo_theme : 'default');
if (!file_exists(_PS_BO_ALL_THEMES_DIR_.$bo_theme.DIRECTORY_SEPARATOR
.'template'))
$bo_theme = 'default';
if ($this->getContext()->controller->ajax)
{
$html = '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.iframe-transport.js"></script>';
$html .= '<script type="text/javascript" src="'.__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload.js"></script>';
}
else
{
$html = '';
$this->getContext()->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/vendor/jquery.ui.widget.js');
//$context->controller->addJs('http://blueimp.github.io/JavaScript-Load-Image/js/load-image.min.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');
/*$context->controller->addJs(__PS_BASE_URI__.$admin_webpath
.'/themes/'.$bo_theme.'/js/jquery.fileupload-image.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())
$this->setTemplate(self::DEFAULT_AJAX_TEMPLATE);
$template = $this->getContext()->smarty->createTemplate(
$this->getTemplateFile($this->getTemplate()), $this->getContext()->smarty
);
$template->assign(array(
'id' => $this->getId(),
'name' => $this->getName(),
'url' => $this->getUrl(),
'multiple' => $this->isMultiple(),
'display_image' => $this->displayImage(),
'image' => $this->getImage(),
'thumb' => $this->getThumb(),
'size' => $this->getSize(),
'delete_url' => $this->getDeleteUrl(),
'title' => $this->getTitle()
));
$html .= $template->fetch();
return $html;
}
public function useAjax()
{
return (isset($this->_use_ajax) && $this->_use_ajax);
}
}