-
Notifications
You must be signed in to change notification settings - Fork 104
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add infrasructure for receipt currency component
This commit sets up the infrastructure for the receipt currency component. This component will provide an on update callback that updates the controller when the user has selected a new currency for the receipt. It will also cache the user's previous choice.
- Loading branch information
Showing
4 changed files
with
67 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
angular.module('bhima.components').component('bhReceiptCurrency', { | ||
templateUrl : 'partials/templates/bhReceiptCurrency.tmpl.html', | ||
controller : ReceiptCurrencyController, | ||
bindings : { | ||
onUpdate : '&' | ||
} | ||
}); | ||
|
||
ReceiptCurrencyController.$inject = ['CurrencyService', 'SessionService', 'AppCache', 'Store']; | ||
|
||
/** | ||
* Receipt Currency Component | ||
* | ||
*/ | ||
function ReceiptCurrencyController(Currencies, Session, AppCache, Store) { | ||
var ctrl = this; | ||
var cache = new AppCache('ReceiptCurrencyComponent'); | ||
|
||
Currencies.read() | ||
.then(function (currencies) { | ||
ctrl.currencies = new Store(); | ||
ctrl.currencies.setData(currencies); | ||
loadDefaultCurrency(); | ||
}); | ||
|
||
ctrl.update = function (currency) { | ||
// update view with currency object (id and symbol) | ||
ctrl.selectedCurrency = currency; | ||
|
||
// update cache with id to select this currency object on next load | ||
cache.selectedCurrencyId = currency.id; | ||
|
||
// update bindings | ||
ctrl.onUpdate({ currencyId : currency.id }); | ||
}; | ||
|
||
function loadDefaultCurrency() { | ||
// if the cache exists - use that | ||
var cached = cache.selectedCurrencyId; | ||
if (cached) { | ||
ctrl.update(ctrl.currencies.get(cached)); | ||
return; | ||
} | ||
|
||
// no cached value - use the enterprise currency | ||
ctrl.update(ctrl.currencies.get(Session.enterprise.currency_id)); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
<div class="btn-group" uib-dropdown dropdown-append-to-body> | ||
<button class="btn btn-default" uib-dropdown-toggle>{{ "INVOICE_REGISTRY.RECEIPT_CURRENCY" | translate }}</button> | ||
<button style="min-width : 30px" class="btn btn-default"> | ||
<span>{{$ctrl.selectedCurrency.symbol || '-'}}</span> | ||
</button> | ||
<ul class="dropdown-menu" uib-dropdown-menu role="menu"> | ||
<li ng-repeat="currency in $ctrl.currencies.data track by currency.id" role="menuitem"> | ||
<a ng-click="$ctrl.update(currency)" href>{{currency.name}} (<b>{{currency.symbol}}</b>)</a> | ||
</li> | ||
</ul> | ||
</div> |