summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorSimon Rettberg2016-08-10 12:24:01 +0200
committerSimon Rettberg2016-08-10 12:24:01 +0200
commit0491f5070c2e1c0931aeb74d06cd47101e9fdcd9 (patch)
treead80c7a6f7a78ddde6214ac7acc60235e904fd3f
parentAdd fallback feature to Dictionary functions (diff)
downloadslx-admin-0491f5070c2e1c0931aeb74d06cd47101e9fdcd9.tar.gz
slx-admin-0491f5070c2e1c0931aeb74d06cd47101e9fdcd9.tar.xz
slx-admin-0491f5070c2e1c0931aeb74d06cd47101e9fdcd9.zip
[baseconfig] Make shadow definition a json (sub)object; fix some display errors
-rw-r--r--modules-available/baseconfig/inc/baseconfigutil.inc.php22
-rw-r--r--modules-available/baseconfig/page.inc.php41
-rw-r--r--modules-available/baseconfig/templates/_page.html36
-rw-r--r--modules-available/baseconfig_bwlp/baseconfig/settings.json9
4 files changed, 71 insertions, 37 deletions
diff --git a/modules-available/baseconfig/inc/baseconfigutil.inc.php b/modules-available/baseconfig/inc/baseconfigutil.inc.php
index ebaefbcf..75173ee6 100644
--- a/modules-available/baseconfig/inc/baseconfigutil.inc.php
+++ b/modules-available/baseconfig/inc/baseconfigutil.inc.php
@@ -47,4 +47,26 @@ class BaseConfigUtil
return $categories;
}
+ /**
+ * Mark variables that would be shadowed according to the given values.
+ *
+ * @param $vars list of vars as obtained from BaseConfigUtil::getVariables()
+ * @param $values key-value-pairs of variable assignments to work with
+ */
+ public static function markShadowedVars(&$vars, $values) {
+ foreach ($vars as $key => &$var) {
+ if (!isset($var['shadows']))
+ continue;
+ foreach ($var['shadows'] as $triggerVal => $destSettings) {
+ if (isset($values[$key]) && $values[$key] !== $triggerVal)
+ continue;
+ foreach ($destSettings as $destSetting) {
+ if (isset($vars[$destSetting])) {
+ $vars[$destSetting]['shadowed'] = true;
+ }
+ }
+ }
+ }
+ }
+
}
diff --git a/modules-available/baseconfig/page.inc.php b/modules-available/baseconfig/page.inc.php
index 9ff8c086..5e99f2a0 100644
--- a/modules-available/baseconfig/page.inc.php
+++ b/modules-available/baseconfig/page.inc.php
@@ -49,14 +49,16 @@ class Page_BaseConfig extends Page
Util::redirect('?do=BaseConfig');
}
}
- //echo "<pre>";
- //var_dump($_POST);
- //echo "</pre>";
// Honor override/enabled checkbox
$override = Request::post('override', array());
// Load all existing config options to validate input
$vars = BaseConfigUtil::getVariables();
+ // First, handle shadowing so we don't create warnings for empty fields
+ BaseConfigUtil::markShadowedVars($vars, $newValues);
+ // Validate input
foreach ($vars as $key => $var) {
+ if (isset($var['shadowed']))
+ continue;
if ($this->targetModule === false) {
// Global mode
$params['enabled'] = (is_array($override) && isset($override[$key]) && $override[$key] === 'on') ? 1 : 0;
@@ -180,12 +182,13 @@ class Page_BaseConfig extends Page
//echo "</pre>";
$settings[$var['catid']]['settings'][$key] += array(
'item' => $this->makeInput(
- $var['validator'],
- $key,
- $settings[$var['catid']]['settings'][$key]['displayvalue'],
- $settings[$var['catid']]['settings'][$key]['shadows']
- ),
- 'description' => Util::markup(Dictionary::translateFileModule($var['module'], 'config-variables', $key))
+ $var['validator'],
+ $key,
+ $settings[$var['catid']]['settings'][$key]['displayvalue'],
+ $settings[$var['catid']]['settings'][$key]['shadows']
+ ),
+ 'description' => Util::markup(Dictionary::translateFileModule($var['module'], 'config-variables', $key)),
+ 'setting' => $key,
);
}
//die();
@@ -264,10 +267,9 @@ class Page_BaseConfig extends Page
private function makeInput($validator, $setting, $current, $shadows)
{
/* for the html snippet we need: */
- $tag = 'input';
- $args = array('type' => 'text', 'class' => 'form-control', 'name' => "setting[$setting]", 'id' => $setting);
+ $args = array('class' => 'form-control', 'name' => "setting[$setting]", 'id' => $setting);
if (!empty($shadows)) {
- $args['data-shadows'] = $shadows;
+ $args['data-shadows'] = json_encode($shadows);
}
$inner = "";
/* -- */
@@ -308,17 +310,20 @@ class Page_BaseConfig extends Page
$tag = 'select';
unset($args['type']);
$current = '';
+ } else {
+ // Everything else is a text input for now
+ $tag = 'input';
+ $args['value'] = $current;
+ $args['type'] = 'text';
+ /* Password field guessing */
+ if (stripos($validator, 'password') !== false) {
+ $args['type'] = Property::getPasswordFieldType();
+ }
}
/* multiinput: enter multiple free-form strings*/
if ($validator === 'multiinput') {
$args['class'] .= " multiinput";
- $args['value'] = $current;
- }
-
- /* Password field guessing */
- if (stripos($validator, 'password') !== false) {
- $args['type'] = Property::getPasswordFieldType();
}
$output = "<$tag ";
diff --git a/modules-available/baseconfig/templates/_page.html b/modules-available/baseconfig/templates/_page.html
index 7bd5f6c9..11b8d8ee 100644
--- a/modules-available/baseconfig/templates/_page.html
+++ b/modules-available/baseconfig/templates/_page.html
@@ -70,27 +70,27 @@
<script type="text/javascript">
function updateShadows(e) {
- var shadowStr = $(e).data('shadows');
+ var rules = $(e).data('shadows');
+ if (!rules) return;
var currentValue = $(e).val();
- var rules = shadowStr.split(',');
- rules.forEach(function(rule) {
- var rule_parts = rule.split('->');
- var triggerVal = rule_parts[0].trim();
- var target = rule_parts[1].trim();
- var inp = $('#' + target);
- var selitem = inp.data('selitem');
-
- if (currentValue === triggerVal) {
- inp.prop('disabled', true);
- if (selitem) selitem.disable();
- $('#' + target + '.multilist').multiselect('disable');
- } else {
- inp.prop('disabled', false);
- if (selitem) selitem.enable();
- $('#' + target + '.multilist').multiselect('enable');
+ for (var triggerVal in rules) {
+ var targets = rules[triggerVal];
+ for (var i = 0; i < targets.length; ++i) {
+ var target = targets[i];
+ var inp = $('#' + target);
+ var selitem = inp.data('selitem');
+ if (currentValue === triggerVal) {
+ inp.prop('disabled', true);
+ if (selitem) selitem.disable();
+ $('#' + target + '.multilist').multiselect('disable');
+ } else {
+ inp.prop('disabled', false);
+ if (selitem) selitem.enable();
+ $('#' + target + '.multilist').multiselect('enable');
+ }
}
- });
+ }
}
diff --git a/modules-available/baseconfig_bwlp/baseconfig/settings.json b/modules-available/baseconfig_bwlp/baseconfig/settings.json
index 5b76eb3f..d5f893e3 100644
--- a/modules-available/baseconfig_bwlp/baseconfig/settings.json
+++ b/modules-available/baseconfig_bwlp/baseconfig/settings.json
@@ -46,7 +46,14 @@
"defaultvalue": "off",
"permissions": "2",
"validator": "list:off|on|auto",
- "shadows": "off -> SLX_PROXY_PORT, off -> SLX_PROXY_TYPE, off -> SLX_PROXY_IP, off -> SLX_PROXY_BLACKLIST"
+ "shadows": {
+ "off": [
+ "SLX_PROXY_PORT",
+ "SLX_PROXY_TYPE",
+ "SLX_PROXY_IP",
+ "SLX_PROXY_BLACKLIST"
+ ]
+ }
},
"SLX_PROXY_PORT": {
"catid": "networking",