Skip to content

Commit

Permalink
feat(reference): implement prototype reference modal
Browse files Browse the repository at this point in the history
This commit implements a reference prototype modal that can be embedded
in any controller to retrieve the uuid of any previous transaction just
given the document reference.

Note: this only implements the UI.  The $http requests are mocked via
the $timeout inject until a backend is created for these queries.
  • Loading branch information
jniles committed Mar 2, 2016
1 parent 94d7911 commit e07f333
Show file tree
Hide file tree
Showing 3 changed files with 145 additions and 1 deletion.
60 changes: 60 additions & 0 deletions client/src/partials/journal/modals/references.modal.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,60 @@
<ng-form name="ModalForm">
<div class="modal-header">
<h4>Receipt Lookup Modal</h4>
</div>

<!-- main form body -->
<div class="modal-body">

<!-- dropdown to choose receipt type -->
<div class="form-group" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.type.$error }">
<label class="control-label">Receipt Type</label>
<select
class="form-control"
name="type"
ng-model="ReferenceLookupModalCtrl.path"
ng-options="tgt.path as tgt.key for tgt in ReferenceLookupModalCtrl.targets | translate track by tgt.path"
required
>
<option value="" disabled>Select a Receipt Type</option>
</select>
</div>

<!-- input to find the correct receipt by reference -->
<div class="form-group has-feedback" ng-class="{ 'has-error' : ModalForm.$submitted && ModalForm.reference.$error }">
<label class="control-label">Reference Lookup</label>
<div class="input-group">
<input
type="text"
name="reference"
class="form-control"
ng-model="ReferenceLookupModalCtrl.reference"
ng-disabled="ReferenceLookupModalCtrl.loading"
required>
<button
class="input-group-btn"
type="button"
ng-click="ReferenceModalCtrl.lookupReference()"
ng-disabled="ReferenceLookupModalCtrl.loading">
<span ng-hide="vm.loading"><span class="glyphicon glyphicon-search"></span> Search</span>
<span ng-show="vm.loading"><span class="glyphicon glyphicon-time"></span> Loading</span>
</button>
</div>
</div>

<!-- preview field for document -->
<div class="form-group" ng-show="ReferenceLookupModalCtrl.document">
<label class="control-label">Preview</label>
<p class="form-control-static">I am a preview field.</p>
</div>
</div>

<div class="modal-footer">
<button type="submit" class="btn btn-primary" ng-click="ReferenceLookupModalCtrl.submit(ModalForm.$invalid)">
{{ "FORM.SUBMIT" | translate }}
</button>
<button type="button" class="btn btn-default" ng-click="ReferenceLookupModalCtrl.dismiss()">
{{ "FORM.CANCEL" | translate }}
</button>
</div>
</ng-form>
85 changes: 85 additions & 0 deletions client/src/partials/journal/modals/references.modal.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
angular.module('bhima.controllers')
.controller('ReferenceLookupModalController', ReferenceLookupModalController);

ReferenceLookupModalController.$inject = [ '$uibModalInstance', '$timeout' ];

/**
* Reference Lookup Modal Controller
*
* This modal contains lookups for the following documents, based on references:
* 1) Patient Invoices
* 2) Cash Payments
* 3) Journal Vouchers
* 4) Purchase Orders
* 5) Payslips (Payroll)
*
* The module itself is simple - it is a typeahead with an async validator to
* verfiy that the modal actually has data.
*
* This is currently just a prototype, to be improved as services become
* available to power the lookups.
*/
function ReferenceLookupModalController(ModalInstance, $timeout) {
var vm = this;

/** bind the dismiss method */
vm.dismiss = ModalInstance.dismiss;
vm.submit = submit;

/** loading indicator */
vm.loading = false;

/** target paths to look up from */
vm.targets = [{
path : '/cash/references/',
key : 'CASH_PAYMENTS'
}, {
path : '/sales/references/',
key : 'PATIENT_INVOICE'
}, {
path : '/purchases/references/',
key : 'PURCHASE_ORDERS'
}, {
path : '/vouchers/references/',
key : 'JOURNAL_VOUCHERS'
}, {
path : '/paychecks/references/',
key : 'PAYSLIPS'
}];

function lookupReference() {

// don't bother trying a lookup if there is no reference.
if (!vm.reference) { return; }

toggleLoading();

// mock lookups
$timeout(function () {

// turn off loading
toggleLoading();

// temporary mock data
vm.document = {
uuid : '03a329b2-03fe-4f73-b40f-56a2870cc7e6',
amount : 10.34,
date : new Date(Date.parse('2016-02-03'))
};

}, 3000);
}

/** modal submit */
function submit(invalid) {
if (invalid) { return; }

/** return the document retrieved from the server */
ModalInstance.close(vm.document);
}

/** toggle modal loading */
function toggleLoading() {
vm.loading = !vm.loading;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@ function HospitalNumber($q, $http) {
registeredValue : '='
},
link : function (scope, elm, attrs, ctrl) {
var nochecks = 0;

ctrl.$asyncValidators.hospitalNumber = function (modelValue, viewValue) {
var deferred;
Expand Down

0 comments on commit e07f333

Please sign in to comment.