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

View file

@ -526,7 +526,7 @@ foreach ($items as $child) {
} 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>';
$i++;
}