- added new "delete old signatures" option to "signature reader" dialog, closed #95
This commit is contained in:
@@ -28,7 +28,7 @@ class Signature extends Controller\AccessController{
|
||||
* -> return value of this is limited to a "SINGLE" system
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function getAll($f3){
|
||||
public function getAll(\Base $f3){
|
||||
$signatureData = [];
|
||||
$systemIds = (array)$f3->get('POST.systemIds');
|
||||
|
||||
@@ -60,12 +60,16 @@ class Signature extends Controller\AccessController{
|
||||
/**
|
||||
* save or update a full signature data set
|
||||
* or save/update just single or multiple signature data
|
||||
* @param $f3
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function save($f3){
|
||||
public function save(\Base $f3){
|
||||
$requestData = $f3->get('POST');
|
||||
|
||||
$signatureData = null;
|
||||
$systemId = (int)$requestData['systemId'];
|
||||
// delete all signatures that are not available in this request
|
||||
$deleteOldSignatures = (bool)$requestData['deleteOld'];
|
||||
|
||||
|
||||
$return = (object) [];
|
||||
$return->error = [];
|
||||
@@ -83,6 +87,8 @@ class Signature extends Controller\AccessController{
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
if($activeCharacter){
|
||||
// signature ids that were updated/created
|
||||
$updatedSignatureIds = [];
|
||||
|
||||
/**
|
||||
* @var Model\SystemModel $system
|
||||
@@ -96,7 +102,7 @@ class Signature extends Controller\AccessController{
|
||||
|
||||
$system->getById( (int)$data['systemId']);
|
||||
|
||||
if(!$system->dry()){
|
||||
if( !$system->dry() ){
|
||||
// update/save signature
|
||||
|
||||
/**
|
||||
@@ -167,6 +173,7 @@ class Signature extends Controller\AccessController{
|
||||
}
|
||||
|
||||
$signature->save();
|
||||
$updatedSignatureIds[] = $signature->id;
|
||||
|
||||
// get a fresh signature object with the new data. This is a bad work around!
|
||||
// but i could not figure out what the problem was when using the signature model, saved above :(
|
||||
@@ -184,6 +191,28 @@ class Signature extends Controller\AccessController{
|
||||
|
||||
$system->reset();
|
||||
}
|
||||
|
||||
// delete "old" signatures ------------------------------------------------------------------
|
||||
if(
|
||||
$deleteOldSignatures &&
|
||||
$systemId
|
||||
){
|
||||
$system->getById($systemId);
|
||||
if(
|
||||
!$system->dry() &&
|
||||
$system->hasAccess($activeCharacter)
|
||||
){
|
||||
$allSignatures = $system->getSignatures();
|
||||
foreach($allSignatures as $tempSignature){
|
||||
if( !in_array($tempSignature->id, $updatedSignatureIds)){
|
||||
$tempSignature->delete( $activeCharacter );
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
@@ -194,7 +223,7 @@ class Signature extends Controller\AccessController{
|
||||
* delete signatures
|
||||
* @param \Base $f3
|
||||
*/
|
||||
public function delete($f3){
|
||||
public function delete(\Base $f3){
|
||||
$signatureIds = $f3->get('POST.signatureIds');
|
||||
$activeCharacter = $this->getCharacter();
|
||||
|
||||
|
||||
@@ -337,7 +337,7 @@ class SystemModel extends BasicModel {
|
||||
|
||||
/**
|
||||
* get all signatures of this system
|
||||
* @return array
|
||||
* @return SystemModel array
|
||||
*/
|
||||
public function getSignatures(){
|
||||
$this->filter('signatures', ['active = ?', 1], ['order' => 'name']);
|
||||
|
||||
@@ -411,10 +411,12 @@ define([
|
||||
callback: function () {
|
||||
// get form Values
|
||||
var form = $('#' + config.signatureReaderDialogId).find('form');
|
||||
|
||||
var formData = $(form).getFormValues();
|
||||
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, formData.clipboard);
|
||||
var signatureOptions = {
|
||||
deleteOld: (formData.deleteOld) ? 1 : 0
|
||||
};
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, formData.clipboard, signatureOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,6 +424,8 @@ define([
|
||||
|
||||
// dialog shown event
|
||||
signatureReaderDialog.on('shown.bs.modal', function(e) {
|
||||
signatureReaderDialog.initTooltips();
|
||||
|
||||
// set focus on sig-input textarea
|
||||
signatureReaderDialog.find('textarea').focus();
|
||||
});
|
||||
@@ -435,8 +439,9 @@ define([
|
||||
* -> Hint: copy&paste signature data (without any open dialog) will add signatures as well
|
||||
* @param systemData
|
||||
* @param clipboard data stream
|
||||
* @param options
|
||||
*/
|
||||
$.fn.updateSignatureTableByClipboard = function(systemData, clipboard){
|
||||
$.fn.updateSignatureTableByClipboard = function(systemData, clipboard, options){
|
||||
|
||||
// check if copy&paste is enabled
|
||||
if( !disableCopyFromClipboard ){
|
||||
@@ -455,7 +460,9 @@ define([
|
||||
disableCopyFromClipboard = true;
|
||||
|
||||
var requestData = {
|
||||
signatures: signatureData
|
||||
signatures: signatureData,
|
||||
deleteOld: (options.deleteOld) ? 1 : 0,
|
||||
systemId: parseInt(systemData.id)
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
@@ -745,7 +752,7 @@ define([
|
||||
$(e.target).prop('tagName').toLowerCase() !== 'textarea'
|
||||
){
|
||||
var clipboard = (e.originalEvent || e).clipboardData.getData('text/plain');
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, clipboard);
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, clipboard, {});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -411,10 +411,12 @@ define([
|
||||
callback: function () {
|
||||
// get form Values
|
||||
var form = $('#' + config.signatureReaderDialogId).find('form');
|
||||
|
||||
var formData = $(form).getFormValues();
|
||||
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, formData.clipboard);
|
||||
var signatureOptions = {
|
||||
deleteOld: (formData.deleteOld) ? 1 : 0
|
||||
};
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, formData.clipboard, signatureOptions);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -422,6 +424,8 @@ define([
|
||||
|
||||
// dialog shown event
|
||||
signatureReaderDialog.on('shown.bs.modal', function(e) {
|
||||
signatureReaderDialog.initTooltips();
|
||||
|
||||
// set focus on sig-input textarea
|
||||
signatureReaderDialog.find('textarea').focus();
|
||||
});
|
||||
@@ -435,8 +439,9 @@ define([
|
||||
* -> Hint: copy&paste signature data (without any open dialog) will add signatures as well
|
||||
* @param systemData
|
||||
* @param clipboard data stream
|
||||
* @param options
|
||||
*/
|
||||
$.fn.updateSignatureTableByClipboard = function(systemData, clipboard){
|
||||
$.fn.updateSignatureTableByClipboard = function(systemData, clipboard, options){
|
||||
|
||||
// check if copy&paste is enabled
|
||||
if( !disableCopyFromClipboard ){
|
||||
@@ -455,7 +460,9 @@ define([
|
||||
disableCopyFromClipboard = true;
|
||||
|
||||
var requestData = {
|
||||
signatures: signatureData
|
||||
signatures: signatureData,
|
||||
deleteOld: (options.deleteOld) ? 1 : 0,
|
||||
systemId: parseInt(systemData.id)
|
||||
};
|
||||
|
||||
$.ajax({
|
||||
@@ -745,7 +752,7 @@ define([
|
||||
$(e.target).prop('tagName').toLowerCase() !== 'textarea'
|
||||
){
|
||||
var clipboard = (e.originalEvent || e).clipboardData.getData('text/plain');
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, clipboard);
|
||||
moduleElement.updateSignatureTableByClipboard(systemData, clipboard, {});
|
||||
}
|
||||
});
|
||||
};
|
||||
|
||||
@@ -1,17 +1,34 @@
|
||||
<div class="row" id="{{id}}">
|
||||
<div class="col-sm-12">
|
||||
<form role="form">
|
||||
<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" autofocus></textarea>
|
||||
<span class="help-block">
|
||||
Copy and paste signatures from your probe scanning window.
|
||||
Hit <kbd>ctrl</kbd> + <kbd>c</kbd> (copy)
|
||||
then <kbd>ctrl</kbd> + <kbd>v</kbd> (paste). This tool can add and update signatures.
|
||||
</span>
|
||||
<div id="{{id}}">
|
||||
<form role="form" class="form-horizontal">
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<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" autofocus></textarea>
|
||||
<span class="help-block">
|
||||
Copy and paste signatures from your probe scanning window.
|
||||
Hit <kbd>ctrl</kbd> + <kbd>c</kbd> (copy)
|
||||
then <kbd>ctrl</kbd> + <kbd>v</kbd> (paste). This tool can add and update signatures.
|
||||
</span>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</form>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
<div class="row">
|
||||
<div class="col-sm-12">
|
||||
<div class="form-group">
|
||||
<div class="col-sm-offset-2 col-sm-10 col-xs-9">
|
||||
<div class="checkbox checkbox-warning">
|
||||
<input id="form_delete" name="deleteOld" value="1" type="checkbox">
|
||||
<label for="form_delete" title="old signatures will be removed. Are you sure?">Delete old</label>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
</form>
|
||||
</div>
|
||||
Reference in New Issue
Block a user