Retail:Developers Guide/How-to/How to add an approval
Contents |
Introduction
There are several actions in Web POS which could need an approval of a supervisor because in some stores cashiers do not have rights to do some actions.
This document explains how to implement this action.
Already exist few approvals implemented: Approvals List
Implementation
Add the approval in the action
This section explains how to add the approval in a component action:
It is enough to add this javascript code, for example, in a tap of a button:
tap: function () { var me = this; OB.UTIL.Approval.requestApproval( me.model, 'OBPOS_approval.deleteLine', function (approved, supervisor, approvalType) { if (approved) { me.owner.doDeleteLine({ line: me.owner.line }); } }); }
It is simple, we have to call OB.UTIL.Approval.requestApproval with parameters: window model, property searchKey(a string or an array of searchKeys) and the callback (the action of the button). If approved parameter is true the credentials of the supervisor are ok and we can do the action.
Create Preferences
Yoy need to create a property in the Reference window in the Property Configuration.
Each action requiring approval can have its own supervisors, thus it is possible for a user to be supervisor of action A but not action's B supervisor.
Each Approvable Action require of a different preference to be set:
- "Approvable Action" Preference with value N at client level. In order to show Approval Modal.
- "Approvable Action" Preference with value Y at user's or role level. In order to give access to this action.
Note that, as opposite as the other security preferences, supervisor preferences require of explicit setting, this means automatic roles are not considered as supervisor unless there is a preference defining it.
Back to How-to
Add custom messages to the approval
It is possible to add custom messages to the approval in order to give an accurate vision of what you are asking for an approval.
OB.UTIL.HookManager.registerHook('OBPOS_CheckPaymentApproval', function (args, callbacks) { var yourMessage = 'I am a dummy message' args.approvals.push({ approval: 'DUMMY_approval.test', message: 'DUMMY_approval.test', params: ['<div style="font-size:16px;padding-left:0.5em">' + yourMessage + '</div>'] }); // Continue normal process OB.UTIL.HookManager.callbackExecutor(args, callbacks); return; });
When you want to throw the approval you can send the property params with the custom message you want to send as its value. HTML code is accepted in order to give a custom style.