Merge pull request #52 from chan-sccp/Fix-Issue-#49
Fix Issue #49 and improve handling of edit defaults
This commit is contained in:
commit
6cf10cc13b
|
@ -1186,6 +1186,9 @@ function sleep(milliseconds)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// There are 2 dynamically created button Classes
|
||||||
|
// sccp_restore for restoring system defaults, and sccp_edit for entering
|
||||||
|
// custom values. Clicking on these buttons is handled by the 2 functions below.
|
||||||
$(".sccp-restore").click(function() {
|
$(".sccp-restore").click(function() {
|
||||||
//input is sent by data-for where for is an attribute
|
//input is sent by data-for where for is an attribute
|
||||||
var id = $(this).data("for"), input = $("#" + id);
|
var id = $(this).data("for"), input = $("#" + id);
|
||||||
|
@ -1195,7 +1198,9 @@ $(".sccp-restore").click(function() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
if ($(this).is(":checked")) {
|
if ($(this).is(":checked")) {
|
||||||
|
console.log('restore/checked');
|
||||||
// Restoring defaults
|
// Restoring defaults
|
||||||
|
// show the edit block and populate with default values.
|
||||||
edit_style.display = 'block';
|
edit_style.display = 'block';
|
||||||
var defaultVal = $(this).data("default");
|
var defaultVal = $(this).data("default");
|
||||||
if ($(this).data("type") === 'radio') {
|
if ($(this).data("type") === 'radio') {
|
||||||
|
@ -1205,7 +1210,7 @@ $(".sccp-restore").click(function() {
|
||||||
radioElement.setAttribute('disabled', true);
|
radioElement.setAttribute('disabled', true);
|
||||||
if (radioElement.value === defaultVal){
|
if (radioElement.value === defaultVal){
|
||||||
radioElement.removeAttribute('disabled');
|
radioElement.removeAttribute('disabled');
|
||||||
radioElement.setAttribute('checked', true);
|
radioElement.checked = true;
|
||||||
} else {
|
} else {
|
||||||
radioElement.removeAttribute('checked');
|
radioElement.removeAttribute('checked');
|
||||||
}
|
}
|
||||||
|
@ -1221,51 +1226,60 @@ $(".sccp-restore").click(function() {
|
||||||
input[0].readOnly = true;
|
input[0].readOnly = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
// editing for custom value
|
console.log('restore/unchecked');
|
||||||
edit_style.display = 'none';
|
edit_style.display = 'none';
|
||||||
|
if ($(this).data("type") === 'radio') {
|
||||||
|
input.forEach(
|
||||||
|
function(radioElement) {
|
||||||
|
//Revert to original value as have unchecked customise.
|
||||||
|
radioElement.checked = radioElement.defaultChecked;
|
||||||
|
radioElement.name.value = radioElement.name.defaultValue;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if ($(this).data("type") === 'text') {
|
||||||
|
//Revert to original value as have unchecked customise.
|
||||||
|
input[0].value = input[0].defaultValue;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
$(".sccp-edit").click(function() {
|
||||||
|
//input is sent by data-xxx where xxx is an attribute
|
||||||
|
var id = $(this).data("for"), input = $("#" + id);
|
||||||
|
var edit_style = document.getElementById("edit_" + id).style;
|
||||||
|
input = document.getElementsByName(id);
|
||||||
|
|
||||||
|
if (input.length === 0) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
if ($(this).is(":checked")) {
|
||||||
|
// editing away from the default value
|
||||||
|
console.log('edit/checked');
|
||||||
|
edit_style.display = 'block';
|
||||||
if ($(this).data("type") === 'radio') {
|
if ($(this).data("type") === 'radio') {
|
||||||
input.forEach(
|
input.forEach(
|
||||||
function(radioElement) {
|
function(radioElement) {
|
||||||
radioElement.removeAttribute('disabled');
|
radioElement.removeAttribute('disabled');
|
||||||
}
|
}
|
||||||
);
|
);
|
||||||
|
return;
|
||||||
|
} else if ($(this).data("type") === 'text') {
|
||||||
|
input[0].focus();
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
console.log('edit/unchecked');
|
||||||
|
edit_style.display = 'none';
|
||||||
|
if ($(this).data("type") === 'radio') {
|
||||||
|
input.forEach(
|
||||||
|
function(radioElement) {
|
||||||
|
//Revert to original value as have unchecked customise.
|
||||||
|
radioElement.checked = radioElement.defaultChecked;
|
||||||
|
}
|
||||||
|
);
|
||||||
|
} else if ($(this).data("type") === 'text') {
|
||||||
|
//Revert to original value as have unchecked customise.
|
||||||
|
input[0].value = input[0].defaultValue;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
|
|
||||||
$(".sccp-edit").click(function() {
|
|
||||||
//input is sent by data-xxx where xxx 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")) {
|
|
||||||
console.log('edit/checked');
|
|
||||||
edit_style.display = 'block';
|
|
||||||
if ($(this).data("type") === 'radio') {
|
|
||||||
// Security - attribute should not exist.
|
|
||||||
input.forEach(
|
|
||||||
function(radioElement) {
|
|
||||||
radioElement.removeAttribute('disabled');
|
|
||||||
}
|
|
||||||
);
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
input.prop("readonly", false);
|
|
||||||
input.focus();
|
|
||||||
} else {
|
|
||||||
console.log('edit/unchecked');
|
|
||||||
edit_style.display = 'none';
|
|
||||||
if ($(this).data("type") === 'radio') {
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
input.data("custom", input.val());
|
|
||||||
input.prop("readonly", true);
|
|
||||||
input.val(input.data("default"));
|
|
||||||
}
|
|
||||||
});
|
|
||||||
|
|
|
@ -78,7 +78,7 @@ and open the template in the editor. Base Version before all crash :-)
|
||||||
<name>servername</name>
|
<name>servername</name>
|
||||||
<default>Asterisk XML</default>
|
<default>Asterisk XML</default>
|
||||||
</input>
|
</input>
|
||||||
<help>Servername: This is the type of server - usually, it will be Asterisk.</help>
|
<help>Servername: This is the name of the server; normally it will be Asterisk.</help>
|
||||||
</item>
|
</item>
|
||||||
<item type="IE" id="3">
|
<item type="IE" id="3">
|
||||||
<label>Bind Address : [ Port ]</label>
|
<label>Bind Address : [ Port ]</label>
|
||||||
|
@ -415,17 +415,6 @@ and open the template in the editor. Base Version before all crash :-)
|
||||||
<button value="no">No</button>
|
<button value="no">No</button>
|
||||||
<help>Use simulated enbloc dialing to speedup connection when dialing while onhook (older phones)</help>
|
<help>Use simulated enbloc dialing to speedup connection when dialing while onhook (older phones)</help>
|
||||||
</item>
|
</item>
|
||||||
<item type="IE" id="5">
|
|
||||||
<label>SCCP SERVER Keepalive</label>
|
|
||||||
<input>
|
|
||||||
<name>keepalive</name>
|
|
||||||
<default>60</default>
|
|
||||||
<class>sccp-custom</class>
|
|
||||||
<type>number</type>
|
|
||||||
<options min="60" max="300"></options>
|
|
||||||
</input>
|
|
||||||
<help>Time between Keep Alive checks. Valid range is 60-300 seconds. After much trial-and-error, the minimum (60) seems to work just fine.</help>
|
|
||||||
</item>
|
|
||||||
<item type="IS" id="11" seq="98">
|
<item type="IS" id="11" seq="98">
|
||||||
<name>phonepersonalization</name>
|
<name>phonepersonalization</name>
|
||||||
<label>Allow push background from server </label>
|
<label>Allow push background from server </label>
|
||||||
|
|
|
@ -89,6 +89,7 @@ class formcreate
|
||||||
// Setting a site specific value
|
// Setting a site specific value
|
||||||
echo " data-for={$res_id}";
|
echo " data-for={$res_id}";
|
||||||
echo " class=sccp-edit";
|
echo " class=sccp-edit";
|
||||||
|
echo " data-type=text";
|
||||||
echo " id=usedefault_{$res_id}";
|
echo " id=usedefault_{$res_id}";
|
||||||
echo " :checked";
|
echo " :checked";
|
||||||
} else {
|
} else {
|
||||||
|
|
Loading…
Reference in a new issue