Use doConfigPageInit BMO method

Increase compliance with BMO. Decreases calls and improves responsiveness
This commit is contained in:
stevenA 2022-01-09 12:58:18 +01:00
parent bd84870c6b
commit ea6b7b3783
12 changed files with 193 additions and 164 deletions

View file

@ -110,6 +110,7 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
if ($freepbx == null) {
throw new Exception("Not given a FreePBX Object");
}
dbug('__construct called', debug_backtrace(2));
$this->class_error = array();
$this->FreePBX = $freepbx;
$this->db = $freepbx->Database;
@ -198,6 +199,11 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
}
public function showPage() {
dbug('showPage called', $_REQUEST);
return;
}
/*
* Show form information - General
*/
@ -296,6 +302,8 @@ class Sccp_manager extends \FreePBX_Helpers implements \BMO {
}
public function phoneShowPage() {
dbug($_REQUEST);
dbug(debug_backtrace(0));
$request = $_REQUEST;
$action = !empty($request['action']) ? $request['action'] : '';
$inputform = !empty($request['tech_hardware']) ? $request['tech_hardware'] : '';

View file

@ -187,7 +187,7 @@ $(document).ready(function () {
$('.dropdown-menu a.dropitem').on("click", function (e) {
$(this).parents('div.btn-group').find('.dropdown_capture').text($(this).text());
// console.log($(this).data('id'));
//console.log($(this).data('id'));
ref_url = "ajax.php?module=sccp_manager&command=getDeviceModel&type=" + $(this).data('id');
$('#table-models').bootstrapTable('refresh', {url: ref_url});
});

View file

@ -14,6 +14,7 @@ if (!defined('FREEPBX_IS_AUTH')) {
// function is called. This is where you do any changes. The page.foo.php
// is only for DISPLAYING things. MVC is a cool idea, ya know?
//
dbug(debug_backtrace());
$spage = FreePBX::create()->Sccp_manager;
if (empty($spage->class_error)) {
$display_page = $spage->phoneShowPage();

View file

@ -15,12 +15,8 @@ trait ajaxHelper {
case 'save_ruser':
case 'save_dialplan_template':
case 'delete_hardware':
case 'getPhoneGrid':
case 'getExtensionGrid':
case 'getDeviceModel':
case 'getUserGrid':
case 'getSoftKey':
case 'getDialTemplate':
case 'get_ext_files':
case 'create_hw_tftp':
case 'reset_dev':
@ -49,6 +45,7 @@ trait ajaxHelper {
$request = $_REQUEST;
$msg = array();
$cmd_id = $request['command'];
dbug('ajax', $cmd_id);
switch ($cmd_id) {
case 'savesettings':
// Consolidate this into a separate method to improve legibility
@ -265,113 +262,6 @@ trait ajaxHelper {
return array('status' => true, 'table_reload' => true);
}
break;
case 'getSoftKey':
$result = array();
$i = 0;
$keyl = 'default';
foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
$result[$i]['softkeys'] = $keyl;
if ($keyl == 'default') {
foreach ($this->extconfigs->getExtConfig('keyset') as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
} else {
foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
}
$i++;
}
return $result;
break;
case 'getExtensionGrid':
$lineList = $this->dbinterface->getSccpDeviceTableData($request['type']);
if (empty($lineList)) {
return array();
}
$activeDevices = $this->aminterface->sccp_get_active_device();
$uniqueLineList = array();
foreach ($lineList as $key => &$lineArr) {
if (array_key_exists($lineArr['mac'], $activeDevices)) {
$lineArr['line_status'] = "{$activeDevices[$lineArr['mac']]['status']} | {$activeDevices[$lineArr['mac']]['act']}";
}
if (array_key_exists($lineArr['name'], $uniqueLineList)) {
$lineList[$uniqueLineList[$lineArr['name']]]['mac'] .= '<br>' . $lineArr['mac'];
$lineList[$uniqueLineList[$lineArr['name']]]['line_status'] .= '<br>' . $lineArr['line_status'];
unset($lineList[$key]); // Drop this array as no longer used
continue;
}
$uniqueLineList[$lineArr['name']] = $key;
}
unset($lineArr, $uniqueLineList); // unset reference and temp vars.
return array_values($lineList); // Reindex array and return
break;
case 'getPhoneGrid':
$dbDevices = array();
// Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $request['type']));
// Return if only interested in SIP devices
if ($request['type'] == 'cisco-sip') {
return $dbDevices; //this may be empty
}
// Find all devices currently connected
$activeDevices = $this->aminterface->sccp_get_active_device();
foreach ($dbDevices as &$dev_id) {
if (!empty($activeDevices[$dev_id['name']])) {
// Device is in db and is connected
$dev_id['description'] = $activeDevices[$dev_id['name']]['descr'];
$dev_id['status'] = $activeDevices[$dev_id['name']]['status'];
$dev_id['address'] = $activeDevices[$dev_id['name']]['address'];
$dev_id['new_hw'] = 'N';
// No further action required on this active device
unset($activeDevices[$dev_id['name']]);
}
}
unset($dev_id); // unset reference.
if (!empty($activeDevices)) {
// Have a device that is connected but is not currently in the database
// This device must have connected via hotline or config in sccp.conf.
// Pass parameters to addDevice so that can be added to db.
foreach ($activeDevices as $dev_ids) {
$id_name = $dev_ids['name'];
$dev_data = $this->aminterface->sccp_getdevice_info($id_name);
if (!empty($dev_data['SCCP_Vendor']['model_id'])) {
$dev_addon = $dev_data['SCCP_Vendor']['model_addon'];
if (empty($dev_addon)) {
$dev_addon = null;
}
$dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id']));
if (empty($dev_schema)) {
$dev_schema[0]['model'] = "ERROR in Model Schema";
}
$dbDevices[] = array(
'name' => $id_name,
'mac' => $id_name,
'button' => '---',
'type' => $dev_schema[0]['model'],
'new_hw' => 'Y',
'description' => '*NEW* ' . $dev_ids['descr'],
'status' => '*NEW* ' . $dev_ids['status'],
'address' => $dev_ids['address'],
'addon' => $dev_addon
);
}
}
}
return $dbDevices;
break;
case 'getDialTemplate':
// ------------------------------- Old device support - In the development---
$result = $this->getDialPlanList();
if (empty($result)) {
$result = array();
}
return $result;
break;
case 'backupsettings':
// ------------------------------- Old device support - In the development---
$filename = $this->createSccpBackup();

View file

@ -5,41 +5,148 @@ namespace FreePBX\modules\Sccp_manager\sccpManTraits;
trait bmoFunctions {
//Need to reload freePBX for modifications below to work
/*
//want to catch extensions
public static function myConfigPageInits() {
return array("extensions");
return array('sccpsettings', 'sccp_phone','sccp_adv');
}
*/
public function doConfigPageInit($page) {
if ($page == "extensions") {
switch ($page) {
case 'sccpsettings':
dbug('doConfigPageInit called for', $page);
break;
case 'sccp_phone':
dbug('doConfigPageInit called for', $page);
//dbug('doConfigPageInit called from', debug_backtrace());
//"ajax.php?module=sccp_manager&command=getExtensionGrid&type=extGrid"
//header('Content-type: application/json');
$this->extensionData = json_encode($this->getExtensionGrid('extGrid'));
//$this->extensionData = $this->getExtensionGrid('extGrid');
//"ajax.php?module=sccp_manager&command=getPhoneGrid&type=sccp
$this->sccpPhoneData = json_encode($this->getPhoneGrid('sccp'));
$this->sipPhoneData = json_encode($this->getPhoneGrid('cisco-sip'));
break;
case 'sccp_adv':
dbug('doConfigPageInit called for', $page);
$this->dialTemplateData = json_encode($this->getDialTemplate());
$this->softKeyData = json_encode($this->getSoftKey());
$this->deviceModelData = json_encode($this->ajaxHandler($_REQUEST = array('command'=>'getDeviceModel', 'type'=>'enabled')));
//dbug($this->deviceModelData);
break;
default:
break;
}
$this->doGeneralPost();
}
// Try to change extensions which is part of core
/*
public static function myGuiHooks() {
return array('core');
}
*/
/*
public function doGuiHook(&$cc) {
if ($_REQUEST['display'] == "extensions" ) {
if ($_REQUEST['tech_hardware'] == 'sccp_custom') {
function getPhoneGrid(string $type){
$dbDevices = array();
// Find all devices defined in the database.
$dbDevices = $this->dbinterface->getSccpDeviceTableData('phoneGrid', array('type' => $type));
this is the add extensions form
On submit returns to extensions page. Users prefer that it returns
To Sccp Phone.
Below adds redirect URL, but it is not followed
$cc->setRedirectURL("config.php?display=sccp_phone");
so force redirect at end of addDevice in SccpClass
// Return if only interested in SIP devices
if ($type == 'cisco-sip') {
return $dbDevices; //this may be empty
}
// Find all devices currently connected
$activeDevices = $this->aminterface->sccp_get_active_device();
foreach ($dbDevices as &$dev_id) {
if (!empty($activeDevices[$dev_id['name']])) {
// Device is in db and is connected
$dev_id['description'] = $activeDevices[$dev_id['name']]['descr'];
$dev_id['status'] = $activeDevices[$dev_id['name']]['status'];
$dev_id['address'] = $activeDevices[$dev_id['name']]['address'];
$dev_id['new_hw'] = 'N';
// No further action required on this active device
unset($activeDevices[$dev_id['name']]);
}
}
unset($dev_id); // unset reference.
if (!empty($activeDevices)) {
// Have a device that is connected but is not currently in the database
// This device must have connected via hotline or config in sccp.conf.
// Pass parameters to addDevice so that can be added to db.
foreach ($activeDevices as $dev_ids) {
$id_name = $dev_ids['name'];
$dev_data = $this->aminterface->sccp_getdevice_info($id_name);
if (!empty($dev_data['SCCP_Vendor']['model_id'])) {
$dev_addon = $dev_data['SCCP_Vendor']['model_addon'];
if (empty($dev_addon)) {
$dev_addon = null;
}
$dev_schema = $this->getSccpModelInformation('byciscoid', false, "all", array('model' => $dev_data['SCCP_Vendor']['model_id']));
if (empty($dev_schema)) {
$dev_schema[0]['model'] = "ERROR in Model Schema";
}
$dbDevices[] = array(
'name' => $id_name,
'mac' => $id_name,
'button' => '---',
'type' => $dev_schema[0]['model'],
'new_hw' => 'Y',
'description' => '*NEW* ' . $dev_ids['descr'],
'status' => '*NEW* ' . $dev_ids['status'],
'address' => $dev_ids['address'],
'addon' => $dev_addon
);
}
}
}
*/
return $dbDevices;
}
function getExtensionGrid(string $type) {
$lineList = $this->dbinterface->getSccpDeviceTableData($type);
if (empty($lineList)) {
return array();
}
$activeDevices = $this->aminterface->sccp_get_active_device();
$uniqueLineList = array();
foreach ($lineList as $key => &$lineArr) {
if (array_key_exists($lineArr['mac'], $activeDevices)) {
$lineArr['line_status'] = "{$activeDevices[$lineArr['mac']]['status']} | {$activeDevices[$lineArr['mac']]['act']}";
}
if (array_key_exists($lineArr['name'], $uniqueLineList)) {
$lineList[$uniqueLineList[$lineArr['name']]]['mac'] .= '<br>' . $lineArr['mac'];
$lineList[$uniqueLineList[$lineArr['name']]]['line_status'] .= '<br>' . $lineArr['line_status'];
unset($lineList[$key]); // Drop this array as no longer used
continue;
}
$uniqueLineList[$lineArr['name']] = $key;
}
unset($lineArr, $uniqueLineList); // unset reference and temp vars.
return array_values($lineList); // Reindex array and return
}
function getDialTemplate() {
// ------------------------------- Old device support - In the development---
$result = array();
$result = $this->getDialPlanList();
return $result;
}
function getSoftKey() {
$result = array();
$i = 0;
$keyl = 'default';
foreach ($this->aminterface->sccp_list_keysets() as $keyl => $vall) {
$result[$i]['softkeys'] = $keyl;
if ($keyl == 'default') {
foreach ($this->extconfigs->getExtConfig('keyset') as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
} else {
foreach ($this->getMyConfig('softkeyset', $keyl) as $key => $value) {
$result[$i][$key] = str_replace(',', '<br>', $value);
}
}
$i++;
}
return $result;
}
/* unused but FPBX API requires it */
public function install() {
@ -140,7 +247,7 @@ trait bmoFunctions {
public function getRightNav($request) {
global $amp_conf;
if (isset($request['tech_hardware']) && ($request['tech_hardware'] == 'cisco')) {
return load_view($amp_conf['AMPWEBROOT'] .'/admin/modules/sccp_manager/views/hardware.rnav.php', array('request' => $request));
return load_view($amp_conf['AMPWEBROOT'] .'/admin/modules/sccp_manager/views/hardware.rnav.php', array('data' => $this->sccpPhoneData));
}
}

View file

@ -265,6 +265,7 @@ trait helperfunctions {
return true;
}
public function getChanSccpSettings() {
// This is a utility function for debug only, and is not used by core code
foreach (array('general','line', 'device') as $section) {

View file

@ -17,7 +17,7 @@
<i class="glyphicon glyphicon-remove"></i> <span><?php echo _('Delete') ?></span>
</button>
</div>
<table data-cookie="true" data-cookie-id-table="sccp-dialtemplate-table" data-url="ajax.php?module=sccp_manager&command=getDialTemplate" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-dialtemplate" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-dialtemplate" data-id="id">
<table data-cookie="true" data-cookie-id-table="sccp-dialtemplate-table" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-dialtemplate" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-dialtemplate" data-id="id">
<thead>
<tr>
<!-- <th data-checkbox="true"></th> -->
@ -31,6 +31,11 @@
</div>
</div>
<script>
$(function() {
$('#table-sccp-dialtemplate').bootstrapTable({data: <?php echo $this->dialTemplateData ?>});
})
function DispayDPActionsKeyFormatter(value, row, index) {
var exp_model = '';
exp_model += '<a href="?display=sccp_adv&tech_hardware=dialplan&extdisplay=' + row['id'] + '"><i class="fa fa-pencil"></i></a> &nbsp; &nbsp;\n';

View file

@ -36,7 +36,7 @@ global $amp_conf;
<button type="button" class="btn btn-primary btn-lg" data-toggle="modal" data-target=".get_ext_file_<?php echo $requestType; ?>"><i class="fa fa-bolt"></i> <?php echo _("Update Files from Provisioner"); ?>
</button>
</div>
<table data-cookie="true" data-row-style="SetRowColor" data-cookie-id-table="sccp_model-all" data-url="ajax.php?module=sccp_manager&command=getDeviceModel&type=enabled" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-model" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-condensed" id="table-models" data-id="model" data-unique-id="model">
<table data-cookie="true" data-row-style="SetRowColor" data-cookie-id-table="sccp_model-all" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-model" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-condensed" id="table-models" data-id="model" data-unique-id="model">
<thead>
<tr>
<th data-checkbox="true"></th>
@ -263,9 +263,27 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa
</div>
</div>
<script>
$(function() {
$('#table-models').bootstrapTable({data: <?php echo $this->deviceModelData ?>});
})
function load_model(elmnt,clr) {
var drow = $("#table-models").bootstrapTable('getRowByUniqueId',clr);
if (drow == null) {
alert(drow);
} else {
document.getElementById("editd_model").value = clr;
document.getElementById("editd_loadimage").value = drow['loadimage'];
document.getElementById("editd_nametemplate").value = drow['nametemplate'];
document.getElementById("editd_loadinformationid").value = drow['loadinformationid'];
document.getElementById("editd_dns").value = drow['dns'];
document.getElementById("editd_vendor").value = drow['vendor'];
document.getElementById("editd_buttons").value = drow['buttons'];
}
}
function StatusIconFormatter(value, row) {
return (value === '1') ? '<i class="fa fa-check-square-o" style="color:green" title="<?php echo _("Device is enabled")?>"></i>' : '<i class="fa fa-square-o" title="<?php echo _("Device is disabled")?>"></i>';
}
@ -274,10 +292,6 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa
return exp_model[value];
}
// function DispayInputFormatter(value, row, index) {
// return (value == null) ? '<input class="tabl-edit form-control" name="' + row['model'] + '_template" type="text" value="">' : '<input class="tabl-edit form-control" name="' + row['model'] + '_template" type="text" value="' + value + '">';
// }
function DispayActionsModelFormatter(value, row, index) {
var exp_model = '';
// exp_model += '<a href="#edit_model" class="btn btn-info" onclick="load_model(this, &quot;'+row['model']+'&quot;)" data-toggle="modal"><i class="fa fa-pencil"></i></a>';
@ -312,19 +326,5 @@ include($amp_conf['AMPWEBROOT'] . '/admin/modules/sccp_manager/views/getFileModa
return {classes: tclass};
}
function load_model(elmnt,clr) {
// $("#edit_devmodel").text(clr);
var drow = $("#table-models").bootstrapTable('getRowByUniqueId',clr);
if (drow == null) {
alert(drow);
} else {
document.getElementById("editd_model").value = clr;
document.getElementById("editd_loadimage").value = drow['loadimage'];
document.getElementById("editd_nametemplate").value = drow['nametemplate'];
document.getElementById("editd_loadinformationid").value = drow['loadinformationid'];
document.getElementById("editd_dns").value = drow['dns'];
document.getElementById("editd_vendor").value = drow['vendor'];
document.getElementById("editd_buttons").value = drow['buttons'];
}
}
</script>

View file

@ -20,7 +20,7 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
<div id="toolbar-sccp-extension">
<a class="btn btn-default" href="config.php?display=extensions&tech_hardware=sccp_custom"><i class="fa fa-plus">&nbsp;</i><?php echo _("Add Extension") ?></a>
</div>
<table data-cookie="true" data-cookie-id-table="sccp-extension-table" data-url="ajax.php?module=sccp_manager&command=getExtensionGrid&type=extGrid" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sip" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-extension" data-id="name">
<table data-cookie="true" data-cookie-id-table="sccp-extension-table" data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sip" data-maintain-selected="true" data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true" data-search="true" class="table table-striped ext-list-sccp" id="table-sccp-extension" data-id="name">
<thead>
<tr>
<th data-sortable="true" data-field="name"><?php echo _('Extension') ?></th>
@ -36,6 +36,11 @@ if (!empty($this->sccpvalues['system_rouminguser'])) {
</div>
</div>
<script>
$(function() {
$('#table-sccp-extension').bootstrapTable({data: <?php echo $this->extensionData ?>});
})
function DispayPhoneActionsKeyFormatter(value, row, index) {
var exp_dev = '';
var rmn_dev = '<?php echo $roming_enable ?>';

View file

@ -31,7 +31,7 @@
<i class="glyphicon glyphicon-ok"></i> <span><?php echo _('Reset Token Device') ?></span>
</button>
</div>
<table data-cookie="true" data-cookie-id-table="sccp-phone" data-url="ajax.php?module=sccp_manager&command=getPhoneGrid&type=sccp"
<table data-cookie="true" data-cookie-id-table="sccp-phone" id="table-sccp-phone"
data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sccp" data-maintain-selected="true"
data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true"
data-search="true" class="table table-striped ext-list" id="table-sccp" data-id="name">
@ -54,6 +54,11 @@
</div>
<script>
$(function() {
$('#table-sccp-phone').bootstrapTable({data: <?php echo $this->sccpPhoneData ?>});
})
function DispayTypeFormatter(value, row, index) {
var exp_model = value;
if (row['addon'] !== null ) {

View file

@ -11,7 +11,6 @@
<table id="sccpnavgrid"
data-search="true"
data-toolbar="#toolbar-sccp-rnav"
data-url="ajax.php?module=sccp_manager&command=getPhoneGrid&type=sccp"
data-cache="false"
data-toggle="table"
class="table">
@ -22,7 +21,13 @@
</tr>
</thead>
</table>
<script type="text/javascript">
$(function() {
$('#sccpnavgrid').bootstrapTable({data: <?php echo $data ?>});
})
$("#sccpnavgrid").on('click-row.bs.table',function(e,row,elem){
if (row['new_hw'] == 'Y' ) {
window.location = '?display=sccp_phone&tech_hardware=cisco&new_id=' +row['name'] +'&' +row['type'];

View file

@ -21,7 +21,7 @@
<i class="glyphicon glyphicon-ok"></i> <span><?php echo _('Create CNF') ?></span>
</button>
</div>
<table data-cookie="true" data-cookie-id-table="sccp-sphone" data-url="ajax.php?module=sccp_manager&command=getPhoneGrid&type=cisco-sip"
<table data-cookie="true" data-cookie-id-table="sccp-sphone" id="table-sip-phone"
data-cache="false" data-show-refresh="true" data-toolbar="#toolbar-sip" data-maintain-selected="true"
data-show-columns="true" data-show-toggle="true" data-toggle="table" data-pagination="true"
data-search="true" class="table table-striped ext-list" id="table-sip" data-id="name">
@ -45,7 +45,9 @@
<script>
$(function() {
$('#table-sip-phone').bootstrapTable({data: <?php echo $this->sipPhoneData ?>});
})
function DispayTypeFormatter(value, row, index) {
var exp_model = value;