Skip to content

Commit

Permalink
feat(component): add a component to select a supplier
Browse files Browse the repository at this point in the history
  • Loading branch information
DedrickEnc committed Aug 15, 2017
1 parent f389273 commit caf3e0e
Show file tree
Hide file tree
Showing 2 changed files with 69 additions and 0 deletions.
44 changes: 44 additions & 0 deletions client/src/js/components/bhSupplierSelect.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
angular.module('bhima.components')
.component('bhSupplierSelect', {
templateUrl : 'modules/templates/bhSupplierSelect.tmpl.html',
controller : SupplierSelectController,
transclude : true,
bindings : {
supplierId : '<',
onSelectCallback : '&',
label : '@?',
required : '<?',
validateTrigger : '<?',
},
});

SupplierSelectController.$inject = [
'SupplierService'
];

/**
* Supplier selection component
*
*/
function SupplierSelectController(Suppliers) {
var $ctrl = this;

$ctrl.$onInit = function onInit() {
// fired when an Supplier has been selected
$ctrl.onSelectCallback = $ctrl.onSelectCallback || angular.noop;

// default for label
$ctrl.label = $ctrl.label || 'FORM.LABELS.SUPPLIER';

// load all Suppliers
Suppliers.read()
.then(function (suppliers) {
$ctrl.suppliers = suppliers;
});
};

// fires the onSelectCallback bound to the component boundary
$ctrl.onSelect = function ($item, $model) {
$ctrl.onSelectCallback({ supplier : $item });
};
}
25 changes: 25 additions & 0 deletions client/src/modules/templates/bhSupplierSelect.tmpl.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
<div ng-form="SupplierForm" bh-supplier-select ng-model-options="{ updateOn: 'default' }">
<div
class="form-group"
ng-class="{ 'has-error' : $ctrl.validateTrigger && SupplierForm.supplier_id.$invalid }">

<label class="control-label" translate>
{{$ctrl.label}}
</label>

<ng-transclude></ng-transclude>
<ui-select
name="supplier_id"
ng-model="$ctrl.supplierId"
on-select="$ctrl.onSelect($item, $model)">
<ui-select-match placeholder="{{ 'FORM.SELECT.SUPPLIER' | translate }}">{{$select.selected.display_name}}</span></ui-select-match>
<ui-select-choices ui-select-focus-patch repeat="supplier.id as supplier in $ctrl.suppliers | filter: { 'display_name': $select.search }">
<span ng-bind-html="supplier.display_name | highlight:$select.search"></span>
</ui-select-choices>
</ui-select>

<div class="help-block" ng-messages="SupplierForm.supplier_id.$error" ng-show="$ctrl.validateTrigger">
<div ng-messages-include="modules/templates/messages.tmpl.html"></div>
</div>
</div>
</div>

0 comments on commit caf3e0e

Please sign in to comment.