Do not try to write SEP file if no line defined. Save settings and warn user via toast
Fix feedback to ajax by separately submitting data before return
Fix freepbx overwriting data and causing fail, by separating json into two blocks and only parsing the first
Fix return to tab on save (set location hash) when tabs changed in settings
Fix return to calling page on save when device updated
This commit is contained in:
stevenA 2022-01-04 14:41:43 +01:00
parent 8c725874d7
commit 1f73ade196
6 changed files with 60 additions and 30 deletions

View file

@ -870,6 +870,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
$sccp_native = false;
$tmp_bind = $this->sipconfigs->getSipConfig();
$dev_ext_config = $this->dbinterface->getSccpDeviceTableData("SccpDevice", array('name' => $dev_id, 'fields' => 'sip_ext'));
if (empty($dev_ext_config)){
// TODO: Placeholder. Have no associated sip line so cannot generate SEP Xml for SIP.
// Need to return and inform user
return false;
}
$data_value = array_merge($data_value, $dev_ext_config);
$data_tmp = explode(';', $dev_ext_config['sip_lines']);
$data_value['sbind'] = array();

View file

@ -54,7 +54,7 @@ $(document).ready(function () {
if (data.message) {
bs_alert(data.message,data.status);
} else {
fpbxToast(_('Data saved'),_('Data saved'), 'success');
fpbxToast(_('Data saved'),'', 'success');
}
} else {
bs_alert(data.message,data.status);
@ -86,27 +86,27 @@ $(document).ready(function () {
url: 'ajax.php?module=sccp_manager&command=' + snd_command,
data: vdata,
success: function (data) {
// FreePbx handles first and returns its own values removing data sent
// so ajaxHandler echos data before return, and appends the ";#;" separator
// FreePbx own data is the second json after the separator
// without this this function fails as have 2 json fields.
data = JSON.parse(data.split(';#;')[0]);
if (data.status === true) {
if (data.table_reload === true) {
$('table').bootstrapTable('refresh');
}
if (data.hash != null) {
location.hash = data.hash;
}
if (data.href != null) {
location.href = data.href;
}
if (data.path != null) {
location.path = data.path;
}
if (data.search != null) {
location.search = data.search;
}
var newLocation = location.href;
newLocation = ('path' in data && data.path !== '') ? data.path : location.pathname;
newLocation += ('search' in data && data.search !== '') ? `${data.search}` : `${location.search}`;
// location.hash is set by (".change-tab") at line 198 for settings
newLocation += ('hash' in data && data.hash !== '' ) ? data.hash : location.hash;
if (data.message) {
fpbxToast(_('Configuration saved. Reloading Module'),_('Configuration saved'), 'success');
fpbxToast(_(data.message),'', data.toastFlag);
// If posting warning, allow time to read
var toastDelay = (data.toastFlag == 'success') ? 500 : 1500;
if (data.reload === true) {
//Need setTimout or reload will kill Toast
setTimeout(function(){location.reload();},500);
setTimeout(function(){location.replace(newLocation);},toastDelay);
}
}
} else {
@ -128,7 +128,6 @@ $(document).ready(function () {
del_dynamic_table($(this), $(this).data('for'));
});
$(".table").on('click', '.btn-item-delete', function (e) {
var dev_cmd = '';
var dev_id = $(this).data('id');
@ -194,7 +193,10 @@ $(document).ready(function () {
});
// ---------------------------------------
// Set location.hash when changing tabs so that can return to same tab after reload.
$(".change-tab").click(function(){
window.location.hash = '#' + $(this).attr('data-name');
});
$('.btnMultiselect').click(function (e) {
var kid = $(this).data('id');

View file

@ -1,7 +1,7 @@
<module>
<rawname>sccp_manager</rawname>
<name>SCCP Manager</name>
<version>14.3.0.25</version>
<version>14.3.0.26</version>
<type>setup</type>
<category>SCCP Connectivity</category>
<publisher>Steve Lad, Alex GP</publisher>

View file

@ -517,10 +517,18 @@ trait ajaxHelper {
}
// rewrite sccp.conf
$this->createDefaultSccpConfig($this->sccpvalues, $this->sccppath["asterisk"]);
$save_settings[] = array('status' => true, );
$this->createDefaultSccpXml();
return $save_settings;
$toastFlag = 'success';
$msg = 'Data saved';
$search = '?display=sccpsettings';
$hash = '';
echo json_encode(array('status' => true, 'message' => $msg, 'reload' => true, 'toastFlag' => $toastFlag, 'search' => $search, 'hash' => $hash)). ";#;" ;
ob_flush();
flush();
return $true;
}
public function getMyConfig($var = null, $id = "noid") {
@ -646,6 +654,7 @@ trait ajaxHelper {
}
function saveSccpDevice($get_settings, $validateonly = false) {
dbug($get_settings);
$hdr_prefix = 'sccp_hw_';
$hdr_arprefix = 'sccp_hw-ar_';
$hdr_vendPrefix = 'vendorconfig_';
@ -761,15 +770,28 @@ trait ajaxHelper {
$this->dbinterface->write('sccpbuttons', $save_buttons, $update_hw, '', $name_dev);
// Create new XML for this device, and then reset or restart the device
// so that it loads the file from TFT.
$this->createSccpDeviceXML($name_dev);
$msg = "Device Saved";
$toastFlag = 'success';
if (!$this->createSccpDeviceXML($name_dev)){
// will only be false if creating SIP SEP with no line.
$msg = "Device Saved but SEP config file not created as no SIP line attached to this device";
$toastFlag = 'warning';
};
$hash = '#sipdevice';
if ($get_settings['command'] != 'save_sip_device') {
$hash = '#sccpdevice';
// cannot restart SIP device via chan-sccp.
if ($hw_id == 'new') {
$this->aminterface->sccpDeviceReset($name_dev, 'reset');
} else {
$this->aminterface->sccpDeviceReset($name_dev, 'restart');
}
$msg = "Device Saved";
return array('status' => true, 'message' => $msg, 'reload' => true);
}
$search = '?display=sccp_phone';
echo json_encode(array('status' => true, 'message' => $msg, 'reload' => true, 'toastFlag' => $toastFlag, 'search' => $search, 'hash' => $hash)). ";#;" ;
ob_flush();
flush();
return true;
}
}

View file

@ -2,7 +2,7 @@
"rawname": "sccp_manager",
"repo": "stable",
"name": "Sccp Manager",
"version": "14.3.0.25",
"version": "14.3.0.26",
"publisher": "Steve Lad",
"license": "GPL",
"licenselink": "http://www.gnu.org/licenses/gpl.txt",
@ -15,7 +15,7 @@
"supported": {
"version": "13.0"
},
"location": "https://github.com/chan-sccp/sccp_manager/archive/refs/tags/v14.3.0.25.tar.gz",
"location": "https://github.com/chan-sccp/sccp_manager/archive/refs/tags/v14.3.0.26.tar.gz",
"md5sum": "0da5aac57e47f27e8fad4cfb8c2b5629",
"packaged": "1641125511"
}

View file

@ -101,6 +101,7 @@ if (!empty($def_val['type'])) {
<form autocomplete="off" name="frm_adddevice" id="frm_adddevice" class="fpbx-submit" action="" method="post" data-id="hw_edit">
<input type="hidden" name="category" value="adddevice_form">
<input type="hidden" name="Submit" value="Submit">
<input type="hidden" name="sccp_device_typeid" value="sccpdevice">
<?php
if (empty($dev_id)) {