Commit b36e8a1b88b04cdbf6a86f40ec32fc1ad0247e2b

Authored by Igor Kulikov
1 parent 10e588aa

Improve entity select component.

... ... @@ -22,14 +22,26 @@ import entitySelectTemplate from './entity-select.tpl.html';
22 22 /* eslint-enable import/no-unresolved, import/default */
23 23
24 24 /*@ngInject*/
25   -export default function EntitySelect($compile, $templateCache) {
  25 +export default function EntitySelect($compile, $templateCache, entityService) {
26 26
27 27 var linker = function (scope, element, attrs, ngModelCtrl) {
28 28 var template = $templateCache.get(entitySelectTemplate);
29 29 element.html(template);
30 30
31 31 scope.tbRequired = angular.isDefined(scope.tbRequired) ? scope.tbRequired : false;
32   - scope.model = {};
  32 +
  33 + var entityTypes = entityService.prepareAllowedEntityTypesList(scope.allowedEntityTypes, scope.useAliasEntityTypes);
  34 +
  35 + if (entityTypes.length === 1) {
  36 + scope.displayEntityTypeSelect = false;
  37 + scope.defaultEntityType = entityTypes[0];
  38 + } else {
  39 + scope.displayEntityTypeSelect = true;
  40 + }
  41 +
  42 + scope.model = {
  43 + entityType: scope.defaultEntityType
  44 + };
33 45
34 46 scope.updateView = function () {
35 47 if (!scope.disabled) {
... ... @@ -54,7 +66,7 @@ export default function EntitySelect($compile, $templateCache) {
54 66 scope.model.entityType = value.entityType;
55 67 scope.model.entityId = value.id;
56 68 } else {
57   - scope.model.entityType = null;
  69 + scope.model.entityType = scope.defaultEntityType;
58 70 scope.model.entityId = null;
59 71 }
60 72 initWatchers();
... ... @@ -106,6 +118,7 @@ export default function EntitySelect($compile, $templateCache) {
106 118 theForm: '=?',
107 119 tbRequired: '=?',
108 120 disabled:'=ngDisabled',
  121 + allowedEntityTypes: "=?",
109 122 useAliasEntityTypes: "=?"
110 123 }
111 124 };
... ...
... ... @@ -17,10 +17,12 @@
17 17 -->
18 18 <div layout='row' class="tb-entity-select">
19 19 <tb-entity-type-select style="min-width: 100px;"
  20 + ng-if="displayEntityTypeSelect"
20 21 the-form="theForm"
21 22 ng-disabled="disabled"
22 23 tb-required="tbRequired"
23 24 use-alias-entity-types="useAliasEntityTypes"
  25 + allowed-entity-types="allowedEntityTypes"
24 26 ng-model="model.entityType">
25 27 </tb-entity-type-select>
26 28 <tb-entity-autocomplete flex ng-if="model.entityType"
... ...