From 01b5e9e868c941fc2ca25b50b399a13d73df5997 Mon Sep 17 00:00:00 2001 From: steve-lad <72376554+steve-lad@users.noreply.github.com> Date: Wed, 30 Jun 2021 13:43:52 +0200 Subject: [PATCH] Use Dynamic Checkbox --- assets/js/sccp_manager.js | 27 +++++++++++++++-- views/formShow.php | 10 +++--- views/formShowSysDefs.php | 64 +++++++++++++++++++++++++-------------- 3 files changed, 70 insertions(+), 31 deletions(-) diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index 30d2b3c..d50ea42 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -1056,11 +1056,32 @@ function sleep(milliseconds) } } -$(".custom").click(function() { - $(this).parents(".element-container").removeClass("has-error"); +$(".sccp-restore").click(function() { + //input is sent by data-for where for is an attribute var id = $(this).data("for"), input = $("#" + id); var edit_style = document.getElementById("edit_" + id).style; - console.log(id); + + console.log(input); + if (input.length === 0) { + return; + } + if ($(this).is(":checked")) { + edit_style.display = 'block'; + input.prop("readonly", true); + } else { + edit_style.display = 'none'; + input.data("custom", input.val()); + input.prop("readonly", true); + input.val(input.data("default")); + } +}); + +$(".sccp-edit").click(function() { + //input is sent by data-for where for is an attribute + var id = $(this).data("for"), input = $("#" + id); + var edit_style = document.getElementById("edit_" + id).style; + + console.log(input); if (input.length === 0) { return; } diff --git a/views/formShow.php b/views/formShow.php index b3c691f..ed6288c 100644 --- a/views/formShow.php +++ b/views/formShow.php @@ -88,11 +88,11 @@ foreach ($items as $child) { if ($child['type'] == 'IE') { $res_input = ''; $res_name = ''; - $res_oid = (string)$child->input[0]->name; - $res_id = $npref.$res_oid; - if (!empty($metainfo[$res_oid])) { + $shortID = (string)$child->input[0]->name; + $res_id = $npref.$shortID; + if (!empty($metainfo[$shortID])) { if ($child->meta_help == '1' || $child->help == 'Help!') { - $child->help = $metainfo[$res_oid]; + $child->help = $metainfo[$shortID]; } } @@ -172,7 +172,6 @@ foreach ($items as $child) { } if ($child['type'] == 'IED') { $res_input = ''; - $res_name = ''; $res_value = ''; $opt_at = array(); $res_n = (string)$child->name; @@ -748,7 +747,6 @@ foreach ($items as $child) { } if ($child['type'] == 'ITED') { $res_input = ''; - $res_name = ''; $res_na = (string)$child->name; // $res_value diff --git a/views/formShowSysDefs.php b/views/formShowSysDefs.php index 335daa3..349e276 100644 --- a/views/formShowSysDefs.php +++ b/views/formShowSysDefs.php @@ -89,6 +89,7 @@ foreach ($items as $child) { $res_input = ''; $res_name = ''; $usingSysDefaults = true; + // if there are multiple inputs, take the first for res_id and shortId $shortId = (string)$child->input[0]->name; $res_id = $npref.$shortId; if (!empty($metainfo[$shortId])) { @@ -121,31 +122,26 @@ foreach ($items as $child) { xpath('input') as $value) { - $res_n = (string)$value->name; - $res_name = $npref . $res_n; - if (empty($res_id)) { - $res_id = $res_name; - } - if (!empty($fvalues[$res_n])) { - if (!empty($fvalues[$res_n]['data'])) { + $res_n = (string)$value->name; + $res_name = $npref . $res_n; + //if (!empty($fvalues[$res_n])) { + //if (!empty($fvalues[$res_n]['data'])) { if (!empty($sccp_defaults[$res_n]['systemdefault']) && ($sccp_defaults[$res_n]['systemdefault'] != $fvalues[$res_n]['data'])) { $usingSysDefaults = false; } $value->value = $fvalues[$res_n]['data']; - } - } - if (empty($value->value)) { - $value->value = $value->default; - } + //} + //} + // Default to chan-sccp defaults, not xml defaults. + //if (empty($value->value)) { + //$value->value = $sccp_defaults[$res_n]['systemdefault']; + //} if (empty($value->type)) { $value->type = 'text'; } if (empty($value->class)) { $value->class = 'form-control'; } - // TODO: This is a temporary workaround and should be fixed - $item = array('id' => $res_id, 'setting' => $child->label, 'feature' => $res_id, 'iscustom' => 'checked'); - if ($i > 0) { echo $child->nameseparator; } @@ -156,13 +152,36 @@ foreach ($items as $child) {