Improve entity select component.
This commit is contained in:
parent
10e588aaf4
commit
b36e8a1b88
@ -22,14 +22,26 @@ import entitySelectTemplate from './entity-select.tpl.html';
|
||||
/* eslint-enable import/no-unresolved, import/default */
|
||||
|
||||
/*@ngInject*/
|
||||
export default function EntitySelect($compile, $templateCache) {
|
||||
export default function EntitySelect($compile, $templateCache, entityService) {
|
||||
|
||||
var linker = function (scope, element, attrs, ngModelCtrl) {
|
||||
var template = $templateCache.get(entitySelectTemplate);
|
||||
element.html(template);
|
||||
|
||||
scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false;
|
||||
scope.model = {};
|
||||
|
||||
var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes);
|
||||
|
||||
if (entityTypes.length === 1) {
|
||||
scope.displayEntityTypeSelect = false;
|
||||
scope.defaultEntityType = entityTypes[0];
|
||||
} else {
|
||||
scope.displayEntityTypeSelect = true;
|
||||
}
|
||||
|
||||
scope.model = {
|
||||
entityType: scope.defaultEntityType
|
||||
};
|
||||
|
||||
scope.updateView = function () {
|
||||
if (!scope.disabled) {
|
||||
@ -54,7 +66,7 @@ export default function EntitySelect($compile, $templateCache) {
|
||||
scope.model.entityType = value.entityType;
|
||||
scope.model.entityId = value.id;
|
||||
} else {
|
||||
scope.model.entityType = null;
|
||||
scope.model.entityType = scope.defaultEntityType;
|
||||
scope.model.entityId = null;
|
||||
}
|
||||
initWatchers();
|
||||
@ -106,6 +118,7 @@ export default function EntitySelect($compile, $templateCache) {
|
||||
theForm: '=?',
|
||||
tbRequired: '=?',
|
||||
disabled:'=ngDisabled',
|
||||
allowedEntityTypes: "=?",
|
||||
useAliasEntityTypes: "=?"
|
||||
}
|
||||
};
|
||||
|
||||
@ -17,10 +17,12 @@
|
||||
-->
|
||||
<div layout='row' class="tb-entity-select">
|
||||
<tb-entity-type-select style="min-width: 100px;"
|
||||
ng-if="displayEntityTypeSelect"
|
||||
the-form="theForm"
|
||||
ng-disabled="disabled"
|
||||
tb-required="tbRequired"
|
||||
use-alias-entity-types="useAliasEntityTypes"
|
||||
allowed-entity-types="allowedEntityTypes"
|
||||
ng-model="model.entityType">
|
||||
</tb-entity-type-select>
|
||||
<tb-entity-autocomplete flex ng-if="model.entityType"
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user