From 06cc9cff99b6bd03cff93199a511e7d4cd625452 Mon Sep 17 00:00:00 2001 From: rMalie Date: Wed, 3 Aug 2011 18:06:51 +0000 Subject: [PATCH] // 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 --- admin-dev/tabs/AdminPreferences.php | 33 +++++++++---- classes/AdminTab.php | 73 +++++++++++------------------ classes/Configuration.php | 19 ++++++++ css/admin.css | 35 +++++++++++++- 4 files changed, 103 insertions(+), 57 deletions(-) diff --git a/admin-dev/tabs/AdminPreferences.php b/admin-dev/tabs/AdminPreferences.php index 35db529f8..5c13c3b7a 100644 --- a/admin-dev/tabs/AdminPreferences.php +++ b/admin-dev/tabs/AdminPreferences.php @@ -358,19 +358,28 @@ class AdminPreferences extends AdminTab if (isset($field['required']) AND $field['required']) $required = true; $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'])) { - echo '
'; - $this->getHtmlDefaultConfigurationValue($key, $languages); - + echo '
'; if ($field['title']) - echo ''; + echo ''; echo '
'; } - $isDisabled = (Shop::isMultiShopActivated() && isset($field['visibility']) && $field['visibility'] > $this->context->shop->getContextType()) ? true : false; - /* Display the appropriate input type for each field */ switch ($field['type']) { @@ -485,16 +494,20 @@ class AdminPreferences extends AdminTab break; case 'maintenance_ip': - echo ''.(isset($field['next']) ? ' '.strval($field['next']) : '').'  '.$this->l('Add my IP').''; + echo ''.(isset($field['next']) ? ' '.strval($field['next']) : '').'  '.$this->l('Add my IP').''; break; case 'text': default: - echo ''.(isset($field['next']) ? ' '.strval($field['next']) : ''); + echo ''.(isset($field['next']) ? ' '.strval($field['next']) : ''); } echo ((isset($field['required']) AND $field['required'] AND !in_array($field['type'], array('image', 'radio'))) ? ' *' : ''); - echo (isset($field['desc']) ? '

'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? ''.$field['title'].'' : '' ).$field['desc'].'

' : ''); - echo ($isDisabled) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; + + if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible) + echo '
'; + + echo (isset($field['desc']) ? '

'.((isset($field['thumb']) AND $field['thumb'] AND $field['thumb']['pos'] == 'after') ? ''.$field['title'].'' : '' ).$field['desc'].'

' : ''); + echo ($isInvisible) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; if (!in_array($field['type'], array('image', 'radio', 'container', 'container_end')) OR isset($field['show'])) echo '
'; } diff --git a/classes/AdminTab.php b/classes/AdminTab.php index 76c9f4fbb..342a424a9 100644 --- a/classes/AdminTab.php +++ b/classes/AdminTab.php @@ -93,6 +93,8 @@ abstract class AdminTabCore /** @var array Fields to display in list */ public $fieldsDisplay = array(); + public $optionTitle = null; + /** @var string shop | group_shop */ public $shopLinkType; @@ -152,6 +154,8 @@ abstract class AdminTabCore /** @var bool If false, don't add form tags in options forms */ protected $formOptions = true; + + public $_fieldsOptions = array(); protected $_languages = NULL; protected $_defaultFormLanguage = NULL; @@ -1677,25 +1681,25 @@ abstract class AdminTabCore { if (is_null($fieldsOptions)) $fieldsOptions = $this->_fieldsOptions; - - if (is_null($optionTitle)) - $optionTitle = $this->optionTitle; if (!isset($fieldsOptions) OR !sizeof($fieldsOptions)) return false; - + + if (is_null($optionTitle)) + $optionTitle = $this->optionTitle; + $defaultLanguage = (int)$this->context->language->id; $this->_languages = Language::getLanguages(false); $tab = Tab::getTab($defaultLanguage, $this->id); echo '

'; - echo (isset($optionTitle) ? '

'.$optionTitle.'

' : ''); + echo ($optionTitle ? '

'.$optionTitle.'

' : ''); echo ' '.(($this->formOptions) ? '
' : '').'
'; - echo (isset($optionTitle) ? ' + echo ($optionTitle ? ' ' .$optionTitle.'' : ''); if ($optionDescription) @@ -1711,10 +1715,20 @@ abstract class AdminTabCore if (isset($field['defaultValue']) && !$val) $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 ' + echo '
'; switch ($field['type']) { @@ -1770,12 +1784,15 @@ abstract class AdminTabCore break; } + if (Shop::isMultiShopActivated() && Context::shop() != Shop::CONTEXT_ALL && !$isInvisible) + echo '
'; + if (isset($field['required']) AND $field['required']) echo ' *'; echo (isset($field['desc']) ? '

'.$field['desc'].'

' : ''); - echo ($isDisabled) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; - echo '
'; + echo ($isInvisible) ? '

'.$this->l('You can\'t change the value of this configuration field in this shop context').'

' : ''; + echo '
'; } echo '
@@ -2121,40 +2138,6 @@ EOF; 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 '
'; - echo ''; - echo '
'; - echo ' '.$this->l('Use default value'); - echo '
'; - echo '
'; - } - } - /** * Process the submission of a configuration form * diff --git a/classes/Configuration.php b/classes/Configuration.php index df5e6321e..b3d6f5101 100644 --- a/classes/Configuration.php +++ b/classes/Configuration.php @@ -405,6 +405,25 @@ class ConfigurationCore extends ObjectModel 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 * diff --git a/css/admin.css b/css/admin.css index b5b4e31e7..c140d16b2 100644 --- a/css/admin.css +++ b/css/admin.css @@ -1595,8 +1595,7 @@ a.action_module_delete { border: 1px dotted #000000; } -fieldset .optionsDescription -{ +fieldset .optionsDescription{ background: url("../img/admin/help2.png") no-repeat scroll 6px center #DDE9F7; border: 1px solid #50B0EC; color: #7F7F7F; @@ -1604,4 +1603,36 @@ fieldset .optionsDescription font-size: 0.85em; margin-bottom: 15px; 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; } \ No newline at end of file