Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
5412: Extend date picker to support disabling r=jniles a=jmcameron

This PR extends the bhDatePicker component to support disabling the field.   

Closes Third-Culture-Software#5388 

To use this feature: when setting up the bh-date-picker component, add this parameter:

    disabled="obj.disabled"

Where "obj" is the input field for the date picker and 'disabled' is a variable in the object that evaluates to **true** when the field should be disabled.  This should be backwards compatible.

This is currently implemented for the Stock entry page (when selecting/creating lots).  You can see examples of its use in
- client/src/modules/stock/entry/modals/lots.modal.js (search for 'disabled')
- client/src/modules/stock/entry/modals/templates/lot.expiration.tmpl.html

**TESTING**
- Use any database (eg, bhima_test)
- Use Stock > Lots to find an inventory item that has lots that are not expired  (for bhima_test, try inventory Item: Vitamines B1+B6+B12
- Go to Stock > Entry
   - Use integration
   - Do "Add" and select the inventory item from the previous step
   - Click on the "Lots" field to get the lot selection/creation modal
   - On the first row, notice that the expiration date can be changed.
   - Select one of the existing lots using the lot selection typeahead
   - Notice that the expiration date has been overwriten and cannot be modified.





Co-authored-by: Jonathan Cameron <jmcameron@gmail.com>
  • Loading branch information
bors[bot] and jmcameron authored Feb 24, 2021
2 parents 81cd8d0 + 910e42f commit da8f839
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 4 deletions.
5 changes: 5 additions & 0 deletions client/src/js/components/bhDatePicker.js
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ angular.module('bhima.components')
onChange : '&', // use a callback to notify for changes
format : '<?',
mode : '@?', // will this ever change? If so, we can use '<'
disabled : '<?', // Optional flag to disable this field
required : '<?',
},
});
Expand Down Expand Up @@ -43,6 +44,10 @@ function DatePickerController(Modal, bhConstants) {
}

function open() {
if (vm.disabled) {
// Do not open the date picker popup if the field is disabled
return;
}
openDatePicker({ mode : vm.mode })
.then(date => {
// notify the parent controller of a date change via a callback
Expand Down
1 change: 1 addition & 0 deletions client/src/modules/stock/entry/modals/lots.modal.js
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,7 @@ function StockDefineLotsModalController(
function onSelectLot(entity, item) {
const lot = vm.stockLine.candidateLots.find(l => l.uuid === item.uuid);
entity.expiration_date = new Date(lot.expiration_date);
entity.disabled = true;
onChanges();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
<bh-date-picker
date="row.entity.expiration_date"
on-change="grid.appScope.onDateChange(date, row.entity)"
ng-disabled="row.entity._initialized"
disabled="row.entity.disabled"
required="true">
</bh-date-picker>
</div>
7 changes: 4 additions & 3 deletions client/src/modules/templates/bhDatePickerAction.tmpl.html
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<span class="text-action" ng-dblclick="$ctrl.open()">
<input
<input
uib-datepicker-popup="{{ $ctrl.dateFormat }}"
class="form-control text-right"
type="text"
class="form-control text-right"
type="text"
ng-change="$ctrl.notifyDateChange()"
ng-model="$ctrl.date"
ng-model-options="{ 'debounce' : { 'default' : 150, 'blur' : 0 }}"
ng-disabled="$ctrl.disabled"
ng-required="$ctrl.required">
</span>

0 comments on commit da8f839

Please sign in to comment.