[*] BO #PSFV-94 : update of the displayform method by helperForm in AdminShopUrlController
This commit is contained in:
@@ -38,6 +38,9 @@
|
||||
{/foreach}
|
||||
displayFlags(languages, id_language, {$allowEmployeeFormLang});
|
||||
});
|
||||
{if isset($script)}
|
||||
{$script}
|
||||
{/if}
|
||||
</script>
|
||||
{/if}
|
||||
|
||||
@@ -57,27 +60,55 @@
|
||||
<label>{$input.label} </label>
|
||||
<div class="margin-form">
|
||||
{if $input.type == 'text'}
|
||||
<input type="text" {if isset($input.size)}size="{$input.size}"{/if} name="{$input.name}" value="{$fields_value[$input.name]}" {if isset($input.class)}class="{$input.class}"{/if} />
|
||||
<input type="text"
|
||||
name="{$input.name}"
|
||||
id="{$input.name}"
|
||||
value="{$fields_value[$input.name]}"
|
||||
{if isset($input.size)}size="{$input.size}"{/if}
|
||||
{if isset($input.class)}class="{$input.class}"{/if}
|
||||
{if isset($input.readonly) && $input.readonly}readonly="readonly"{/if} />
|
||||
{elseif $input.type == 'select'}
|
||||
<select name="{$input.name}">
|
||||
{foreach $input.options.query AS $option}
|
||||
<option value="{$option[$input.options.id]}" {if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}>{$option[$input.options.name]}</option>
|
||||
{/foreach}
|
||||
<select name="{$input.name}" id="{$input.name}" {if isset($input.onchange)}onchange="{$input.onchange}"{/if}>
|
||||
{if isset($input.options.optiongroup)}
|
||||
{foreach $input.options.optiongroup.query AS $optiongroup}
|
||||
<optgroup label="{$optiongroup[$input.options.optiongroup.label]}">
|
||||
{foreach $optiongroup[$input.options.options.query] as $option}
|
||||
<option value="{$option[$input.options.options.id]}"
|
||||
{if $fields_value[$input.name] == $option[$input.options.options.id]}selected="selected"{/if}>{$option[$input.options.options.name]}</option>
|
||||
{/foreach}
|
||||
</optgroup>
|
||||
{/foreach}
|
||||
{else}
|
||||
{foreach $input.options.query AS $option}
|
||||
<option value="{$option[$input.options.id]}"
|
||||
{if $fields_value[$input.name] == $option[$input.options.id]}selected="selected"{/if}>{$option[$input.options.name]}</option>
|
||||
{/foreach}
|
||||
{/if}
|
||||
</select>
|
||||
{elseif $input.type == 'radio'}
|
||||
{foreach $input.values as $value}
|
||||
<input type="radio" name="{$input.name}" id="{$value.id}" value="{$value.value}" {if $fields_value[$input.name] == $value.value}checked="checked"{/if}/>
|
||||
<input type="radio"
|
||||
name="{$input.name}"
|
||||
id="{$value.id}"
|
||||
value="{$value.value}"
|
||||
{if $fields_value[$input.name] == $value.value}checked="checked"{/if} />
|
||||
<label {if isset($input.class)}class="{$input.class}"{/if} for="{$value.id}"> {$value.label}</label>
|
||||
{/foreach}
|
||||
{elseif $input.type == 'textarea'}
|
||||
<textarea name="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
|
||||
<textarea name="{$input.name}" id="{$input.name}" cols="{$input.cols}" rows="{$input.rows}">{$fields_value[$input.name]}</textarea>
|
||||
{elseif $input.type == 'checkbox'}
|
||||
|
||||
{/if}
|
||||
{if isset($input.required) && $input.required} <sup>*</sup>{/if}
|
||||
{if isset($input.p)}
|
||||
<p class="clear">
|
||||
{if is_array($input.p)}
|
||||
{foreach $input.p as $p}
|
||||
{$p}<br />
|
||||
{if is_array($p)}
|
||||
<span id="{$p.id}">{$p.text}</span><br />
|
||||
{else}
|
||||
{$p}<br />
|
||||
{/if}
|
||||
{/foreach}
|
||||
{else}
|
||||
{$input.p}
|
||||
|
||||
@@ -0,0 +1,67 @@
|
||||
{*
|
||||
* 2007-2011 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 <contact@prestashop.com>
|
||||
* @copyright 2007-2011 PrestaShop SA
|
||||
* @version Release: $Revision: 8897 $
|
||||
* @license http://opensource.org/licenses/afl-3.0.php Academic Free License (AFL 3.0)
|
||||
* International Registered Trademark & Property of PrestaShop SA
|
||||
*}
|
||||
function fillShopUrl()
|
||||
{
|
||||
var domain = $('#domain').val();
|
||||
var physical = $('#physical_uri').val();
|
||||
var virtual = $('#virtual_uri').val();
|
||||
url = ((domain) ? domain : '???');
|
||||
if (physical)
|
||||
url += '/'+physical;
|
||||
if (virtual)
|
||||
url += '/'+virtual;
|
||||
url = url.replace(/\/+/g, "/");
|
||||
$('#final_url').val('http://'+url);
|
||||
};
|
||||
|
||||
var shopUrl = {$jsShopUrl};
|
||||
|
||||
function checkMainUrlInfo(shopID)
|
||||
{
|
||||
if (!shopID)
|
||||
shopID = $('#id_shop').val();
|
||||
|
||||
if (!shopUrl[shopID])
|
||||
{
|
||||
$('#main_off').attr('disabled', true);
|
||||
$('#main_on').attr('checked', true);
|
||||
$('#mainUrlInfo').css('display', 'block');
|
||||
$('#mainUrlInfoExplain').css('display', 'none');
|
||||
}
|
||||
else
|
||||
{
|
||||
$('#main_off').attr('disabled', false);
|
||||
$('#mainUrlInfo').css('display', 'none');
|
||||
$('#mainUrlInfoExplain').css('display', 'block');
|
||||
}
|
||||
}
|
||||
|
||||
$().ready(function()
|
||||
{
|
||||
fillShopUrl();
|
||||
checkMainUrlInfo();
|
||||
$('#domain, #physical_uri, #virtual_uri').keyup(fillShopUrl);
|
||||
});
|
||||
@@ -57,7 +57,115 @@ class AdminShopUrlControllerCore extends AdminController
|
||||
'active' => array('title' => $this->l('Enabled'), 'align' => 'center', 'active' => 'status', 'type' => 'bool', 'orderby' => false, 'filter_key' => 'active'),
|
||||
);
|
||||
|
||||
$this->template = 'adminShopUrl.tpl';
|
||||
$this->fields_form = array(
|
||||
'legend' => array(
|
||||
'title' => $this->l('Shop Url')
|
||||
),
|
||||
'input' => array(
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Domain:'),
|
||||
'name' => 'domain'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Domain SSL:'),
|
||||
'name' => 'domain_ssl'
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Physical URI:'),
|
||||
'name' => 'physical_uri',
|
||||
'p' => $this->l('Physical folder of your store on your server. Leave this field empty if your store is installed on root path.')
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Virtual URI:'),
|
||||
'name' => 'virtual_uri',
|
||||
'p' => array(
|
||||
$this->l('This virtual folder must not exist on your server and is used to associate an URI to a shop.'),
|
||||
'<strong>'.$this->l('URL rewriting must be activated on your server to use this feature.').'</strong>'
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'text',
|
||||
'label' => $this->l('Your final URL will be:'),
|
||||
'name' => 'final_url',
|
||||
'size' => 76,
|
||||
'readonly' => true
|
||||
),
|
||||
array(
|
||||
'type' => 'select',
|
||||
'label' => $this->l('Shop:'),
|
||||
'name' => 'id_shop',
|
||||
'onchange' => 'checkMainUrlInfo(this.value);',
|
||||
'options' => array(
|
||||
'optiongroup' => array (
|
||||
'query' => Shop::getTree(),
|
||||
'label' => 'name'
|
||||
),
|
||||
'options' => array (
|
||||
'query' => 'shops',
|
||||
'id' => 'id_shop',
|
||||
'name' => 'name'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Main URL:'),
|
||||
'name' => 'main',
|
||||
'class' => 't',
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'main_on',
|
||||
'value' => 1,
|
||||
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" />'
|
||||
),
|
||||
array(
|
||||
'id' => 'main_off',
|
||||
'value' => 0,
|
||||
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />'
|
||||
)
|
||||
),
|
||||
'p' => array(
|
||||
$this->l('If you set this url as main url for selected shop, all urls set to this shop will be redirected to this url (you can only have one main url per shop).'),
|
||||
array(
|
||||
'text' => $this->l('Since the selected shop has no main url, you have to set this url as main'),
|
||||
'id' => 'mainUrlInfo'
|
||||
),
|
||||
array(
|
||||
'text' => $this->l('The selected shop has already a main url, if you set this one as main url, the older one will be set as normal url'),
|
||||
'id' => 'mainUrlInfoExplain'
|
||||
)
|
||||
)
|
||||
),
|
||||
array(
|
||||
'type' => 'radio',
|
||||
'label' => $this->l('Status:'),
|
||||
'name' => 'active',
|
||||
'required' => false,
|
||||
'class' => 't',
|
||||
'values' => array(
|
||||
array(
|
||||
'id' => 'active_on',
|
||||
'value' => 1,
|
||||
'label' => '<img src="../img/admin/enabled.gif" alt="'.$this->l('Enabled').'" title="'.$this->l('Enabled').'" />'
|
||||
),
|
||||
array(
|
||||
'id' => 'active_off',
|
||||
'value' => 0,
|
||||
'label' => '<img src="../img/admin/disabled.gif" alt="'.$this->l('Disabled').'" title="'.$this->l('Disabled').'" />'
|
||||
)
|
||||
),
|
||||
'p' => $this->l('Enabled or disabled')
|
||||
)
|
||||
),
|
||||
'submit' => array(
|
||||
'title' => $this->l(' Save '),
|
||||
'class' => 'button'
|
||||
)
|
||||
);
|
||||
|
||||
parent::__construct();
|
||||
}
|
||||
@@ -76,10 +184,10 @@ class AdminShopUrlControllerCore extends AdminController
|
||||
|
||||
if (($object->main || Tools::getValue('main')) && !Tools::getValue('active'))
|
||||
$this->_errors[] = Tools::displayError('You can\'t disable a main url');
|
||||
|
||||
|
||||
if ($object->canAddThisUrl(Tools::getValue('domain'), Tools::getValue('domain_ssl'), Tools::getValue('physical_uri'), Tools::getValue('virtual_uri')))
|
||||
$this->_errors[] = Tools::displayError('A shop url that use this domain and uri already exists');
|
||||
|
||||
|
||||
parent::postProcess();
|
||||
Tools::generateHtaccess(dirname(__FILE__).'/../../.htaccess', Configuration::get('PS_REWRITING_SETTINGS'), Configuration::get('PS_HTACCESS_CACHE_CONTROL'), '');
|
||||
}
|
||||
@@ -106,41 +214,6 @@ class AdminShopUrlControllerCore extends AdminController
|
||||
return parent::postProcess();
|
||||
}
|
||||
|
||||
public function displayForm($isMainTab = true)
|
||||
{
|
||||
$this->content = parent::displayForm($isMainTab);
|
||||
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
$current_shop = Shop::initialize();
|
||||
|
||||
$list_shop_with_url = array();
|
||||
foreach (Shop::getShops(false, null, true) as $id)
|
||||
$list_shop_with_url[$id] = (bool)count(ShopUrl::getShopUrls($id));
|
||||
|
||||
$js_shop_url = Tools::jsonEncode($list_shop_with_url);
|
||||
|
||||
$domain = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain') : $current_shop->domain;
|
||||
$domain_ssl = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain_ssl') : $current_shop->domain_ssl;
|
||||
$physical_uri = Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'physical_uri') : $current_shop->physical_uri;
|
||||
|
||||
$this->context->smarty->assign('tab_form', array(
|
||||
'current' => self::$currentIndex,
|
||||
'table' => $this->table,
|
||||
'token' => $this->token,
|
||||
'id' => $obj->id,
|
||||
'domain' => $domain,
|
||||
'domain_ssl' => $domain_ssl,
|
||||
'physical_uri' => $physical_uri,
|
||||
'virtual_uri' => $this->getFieldValue($obj, 'virtual_uri'),
|
||||
'getTree' => Shop::getTree(),
|
||||
'id_shop' => $obj->id_shop,
|
||||
'main' => $this->getFieldValue($obj, 'main') ? true : false,
|
||||
'active' => $this->getFieldValue($obj, 'active') ? true : false,
|
||||
'jsShopUrl' => $js_shop_url
|
||||
));
|
||||
}
|
||||
|
||||
protected function afterUpdate($object)
|
||||
{
|
||||
if (Tools::getValue('main'))
|
||||
@@ -149,12 +222,31 @@ class AdminShopUrlControllerCore extends AdminController
|
||||
|
||||
public function initContent()
|
||||
{
|
||||
if ($this->display != 'edit')
|
||||
if ($this->display != 'edit' && $this->display != 'add')
|
||||
$this->display = 'list';
|
||||
else
|
||||
{
|
||||
if (!($obj = $this->loadObject(true)))
|
||||
return;
|
||||
$current_shop = Shop::initialize();
|
||||
|
||||
$list_shop_with_url = array();
|
||||
foreach (Shop::getShops(false, null, true) as $id)
|
||||
$list_shop_with_url[$id] = (bool)count(ShopUrl::getShopUrls($id));
|
||||
|
||||
$smarty = $this->context->smarty;
|
||||
$smarty->assign('jsShopUrl', Tools::jsonEncode($list_shop_with_url));
|
||||
$smarty->assign('script', $smarty->fetch($smarty->template_dir.'/'.$this->tpl_folder.'script.tpl'));
|
||||
|
||||
$this->fields_value = array(
|
||||
'domain' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain') : $current_shop->domain,
|
||||
'domain_ssl' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'domain_ssl') : $current_shop->domain_ssl,
|
||||
'physical_uri' => Validate::isLoadedObject($obj) ? $this->getFieldValue($obj, 'physical_uri') : $current_shop->physical_uri
|
||||
);
|
||||
}
|
||||
|
||||
parent::initContent();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user