Enable addition of sidecars to an existing device

This commit is contained in:
steve-lad 2021-07-29 13:50:31 +02:00
parent b753482898
commit d43570b471
4 changed files with 31 additions and 21 deletions

View file

@ -281,7 +281,8 @@ $(document).ready(function () {
}); });
// Form.adddevice // Form.adddevice
$('.hw_select').change(function (e) { $('.hw_select').change(function (e) {
// console.log('HwSelect'); // data-val contains the number of buttons for this type
// data-id contains the max number of addons (1 = 0, 3 = 2)
var type_id = $('#sccp_hw_type').find(':selected').data('id'); var type_id = $('#sccp_hw_type').find(':selected').data('id');
var btn_dev = $('#sccp_hw_type').find(':selected').data('val'); var btn_dev = $('#sccp_hw_type').find(':selected').data('val');
if (type_id === 1) { if (type_id === 1) {
@ -290,17 +291,26 @@ $(document).ready(function () {
} }
$('#sccp_hw_addon').attr("disabled", "disabled"); $('#sccp_hw_addon').attr("disabled", "disabled");
} else { } else {
$('#sccp_hw_addon').removeAttr('disabled'); $('#sccp_hw_addon').prop('disabled',false);
}
// when edit, btn_dev is undefined as no select, so send btn_dev with page
if (btn_dev == null) {
var btn_dev = $('#devButtonCnt').val();
} }
var btn_add = $('#sccp_hw_addon').find(':selected').data('val'); var btn_add = $('#sccp_hw_addon').find(':selected').data('val');
$('#buttonscount').attr('value',btn_dev + btn_add); // btn_add is empty if none selected
if ((btn_add == null) || (btn_add == '')) {
var btn_add = 0;
}
var totButtons = parseInt(btn_dev, 10) + parseInt(btn_add, 10);
$('#buttonscount').attr('value', totButtons);
$('.line_button').each(function () { $('.line_button').each(function () {
if ($(this).data('id') < btn_dev + btn_add) { if ($(this).data('id') < totButtons) {
$(this).removeClass('hidden'); $(this).removeClass('hidden');
$(this).removeAttr('hidden') $(this).removeAttr('hidden');
} else { } else {
$(this).addClass('hidden'); $(this).addClass('hidden');
$(this).attr('hidden', true);
} }
}); });
}); });

View file

@ -1298,13 +1298,12 @@ and open the template in the editor. Base Version before all crash :-)
</input> </input>
<help>The type of phone: 7911, 7940, 7960, etc. Important note: the 'G' models are handled as the base model (e.g., 7962G is handled as 7962). In the Display mode, this field is read-only because the MAC address and the model number are a pair.</help> <help>The type of phone: 7911, 7940, 7960, etc. Important note: the 'G' models are handled as the base model (e.g., 7962G is handled as 7962). In the Display mode, this field is read-only because the MAC address and the model number are a pair.</help>
</item> </item>
<item type="IE" id="3" seq="99"> <item type="SDE" id="3" seq="99">
<label>Addon</label> <label>Addon</label>
<input> <name>addon</name>
<name>addon</name> <default>NONE</default>
<default>NONE</default> <select name="model" dataval="buttons">description</select>
<class>sccp-custom</class> <class>hw_select form-control</class>
</input>
<help>Addon: Addons are model specific and only work with certain base phones. This phone model is identified as being a phone that does not accept sidecars. Update devmodel if this is not correct.</help> <help>Addon: Addons are model specific and only work with certain base phones. This phone model is identified as being a phone that does not accept sidecars. Update devmodel if this is not correct.</help>
</item> </item>
</page_group> </page_group>

View file

@ -759,7 +759,7 @@ class formcreate
break; break;
case 'SDE': case 'SDE':
$extension_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('extension', 'model'); $extension_list = \FreePBX::Sccp_manager()->dbinterface->getDb_model_info('extension', 'model');
$extension_list[]=array( 'model' => 'NONE', 'vendor' => 'CISCO', 'dns' => '0'); $extension_list[] = array( 'model' => 'NONE', 'vendor' => 'CISCO', 'dns' => '0');
foreach ($extension_list as &$data) { foreach ($extension_list as &$data) {
$d_name = explode(';', $data['model']); $d_name = explode(';', $data['model']);
if (is_array($d_name) && (count($d_name) > 1)) { if (is_array($d_name) && (count($d_name) > 1)) {

View file

@ -31,30 +31,30 @@ $hint_list = $this->getHintInformation(true, array('context'=>'park-hints')) ;
// print_r($hint_list); // print_r($hint_list);
$line_id =0; $line_id =0;
$max_buttons =56; //Don't know hardware type so et a maximum. On save, this is set to actual max buttons $max_buttons =56; //Don't know hardware type so set a maximum. On save, this is set to actual max buttons
$show_buttons =1; $show_buttons =1;
//print_r($hint_list); //print_r($hint_list);
if (!empty($_REQUEST['id'])) { if (!empty($_REQUEST['id'])) {
$dev_id = $_REQUEST['id']; $dev_id = $_REQUEST['id'];
$db_buttons = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_buttons', array("id" => $dev_id)); $db_buttons = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_buttons', array("id" => $dev_id));
$db_device = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id)); $db_device = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $dev_id));
$max_buttons = $db_device['buttons']; $show_buttons = $db_device['buttons'];
if (!empty($db_device['addon_buttons'])) { if (!empty($db_device['addon_buttons'])) {
$max_buttons += $db_device['addon_buttons']; $show_buttons += $db_device['addon_buttons'];
} }
$show_buttons = $max_buttons; //$show_buttons = $max_buttons;
} }
if (!empty($_REQUEST['new_id'])) { if (!empty($_REQUEST['new_id'])) {
$val = $_REQUEST['type']; $val = $_REQUEST['type'];
$dev_schema = $this-> getSccpModelInformation('byid', false, "all", array('model' =>$val)); $dev_schema = $this-> getSccpModelInformation('byid', false, "all", array('model' =>$val));
// $db_device = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $val)); // $db_device = $this->dbinterface->getSccpDeviceTableData('get_sccpdevice_byid', array("id" => $val));
$max_buttons = $dev_schema[0]['buttons']; $show_buttons = $dev_schema[0]['buttons'];
if (!empty($_REQUEST['addon'])) { if (!empty($_REQUEST['addon'])) {
$val = $_REQUEST['addon']; $val = $_REQUEST['addon'];
$dev_schema = $this-> getSccpModelInformation('byid', false, "all", array('model' =>$val)); $dev_schema = $this-> getSccpModelInformation('byid', false, "all", array('model' =>$val));
$max_buttons += $dev_schema[0]['buttons']; $show_buttons += $dev_schema[0]['buttons'];
} }
$show_buttons = $max_buttons; //$show_buttons = $max_buttons;
} }
if (!empty($_REQUEST['ru_id'])) { if (!empty($_REQUEST['ru_id'])) {
$dev_id = $_REQUEST['ru_id']; $dev_id = $_REQUEST['ru_id'];
@ -67,7 +67,8 @@ if (!empty($_REQUEST['ru_id'])) {
<form autocomplete="off" name="frm_editbuttons" id="frm_editbuttons" class="fpbx-submit" action="" method="post" data-id="hw_edit"> <form autocomplete="off" name="frm_editbuttons" id="frm_editbuttons" class="fpbx-submit" action="" method="post" data-id="hw_edit">
<input type="hidden" name="category" value="frm_editbuttons"> <input type="hidden" name="category" value="frm_editbuttons">
<input type="hidden" name="Submit" value="Submit"> <input type="hidden" name="Submit" value="Submit">
<input type="hidden" name="buttonscount" id="buttonscount" value="<?php echo $max_buttons?>"> <input type="hidden" name="buttonscount" id="buttonscount" value="<?php echo $show_buttons;?>">
<input type="hidden" name="devButtonCnt" id="devButtonCnt" value="<?php echo (!empty($db_device['buttons']))?$db_device['buttons']:0;?>">
<div class="section-title" data-for="<?php echo $forminfo[0]['name'];?>"> <div class="section-title" data-for="<?php echo $forminfo[0]['name'];?>">
<h3><i class="fa fa-minus"></i><?php echo _($forminfo[0]['label']) ?></h3> <h3><i class="fa fa-minus"></i><?php echo _($forminfo[0]['label']) ?></h3>
</div> </div>