From fa7b7928197f4a0a81dad42e94700ac45391bc36 Mon Sep 17 00:00:00 2001 From: Damien <damien.burel@maarch.org> Date: Thu, 9 Nov 2017 15:43:10 +0100 Subject: [PATCH] FEAT #6273 informations about requested_signature on signature book --- .../angular/app/signature-book.component.js | 30 +++++-- .../angular/app/signature-book.component.ts | 79 ++++++++++++------- core/Controllers/ListinstanceController.php | 31 ++++++++ core/Models/ListinstanceModelAbstract.php | 22 ++++++ modules/visa/Controllers/VisaController.php | 1 + rest/index.php | 3 + 6 files changed, 130 insertions(+), 36 deletions(-) create mode 100644 core/Controllers/ListinstanceController.php diff --git a/apps/maarch_entreprise/js/angular/app/signature-book.component.js b/apps/maarch_entreprise/js/angular/app/signature-book.component.js index 834bf70ba37..e93fa6aa588 100755 --- a/apps/maarch_entreprise/js/angular/app/signature-book.component.js +++ b/apps/maarch_entreprise/js/angular/app/signature-book.component.js @@ -456,22 +456,40 @@ var SignatureBookComponent = (function () { SignatureBookComponent.prototype.validForm = function () { var _this = this; if ($j("#signatureBookActions option:selected")[0].value != "") { - unlockDocument(this.resId); - if (this.signatureBook.resList.length == 0) { - this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList') + if (this.signatureBook['listinstance']['requested_signature'] == true) { + this.http.get(this.coreUrl + 'rest/listinstance/' + this.signatureBook['listinstance']['listinstance_id']) .subscribe(function (data) { - _this.signatureBook.resList = data.resList; - valid_action_form('empty', 'index.php?display=true&page=manage_action&module=core', _this.signatureBook.currentAction.id, _this.resId, 'res_letterbox', 'null', 'letterbox_coll', 'page', false, [$j("#signatureBookActions option:selected")[0].value]); + var r = true; + if (data['signatory'] == false) { + r = confirm("Vous n’avez signé aucun document. Êtes-vous sûr de vouloir continuer ?"); + } + if (r) { + _this.sendActionForm(); + } }); } else { - valid_action_form('empty', 'index.php?display=true&page=manage_action&module=core', this.signatureBook.currentAction.id, this.resId, 'res_letterbox', 'null', 'letterbox_coll', 'page', false, [$j("#signatureBookActions option:selected")[0].value]); + this.sendActionForm(); } } else { alert("Aucune action choisie"); } }; + SignatureBookComponent.prototype.sendActionForm = function () { + var _this = this; + unlockDocument(this.resId); + if (this.signatureBook.resList.length == 0) { + this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList') + .subscribe(function (data) { + _this.signatureBook.resList = data.resList; + valid_action_form('empty', 'index.php?display=true&page=manage_action&module=core', _this.signatureBook.currentAction.id, _this.resId, 'res_letterbox', 'null', 'letterbox_coll', 'page', false, [$j("#signatureBookActions option:selected")[0].value]); + }); + } + else { + valid_action_form('empty', 'index.php?display=true&page=manage_action&module=core', this.signatureBook.currentAction.id, this.resId, 'res_letterbox', 'null', 'letterbox_coll', 'page', false, [$j("#signatureBookActions option:selected")[0].value]); + } + }; return SignatureBookComponent; }()); SignatureBookComponent = __decorate([ diff --git a/apps/maarch_entreprise/js/angular/app/signature-book.component.ts b/apps/maarch_entreprise/js/angular/app/signature-book.component.ts index 715ed1020da..af20548b3ab 100755 --- a/apps/maarch_entreprise/js/angular/app/signature-book.component.ts +++ b/apps/maarch_entreprise/js/angular/app/signature-book.component.ts @@ -469,42 +469,61 @@ export class SignatureBookComponent implements OnInit { validForm() { if ($j("#signatureBookActions option:selected")[0].value != "") { - unlockDocument(this.resId); + if (this.signatureBook['listinstance']['requested_signature'] == true) { + this.http.get(this.coreUrl + 'rest/listinstance/' + this.signatureBook['listinstance']['listinstance_id']) + .subscribe((data: any) => { + var r = true; + if (data['signatory'] == false) { + r = confirm("Vous n’avez signé aucun document. Êtes-vous sûr de vouloir continuer ?"); + } - if (this.signatureBook.resList.length == 0) { - this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList') - .subscribe((data : any) => { - this.signatureBook.resList = data.resList; - - valid_action_form( - 'empty', - 'index.php?display=true&page=manage_action&module=core', - this.signatureBook.currentAction.id, - this.resId, - 'res_letterbox', - 'null', - 'letterbox_coll', - 'page', - false, - [$j("#signatureBookActions option:selected")[0].value] - ); + if (r) { + this.sendActionForm(); + } }); } else { - valid_action_form( - 'empty', - 'index.php?display=true&page=manage_action&module=core', - this.signatureBook.currentAction.id, - this.resId, - 'res_letterbox', - 'null', - 'letterbox_coll', - 'page', - false, - [$j("#signatureBookActions option:selected")[0].value] - ); + this.sendActionForm(); } } else { alert("Aucune action choisie"); } } + + sendActionForm() { + unlockDocument(this.resId); + + if (this.signatureBook.resList.length == 0) { + this.http.get(this.coreUrl + 'rest/' + this.basketId + '/signatureBook/resList') + .subscribe((data: any) => { + this.signatureBook.resList = data.resList; + + valid_action_form( + 'empty', + 'index.php?display=true&page=manage_action&module=core', + this.signatureBook.currentAction.id, + this.resId, + 'res_letterbox', + 'null', + 'letterbox_coll', + 'page', + false, + [$j("#signatureBookActions option:selected")[0].value] + ); + }); + } else { + valid_action_form( + 'empty', + 'index.php?display=true&page=manage_action&module=core', + this.signatureBook.currentAction.id, + this.resId, + 'res_letterbox', + 'null', + 'letterbox_coll', + 'page', + false, + [$j("#signatureBookActions option:selected")[0].value] + ); + } + } + } diff --git a/core/Controllers/ListinstanceController.php b/core/Controllers/ListinstanceController.php new file mode 100644 index 00000000000..360148e52de --- /dev/null +++ b/core/Controllers/ListinstanceController.php @@ -0,0 +1,31 @@ +<?php + +/** + * Copyright Maarch since 2008 under licence GPLv3. + * See LICENCE.txt file at the root folder for more details. + * This file is part of Maarch software. + * + */ + +/** + * @brief Listinstance Controller + * @author dev@maarch.org + * @ingroup core + */ + +namespace Core\Controllers; + +use Core\Models\ListinstanceModel; +use Psr\Http\Message\RequestInterface; +use Psr\Http\Message\ResponseInterface; + + +class ListinstanceController +{ + public function getById(RequestInterface $request, ResponseInterface $response, $aArgs) + { + $listinstance = ListinstanceModel::getById(['id' => $aArgs['id']]); + + return $response->withJson($listinstance); + } +} diff --git a/core/Models/ListinstanceModelAbstract.php b/core/Models/ListinstanceModelAbstract.php index 1e6783c5372..3da3f7eef61 100644 --- a/core/Models/ListinstanceModelAbstract.php +++ b/core/Models/ListinstanceModelAbstract.php @@ -54,4 +54,26 @@ class ListinstanceModelAbstract return true; } + + public static function getCurrentStepByResId(array $aArgs) + { + ValidatorModel::notEmpty($aArgs, ['resId']); + ValidatorModel::intVal($aArgs, ['resId']); + ValidatorModel::arrayType($aArgs, ['select']); + + $aListinstance = DatabaseModel::select([ + 'select' => empty($aArgs['select']) ? ['*'] : $aArgs['select'], + 'table' => ['listinstance'], + 'where' => ['res_id = ?', 'difflist_type = ?', 'process_date is null'], + 'data' => [$aArgs['resId'], 'VISA_CIRCUIT'], + 'order_by' => ['listinstance_id ASC'], + 'limit' => 1 + ]); + + if (empty($aListinstance[0])) { + return []; + } + + return $aListinstance[0]; + } } diff --git a/modules/visa/Controllers/VisaController.php b/modules/visa/Controllers/VisaController.php index 7f5006f7a94..5d4c72e6583 100755 --- a/modules/visa/Controllers/VisaController.php +++ b/modules/visa/Controllers/VisaController.php @@ -84,6 +84,7 @@ class VisaController $datas['signatures'] = UserModel::getSignaturesById(['id' => $user['id']]); $datas['consigne'] = UserModel::getCurrentConsigneById(['resId' => $resId]); $datas['hasWorkflow'] = VisaModel::hasVisaWorkflowByResId(['resId' => $resId]); + $datas['listinstance'] = ListinstanceModel::getCurrentStepByResId(['resId' => $resId]); $datas['canSign'] = ServiceModel::hasService(['id' => 'sign_document', 'userId' => $_SESSION['user']['UserId'], 'location' => 'visa', 'type' => 'use']); $datas['lang'] = LangModel::getSignatureBookLang(); diff --git a/rest/index.php b/rest/index.php index 40c67c71f05..f941d3b4108 100755 --- a/rest/index.php +++ b/rest/index.php @@ -234,6 +234,9 @@ $app->delete('/notifications/{id}', \Notifications\Controllers\NotificationContr $app->get('/reports/groups/{groupId}', \Core\Controllers\ReportController::class . ':getByGroupId'); $app->put('/reports/groups/{groupId}', \Core\Controllers\ReportController::class . ':updateForGroupId'); +//Listinstance +$app->get('/listinstance/{id}', \Core\Controllers\ListinstanceController::class . ':getById'); + //Contacts $app->post('/contacts', \Core\Controllers\ContactController::class . ':create'); -- GitLab