From 55a64b664b17f0c045f7be841e82b8842997b6b4 Mon Sep 17 00:00:00 2001 From: Exodus4D Date: Mon, 16 Nov 2015 23:44:09 +0100 Subject: [PATCH] #65 fixed "looping" on sig-table after signatures added on "bulk", signature information will now only change if "real" data has changed and not the "updateCharacter", Added autofocus to sigReader textarea field. --- app/main/controller/api/signature.php | 23 +++++++--- app/main/model/systemsignaturemodel.php | 23 +++++++++- js/app/ui/system_signature.js | 44 +++++++++++++------ .../modules/signature_reader_dialog.html | 2 +- 4 files changed, 69 insertions(+), 23 deletions(-) diff --git a/app/main/controller/api/signature.php b/app/main/controller/api/signature.php index 565f3efb..bd43f344 100644 --- a/app/main/controller/api/signature.php +++ b/app/main/controller/api/signature.php @@ -77,11 +77,15 @@ class Signature extends \Controller\AccessController{ $user = $this->_getUser(); if($user){ - $activeCharacter = $user->getActiveUserCharacter(); + $activeUserCharacter = $user->getActiveUserCharacter(); + $activeCharacter = $activeUserCharacter->getCharacter(); $system = Model\BasicModel::getNew('SystemModel'); // update/add all submitted signatures foreach($signatureData as $data){ + // this key should not be saved (it is an obj) + unset($data['updated']); + $system->getById( (int)$data['systemId']); if(!$system->dry()){ @@ -99,12 +103,11 @@ class Signature extends \Controller\AccessController{ $signature = Model\BasicModel::getNew('SystemSignatureModel'); } - $signature->updatedCharacterId = $activeCharacter->getCharacter(); - if($signature->dry()){ // new signature $signature->systemId = $system; - $signature->createdCharacterId = $activeCharacter->getCharacter(); + $signature->updatedCharacterId = $activeCharacter; + $signature->createdCharacterId = $activeCharacter; $signature->setData($data); }else{ // update signature @@ -126,10 +129,13 @@ class Signature extends \Controller\AccessController{ }else{ // update complete signature (signature reader dialog) + // systemId should not be updated + unset( $data['systemId'] ); + // description should not be updated unset( $data['description'] ); - // wormhole typeID canīt figured out/saved by the sig reader dialog + // wormhole typeID can not figured out/saved by the sig reader dialog if($data['groupId'] == 5){ unset( $data['typeId'] ); } @@ -137,10 +143,13 @@ class Signature extends \Controller\AccessController{ $newData = $data; } - $signature->setData($newData); + if( $signature->hasChanged($newData) ){ + // Character should only be changed if something else has changed + $signature->updatedCharacterId = $activeCharacter; + $signature->setData($newData); + } } - $signature->save(); // get a fresh signature object with the new data. This is a bad work around! diff --git a/app/main/model/systemsignaturemodel.php b/app/main/model/systemsignaturemodel.php index bab1648c..feaacdc2 100644 --- a/app/main/model/systemsignaturemodel.php +++ b/app/main/model/systemsignaturemodel.php @@ -69,12 +69,33 @@ class SystemSignatureModel extends BasicModel { 'character' => $this->updatedCharacterId->getData(), 'updated' => strtotime($this->updated) ] - ]; return $signatureData; } + /** + * compares a new data set (array) with the current values + * and checks if something has changed + * @param $signatureData + * @return bool + */ + public function hasChanged($signatureData){ + $hasChanged = false; + + foreach((array)$signatureData as $key => $value){ + if( + $this->exists($key) && + $this->$key != $value + ){ + $hasChanged = true; + break; + } + } + + return $hasChanged; + } + /** * check object for model access * @param $accessObject diff --git a/js/app/ui/system_signature.js b/js/app/ui/system_signature.js index 268e4bd1..f8004034 100644 --- a/js/app/ui/system_signature.js +++ b/js/app/ui/system_signature.js @@ -171,16 +171,19 @@ define([ * Updates a signature table, changes all signatures where name matches * add all new signatures as a row * - * @param signatureData + * @param signatureDataOrig * @param deleteOutdatedSignatures -> set to "true" if signatures should be deleted that are not included in "signatureData" */ - $.fn.updateSignatureTable = function(signatureData, deleteOutdatedSignatures){ + $.fn.updateSignatureTable = function(signatureDataOrig, deleteOutdatedSignatures){ // check if table update is allowed if(disableTableUpdate === true){ return; } + // clone signature array because of further manipulation + var signatureData = $.extend([], signatureDataOrig); + // disable update until function is ready; disableTableUpdate = true; @@ -241,20 +244,19 @@ define([ // delete signatures ==================================================== if(deleteOutdatedSignatures === true){ + + // callback function after row deleted + var toggleTableRowCallback = function(tempRowElement){ + // hide open editable fields on the row before removing them + tempRowElement.find('.editable').editable('destroy'); + + // delete signature row + signatureTableApi.row(tempRowElement).remove().draw(); + }; + for(var l = 0; l < tableData.length; l++){ - var rowElement = signatureTableApi.row(tableData[l].index).nodes().to$(); - - rowElement.toggleTableRow(function(tempRowElement){ - - // hide open editable fields on the row before removing them - tempRowElement.find('.editable').editable('destroy'); - - // delete signature row - signatureTableApi.row(tempRowElement).remove().draw(); - }); - - + rowElement.toggleTableRow(toggleTableRowCallback); notificationCounter.deleted++; } } @@ -432,6 +434,14 @@ define([ } } }); + + // dialog shown event + signatureReaderDialog.on('shown.bs.modal', function(e) { + // set focus on sig-input textarea + signatureReaderDialog.find('textarea').focus(); + }); + + }); }; @@ -453,6 +463,9 @@ define([ if(signatureData.length > 0){ // save signature data + // lock update function until request is finished + disableTableUpdate = true; + // lock copy during request (prevent spamming (ctrl + c ) disableCopyFromClipboard = true; @@ -466,6 +479,8 @@ define([ data: requestData, dataType: 'json' }).done(function(responseData){ + disableTableUpdate = false; + // updates table with new/updated signature information moduleElement.updateSignatureTable(responseData.signatures, false); }).fail(function( jqXHR, status, error) { @@ -473,6 +488,7 @@ define([ Util.showNotify({title: jqXHR.status + ': Update signatures', text: reason, type: 'warning'}); $(document).setProgramStatus('problem'); }).always(function() { + disableTableUpdate = false; disableCopyFromClipboard = false; }); } diff --git a/public/templates/modules/signature_reader_dialog.html b/public/templates/modules/signature_reader_dialog.html index 115f202d..5e93d621 100644 --- a/public/templates/modules/signature_reader_dialog.html +++ b/public/templates/modules/signature_reader_dialog.html @@ -4,7 +4,7 @@
- + Copy and paste signatures from your probe scanning window. Hit ctrl + c (for copy)