// Improve ergonomy of configuration for multishop

git-svn-id: http://dev.prestashop.com/svn/v1/branches/1.5.x@7879 b9a71923-0436-4b27-9f14-aed3839534dd
This commit is contained in:
rMalie
2011-08-03 18:06:51 +00:00
parent f2b5ee338b
commit 06cc9cff99
4 changed files with 103 additions and 57 deletions
+23 -10
View File
@@ -358,19 +358,28 @@ class AdminPreferences extends AdminTab
if (isset($field['required']) AND $field['required']) if (isset($field['required']) AND $field['required'])
$required = true; $required = true;
$val = $this->getVal($confValues, $key); $val = $this->getVal($confValues, $key);
// Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop)
$isDisabled = $isInvisible = false;
if (Shop::isMultiShopActivated())
{
if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType())
{
$isDisabled = true;
$isInvisible = true;
}
else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key))
$isDisabled = true;
}
if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show'])) if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show']))
{ {
echo '<div style="clear: both; padding-top:15px;">'; echo '<div style="clear: both; padding-top:15px;" id="conf_id_'.$key.'">';
$this->getHtmlDefaultConfigurationValue($key, $languages);
if ($field['title']) if ($field['title'])
echo '<label>'.$field['title'].'</label>'; echo '<label class="conf_title '.(($isDisabled) ? 'isDisabled' : '').'">'.$field['title'].'</label>';
echo '<div class="margin-form" style="padding-top:5px;">'; echo '<div class="margin-form" style="padding-top:5px;">';
} }
$isDisabled = (Shop::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) ? true : false;
/* Display the appropriate input type for each field */ /* Display the appropriate input type for each field */
switch ($field['type']) switch ($field['type'])
{ {
@@ -485,16 +494,20 @@ class AdminPreferences extends AdminTab
break; break;
case 'maintenance_ip': case 'maintenance_ip':
echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : '').' &nbsp<a href="#" class="button" onclick="addRemoteAddr(); return false;">'.$this->l('Add my IP').'</a>'; echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').(($isDisabled) ? 'disabled="disabled"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : '').' &nbsp<a href="#" class="button" onclick="addRemoteAddr(); return false;">'.$this->l('Add my IP').'</a>';
break; break;
case 'text': case 'text':
default: default:
echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').(($isDisabled) ? ' disabled="disabled"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : ''); echo '<input type="'.$field['type'].'"'.(isset($field['id']) === true ? ' id="'.$field['id'].'"' : '').(($isDisabled) ? 'disabled="disabled"' : '').' size="'.(isset($field['size']) ? (int)($field['size']) : 5).'" name="'.$key.'" value="'.($field['type'] == 'password' ? '' : htmlentities($val, ENT_COMPAT, 'UTF-8')).'" />'.(isset($field['next']) ? '&nbsp;'.strval($field['next']) : '');
} }
echo ((isset($field['required']) AND $field['required'] AND !in_array($field['type'], array('image', 'radio'))) ? ' <sup>*</sup>' : ''); echo ((isset($field['required']) AND $field['required'] AND !in_array($field['type'], array('image', 'radio'))) ? ' <sup>*</sup>' : '');
echo (isset($field['desc']) ? '<p style="clear:both">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
echo ($isDisabled) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : ''; if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible)
echo '<div class="preference_default_multishop"><label><input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '') .' onclick="$(\'#conf_id_'.$key.' input, #conf_id_'.$key.' textarea, #conf_id_'.$key.' select\').attr(\'disabled\', $(this).attr(\'checked\')); $(\'#conf_id_'.$key.' .preference_default_multishop input\').attr(\'disabled\', false); $(\'#conf_id_'.$key.' label.conf_title\').toggleClass(\'isDisabled\');" /> '.$this->l('Use default value').'</label></div>';
echo (isset($field['desc']) ? '<p class="preference_description">'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? '<img src="'.$field['thumb']['file'].'" alt="'.$field['title'].'" title="'.$field['title'].'" style="float:left;" />' : '' ).$field['desc'].'</p>' : '');
echo ($isInvisible) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : '';
if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show'])) if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show']))
echo '</div></div>'; echo '</div></div>';
} }
+28 -45
View File
@@ -93,6 +93,8 @@ abstract class AdminTabCore
/** @var array Fields to display in list */ /** @var array Fields to display in list */
public $fieldsDisplay = array(); public $fieldsDisplay = array();
public $optionTitle = null;
/** @var string shop | group_shop */ /** @var string shop | group_shop */
public $shopLinkType; public $shopLinkType;
@@ -152,6 +154,8 @@ abstract class AdminTabCore
/** @var bool If false, don't add form tags in options forms */ /** @var bool If false, don't add form tags in options forms */
protected $formOptions = true; protected $formOptions = true;
public $_fieldsOptions = array();
protected $_languages = NULL; protected $_languages = NULL;
protected $_defaultFormLanguage = NULL; protected $_defaultFormLanguage = NULL;
@@ -1677,25 +1681,25 @@ abstract class AdminTabCore
{ {
if (is_null($fieldsOptions)) if (is_null($fieldsOptions))
$fieldsOptions = $this->_fieldsOptions; $fieldsOptions = $this->_fieldsOptions;
if (is_null($optionTitle))
$optionTitle = $this->optionTitle;
if (!isset($fieldsOptions) OR !sizeof($fieldsOptions)) if (!isset($fieldsOptions) OR !sizeof($fieldsOptions))
return false; return false;
if (is_null($optionTitle))
$optionTitle = $this->optionTitle;
$defaultLanguage = (int)$this->context->language->id; $defaultLanguage = (int)$this->context->language->id;
$this->_languages = Language::getLanguages(false); $this->_languages = Language::getLanguages(false);
$tab = Tab::getTab($defaultLanguage, $this->id); $tab = Tab::getTab($defaultLanguage, $this->id);
echo '<br /><br />'; echo '<br /><br />';
echo (isset($optionTitle) ? '<h2>'.$optionTitle.'</h2>' : ''); echo ($optionTitle ? '<h2>'.$optionTitle.'</h2>' : '');
echo ' echo '
<script type="text/javascript"> <script type="text/javascript">
id_language = Number('.$defaultLanguage.'); id_language = Number('.$defaultLanguage.');
</script> </script>
'.(($this->formOptions) ? '<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">' : '').' '.(($this->formOptions) ? '<form action="'.self::$currentIndex.'" id="'.$tab['name'].'" name="'.$tab['name'].'" method="post">' : '').'
<fieldset>'; <fieldset>';
echo (isset($optionTitle) ? '<legend> echo ($optionTitle ? '<legend>
<img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />' <img src="'.(!empty($tab['module']) && file_exists($_SERVER['DOCUMENT_ROOT']._MODULE_DIR_.$tab['module'].'/'.$tab['class_name'].'.gif') ? _MODULE_DIR_.$tab['module'].'/' : '../img/t/').$tab['class_name'].'.gif" />'
.$optionTitle.'</legend>' : ''); .$optionTitle.'</legend>' : '');
if ($optionDescription) if ($optionDescription)
@@ -1711,10 +1715,20 @@ abstract class AdminTabCore
if (isset($field['defaultValue']) && !$val) if (isset($field['defaultValue']) && !$val)
$val = $field['defaultValue']; $val = $field['defaultValue'];
$isDisabled = (Shop::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) ? true : false; // Check if var is invisible (can't edit it in current shop context), or disable (use default value for multishop)
$isDisabled = $isInvisible = false;
if (Shop::isMultiShopActivated())
{
if (isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType())
{
$isDisabled = true;
$isInvisible = true;
}
else if (Context::shop() != Shop::CONTEXT_ALL && !Configuration::isOverridenByCurrentContext($key))
$isDisabled = true;
}
echo $this->getHtmlDefaultConfigurationValue($key, $this->_languages); echo '<div id="conf_id_'.$key.'"><label>'.$field['title'].' </label>
echo '<label>'.$field['title'].' </label>
<div class="margin-form">'; <div class="margin-form">';
switch ($field['type']) switch ($field['type'])
{ {
@@ -1770,12 +1784,15 @@ abstract class AdminTabCore
break; break;
} }
if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible)
echo '<div class="preference_default_multishop"><label><input type="checkbox" name="configUseDefault['.$key.']" value="1" '.(($isDisabled) ? 'checked="checked"' : '') .' onclick="$(\'#conf_id_'.$key.' input, #conf_id_'.$key.' textarea, #conf_id_'.$key.' select\').attr(\'disabled\', $(this).attr(\'checked\')); $(\'#conf_id_'.$key.' .preference_default_multishop input\').attr(\'disabled\', false); $(\'#conf_id_'.$key.' label.conf_title\').toggleClass(\'isDisabled\');" /> '.$this->l('Use default value').'</label></div>';
if (isset($field['required']) AND $field['required']) if (isset($field['required']) AND $field['required'])
echo ' <sup>*</sup>'; echo ' <sup>*</sup>';
echo (isset($field['desc']) ? '<p>'.$field['desc'].'</p>' : ''); echo (isset($field['desc']) ? '<p>'.$field['desc'].'</p>' : '');
echo ($isDisabled) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : ''; echo ($isInvisible) ? '<p><img src="../img/admin/warning.gif" /> <b>'.$this->l('You can\'t change the value of this configuration field in this shop context').'</b></p>' : '';
echo '</div>'; echo '</div></div>';
} }
echo '<div class="margin-form"> echo '<div class="margin-form">
<input type="submit" value="'.$this->l(' Save ').'" name="submitOptions'.$this->table.'" class="button" /> <input type="submit" value="'.$this->l(' Save ').'" name="submitOptions'.$this->table.'" class="button" />
@@ -2121,40 +2138,6 @@ EOF;
return $url; return $url;
} }
/**
* Display the button to set default value of a configuration field
*
* @todo Improve system for modules
* @param string $key
* @return string
*/
protected function getHtmlDefaultConfigurationValue($key, $languages)
{
if (Configuration::isLangKey($key))
{
$testContext = false;
foreach ($languages as $lang)
if (($this->context->shop->getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_SHOP))
|| ($this->context->shop->getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_GROUP)))
$testContext = true;
}
else
{
$testContext = (($this->context->shop->getContextType() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, null, Shop::CONTEXT_SHOP))
|| ($this->context->shop->getContextType() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false;
}
if (Shop::isMultiShopActivated() && $this->context->shop->getContextType() != Shop::CONTEXT_ALL && $testContext)
{
echo '<div class="multishop_config">';
echo '<a href="#" title="'.$this->l('Click here to use default value for this field').'"><img src="../img/admin/multishop_config.png" /></a>';
echo '<div>';
echo '<input type="checkbox" name="configUseDefault['.$key.']" value="1" /> '.$this->l('Use default value');
echo '</div>';
echo '</div>';
}
}
/** /**
* Process the submission of a configuration form * Process the submission of a configuration form
* *
+19
View File
@@ -405,6 +405,25 @@ class ConfigurationCore extends ObjectModel
return false; return false;
} }
public static function isOverridenByCurrentContext($key)
{
if (Configuration::isLangKey($key))
{
$testContext = false;
foreach (Language::getLanguages(false) as $lang)
if ((Context::shop() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_SHOP))
|| (Context::shop() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, $lang['id_lang'], Shop::CONTEXT_GROUP)))
$testContext = true;
}
else
{
$testContext = ((Context::shop() == Shop::CONTEXT_SHOP && Configuration::hasContext($key, null, Shop::CONTEXT_SHOP))
|| (Context::shop() == Shop::CONTEXT_GROUP && Configuration::hasContext($key, null, Shop::CONTEXT_GROUP))) ? true : false;
}
return (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && $testContext);
}
/** /**
* Check if a key was loaded as multi lang * Check if a key was loaded as multi lang
* *
+33 -2
View File
@@ -1595,8 +1595,7 @@ a.action_module_delete {
border: 1px dotted #000000; border: 1px dotted #000000;
} }
fieldset .optionsDescription fieldset .optionsDescription{
{
background: url("../img/admin/help2.png") no-repeat scroll 6px center #DDE9F7; background: url("../img/admin/help2.png") no-repeat scroll 6px center #DDE9F7;
border: 1px solid #50B0EC; border: 1px solid #50B0EC;
color: #7F7F7F; color: #7F7F7F;
@@ -1604,4 +1603,36 @@ fieldset .optionsDescription
font-size: 0.85em; font-size: 0.85em;
margin-bottom: 15px; margin-bottom: 15px;
padding: 5px 5px 5px 40px; padding: 5px 5px 5px 40px;
}
p.preference_description{
clear: both;
text-align: justify;
width: 500px;
}
.preference_default_multishop{
float: right;
margin-right: 40px;
}
.preference_default_multishop input{
margin-top: -3px;
}
.preference_default_multishop label{
float: none;
font-size: 12px;
color: #666666;
font-style: italic;
}
.isDisabled{
color: #3F3F3F;
font-style: italic;
}
input.disable_me[disabled=disabled]
{
background-color: red;
} }