#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.

This commit is contained in:
Exodus4D
2015-11-16 23:44:09 +01:00
parent 5a03d318a2
commit 55a64b664b
4 changed files with 69 additions and 23 deletions

View File

@@ -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<EFBFBD>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!

View File

@@ -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

View File

@@ -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;
});
}

View File

@@ -4,7 +4,7 @@
<div class="form-group">
<label class="col-sm-2 control-label" for="form_result">Scan result</label>
<div class="col-sm-10">
<textarea style="resize: vertical" rows="3" id="form_result" name="clipboard" class="form-control custom-scroll"></textarea>
<textarea style="resize: vertical" rows="3" id="form_result" name="clipboard" class="form-control custom-scroll" autofocus></textarea>
<span class="help-block">
Copy and paste signatures from your probe scanning window.
Hit <kbd>ctrl</kbd> + <kbd>c</kbd> (for copy)