Enable/Disable buttons when setting chan-sccp defaults

First version - Needs simplifying!
This commit is contained in:
steve-lad 2021-07-03 12:10:44 +02:00
parent 93fe6d45e1
commit 7dc4438ad8
2 changed files with 31 additions and 13 deletions

View file

@ -1058,12 +1058,10 @@ function sleep(milliseconds)
$(".sccp-restore").click(function() { $(".sccp-restore").click(function() {
//input is sent by data-for where for as an attribute //input is sent by data-for where for as an attribute
var id = $(this).data("for"), input = $("#" + id); var id = $(this).data("for"), input = $("#" + id), radId = id + "_";
var edit_style = document.getElementById("edit_" + id).style; var edit_style = document.getElementById("edit_" + id).style;
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
input = document.getElementsByName(id); input = document.getElementsByName(id);
console.log('have radio type');
// Need to use getElementBy Name
} }
console.log(input); console.log(input);
@ -1075,13 +1073,29 @@ $(".sccp-restore").click(function() {
edit_style.display = 'block'; edit_style.display = 'block';
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
// simulate read only for checkboxes // simulate read only for checkboxes
$(':radio:not(:checked)').attr('disabled', true) input.forEach(
return; function(radioElement) {
radioElement.setAttribute('disabled', true);
if (radioElement.hasAttribute('checked')) {
radioElement.removeAttribute('disabled');
}
}
);
return;
} }
input.prop("readonly", true); input.prop("readonly", true);
} else { } else {
console.log('restore/unchecked'); console.log('restore/unchecked');
edit_style.display = 'none'; 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.data("custom", input.val());
input.prop("readonly", true); input.prop("readonly", true);
input.val(input.data("default")); input.val(input.data("default"));
@ -1094,9 +1108,6 @@ $(".sccp-edit").click(function() {
var edit_style = document.getElementById("edit_" + id).style; var edit_style = document.getElementById("edit_" + id).style;
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
input = document.getElementsByName(id); input = document.getElementsByName(id);
console.log('have radio type');
// $(':radio:not(:checked)').attr('disabled', true); to make readonly
// Need to use getElementBy Name
} }
console.log(input); console.log(input);
@ -1107,15 +1118,22 @@ $(".sccp-edit").click(function() {
console.log('edit/checked'); console.log('edit/checked');
edit_style.display = 'block'; edit_style.display = 'block';
if ($(this).data("type") === 'radio') { if ($(this).data("type") === 'radio') {
$(':radio:not(:checked)').attr('disabled', false) // Security - attribute should not exist.
return; input.forEach(
function(radioElement) {
if (radioElement.hasAttribute('disabled')) {
radioElement.removeAttribute('disabled');
}
}
);
return;
} }
input.prop("readonly", false); input.prop("readonly", false);
input.focus(); input.focus();
} else { } else {
console.log('edit/unchecked'); console.log('edit/unchecked');
edit_style.display = 'none'; edit_style.display = 'none';
if (input == 'radio') { if ($(this).data("type") === 'radio') {
return; return;
} }
input.data("custom", input.val()); input.data("custom", input.val());

View file

@ -127,7 +127,7 @@ foreach ($items as $child) {
if (!empty($fvalues[$res_n]['data'])) { if (!empty($fvalues[$res_n]['data'])) {
if (!empty($sccp_defaults[$res_n]['systemdefault']) && ($sccp_defaults[$res_n]['systemdefault'] != $fvalues[$res_n]['data'])) { if (!empty($sccp_defaults[$res_n]['systemdefault']) && ($sccp_defaults[$res_n]['systemdefault'] != $fvalues[$res_n]['data'])) {
$usingSysDefaults = false; $usingSysDefaults = false;
} }
} }
//} //}
// Default to chan-sccp defaults, not xml defaults. // Default to chan-sccp defaults, not xml defaults.
@ -526,7 +526,7 @@ foreach ($items as $child) {
} else {$val_check = "";} } else {$val_check = "";}
} else {$val_check = "";} } else {$val_check = "";}
} }
echo '<input type="radio" name="' . $res_id . '" id="' . $res_id. '_' . $i .'" value="' . $value[@value] . '"' . $val_check . $opt_hide.'>'; echo "<input type=radio name= {$res_id} id=${res_id}_{$i} value={$value[@value]} {$val_check}{$opt_hide}>";
echo '<label for="' . $res_id. '_' . $i . '">' . _($value) . '</label>'; echo '<label for="' . $res_id. '_' . $i . '">' . _($value) . '</label>';
$i++; $i++;
} }