From 8268bbf81a544394ff26d87a9a2407bf0feef200 Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 31 Dec 2021 12:45:12 +0100 Subject: [PATCH 1/4] Fix restore defaults for radio buttons Fix restore defaults for radio buttons --- assets/js/sccp_manager.js | 21 +++++++++++++-------- sccpManClasses/formcreate.class.php | 1 + 2 files changed, 14 insertions(+), 8 deletions(-) diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index f318418..0fedd6f 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -1197,17 +1197,22 @@ $(".sccp-restore").click(function() { return; } if ($(this).is(":checked")) { - console.log('restore/checked'); edit_style.display = 'block'; + var defaultVal = $(this).data("default"); if ($(this).data("type") === 'radio') { // simulate read only for checkboxes - input.forEach( - function(radioElement) { - radioElement.setAttribute('disabled', true); - if (radioElement.hasAttribute('checked')) { - radioElement.removeAttribute('disabled'); - } - } + console.log(input); + input.forEach( + function(radioElement) { + radioElement.setAttribute('disabled', true); + if (radioElement.value === defaultVal){ + radioElement.removeAttribute('disabled'); + radioElement.setAttribute('checked', true); + } else { + radioElement.setAttribute('disabled', true); + radioElement.removeAttribute('checked'); + } + } ); return; } diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index ca7d139..75afdee 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -398,6 +398,7 @@ class formcreate // reverting to chan-sccp default values echo " data-for={$res_id}"; echo " data-type=radio"; + echo " data-default={$sccp_defaults[$res_n]['systemdefault']}"; echo " class=sccp-restore"; echo " id=usedefault_{$res_id}"; echo " "; From 8953484e1fd848696352342f9310e9cb456a5f22 Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 31 Dec 2021 15:01:02 +0100 Subject: [PATCH 2/4] Fix reset of defaults for text fields Still need to address bindaddress:port and externalIP: Name --- assets/js/sccp_manager.js | 87 +++++++++++++++-------------- sccpManClasses/formcreate.class.php | 2 + 2 files changed, 46 insertions(+), 43 deletions(-) diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index 0fedd6f..0bf2f37 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -1187,52 +1187,53 @@ function sleep(milliseconds) } $(".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; - if ($(this).data("type") === 'radio') { - input = document.getElementsByName(id); - } - if (input.length === 0) { - return; - } - if ($(this).is(":checked")) { - edit_style.display = 'block'; - var defaultVal = $(this).data("default"); + //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; if ($(this).data("type") === 'radio') { - // simulate read only for checkboxes - console.log(input); - input.forEach( - function(radioElement) { - radioElement.setAttribute('disabled', true); - if (radioElement.value === defaultVal){ - radioElement.removeAttribute('disabled'); - radioElement.setAttribute('checked', true); - } else { + input = document.getElementsByName(id); + } else if ($(this).data("type") === 'text') { + input = document.getElementsByName(id); + } + if (input.length === 0) { + return; + } + if ($(this).is(":checked")) { + console.log("Restore checked"); + edit_style.display = 'block'; + var defaultVal = $(this).data("default"); + if ($(this).data("type") === 'radio') { + // simulate read only for checkboxes except default + input.forEach( + function(radioElement) { radioElement.setAttribute('disabled', true); - radioElement.removeAttribute('checked'); + if (radioElement.value === defaultVal){ + radioElement.removeAttribute('disabled'); + radioElement.setAttribute('checked', true); + } else { + radioElement.removeAttribute('checked'); + } } - } - ); - return; - } - input.prop("readonly", true); - } else { - console.log('restore/unchecked'); - edit_style.display = 'none'; - if ($(this).data("type") === 'radio') { - // simulate read only for checkboxes - input.forEach( - function(radioElement) { - radioElement.removeAttribute('disabled'); - } - ); - return; - } - input.data("custom", input.val()); - input.prop("readonly", true); - input.val(input.data("default")); - } + ); + return; + } else if ($(this).data("type") === 'text') { + input[0].value = defaultVal; + input[0].readOnly = true; + } + } else { + edit_style.display = 'none'; + if ($(this).data("type") === 'radio') { + input.forEach( + function(radioElement) { + radioElement.removeAttribute('disabled'); + } + ); + return; + } + input.data("custom", input.val()); + input.prop("readonly", true); + input.val(input.data("default")); + } }); $(".sccp-edit").click(function() { diff --git a/sccpManClasses/formcreate.class.php b/sccpManClasses/formcreate.class.php index 75afdee..0fe61cd 100644 --- a/sccpManClasses/formcreate.class.php +++ b/sccpManClasses/formcreate.class.php @@ -94,8 +94,10 @@ class formcreate } else { // reverting to chan-sccp default values echo " data-for={$res_id}"; + echo " data-type=text"; echo " class=sccp-restore"; echo " id=usedefault_{$res_id}"; + echo " data-default={$sccp_defaults[$res_n]['systemdefault']}"; echo " "; } ?> From 89b1a1cd3f337449ebac41306e7a77a95cd7aad0 Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 31 Dec 2021 15:31:56 +0100 Subject: [PATCH 3/4] Fix defaults for string settings Hack to fix bindaddr / externip --- assets/js/sccp_manager.js | 20 +++++++++----------- 1 file changed, 9 insertions(+), 11 deletions(-) diff --git a/assets/js/sccp_manager.js b/assets/js/sccp_manager.js index 0bf2f37..e1c0a35 100644 --- a/assets/js/sccp_manager.js +++ b/assets/js/sccp_manager.js @@ -1190,16 +1190,12 @@ $(".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; - if ($(this).data("type") === 'radio') { - input = document.getElementsByName(id); - } else if ($(this).data("type") === 'text') { - input = document.getElementsByName(id); - } + input = document.getElementsByName(id); if (input.length === 0) { - return; + return; } if ($(this).is(":checked")) { - console.log("Restore checked"); + // Restoring defaults edit_style.display = 'block'; var defaultVal = $(this).data("default"); if ($(this).data("type") === 'radio') { @@ -1217,10 +1213,16 @@ $(".sccp-restore").click(function() { ); return; } else if ($(this).data("type") === 'text') { + if ((input[0].id === "sccp_bindaddr") || (input[0].id === "sccp_externip")) { + // TODO: This is a dirty hack as default value is wrong - need to improve + input[0].value = '0.0.0.0'; + } else { input[0].value = defaultVal; input[0].readOnly = true; + } } } else { + // editing for custom value edit_style.display = 'none'; if ($(this).data("type") === 'radio') { input.forEach( @@ -1228,11 +1230,7 @@ $(".sccp-restore").click(function() { radioElement.removeAttribute('disabled'); } ); - return; } - input.data("custom", input.val()); - input.prop("readonly", true); - input.val(input.data("default")); } }); From 84b65309a3952ea9902d3877fbeb8e6a4d7db6ba Mon Sep 17 00:00:00 2001 From: stevenA Date: Fri, 31 Dec 2021 15:32:44 +0100 Subject: [PATCH 4/4] Update Version --- module.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/module.xml b/module.xml index 0b772da..7fa4c4a 100644 --- a/module.xml +++ b/module.xml @@ -1,7 +1,7 @@ sccp_manager SCCP Manager - 14.3.0.21 + 14.3.0.22 setup SCCP Connectivity Steve Lad, Alex GP