Skip to content

Commit

Permalink
feat: confirm before delete
Browse files Browse the repository at this point in the history
This commit implements the ConfirmModal on the delete routes to make
sure that users do not haphazardly delete records.
  • Loading branch information
jniles committed Oct 13, 2017
1 parent dcdaf65 commit 0b38588
Show file tree
Hide file tree
Showing 16 changed files with 128 additions and 73 deletions.
48 changes: 26 additions & 22 deletions client/src/i18n/en/errors.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
{"ERRORS":{"BAD_DATE_INTERVAL":"Bad date interval",
"BAD_REQUEST":"You are not allowed to perform this operation",
"ERR_INTERNET_DISCONNECTED":"You are not connected to the network.",
"MISSING_INVENTORY_ACCOUNTS":"Some selected inventories doesn't have stock accounts associated",
"NO_EXCHANGE_RATE":"No Exchange rate defined",
"NOT_ALLOWED":"You are not allowed to perform this action",
"NOT_FOUND":"This record could not be found",
"NO_PERMISSIONS":"The login succeeded, but you have no permissions. Please see a system administrator.",
"NO_PROJECT":"No permissions for that project, Please see a system administrator",
"UNAUTHORIZED":"You have submitted a bad username or password combination. Please login in with valid credentials to continue.",
"UNKNOWN":"An error occurred.",
"OVERPAID_INVOICE":"You have overpaid the invoices.",
"ER_DUP_KEY":"A key collided in a unique database field. Please retry your action. If the problem persists, contact the developers.",
"ER_DUP_ENTRY":"You have duplicated a value in a unique field! Please make sure that the necessary values are unique.",
"ER_BAD_FIELD_ERROR":"Column does not exist in database.",
"ER_ROW_IS_REFERENCED":"Cannot delete entity because entity is used in another table.",
"ER_ROW_IS_REFERENCED_2":"Cannot delete entity because entity is used in another table.",
"ER_BAD_NULL_ERROR":"A column was left NULL that cannot be NULL.",
"ER_PARSE_ERROR":"Your request could not be translated into valid SQL. Please modify your request and try again.",
"ER_EMPTY_QUERY":"Your request seems empty. Are you sure you filled everything in?",
"ER_NO_DEFAULT_FOR_FIELD":"You did not include enough information in your submission! Please check your errors and try again.",
"ER_DATA_TOO_LONG":"One of your form values is too long! Please shorten it and resubmit."}}
{
"ERRORS" : {
"BAD_DATE_INTERVAL" : "Bad date interval",
"BAD_REQUEST" : "You are not allowed to perform this operation",
"ERR_INTERNET_DISCONNECTED" : "You are not connected to the network.",
"MISSING_INVENTORY_ACCOUNTS" : "Some selected inventories doesn't have stock accounts associated",
"NO_EXCHANGE_RATE" : "No Exchange rate defined",
"NOT_ALLOWED" : "You are not allowed to perform this action",
"NOT_FOUND" : "This record could not be found",
"NO_PERMISSIONS" : "The login succeeded, but you have no permissions. Please see a system administrator.",
"NO_PROJECT" : "No permissions for that project, Please see a system administrator",
"UNAUTHORIZED" : "You have submitted a bad username or password combination. Please login in with valid credentials to continue.",
"UNKNOWN" : "An error occurred.",
"OVERPAID_INVOICE" : "You have overpaid the invoices.",
"ER_DUP_KEY" : "A key collided in a unique database field. Please retry your action. If the problem persists, contact the developers.",
"ER_DUP_ENTRY" : "You have duplicated a value in a unique field! Please make sure that the necessary values are unique.",
"ER_BAD_FIELD_ERROR" : "Column does not exist in database.",
"ER_ROW_IS_REFERENCED" : "Cannot delete entity because entity is used in another table.",
"ER_ROW_IS_REFERENCED_2" : "Cannot delete entity because entity is used in another table.",
"ER_BAD_NULL_ERROR" : "A column was left NULL that cannot be NULL.",
"ER_PARSE_ERROR" : "Your request could not be translated into valid SQL. Please modify your request and try again.",
"ER_EMPTY_QUERY" : "Your request seems empty. Are you sure you filled everything in?",
"ER_NO_DEFAULT_FOR_FIELD" : "You did not include enough information in your submission! Please check your errors and try again.",
"ER_DATA_TOO_LONG" : "One of your form values is too long! Please shorten it and resubmit."
}
}
3 changes: 2 additions & 1 deletion client/src/i18n/en/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
},
"DIALOGS": {
"CONFIRM_ACTION": "Do you confirm this action?",
"CONFIRMATION_NEEDED" : "Confirmation Needed",
"CONFIRM_ACTIVATION": "Do you really want to allow this user's system access",
"CONFIRM_CREDIT_NOTE": "The invoice you want to cancel already paid, would you want to cancel this bill",
"CONFIRM_DEACTIVATION": "Do you really want to revoked this user's system access",
Expand Down Expand Up @@ -640,4 +641,4 @@
"NO_CHANGES": "You haven't changed any form values. Nothing will be submitted to the server."
}
}
}
}
6 changes: 5 additions & 1 deletion client/src/i18n/en/transactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"SINGLE_ACCOUNT_TRANSACTION":"This transaction only concerns a single account. Please select multiple accounts to complete the transaction.",
"MISSING_TRANSACTION_TYPE":"Transactions involving cash accounts (banks or cashboxes) must have a transaction type specified to differentiate them in the cashflow report. Please select a transaction type.",
"IMBALANCED_TRANSACTION":"This transaction's debits and credits must balance. Please correct the imbalances before submitting.",
"SINGLE_ROW_TRANSACTION":"This transaction only has a single row, but two rows are required. Please add one or more lines."
"SINGLE_ROW_TRANSACTION":"This transaction only has a single row, but two rows are required. Please add one or more lines.",
"ERRORS" : {
"TRANSACTION_REFERENCED" : "This record is referenced by a transaction. Please remove the reference before removing this record.",
"TRANSACTION_POSTED" : "This record has been posted to the General Ledger; it can no longer be removed. Generate a correcting transaction to annul it."
}
}
}
48 changes: 26 additions & 22 deletions client/src/i18n/fr/errors.json
Original file line number Diff line number Diff line change
@@ -1,22 +1,26 @@
{"ERRORS":{"BAD_DATE_INTERVAL":"Mauvais interval de date",
"BAD_REQUEST":"Vous n'etes pas authorisé à faire cette operation",
"ERR_INTERNET_DISCONNECTED":"Vous n'êtes pas connecté à un réseau.",
"MISSING_INVENTORY_ACCOUNTS":"Certains articles séléctionnés n'ont pas de compte de stock ou de variation de stock associés",
"NO_EXCHANGE_RATE":"Aucun taux de change defini pour aujourd'hui!",
"NOT_ALLOWED":"Vous n'etes pas authorisé à faire cette action",
"NOT_FOUND":"Cet enregistrement n'a pas pu être trouvé",
"NO_PERMISSIONS":"La connexion a réussi, mais vous n'avez aucune autorisation. Veuillez contacter un administrateur système.",
"NO_PROJECT":"Aucune autorisation pour ce projet, Veuillez contacter un administrateur système",
"UNAUTHORIZED":"Vous avez soumis un mauvais nom ou mot de passe. Entrez un nom ou un mot de passe valid pour continuer.",
"UNKNOWN":"Une erreur est survenue.",
"OVERPAID_INVOICE":"Vous avez payé trop aux factures.",
"ER_DUP_KEY":"Il ya déjà un enregistrement avec cette clé. Veuillez réessayer votre action. Si le problème persiste, contactez les développeurs.",
"ER_DUP_ENTRY":"Vous avez dupliqué une valeur dans un champ unique! Assurez-vous que les valeurs nécessaires sont uniques.",
"ER_BAD_FIELD_ERROR":"Vous avez entré un champ qui ne peut pas être stocké dans la base de données.",
"ER_ROW_IS_REFERENCED":"Vous ne pouvez pas supprimer cet enregistrement, car il est référencé par un autre enregistrement dans la base de données.",
"ER_ROW_IS_REFERENCED_2":"Vous ne pouvez pas supprimer cet enregistrement, car il est référencé par un autre enregistrement dans la base de données.",
"ER_BAD_NULL_ERROR":"Un champ a été laissé vide qui ne peut pas être vide.",
"ER_PARSE_ERROR":"Votre demande n'a pas été comprise. Veuillez modifier votre demande et réessayer.",
"ER_EMPTY_QUERY":"Votre demande semble vide. Êtes-vous sûr de remplir tout?",
"ER_NO_DEFAULT_FOR_FIELD":"Vous n'avez pas inclus suffisamment d'informations dans votre soumission! Veuillez vérifier vos erreurs et réessayer.",
"ER_DATA_TOO_LONG":"Une de vos valeurs de formulaire est trop longue! Veuillez le raccourcir et le renvoyer."}}
{
"ERRORS" : {
"BAD_DATE_INTERVAL" : "Mauvais interval de date",
"BAD_REQUEST" : "Vous n'etes pas authorisé à faire cette operation",
"ERR_INTERNET_DISCONNECTED" : "Vous n'êtes pas connecté à un réseau.",
"MISSING_INVENTORY_ACCOUNTS" : "Certains articles séléctionnés n'ont pas de compte de stock ou de variation de stock associés",
"NO_EXCHANGE_RATE" : "Aucun taux de change defini pour aujourd'hui!",
"NOT_ALLOWED" : "Vous n'etes pas authorisé à faire cette action",
"NOT_FOUND" : "Cet enregistrement n'a pas pu être trouvé",
"NO_PERMISSIONS" : "La connexion a réussi, mais vous n'avez aucune autorisation. Veuillez contacter un administrateur système.",
"NO_PROJECT" : "Aucune autorisation pour ce projet, Veuillez contacter un administrateur système",
"UNAUTHORIZED" : "Vous avez soumis un mauvais nom ou mot de passe. Entrez un nom ou un mot de passe valid pour continuer.",
"UNKNOWN" : "Une erreur est survenue.",
"OVERPAID_INVOICE" : "Vous avez payé trop aux factures.",
"ER_DUP_KEY" : "Il ya déjà un enregistrement avec cette clé. Veuillez réessayer votre action. Si le problème persiste, contactez les développeurs.",
"ER_DUP_ENTRY" : "Vous avez dupliqué une valeur dans un champ unique! Assurez-vous que les valeurs nécessaires sont uniques.",
"ER_BAD_FIELD_ERROR" : "Vous avez entré un champ qui ne peut pas être stocké dans la base de données.",
"ER_ROW_IS_REFERENCED" : "Vous ne pouvez pas supprimer cet enregistrement, car il est référencé par un autre enregistrement dans la base de données.",
"ER_ROW_IS_REFERENCED_2" : "Vous ne pouvez pas supprimer cet enregistrement, car il est référencé par un autre enregistrement dans la base de données.",
"ER_BAD_NULL_ERROR" : "Un champ a été laissé vide qui ne peut pas être vide.",
"ER_PARSE_ERROR" : "Votre demande n'a pas été comprise. Veuillez modifier votre demande et réessayer.",
"ER_EMPTY_QUERY" : "Votre demande semble vide. Êtes-vous sûr de remplir tout?",
"ER_NO_DEFAULT_FOR_FIELD" : "Vous n'avez pas inclus suffisamment d'informations dans votre soumission! Veuillez vérifier vos erreurs et réessayer.",
"ER_DATA_TOO_LONG" : "Une de vos valeurs de formulaire est trop longue! Veuillez le raccourcir et le renvoyer."
}
}
1 change: 1 addition & 0 deletions client/src/i18n/fr/form.json
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,7 @@
},
"DIALOGS": {
"CONFIRM_ACTION": "Confirmez vous cette action ?",
"CONFIRMATION_NEEDED" : "Confirmation Nécessaire",
"CONFIRM_ACTIVATION": "Voulez vous vraiment activer les droits d'accès de cet utilisateur",
"CONFIRM_CREDIT_NOTE": "La facture dont vous voulez annuler a déjà été payée, voulez-vous vraiment annuler cette facture ",
"CONFIRM_DEACTIVATION": "Voulez vous vraiment blocker les droits d'accès de cet utilisateur",
Expand Down
6 changes: 5 additions & 1 deletion client/src/i18n/fr/transactions.json
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,10 @@
"SINGLE_ACCOUNT_TRANSACTION" : "Cette transaction contient un seul compte. Veuillez sélectionner plusieurs comptes pour compléter la transaction.",
"MISSING_TRANSACTION_TYPE" : "Les transactions impliquant des comptes de trésorerie (banques ou caisses) doivent avoir un type de transaction spécifié pour les différencier dans le rapport de trésorerie. Veuillez sélectionner un type de transaction.",
"IMBALANCED_TRANSACTION" : "Les débits et les crédits de cette transaction doivent être équilibrés. Veuillez corriger les déséquilibres avant de les soumettre.",
"SINGLE_ROW_TRANSACTION" : "Cette transaction ne comporte qu'une seule ligne, mais deux lignes sont nécessaires. Veuillez ajouter une ou plusieurs lignes."
"SINGLE_ROW_TRANSACTION" : "Cette transaction ne comporte qu'une seule ligne, mais deux lignes sont nécessaires. Veuillez ajouter une ou plusieurs lignes.",
"ERRORS" : {
"TRANSACTION_REFERENCED" : "Cet enregistrement est référencé par une transaction. Veuillez supprimer la référence avant de supprimer cet enregistrement.",
"TRANSACTION_POSTED" : "Cet enregistrement a été posté dans le grand livre; il ne peut plus être supprimé. Générez une transaction de correction pour l'annuler."
}
}
}
5 changes: 2 additions & 3 deletions client/src/js/services/ModalService.js
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ function ModalService(Modal) {
service.openSearchPurchaseOrder = openSearchPurchaseOrder;

// search fiscal year
service.openSelectFiscalYear = openSelectFiscalYear;
service.openSelectFiscalYear = openSelectFiscalYear;

/**
* Opens a "confirm delete" modal with a button for "Confirm" or "Cancel".
Expand All @@ -88,7 +88,6 @@ function ModalService(Modal) {
* @returns {Promise} result - a promise resolved by the modal instance
*/
function confirm(prompt, options) {

// default options for modal rendering
var opts = options || {};

Expand All @@ -98,7 +97,7 @@ function ModalService(Modal) {
size : opts.size || 'md',
controller : 'ConfirmModalController as ConfirmModalCtrl',
resolve : { prompt : function provider() { return prompt;} },
templateUrl : '/modules/templates/modals/confirm.modal.html'
templateUrl : '/modules/templates/modals/confirm.modal.html',
});

return instance.result;
Expand Down
20 changes: 13 additions & 7 deletions client/src/modules/cash/payments/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@ angular.module('bhima.controllers')
CashPaymentRegistryController.$inject = [
'CashService', 'bhConstants', 'NotifyService', 'SessionService', 'uiGridConstants',
'ReceiptModal', 'ModalService', 'GridSortingService', '$state', 'FilterService',
'GridColumnService', 'GridStateService',
'GridColumnService', 'GridStateService', 'ModalService',
];

/**
Expand All @@ -15,9 +15,8 @@ CashPaymentRegistryController.$inject = [
* print and search utilities for the registry.`j
*/
function CashPaymentRegistryController(
Cash, bhConstants, Notify, Session, uiGridConstants,
Receipt, Modal, Sorting, $state, Filters, Columns,
GridState
Cash, bhConstants, Notify, Session, uiGridConstants, Receipt, Modal, Sorting,
$state, Filters, Columns, GridState, Modals
) {
var vm = this;

Expand Down Expand Up @@ -204,9 +203,7 @@ function CashPaymentRegistryController(
gridColumns.openConfigurationModal();
}

// this function deletes the cash payment and associated transactions from
// the database
function deleteCashPayment(entity) {
function remove(entity) {
Cash.remove(entity.uuid)
.then(function () {
Notify.success('FORM.INFO.DELETE_RECORD_SUCCESS');
Expand All @@ -218,5 +215,14 @@ function CashPaymentRegistryController(
.catch(Notify.handleError);
}

// this function deletes the cash payment and associated transactions from
// the database
function deleteCashPayment(entity) {
Modals.confirm('FORM.DIALOGS.CONFIRM_DELETE')
.then(function (isOk) {
if (isOk) { remove(entity); }
});
}

startup();
}
13 changes: 11 additions & 2 deletions client/src/modules/invoices/registry/registry.js
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ InvoiceRegistryController.$inject = [
'PatientInvoiceService', 'bhConstants', 'NotifyService', 'SessionService',
'ReceiptModal', 'uiGridConstants', 'ModalService', 'CashService',
'GridSortingService', 'GridColumnService', 'GridStateService', '$state',
'ModalService'
];

/**
Expand All @@ -14,7 +15,7 @@ InvoiceRegistryController.$inject = [
*/
function InvoiceRegistryController(
Invoices, bhConstants, Notify, Session, Receipt, uiGridConstants,
ModalService, Cash, Sorting, Columns, GridState, $state
ModalService, Cash, Sorting, Columns, GridState, $state, Modals
) {
var vm = this;

Expand Down Expand Up @@ -220,7 +221,7 @@ function InvoiceRegistryController(
.catch(Notify.handleError);
}

function deleteInvoice(entity) {
function remove(entity) {
Invoices.remove(entity.uuid)
.then(function () {
Notify.success('FORM.INFO.DELETE_RECORD_SUCCESS');
Expand All @@ -232,6 +233,14 @@ function InvoiceRegistryController(
.catch(Notify.handleError);
}

// check if it is okay to remove the entity.
function deleteInvoice(entity) {
Modals.confirm('FORM.DIALOGS.CONFIRM_DELETE')
.then(function (isOk) {
if (isOk) { remove(entity); }
});
}

// fire up the module
startup();
}
2 changes: 1 addition & 1 deletion client/src/modules/templates/modals/confirm.modal.html
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<div class="modal-header">
<ol class="headercrumb">
<li class="title">
<i class="fa fa-warning text-warning"></i> <span translate>FORM.DIALOGS.CONFIRM_ACTION</span>
<span translate>FORM.DIALOGS.CONFIRMATION_NEEDED</span>
</li>
</ol>
</div>
Expand Down
10 changes: 6 additions & 4 deletions client/src/modules/templates/modals/confirm.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,14 +4,16 @@ angular.module('bhima.controllers')
ConfirmModalController.$inject = ['$uibModalInstance', 'prompt'];

/**
* Confirm Modal Controller
* @class ConfirmModalController
*
* This controller provides bindings for the confirm modal.
* @description
* This controller provides bindings for a modal that confirms if
* the user should be able to perform an action or not.
*/
function ConfirmModalController(Instance, prompt) {
var vm = this;

vm.dismiss = function dismis() { return Instance.close(false); } ;
vm.dismiss = function dismis() { return Instance.close(false); };
vm.submit = function submit() { return Instance.close(true); };
vm.prompt = prompt || 'FORM.DIALOGS.CONFIRM_DELETE';
vm.prompt = (prompt || 'FORM.DIALOGS.CONFIRM_DELETE');
}
22 changes: 15 additions & 7 deletions client/src/modules/vouchers/voucher-registry.ctrl.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,9 +3,10 @@ angular.module('bhima.controllers')

// dependencies injection
VoucherController.$inject = [
'VoucherService', 'NotifyService', 'uiGridGroupingConstants', 'TransactionTypeService',
'uiGridConstants', 'bhConstants', 'ReceiptModal', 'GridSortingService', 'GridColumnService',
'GridStateService', '$state',
'VoucherService', 'NotifyService', 'uiGridGroupingConstants',
'TransactionTypeService', 'uiGridConstants', 'bhConstants', 'ReceiptModal',
'GridSortingService', 'GridColumnService', 'GridStateService', '$state',
'ModalService',
];

/**
Expand All @@ -17,8 +18,8 @@ VoucherController.$inject = [
* reordering, and many more features.
*/
function VoucherController(
Vouchers, Notify, uiGridGroupingConstants, TransactionTypes,
uiGridConstants, bhConstants, Receipts, Sorting, Columns, GridState, $state
Vouchers, Notify, uiGridGroupingConstants, TransactionTypes, uiGridConstants,
bhConstants, Receipts, Sorting, Columns, GridState, $state, Modals
) {
var vm = this;

Expand Down Expand Up @@ -234,8 +235,7 @@ function VoucherController(
$state.reload();
}

// this function deletes the voucher from the database
function deleteVoucher(entity) {
function remove(entity) {
Vouchers.remove(entity.uuid)
.then(function () {
Notify.success('FORM.INFO.DELETE_RECORD_SUCCESS');
Expand All @@ -247,5 +247,13 @@ function VoucherController(
.catch(Notify.handleError);
}

// this function deletes the voucher from the database
function deleteVoucher(entity) {
Modals.confirm('FORM.DIALOGS.CONFIRM_DELETE')
.then(function (isOk) {
if (isOk) { remove(entity); }
});
}

startup();
}
4 changes: 2 additions & 2 deletions server/controllers/finance/transactions.js
Original file line number Diff line number Diff line change
Expand Up @@ -130,7 +130,7 @@ function deleteTransaction(req, res, next) {
// TODO(@jniles) - i18n
const isPosted = transaction[0].posted;
if (isPosted) {
throw new BadRequest('This transaction is already posted.');
throw new BadRequest('This transaction is already posted.', 'TRANSACTIONS.ERRORS.TRANSACTION_POSTED');
}

// check if the transaction has references elsewhere
Expand All @@ -140,7 +140,7 @@ function deleteTransaction(req, res, next) {
// TODO(@jniles) - i18n
const isReferenced = references.length > 0;
if (isReferenced) {
throw new BadRequest('This transaction is referenced.');
throw new BadRequest('This transaction is referenced.', 'TRANSACTIONS.ERRORS.TRANSACTION_REFERENCED');
}

const documentMapText = transaction[0].identifier;
Expand Down
4 changes: 4 additions & 0 deletions test/end-to-end/cash/cash.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -277,6 +277,10 @@ function CreditNoteTests() {
const row = new GridRow('CP.TPA.4');
row.dropdown().click();
row.remove().click();

// accept the confirm modal
FU.modal.submit();

components.notification.hasSuccess();
});
}
4 changes: 4 additions & 0 deletions test/end-to-end/patient/invoice/registry.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,10 @@ describe('Invoice Registry', () => {

it('deletes an invoice', () => {
page.remove('IV.TPA.3');

// accept the confirm modal
FU.modal.submit();

components.notification.hasSuccess();
});
});
Loading

0 comments on commit 0b38588

Please sign in to comment.