webui: Added validation for Oxidized API URL config (#7978)

* Add http:// to oxidized URLs missing them.

* Fixed typo.

* Form validation instead of backend fix.

* Don't update setting on invalid pattern.
This commit is contained in:
Zmegolaz
2018-01-05 09:58:42 +01:00
committed by Neil Lathwood
parent 4fc946bd21
commit d7b4a30acf
4 changed files with 26 additions and 16 deletions

View File

@ -2173,4 +2173,9 @@ label {
font-weight: bold; font-weight: bold;
vertical-align: middle; vertical-align: middle;
padding: 15px; padding: 15px;
} }
.validation:invalid {
border-color: red;
}

View File

@ -1260,8 +1260,9 @@ function generate_dynamic_config_panel($title, $config_groups, $items = array(),
if ($item['type'] == 'checkbox') { if ($item['type'] == 'checkbox') {
$output .= '<input id="' . $item['name'] . '" type="checkbox" name="global-config-check" ' . $config_groups[$item['name']]['config_checked'] . ' data-on-text="Yes" data-off-text="No" data-size="small" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">'; $output .= '<input id="' . $item['name'] . '" type="checkbox" name="global-config-check" ' . $config_groups[$item['name']]['config_checked'] . ' data-on-text="Yes" data-off-text="No" data-size="small" data-config_id="' . $config_groups[$item['name']]['config_id'] . '">';
} elseif ($item['type'] == 'text') { } elseif ($item['type'] == 'text') {
$pattern = isset($item['pattern']) ? ' required pattern="' . $item['pattern'] . '"' : "";
$output .= ' $output .= '
<input id="' . $item['name'] . '" class="form-control" type="text" name="global-config-input" value="' . $config_groups[$item['name']]['config_value'] . '" data-config_id="' . $config_groups[$item['name']]['config_id'] . '"> <input id="' . $item['name'] . '" class="form-control validation" type="text" name="global-config-input" value="' . $config_groups[$item['name']]['config_value'] . '" data-config_id="' . $config_groups[$item['name']]['config_id'] . '"' . $pattern . '>
<span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span> <span class="form-control-feedback"><i class="fa" aria-hidden="true"></i></span>
'; ';
} elseif ($item['type'] == 'password') { } elseif ($item['type'] == 'password') {

View File

@ -87,22 +87,25 @@ $(document).ready(function() {
var $this = $(this); var $this = $(this);
var config_id = $this.data("config_id"); var config_id = $this.data("config_id");
var config_value = $this.val(); var config_value = $this.val();
$.ajax({ var required = $this.prop('required');
type: 'POST', if (required == false) {
url: 'ajax_form.php', $.ajax({
data: {type: "update-config-item", config_id: config_id, config_value: config_value}, type: 'POST',
dataType: "json", url: 'ajax_form.php',
success: function (data) { data: {type: "update-config-item", config_id: config_id, config_value: config_value},
if (data.status == 'ok') { dataType: "json",
toastr.success('Config updated'); success: function (data) {
} else { if (data.status == 'ok') {
toastr.success('Config updated');
} else {
toastr.error(data.message);
}
},
error: function () {
toastr.error(data.message); toastr.error(data.message);
} }
}, });
error: function () { }
toastr.error(data.message);
}
});
}); });
// Select config ajax calls // Select config ajax calls

View File

@ -12,6 +12,7 @@ $oxidized_conf = array(
array('name' => 'oxidized.url', array('name' => 'oxidized.url',
'descr' => 'URL to your Oxidized API', 'descr' => 'URL to your Oxidized API',
'type' => 'text', 'type' => 'text',
'pattern' => '[a-zA-Z0-9]{1,5}://.*',
), ),
array('name' => 'oxidized.features.versioning', array('name' => 'oxidized.features.versioning',
'descr' => 'Enable config versioning access', 'descr' => 'Enable config versioning access',