diff --git a/CHANGELOG b/CHANGELOG index 7009662..776c6c7 100755 --- a/CHANGELOG +++ b/CHANGELOG @@ -39,6 +39,7 @@ Contents **Changes introduced in 0.3.17 [Fix] Error when configuring managed cable connector type as ST +[Enhance] Added ability to delete managed cable from Cable Inventory **Changes introduced in 0.3.17 [Fix] Backup export not converting HTML code to ASCII hyphen diff --git a/assets/pages/jquery.cable_manager.js b/assets/pages/jquery.cable_manager.js index 72aa52a..919ecae 100755 --- a/assets/pages/jquery.cable_manager.js +++ b/assets/pages/jquery.cable_manager.js @@ -32,10 +32,52 @@ $( document ).ready(function() { var action = $(linkEditable).attr('data-action'); var cableID = $(linkEditable).attr('data-cableID'); - var data = { - cableID: cableID, - action: action + if(action == 'delete') { + + $(document).data('selectedCableID', cableID); + + $('#modalConfirmTitle').html('Delete Cable'); + $('#modalConfirmBody').html('Delete cable?'); + + } else { + var data = { + cableID: cableID, + action: action + } + data = JSON.stringify(data); + + $.post("backend/process_cable-editable.php", {data:data}, function(response){ + var responseJSON = JSON.parse(response); + if (responseJSON.active == 'inactive'){ + window.location.replace("/"); + } else if ($(responseJSON.error).size() > 0){ + displayError(responseJSON.error); + } else { + + if(action == 'lock') { + $(linkEditable).html(''); + $(linkEditable).attr('data-action', 'unlock'); + $(linkEditable).attr('title', 'Unlock cable for editing'); + + } else if(action == 'unlock') { + $(linkEditable).html(''); + $(linkEditable).attr('data-action', 'lock'); + $(linkEditable).attr('title', 'Lock cable for editing'); + } + } + }); } + }); + + // Delete a temlate + $('#modalConfirmBtn').click(function(){ + var selectedCableID = $(document).data('selectedCableID'); + + var data = { + cableID: selectedCableID, + action: 'delete' + } + data = JSON.stringify(data); $.post("backend/process_cable-editable.php", {data:data}, function(response){ @@ -45,22 +87,8 @@ $( document ).ready(function() { } else if ($(responseJSON.error).size() > 0){ displayError(responseJSON.error); } else { - var pill = $(linkEditable).siblings('.label-pill'); - if(action == 'finalize') { - $(pill).removeClass('label-danger').addClass('label-success'); - $(pill).html('Yes'); - $(linkEditable).html('unFinalize'); - $(linkEditable).attr('data-action', 'unfinalize'); - $(linkEditable).attr('title', 'Allow cable properties to be edited.'); - - } else if(action == 'unfinalize') { - $(pill).removeClass('label-success').addClass('label-danger'); - $(pill).html('No'); - $(linkEditable).html('Finalize'); - $(linkEditable).attr('data-action', 'finalize'); - $(linkEditable).attr('title', 'Remove the ability to edit cable properties.'); - } + $('#'+selectedCableID).remove(); } }); }); diff --git a/backend/process_cable-editable.php b/backend/process_cable-editable.php index d53b192..1309e4b 100755 --- a/backend/process_cable-editable.php +++ b/backend/process_cable-editable.php @@ -20,15 +20,37 @@ if($_SERVER['REQUEST_METHOD'] == 'POST'){ $cableID = $data['cableID']; $action = $data['action']; - $editable = $action == 'finalize' ? 0 : 1; - - $qls->SQL->update('app_inventory', array('editable' => $editable), array('id' => array('=', $cableID))); + if($action == 'lock' or $action == 'unlock') { + + $editable = $action == 'lock' ? 0 : 1; + + $qls->SQL->update('app_inventory', array('editable' => $editable), array('id' => array('=', $cableID))); + + } else if($action == 'delete') { + + + + if(isset($qls->App->inventoryAllArray[$cableID])) { + $cable = $qls->App->inventoryAllArray[$cableID]; + + if($cable['a_object_id'] != 0 and $cable['b_object_id'] != 0) { + + $qls->SQL->delete('app_inventory', array('id' => array('=', $cableID))); + + } else { + + $errMsg = 'Unable to delete managed cables that are connected to ports. Clear cable connection(s) and try again.'; + array_push($validate->returnData['error'], $errMsg); + } + } + + } } echo json_encode($validate->returnData); } function validate($data, &$validate, &$qls){ - $actionArray = array('finalize', 'unfinalize'); + $actionArray = array('lock', 'unlock', 'delete'); $validate->validateID($data['cableID'], 'cable ID'); diff --git a/includes/Update.class.php b/includes/Update.class.php index 4825fbe..40b8db3 100755 --- a/includes/Update.class.php +++ b/includes/Update.class.php @@ -128,6 +128,14 @@ var $qls; // Set app version to 0.3.18 $this->qls->SQL->update('app_organization_data', array('version' => $incrementalVersion), array('id' => array('=', 1))); + // Fix port description table + $query = $this->qls->SQL->query("SHOW COLUMNS FROM `{$this->qls->config['sql_prefix']}app_port_description` LIKE 'description'"); + if(!$this->qls->SQL->num_rows($query)) { + + // Add description column + $this->qls->SQL->alter('app_port_description', 'add', 'description', 'varchar(255)'); + } + } /** diff --git a/includes/content-cable_inventory.php b/includes/content-cable_inventory.php index cf7976d..c0a4541 100755 --- a/includes/content-cable_inventory.php +++ b/includes/content-cable_inventory.php @@ -18,9 +18,9 @@ echo 'ID'; echo 'Connector'; echo 'Connected'; - echo 'Finalized'; echo 'Media'; echo 'Length'; + echo 'Action'; echo ''; echo ''; echo ''; @@ -30,7 +30,7 @@ $lengthValue = $row['length']; $length = $qls->App->calculateCableLength($mediaTypeID, $lengthValue); - echo ''; + echo ''; echo ''.$row['a_code39'].''; echo ''.$connectorTable[$row['a_connector']]['name'].''; if($row['a_object_id'] == 0) { @@ -45,13 +45,23 @@ } else { echo ''.$pillYes.''; } - if($row['editable'] == 0) { - echo ''.$pillYes.'  unFinalize'; - } else { - echo ''.$pillNo.'  Finalize'; - } echo ''.$mediaTypeTable[$row['mediaType']]['name'].''; echo ''.$length.''; + echo ''; + if($row['editable'] == 0) { + echo ''; + echo ''; + echo ''; + } else { + echo ''; + echo ''; + echo ''; + } + echo '  '; + echo ''; + echo ''; + echo ''; + echo ''; echo ''; } echo ''; diff --git a/install/schemas/mysql.sql b/install/schemas/mysql.sql index 94f7e8f..f94ee4e 100755 --- a/install/schemas/mysql.sql +++ b/install/schemas/mysql.sql @@ -544,5 +544,6 @@ CREATE TABLE `{database_prefix}app_port_description` ( `object_face` int(11) NOT NULL, `object_depth` int(11) NOT NULL, `port_id` int(11) NOT NULL, + `description` varchar(255) NOT NULL, PRIMARY KEY(`id`) ); \ No newline at end of file diff --git a/scan.php b/scan.php index 03ab459..fc14f64 100755 --- a/scan.php +++ b/scan.php @@ -78,7 +78,7 @@ $qls->Security->check_auth_page('operator.php');