summaryrefslogtreecommitdiffstats
path: root/modules-available/baseconfig
diff options
context:
space:
mode:
Diffstat (limited to 'modules-available/baseconfig')
-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
3 files changed, 63 insertions, 36 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');
+ }
}
- });
+ }
}