-
Notifications
You must be signed in to change notification settings - Fork 105
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: add bh-account-typeahead-inline component
This commit adds the bhAccountTypeaheadInlineComponent for use in grids, such as the Complex Voucher grid. It is prototyped and demonstrated in the Complex Vouchers module. Closes #1289.
- Loading branch information
Showing
14 changed files
with
238 additions
and
112 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
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,73 @@ | ||
angular.module('bhima.components') | ||
.component('bhAccountTypeaheadInline', { | ||
templateUrl : 'modules/templates/bhAccountTypeaheadInline.html', | ||
controller : AccountTypeaheadInlineController, | ||
bindings : { | ||
accountId : '<', | ||
onSelectCallback : '&', | ||
name : '@?', | ||
}, | ||
}); | ||
|
||
AccountTypeaheadInlineController.$inject = [ | ||
'AccountService', '$timeout', '$scope', 'Store', | ||
]; | ||
|
||
/** | ||
* Inline Account Typeahead | ||
* | ||
* This component is much more limited in options compared to the bhAccountSelect. | ||
* It is intended to be used in ui-grids to facilitate entering accounts easily | ||
* without having a heavy uiSelect component. | ||
*/ | ||
function AccountTypeaheadInlineController(Accounts, $timeout, $scope, Store) { | ||
var $ctrl = this; | ||
var store = new Store(); | ||
|
||
// fired at the beginning of the account select | ||
$ctrl.$onInit = function $onInit() { | ||
// fired when an account has been selected | ||
$ctrl.onSelectCallback = $ctrl.onSelectCallback || angular.noop; | ||
|
||
// default for form name | ||
$ctrl.name = $ctrl.name || 'AccountForm'; | ||
|
||
// load accounts | ||
loadAccounts(); | ||
|
||
// alias the name as AccountForm | ||
$timeout(aliasComponentForm); | ||
}; | ||
|
||
// this makes the HTML much more readable by reference AccountForm instead of the name | ||
function aliasComponentForm() { | ||
$scope.AccountForm = $scope[$ctrl.name]; | ||
} | ||
|
||
// loads accounts from the server | ||
function loadAccounts() { | ||
Accounts.read() | ||
.then(function (elements) { | ||
// bind the accounts to the controller | ||
var accounts = Accounts.order(elements); | ||
$ctrl.accounts = Accounts.filterTitleAccounts(accounts); | ||
|
||
store.setData($ctrl.accounts); | ||
}); | ||
} | ||
|
||
$ctrl.$onChanges = function $onChanges(changes) { | ||
var accountId = changes.accountId && changes.accountId.currentValue; | ||
if (accountId) { | ||
$ctrl.account = store.get(accountId); | ||
} | ||
}; | ||
|
||
// fires the onSelectCallback bound to the component boundary | ||
$ctrl.onSelect = function onSelect($item) { | ||
$ctrl.onSelectCallback({ accountId : $item.id }); | ||
|
||
// alias the AccountForm name so that we can find it via filterFormElements | ||
$scope[$ctrl.name].$bhValue = $item.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 was deleted.
Oops, something went wrong.
26 changes: 26 additions & 0 deletions
26
client/src/modules/templates/bhAccountTypeaheadInline.html
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,26 @@ | ||
<div ng-form="{{ $ctrl.name }}" bh-account-typeahead-inline ng-model-options="{ updateOn: 'default' }"> | ||
<div | ||
class="form-group" | ||
style="margin-bottom:0;" | ||
ng-class="{ 'has-error' : AccountForm.account.$error && AccountForm.$$parentForm.$submitted }"> | ||
<input | ||
name="account" | ||
type="text" | ||
class="form-control" | ||
placeholder="{{ ::'FORM.PLACEHOLDERS.ACCOUNT' | translate }}" | ||
ng-model="$ctrl.account" | ||
uib-typeahead="account as account.hrlabel for account in $ctrl.accounts | filter:{ hrlabel: $viewValue } | limitTo:10" | ||
typeahead-template-url="bhAccountTypeaheadItem.html" | ||
typeahead-on-select="$ctrl.onSelect($item)" | ||
typeahead-append-to-body="true" | ||
required> | ||
</div> | ||
|
||
<script type="text/ng-template" id="bhAccountTypeaheadItem.html"> | ||
<a id="account-number-{{ match.model.number }}" href> | ||
<span ng-bind-html="match.model.hrlabel | uibTypeaheadHighlight:query"></span> | ||
</a> | ||
</script> | ||
|
||
</div> | ||
|
25 changes: 6 additions & 19 deletions
25
client/src/modules/vouchers/templates/account.grid.tmpl.html
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 |
---|---|---|
@@ -1,20 +1,7 @@ | ||
<div> | ||
<ui-select | ||
ng-model="row.entity.account_id" | ||
ng-change="grid.appScope.Voucher.configureRow(row.entity)" | ||
name="account" | ||
append-to-body="true" | ||
required> | ||
<ui-select-match placeholder="{{ 'FORM.PLACEHOLDERS.ACCOUNT' | translate }}"> | ||
<span><strong>{{$select.selected.number}}</strong> {{$select.selected.label}}</span> | ||
</ui-select-match> | ||
<ui-select-choices | ||
class="ui-grid-ui-select" | ||
ui-select-focus-patch | ||
ui-disable-choice="account.type_id === grid.appScope.bhConstants.accounts.TITLE" | ||
repeat="account.id as account in grid.appScope.Voucher.accounts | filter: { 'hrlabel' : $select.search } track by account.id"> | ||
<strong ng-bind-html="account.number | highlight:$select.search"></strong> | ||
<span ng-bind-html="account.label | highlight:$select.search"></span> | ||
</ui-select-choices> | ||
</ui-select> | ||
<div class="ui-grid-cell-contents"> | ||
<bh-account-typeahead-inline | ||
account-id="row.entity.account_id" | ||
name="account" | ||
on-select-callback="grid.appScope.Voucher.setAccountOnRow(row.entity, accountId)"> | ||
</bh-account-typeahead-inline> | ||
</div> |
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
Oops, something went wrong.