@po-ui/ng-components 5.17.0 → 5.18.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. package/bundles/po-ui-ng-components.umd.js +992 -676
  2. package/bundles/po-ui-ng-components.umd.js.map +1 -1
  3. package/esm2015/lib/components/po-field/po-lookup/interfaces/po-lookup-filter.interface.js +1 -1
  4. package/esm2015/lib/components/po-field/po-lookup/po-lookup-base.component.js +79 -22
  5. package/esm2015/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.js +40 -10
  6. package/esm2015/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal.component.js +45 -7
  7. package/esm2015/lib/components/po-field/po-lookup/po-lookup.component.js +136 -13
  8. package/esm2015/lib/components/po-field/po-lookup/services/po-lookup-filter.service.js +19 -4
  9. package/esm2015/lib/components/po-field/po-lookup/services/po-lookup-modal.service.js +9 -2
  10. package/esm2015/lib/components/po-stepper/po-stepper.component.js +14 -13
  11. package/esm2015/lib/components/po-table/po-table-base.component.js +2 -2
  12. package/esm2015/lib/components/po-table/po-table.component.js +41 -1
  13. package/fesm2015/po-ui-ng-components.js +933 -625
  14. package/fesm2015/po-ui-ng-components.js.map +1 -1
  15. package/lib/components/po-field/po-lookup/interfaces/po-lookup-filter.interface.d.ts +5 -2
  16. package/lib/components/po-field/po-lookup/po-lookup-base.component.d.ts +50 -6
  17. package/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal-base.component.d.ts +22 -2
  18. package/lib/components/po-field/po-lookup/po-lookup-modal/po-lookup-modal.component.d.ts +10 -3
  19. package/lib/components/po-field/po-lookup/po-lookup.component.d.ts +25 -2
  20. package/lib/components/po-field/po-lookup/services/po-lookup-filter.service.d.ts +6 -2
  21. package/lib/components/po-field/po-lookup/services/po-lookup-modal.service.d.ts +7 -0
  22. package/lib/components/po-stepper/po-stepper.component.d.ts +6 -2
  23. package/lib/components/po-table/po-table.component.d.ts +13 -0
  24. package/package.json +4 -4
  25. package/po-ui-ng-components-5.18.0.tgz +0 -0
  26. package/po-ui-ng-components.metadata.json +1 -1
  27. package/schematics/ng-add/index.js +1 -1
  28. package/schematics/ng-update/v2/index.js +1 -1
  29. package/schematics/ng-update/v3/index.js +1 -1
  30. package/schematics/ng-update/v4/index.js +1 -1
  31. package/schematics/ng-update/v5/index.js +1 -1
  32. package/po-ui-ng-components-5.17.0.tgz +0 -0
@@ -13735,7 +13735,7 @@
13735
13735
  this.items.forEach(function (item) {
13736
13736
  item.$selected = _this.selectAll;
13737
13737
  });
13738
- this.emitSelectAllEvents(this.selectAll, this.items);
13738
+ this.emitSelectAllEvents(this.selectAll, __spreadArray([], __read(this.items)));
13739
13739
  }
13740
13740
  };
13741
13741
  PoTableBaseComponent.prototype.selectRow = function (row) {
@@ -14623,6 +14623,30 @@
14623
14623
  this.toggleRowAction(row);
14624
14624
  }
14625
14625
  };
14626
+ /**
14627
+ * Desmarca uma linha que está selecionada.
14628
+ */
14629
+ PoTableComponent.prototype.unselectRowItem = function (itemfn) {
14630
+ this.toggleSelect(itemfn, false);
14631
+ if (this.items.every(function (item) { return !item.$selected; })) {
14632
+ this.selectAll = false;
14633
+ }
14634
+ else {
14635
+ this.selectAll = null;
14636
+ }
14637
+ };
14638
+ /**
14639
+ * Seleciona uma linha do 'po-table'.
14640
+ */
14641
+ PoTableComponent.prototype.selectRowItem = function (itemfn) {
14642
+ this.toggleSelect(itemfn, true);
14643
+ if (this.items.every(function (item) { return item.$selected; })) {
14644
+ this.selectAll = true;
14645
+ }
14646
+ else {
14647
+ this.selectAll = null;
14648
+ }
14649
+ };
14626
14650
  PoTableComponent.prototype.formatNumber = function (value, format) {
14627
14651
  if (!format) {
14628
14652
  return value;
@@ -14861,6 +14885,22 @@
14861
14885
  this.calculateHeightTableContainer(this.height);
14862
14886
  }
14863
14887
  };
14888
+ PoTableComponent.prototype.toggleSelect = function (compare, selectValue) {
14889
+ if (typeof compare !== 'function') {
14890
+ this.items.forEach(function (item) {
14891
+ if (item === compare) {
14892
+ item.$selected = selectValue;
14893
+ }
14894
+ });
14895
+ }
14896
+ else {
14897
+ this.items.forEach(function (item) {
14898
+ if (compare(item)) {
14899
+ item.$selected = selectValue;
14900
+ }
14901
+ });
14902
+ }
14903
+ };
14864
14904
  return PoTableComponent;
14865
14905
  }(PoTableBaseComponent));
14866
14906
  PoTableComponent.decorators = [
@@ -19397,6 +19437,7 @@
19397
19437
  this.headers = new i1.HttpHeaders({
19398
19438
  'X-PO-No-Message': 'true'
19399
19439
  });
19440
+ this.multiple = false;
19400
19441
  }
19401
19442
  PoLookupFilterService.prototype.getFilteredItems = function (filteredItemsParams) {
19402
19443
  var filterParams = filteredItemsParams.filterParams, advancedFilters = filteredItemsParams.advancedFilters, restFilteredItemsParams = __rest(filteredItemsParams, ["filterParams", "advancedFilters"]);
@@ -19406,12 +19447,25 @@
19406
19447
  return this.httpClient.get(this.url, { headers: this.headers, params: params });
19407
19448
  };
19408
19449
  PoLookupFilterService.prototype.getObjectByValue = function (value, filterParams) {
19409
- var encodedValue = encodeURIComponent(value);
19410
19450
  var validatedFilterParams = this.validateParams(filterParams);
19411
- return this.httpClient.get(this.url + "/" + encodedValue, { headers: this.headers, params: validatedFilterParams });
19451
+ var newURL;
19452
+ var encodedValue;
19453
+ if (this.multiple) {
19454
+ encodedValue = encodeURIComponent(Array.isArray(value) ? value.join(',') : value);
19455
+ newURL = this.url + "?" + this.fieldValue + "=" + encodedValue;
19456
+ }
19457
+ else {
19458
+ encodedValue = encodeURIComponent(value);
19459
+ newURL = this.url + "/" + encodedValue;
19460
+ }
19461
+ return this.httpClient
19462
+ .get(newURL, { headers: this.headers, params: validatedFilterParams })
19463
+ .pipe(operators.map(function (response) { return ('items' in response ? response.items : response); }));
19412
19464
  };
19413
- PoLookupFilterService.prototype.setUrl = function (url) {
19465
+ PoLookupFilterService.prototype.setConfig = function (url, fieldValue, multiple) {
19414
19466
  this.url = url;
19467
+ this.fieldValue = fieldValue;
19468
+ this.multiple = multiple;
19415
19469
  };
19416
19470
  PoLookupFilterService.prototype.validateParams = function (params) {
19417
19471
  return isTypeof(params, 'object') && !Array.isArray(params) ? params : undefined;
@@ -19429,7 +19483,7 @@
19429
19483
  * @description
19430
19484
  *
19431
19485
  * Componente utilizado para abrir uma janela de busca com uma tabela que lista dados de um serviço. Nesta janela é possível buscar e
19432
- * selecionar o registro que será enviado para o campo. O `po-lookup` permite que o usuário digite um valor e pressione a tecla *TAB* para
19486
+ * selecionar um ou mais registros que serão enviados para o campo. O `po-lookup` permite que o usuário digite um valor e pressione a tecla *TAB* para
19433
19487
  * buscar um registro.
19434
19488
  *
19435
19489
  * > Caso o campo seja iniciado ou preenchido com um valor inexistente na busca, o mesmo será limpado.
@@ -19469,6 +19523,29 @@
19469
19523
  this.infiniteScroll = false;
19470
19524
  /** Exibe um ícone que permite limpar o campo. */
19471
19525
  this.clean = false;
19526
+ /**
19527
+ * @optional
19528
+ *
19529
+ * @description
19530
+ *
19531
+ * Permite a seleção de múltiplos itens.
19532
+ *
19533
+ * > Quando habilitado o valor do campo passará a ser uma lista de valores, por exemplo: `[ 12345, 67890 ]`
19534
+ *
19535
+ * @default `false`
19536
+ */
19537
+ this.multiple = false;
19538
+ /**
19539
+ * @optional
19540
+ *
19541
+ * @description
19542
+ *
19543
+ * Define que a altura do componente será auto ajustável, possuindo uma altura minima porém a altura máxima será de acordo
19544
+ * com o número de itens selecionados e a extensão dos mesmos, mantendo-os sempre visíveis.
19545
+ *
19546
+ * @default `false`
19547
+ */
19548
+ this.autoHeight = false;
19472
19549
  /**
19473
19550
  * Evento será disparado quando ocorrer algum erro na requisição de busca do item.
19474
19551
  * Será passado por parâmetro o objeto de erro retornado.
@@ -19492,6 +19569,7 @@
19492
19569
  * Por parâmetro será passado o novo valor.
19493
19570
  */
19494
19571
  this.change = new i0.EventEmitter();
19572
+ this.selectedOptions = [];
19495
19573
  this.oldValue = '';
19496
19574
  this.oldValueToModel = null;
19497
19575
  // eslint-disable-next-line
@@ -19499,6 +19577,7 @@
19499
19577
  this._disabled = false;
19500
19578
  this._placeholder = '';
19501
19579
  this._required = false;
19580
+ this._autoHeight = false;
19502
19581
  this.onChangePropagate = null;
19503
19582
  }
19504
19583
  Object.defineProperty(PoLookupBaseComponent.prototype, "placeholder", {
@@ -19556,6 +19635,20 @@
19556
19635
  * url + ?page=1&pageSize=20&age=23&filter=Peter
19557
19636
  * ```
19558
19637
  *
19638
+ * Ao iniciar o campo com valor, os registros serão buscados da seguinte forma:
19639
+ * ```
19640
+ * model = 1234;
19641
+ *
19642
+ * GET url/1234
19643
+ * ```
19644
+ *
19645
+ * Caso estiver com múltipla seleção habilitada:
19646
+ * ```
19647
+ * model = [1234, 5678]
19648
+ *
19649
+ * GET url?${fieldValue}=1234,5678
19650
+ * ```
19651
+ *
19559
19652
  * > Esta URL deve retornar e receber os dados no padrão de [API do PO UI](https://po-ui.io/guides/api) e utiliza os valores
19560
19653
  * definidos nas propriedades `p-field-label` e `p-field-value` para a construção do `po-lookup`.
19561
19654
  *
@@ -19648,6 +19741,11 @@
19648
19741
  this.cleanViewValue();
19649
19742
  this.callOnChange(undefined);
19650
19743
  };
19744
+ PoLookupBaseComponent.prototype.ngOnChanges = function (changes) {
19745
+ if (changes.multiple && isTypeof(this.filterService, 'string')) {
19746
+ this.service.setConfig(this.filterService, this.fieldValue, this.multiple);
19747
+ }
19748
+ };
19651
19749
  // Função implementada do ControlValueAccessor
19652
19750
  // Usada para interceptar os estados de habilitado via forms api
19653
19751
  PoLookupBaseComponent.prototype.setDisabledState = function (isDisabled) {
@@ -19668,7 +19766,7 @@
19668
19766
  };
19669
19767
  // Seleciona o valor do model.
19670
19768
  PoLookupBaseComponent.prototype.selectValue = function (valueSelected) {
19671
- this.valueToModel = valueSelected[this.fieldValue];
19769
+ this.valueToModel = valueSelected;
19672
19770
  this.callOnChange(this.valueToModel);
19673
19771
  this.selected.emit(valueSelected);
19674
19772
  };
@@ -19707,10 +19805,12 @@
19707
19805
  }
19708
19806
  }))
19709
19807
  .subscribe(function (element) {
19710
- if (element) {
19711
- _this.oldValue = element[_this.fieldLabel];
19712
- _this.selectValue(element);
19713
- _this.setViewValue(_this.getFormattedLabel(element), element);
19808
+ if ((element === null || element === void 0 ? void 0 : element.length) || (!Array.isArray(element) && element)) {
19809
+ if (Array.isArray(element) && element.length > 1) {
19810
+ _this.setDisclaimers(element);
19811
+ _this.updateVisibleItems();
19812
+ }
19813
+ _this.selectModel(_this.multiple ? element : [element]);
19714
19814
  }
19715
19815
  else {
19716
19816
  _this.cleanModel();
@@ -19734,13 +19834,7 @@
19734
19834
  }
19735
19835
  };
19736
19836
  PoLookupBaseComponent.prototype.writeValue = function (value) {
19737
- if (value && value instanceof Object) {
19738
- // Esta condição é executada quando é retornado o objeto selecionado do componente Po Lookup Modal.
19739
- this.oldValue = value[this.fieldLabel];
19740
- this.valueToModel = value[this.fieldValue];
19741
- this.setViewValue(this.getFormattedLabel(value), value);
19742
- }
19743
- else if (value) {
19837
+ if ((value === null || value === void 0 ? void 0 : value.length) || (!Array.isArray(value) && value)) {
19744
19838
  // Esta condição é executada somente quando é passado o ID para realizar a busca pelo ID.
19745
19839
  this.searchById(value);
19746
19840
  }
@@ -19758,10 +19852,20 @@
19758
19852
  return value ? this.keysDescription.map(function (column) { return value[column]; }).join(' - ') : '';
19759
19853
  };
19760
19854
  // Chama o método writeValue e preenche o model.
19761
- PoLookupBaseComponent.prototype.selectModel = function (value) {
19762
- this.writeValue(value);
19763
- if (value && value instanceof Object) {
19764
- this.selectValue(value);
19855
+ PoLookupBaseComponent.prototype.selectModel = function (options) {
19856
+ var _this = this;
19857
+ if (options.length) {
19858
+ this.selectedOptions = __spreadArray([], __read(options));
19859
+ var newModel = this.multiple ? options.map(function (option) { return option[_this.fieldValue]; }) : options[0][this.fieldValue];
19860
+ this.selectValue(newModel);
19861
+ if (options.length === 1) {
19862
+ this.oldValue = options[0][this.fieldLabel];
19863
+ this.setViewValue(this.getFormattedLabel(options[0]), options[0]);
19864
+ }
19865
+ }
19866
+ else {
19867
+ this.selectValue(undefined);
19868
+ this.cleanViewValue();
19765
19869
  }
19766
19870
  };
19767
19871
  PoLookupBaseComponent.prototype.validateModel = function (model) {
@@ -19775,7 +19879,7 @@
19775
19879
  }
19776
19880
  if (service && isTypeof(service, 'string')) {
19777
19881
  this.service = this.defaultService;
19778
- this.service.setUrl(service);
19882
+ this.service.setConfig(service, this.fieldValue, this.multiple);
19779
19883
  }
19780
19884
  };
19781
19885
  PoLookupBaseComponent.prototype.setControl = function () {
@@ -19818,6 +19922,8 @@
19818
19922
  advancedFilters: [{ type: i0.Input, args: ['p-advanced-filters',] }],
19819
19923
  infiniteScroll: [{ type: i0.Input, args: ['p-infinite-scroll',] }],
19820
19924
  clean: [{ type: i0.Input, args: ['p-clean',] }],
19925
+ multiple: [{ type: i0.Input, args: ['p-multiple',] }],
19926
+ autoHeight: [{ type: i0.Input, args: ['p-auto-height',] }],
19821
19927
  onError: [{ type: i0.Output, args: ['p-error',] }],
19822
19928
  selected: [{ type: i0.Output, args: ['p-selected',] }],
19823
19929
  change: [{ type: i0.Output, args: ['p-change',] }],
@@ -19835,714 +19941,750 @@
19835
19941
  __decorate([
19836
19942
  InputBoolean()
19837
19943
  ], PoLookupBaseComponent.prototype, "clean", void 0);
19944
+ __decorate([
19945
+ InputBoolean()
19946
+ ], PoLookupBaseComponent.prototype, "multiple", void 0);
19947
+ __decorate([
19948
+ InputBoolean()
19949
+ ], PoLookupBaseComponent.prototype, "autoHeight", void 0);
19838
19950
 
19951
+ var poLookupLiteralsDefault = {
19952
+ en: {
19953
+ modalPrimaryActionLabel: 'Select',
19954
+ modalSecondaryActionLabel: 'Cancel',
19955
+ modalPlaceholder: 'Search',
19956
+ modalTitle: 'Select a record',
19957
+ modalTableNoColumns: poTableLiteralsDefault.en.noColumns,
19958
+ modalTableNoData: poTableLiteralsDefault.en.noData,
19959
+ modalTableLoadingData: poTableLiteralsDefault.en.loadingData,
19960
+ modalTableLoadMoreData: poTableLiteralsDefault.en.loadMoreData,
19961
+ modalAdvancedSearch: 'Advanced search',
19962
+ modalAdvancedSearchTitle: 'Advanced search',
19963
+ modalAdvancedSearchPrimaryActionLabel: 'Filter',
19964
+ modalAdvancedSearchSecondaryActionLabel: 'Return',
19965
+ modalDisclaimerGroupTitle: 'Presenting results filtered by:'
19966
+ },
19967
+ es: {
19968
+ modalPrimaryActionLabel: 'Seleccionar',
19969
+ modalSecondaryActionLabel: 'Cancelar',
19970
+ modalPlaceholder: 'Buscar',
19971
+ modalTitle: 'Seleccione un registro',
19972
+ modalTableNoColumns: poTableLiteralsDefault.es.noColumns,
19973
+ modalTableNoData: poTableLiteralsDefault.es.noData,
19974
+ modalTableLoadingData: poTableLiteralsDefault.es.loadingData,
19975
+ modalTableLoadMoreData: poTableLiteralsDefault.es.loadMoreData,
19976
+ modalAdvancedSearch: 'Búsqueda Avanzada',
19977
+ modalAdvancedSearchTitle: 'Búsqueda Avanzada',
19978
+ modalAdvancedSearchPrimaryActionLabel: 'Filtrar',
19979
+ modalAdvancedSearchSecondaryActionLabel: 'Vuelve',
19980
+ modalDisclaimerGroupTitle: 'Presentar resultados filtrados por:'
19981
+ },
19982
+ pt: {
19983
+ modalPrimaryActionLabel: 'Selecionar',
19984
+ modalSecondaryActionLabel: 'Cancelar',
19985
+ modalPlaceholder: 'Pesquisar',
19986
+ modalTitle: 'Selecione um registro',
19987
+ modalTableNoColumns: poTableLiteralsDefault.pt.noColumns,
19988
+ modalTableNoData: poTableLiteralsDefault.pt.noData,
19989
+ modalTableLoadingData: poTableLiteralsDefault.pt.loadingData,
19990
+ modalTableLoadMoreData: poTableLiteralsDefault.pt.loadMoreData,
19991
+ modalAdvancedSearch: 'Busca avançada',
19992
+ modalAdvancedSearchTitle: 'Busca Avançada',
19993
+ modalAdvancedSearchPrimaryActionLabel: 'Filtrar',
19994
+ modalAdvancedSearchSecondaryActionLabel: 'Voltar',
19995
+ modalDisclaimerGroupTitle: 'Apresentando resultados filtrados por:'
19996
+ },
19997
+ ru: {
19998
+ modalPrimaryActionLabel: 'выбирать',
19999
+ modalSecondaryActionLabel: 'отменить',
20000
+ modalPlaceholder: 'поиск',
20001
+ modalTitle: 'Выберите запись',
20002
+ modalTableNoColumns: poTableLiteralsDefault.ru.noColumns,
20003
+ modalTableNoData: poTableLiteralsDefault.ru.noData,
20004
+ modalTableLoadingData: poTableLiteralsDefault.ru.loadingData,
20005
+ modalTableLoadMoreData: poTableLiteralsDefault.ru.loadMoreData,
20006
+ modalAdvancedSearch: 'Расширенный поиск',
20007
+ modalAdvancedSearchTitle: 'Расширенный поиск',
20008
+ modalAdvancedSearchPrimaryActionLabel: 'Фильтр',
20009
+ modalAdvancedSearchSecondaryActionLabel: 'Вернись',
20010
+ modalDisclaimerGroupTitle: 'Представление результатов отфильтровано по:'
20011
+ }
20012
+ };
19839
20013
  /**
20014
+ * @docsPrivate
19840
20015
  *
19841
- * @description
19842
- *
19843
- * Componente para criação de formulários dinâmicos a partir de uma lista de objetos.
19844
- *
19845
- * Também é possível verificar se o formulário está válido e informar valores para a exibição de informações.
20016
+ * Classe base do componente Po Lookup Modal.
19846
20017
  */
19847
- var PoDynamicFormBaseComponent = /** @class */ (function () {
19848
- function PoDynamicFormBaseComponent() {
19849
- /**
19850
- * @optional
19851
- *
19852
- * @description
19853
- *
19854
- * Na inicialização do componente será repassado o objeto de formulário utilizado no componente,
19855
- * podendo ser utilizado para validações e/ou detecção de mudança dos valores.
19856
- *
19857
- * Portanto existem duas maneiras de recuperar o formulário,
19858
- * através de *template reference* e através do *output*, veja os exemplos abaixo:
19859
- *
19860
- * > *template reference*
19861
- *
19862
- * ```html
19863
- * <po-dynamic-form #dynamicForm>
19864
- * </po-dynamic-form>
19865
- *
19866
- * <po-button p-label="Adicionar" [p-disabled]="dynamicForm?.form.invalid">
19867
- * </po-button>
19868
- *
19869
- * ```
19870
- *
19871
- * > *Output*
19872
- *
19873
- * ```html
19874
- * ...
19875
- * <po-dynamic-form (p-form)="getForm($event)">
19876
- * </po-dynamic-form>
19877
- *
19878
- * <po-button p-label="Adicionar" [p-disabled]="dynamicForm?.invalid">
19879
- * </po-button>
19880
- * ...
19881
- *
19882
- * ```
19883
- *
19884
- * ```ts
19885
- * ...
19886
- *
19887
- * export class AppComponent {
19888
- *
19889
- * dynamicForm: NgForm;
19890
- *
19891
- * getForm(form: NgForm) {
19892
- * this.dynamicForm = form;
19893
- * }
19894
- *
19895
- * }
19896
- * ```
19897
- *
19898
- * > Caso a propriedade `p-group-form` for verdadeira não será repassado o formulário, pois o mesmo utilizará
19899
- * o formulário pai.
19900
- */
19901
- this.formOutput = new i0.EventEmitter();
19902
- this._groupForm = false;
20018
+ var PoLookupModalBaseComponent = /** @class */ (function () {
20019
+ function PoLookupModalBaseComponent(languageService, changeDetector) {
20020
+ var _this = this;
20021
+ this.changeDetector = changeDetector;
20022
+ /** Se verdadeiro, ativa a funcionalidade de scroll infinito para a tabela exibida no retorno da consulta. */
20023
+ this.infiniteScroll = false;
20024
+ /** Se verdadeiro, ativa a funcionalidade de multipla seleção. */
20025
+ this.multiple = false;
20026
+ /** Evento utilizado ao selecionar um registro da tabela. */
20027
+ this.model = new i0.EventEmitter();
20028
+ this.hasNext = true;
20029
+ this.isLoading = false;
20030
+ this.page = 1;
20031
+ this.pageSize = 10;
20032
+ this.searchValue = '';
20033
+ // Propriedade da modal de busca avançada:
20034
+ this.advancedFilterModalTitle = '';
20035
+ this.dynamicFormValue = {};
20036
+ this.isAdvancedFilter = false;
20037
+ this.selecteds = [];
20038
+ this.language = poLocaleDefault;
20039
+ // eslint-disable-next-line @typescript-eslint/member-ordering
20040
+ this.primaryAction = {
20041
+ action: function () {
20042
+ var selectedsItems = _this.selecteds;
20043
+ _this.model.emit(selectedsItems);
20044
+ _this.poModal.close();
20045
+ },
20046
+ label: this.literals.modalPrimaryActionLabel
20047
+ };
20048
+ // eslint-disable-next-line @typescript-eslint/member-ordering
20049
+ this.secondaryAction = {
20050
+ action: function () {
20051
+ _this.model.emit(null);
20052
+ _this.poModal.close();
20053
+ },
20054
+ label: this.literals.modalSecondaryActionLabel
20055
+ };
20056
+ this.language = languageService.getShortLanguage();
19903
20057
  }
19904
- Object.defineProperty(PoDynamicFormBaseComponent.prototype, "groupForm", {
20058
+ Object.defineProperty(PoLookupModalBaseComponent.prototype, "literals", {
19905
20059
  get: function () {
19906
- return this._groupForm;
20060
+ return this._literals || poLookupLiteralsDefault[this.language];
19907
20061
  },
19908
- /**
19909
- * @optional
19910
- *
19911
- * @description
19912
- * Ao informar esta propriedade, o componente passará a utilizar o formulário pai para criar os `FormControl`
19913
- * e com isso é possível recuperar o valor do formulário e suas validações a partir do formulário pai.
19914
- *
19915
- * ```html
19916
- * <form #parentForm="ngForm">
19917
- *
19918
- * <po-dynamic-form p-group-form [p-fields]="fields"></po-dynamic-form>
19919
- *
19920
- * <po-button p-label="Adicionar" [p-disabled]="parentForm.invalid"></po-button>
19921
- * </form>
19922
- * ```
19923
- */
20062
+ /** Objeto com as literais usadas no `po-lookup-modal`. */
19924
20063
  set: function (value) {
19925
- this._groupForm = value === '' ? true : convertToBoolean(value);
19926
- },
19927
- enumerable: false,
19928
- configurable: true
19929
- });
19930
- return PoDynamicFormBaseComponent;
19931
- }());
19932
- PoDynamicFormBaseComponent.decorators = [
19933
- { type: i0.Directive }
19934
- ];
19935
- PoDynamicFormBaseComponent.propDecorators = {
19936
- autoFocus: [{ type: i0.Input, args: ['p-auto-focus',] }],
19937
- fields: [{ type: i0.Input, args: ['p-fields',] }],
19938
- value: [{ type: i0.Input, args: ['p-value',] }],
19939
- formOutput: [{ type: i0.Output, args: ['p-form',] }],
19940
- load: [{ type: i0.Input, args: ['p-load',] }],
19941
- validate: [{ type: i0.Input, args: ['p-validate',] }],
19942
- validateFields: [{ type: i0.Input, args: ['p-validate-fields',] }],
19943
- groupForm: [{ type: i0.Input, args: ['p-group-form',] }]
19944
- };
19945
-
19946
- var PoDynamicFormOperation = /** @class */ (function () {
19947
- function PoDynamicFormOperation(http) {
19948
- this.http = http;
19949
- }
19950
- PoDynamicFormOperation.prototype.execute = function (action, param) {
19951
- return typeof action === 'string' ? this.post(action, param) : rxjs.of(action(param));
19952
- };
19953
- PoDynamicFormOperation.prototype.post = function (url, body) {
19954
- return this.http.post(url, body);
19955
- };
19956
- PoDynamicFormOperation.prototype.setFormDefaultIfEmpty = function (validateFields) {
19957
- return (validateFields || {
19958
- value: {},
19959
- fields: [],
19960
- focus: undefined
19961
- });
19962
- };
19963
- return PoDynamicFormOperation;
19964
- }());
19965
-
19966
- var PoDynamicFormLoadService = /** @class */ (function (_super) {
19967
- __extends(PoDynamicFormLoadService, _super);
19968
- function PoDynamicFormLoadService(http) {
19969
- return _super.call(this, http) || this;
19970
- }
19971
- PoDynamicFormLoadService.prototype.createAndUpdateFieldsForm = function (loadedFields, fields) {
19972
- if (loadedFields === void 0) { loadedFields = []; }
19973
- if (fields === void 0) { fields = []; }
19974
- return __spreadArray([], __read(loadedFields)).reduce(function (updatedFields, field) {
19975
- var index = updatedFields.findIndex(function (updatedField) { return updatedField.property === field.property; });
19976
- var hasProperty = index >= 0;
19977
- if (hasProperty) {
19978
- updatedFields[index] = Object.assign(Object.assign({}, fields[index]), field);
20064
+ if (value instanceof Object && !(value instanceof Array)) {
20065
+ this._literals = Object.assign(Object.assign(Object.assign({}, poLookupLiteralsDefault[poLocaleDefault]), poLookupLiteralsDefault[this.language]), value);
20066
+ if (value.modalTitle) {
20067
+ this.title = this.literals.modalTitle;
20068
+ }
19979
20069
  }
19980
20070
  else {
19981
- updatedFields.push(field);
19982
- }
19983
- return updatedFields;
19984
- }, __spreadArray([], __read(fields)));
19985
- };
19986
- PoDynamicFormLoadService.prototype.executeLoad = function (load, value) {
19987
- var _this = this;
19988
- return this.execute(load, value).pipe(operators.map(function (loadedFormdData) { return _this.setFormDefaultIfEmpty(loadedFormdData); }));
19989
- };
19990
- return PoDynamicFormLoadService;
19991
- }(PoDynamicFormOperation));
19992
- PoDynamicFormLoadService.decorators = [
19993
- { type: i0.Injectable }
19994
- ];
19995
- PoDynamicFormLoadService.ctorParameters = function () { return [
19996
- { type: i1.HttpClient }
19997
- ]; };
19998
-
19999
- var PoDynamicFormValidationService = /** @class */ (function (_super) {
20000
- __extends(PoDynamicFormValidationService, _super);
20001
- function PoDynamicFormValidationService(http) {
20002
- return _super.call(this, http) || this;
20003
- }
20004
- PoDynamicFormValidationService.prototype.sendFieldChange = function (field, value) {
20005
- var _this = this;
20006
- var changedValue = { property: field.property, value: value };
20007
- return this.execute(field.validate, changedValue).pipe(operators.map(function (validateFields) { return _this.setFieldDefaultIfEmpty(validateFields); }));
20008
- };
20009
- PoDynamicFormValidationService.prototype.sendFormChange = function (validate, field, value) {
20010
- var _this = this;
20011
- var changedValue = { property: field.property, value: value };
20012
- return this.execute(validate, changedValue).pipe(operators.map(function (validateFields) { return _this.setFormDefaultIfEmpty(validateFields); }));
20013
- };
20014
- PoDynamicFormValidationService.prototype.updateFieldsForm = function (validatedFields, fields) {
20015
- if (validatedFields === void 0) { validatedFields = []; }
20016
- if (fields === void 0) { fields = []; }
20017
- return __spreadArray([], __read(validatedFields)).reduce(function (updatedFields, validatedField) {
20018
- var index = updatedFields.findIndex(function (field) { return field.property === validatedField.property; });
20019
- var hasProperty = index >= 0;
20020
- if (hasProperty) {
20021
- updatedFields[index] = Object.assign(Object.assign({}, fields[index]), validatedField);
20071
+ this._literals = poLookupLiteralsDefault[this.language];
20022
20072
  }
20023
- return updatedFields;
20024
- }, __spreadArray([], __read(fields)));
20025
- };
20026
- PoDynamicFormValidationService.prototype.setFieldDefaultIfEmpty = function (validateFields) {
20027
- return (validateFields || {
20028
- field: {}
20029
- });
20030
- };
20031
- return PoDynamicFormValidationService;
20032
- }(PoDynamicFormOperation));
20033
- PoDynamicFormValidationService.decorators = [
20034
- { type: i0.Injectable }
20035
- ];
20036
- PoDynamicFormValidationService.ctorParameters = function () { return [
20037
- { type: i1.HttpClient }
20038
- ]; };
20039
-
20040
- /**
20041
- * @docsExtends PoDynamicFormBaseComponent
20042
- *
20043
- * @example
20044
- *
20045
- * <example name="po-dynamic-form-basic" title="PO Dynamic Form Basic">
20046
- * <file name="sample-po-dynamic-form-basic/sample-po-dynamic-form-basic.component.html"> </file>
20047
- * <file name="sample-po-dynamic-form-basic/sample-po-dynamic-form-basic.component.ts"> </file>
20048
- * </example>
20049
- *
20050
- * <example name="po-dynamic-form-register" title="PO Dynamic Form - Register">
20051
- * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.component.html"> </file>
20052
- * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.component.ts"> </file>
20053
- * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.service.ts"> </file>
20054
- * </example>
20055
- */
20056
- var PoDynamicFormComponent = /** @class */ (function (_super) {
20057
- __extends(PoDynamicFormComponent, _super);
20058
- function PoDynamicFormComponent(changes, loadService, validationService) {
20059
- var _this = _super.call(this) || this;
20060
- _this.changes = changes;
20061
- _this.loadService = loadService;
20062
- _this.validationService = validationService;
20063
- _this.comboOptionSubject = new rxjs.Subject();
20064
- return _this;
20065
- }
20066
- Object.defineProperty(PoDynamicFormComponent.prototype, "form", {
20073
+ this.primaryAction.label = this.literals.modalPrimaryActionLabel;
20074
+ this.secondaryAction.label = this.literals.modalSecondaryActionLabel;
20075
+ this.setTableLiterals();
20076
+ },
20077
+ enumerable: false,
20078
+ configurable: true
20079
+ });
20080
+ Object.defineProperty(PoLookupModalBaseComponent.prototype, "title", {
20067
20081
  get: function () {
20068
- return this._form || {};
20082
+ return this._title;
20069
20083
  },
20084
+ /** Título da modal. */
20070
20085
  set: function (value) {
20071
- var _this = this;
20072
- // necessario para nao ocorrer o ExpressionChangedAfterItHasBeenCheckedError
20073
- setTimeout(function () {
20074
- _this._form = value;
20075
- _this.emitForm();
20076
- });
20086
+ this._title = isTypeof(value, 'string') ? value : this.literals.modalTitle;
20077
20087
  },
20078
20088
  enumerable: false,
20079
20089
  configurable: true
20080
20090
  });
20081
- PoDynamicFormComponent.prototype.ngOnDestroy = function () {
20082
- this.removeListeners();
20091
+ PoLookupModalBaseComponent.prototype.ngOnDestroy = function () {
20092
+ if (this.filterSubscription) {
20093
+ this.filterSubscription.unsubscribe();
20094
+ }
20095
+ if (this.searchSubscription) {
20096
+ this.searchSubscription.unsubscribe();
20097
+ }
20098
+ if (this.showMoreSubscription) {
20099
+ this.showMoreSubscription.unsubscribe();
20100
+ }
20083
20101
  };
20084
- PoDynamicFormComponent.prototype.ngOnInit = function () {
20085
- if (this.load) {
20086
- this.loadDataOnInitialize();
20102
+ PoLookupModalBaseComponent.prototype.ngOnInit = function () {
20103
+ this.setAdvancedFilterModalProperties();
20104
+ this.initializeData();
20105
+ this.setTableLiterals();
20106
+ };
20107
+ PoLookupModalBaseComponent.prototype.createDisclaimer = function () {
20108
+ var e_1, _c;
20109
+ this.disclaimerGroup.disclaimers = [];
20110
+ this.searchValue = '';
20111
+ try {
20112
+ for (var _d = __values(Object.entries(this.dynamicFormValue)), _e = _d.next(); !_e.done; _e = _d.next()) {
20113
+ var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
20114
+ this.addDisclaimer(value, key);
20115
+ }
20116
+ }
20117
+ catch (e_1_1) { e_1 = { error: e_1_1 }; }
20118
+ finally {
20119
+ try {
20120
+ if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
20121
+ }
20122
+ finally { if (e_1) throw e_1.error; }
20123
+ }
20124
+ if (!Object.values(this.dynamicFormValue).some(function (v) { return v !== null && typeof v !== 'undefined'; })) {
20125
+ this.initializeData();
20087
20126
  }
20088
20127
  };
20089
- /**
20090
- * Função que atribui foco ao campo desejado.
20091
- *
20092
- * Para utilizá-la é necessário capturar a instância do `dynamic form`, como por exemplo:
20093
- *
20094
- * ``` html
20095
- * <po-dynamic-form #dynamicForm [p-fields]="fields"></po-dynamic-form>
20096
- * ```
20097
- *
20098
- * ``` javascript
20099
- * import { PoDynamicFormComponent, PoDynamicFormField } from '@po-ui/ng-components';
20100
- *
20101
- * ...
20102
- *
20103
- * @ViewChild('dynamicForm', { static: true }) dynamicForm: PoDynamicFormComponent;
20104
- *
20105
- * fields: Array<PoDynamicFormField> = [
20106
- * { property: 'fieldOne' },
20107
- * { property: 'fieldTwo' }
20108
- * ];
20109
- *
20110
- * fieldFocus() {
20111
- * this.dynamicForm.focus('fieldTwo');
20112
- * }
20113
- * ```
20114
- *
20115
- * @param {string} property Nome da propriedade atribuída ao `PoDynamicFormField.property`.
20116
- */
20117
- PoDynamicFormComponent.prototype.focus = function (property) {
20118
- this.fieldsComponent.focus(property);
20128
+ PoLookupModalBaseComponent.prototype.addDisclaimer = function (value, property) {
20129
+ this.disclaimer = { property: property };
20130
+ this.disclaimer.value = value;
20131
+ this.disclaimerGroup.disclaimers = __spreadArray(__spreadArray([], __read(this.disclaimerGroup.disclaimers)), [this.disclaimer]);
20119
20132
  };
20120
- PoDynamicFormComponent.prototype.getObjectValue = function () {
20121
- return this.comboOptionSubject.asObservable();
20133
+ PoLookupModalBaseComponent.prototype.onChangeDisclaimerGroup = function () {
20134
+ if (!this.searchValue) {
20135
+ this.isLoading = true;
20136
+ this.searchValue = '';
20137
+ this.searchFilteredItems();
20138
+ }
20122
20139
  };
20123
- PoDynamicFormComponent.prototype.sendObjectValue = function (objectValue) {
20124
- this.comboOptionSubject.next(objectValue);
20140
+ PoLookupModalBaseComponent.prototype.search = function () {
20141
+ this.page = 1;
20142
+ if (this.searchValue) {
20143
+ this.isLoading = true;
20144
+ this.disclaimerGroup.disclaimers = [];
20145
+ this.searchFilteredItems();
20146
+ }
20147
+ else {
20148
+ this.initializeData();
20149
+ }
20125
20150
  };
20126
- PoDynamicFormComponent.prototype.validateForm = function (field) {
20151
+ PoLookupModalBaseComponent.prototype.searchFilteredItems = function () {
20127
20152
  var _this = this;
20128
- var previousFocusElement = document.activeElement;
20129
- this.disableForm(true);
20130
- var errorOnValidation = function () { return _this.disableForm(false); };
20131
- this.sendFormSubscription = this.validationService
20132
- .sendFormChange(this.validate, field, this.value)
20133
- .subscribe(this.applyFormValidation(previousFocusElement), errorOnValidation);
20153
+ this.searchSubscription = this.getFilteredItems(this.searchValue)
20154
+ .pipe(operators.catchError(function (error) {
20155
+ _this.setLookupResponseProperties();
20156
+ return rxjs.throwError(error);
20157
+ }))
20158
+ .subscribe(function (data) { return _this.setLookupResponseProperties(data); }, function () { });
20134
20159
  };
20135
- PoDynamicFormComponent.prototype.applyFormUpdatesOnLoad = function (previousFocusElement) {
20160
+ PoLookupModalBaseComponent.prototype.showMoreEvent = function () {
20136
20161
  var _this = this;
20137
- return function (dynamicFormData) {
20138
- _this.updateModelOnLoad(dynamicFormData);
20139
- _this.disableForm(false);
20140
- _this.setFocusOnFieldByProperty(dynamicFormData.focus, previousFocusElement);
20141
- };
20162
+ this.page++;
20163
+ this.isLoading = true;
20164
+ this.showMoreSubscription = this.getFilteredItems(this.searchValue)
20165
+ .pipe(operators.catchError(function (error) {
20166
+ _this.hasNext = false;
20167
+ _this.isLoading = false;
20168
+ return rxjs.throwError(error);
20169
+ }))
20170
+ .subscribe(function (data) {
20171
+ _this.items = __spreadArray(__spreadArray([], __read(_this.items)), __read(data.items));
20172
+ _this.hasNext = data.hasNext;
20173
+ _this.isLoading = false;
20174
+ _this.changeDetector.detectChanges();
20175
+ _this.setSelectedItems();
20176
+ }, function () { });
20142
20177
  };
20143
- PoDynamicFormComponent.prototype.applyFormValidation = function (previousFocusElement) {
20178
+ //Método responsável por selecionar as linhas quando abre o modal.
20179
+ PoLookupModalBaseComponent.prototype.setSelectedItems = function () {
20144
20180
  var _this = this;
20145
- return function (dynamicFormData) {
20146
- _this.updateModelWithValidation(dynamicFormData);
20147
- _this.disableForm(false);
20148
- _this.setFocusOnFieldByProperty(dynamicFormData.focus, previousFocusElement);
20149
- };
20181
+ this.selecteds.forEach(function (selectedItem) { return _this.poTable.selectRowItem(function (item) { return item[_this.fieldValue] === selectedItem.value; }); });
20150
20182
  };
20151
- PoDynamicFormComponent.prototype.disableForm = function (value) {
20152
- this.disabledForm = value;
20153
- this.changes.detectChanges();
20154
- };
20155
- PoDynamicFormComponent.prototype.emitForm = function () {
20156
- if (!this.groupForm && this.formOutput.observers.length) {
20157
- this.formOutput.emit(this.form);
20183
+ //Método responsável por criar os disclaimers quando abre o modal.
20184
+ PoLookupModalBaseComponent.prototype.setDisclaimersItems = function () {
20185
+ if (this.selectedItems && !Array.isArray(this.selectedItems)) {
20186
+ this.selecteds = [{ value: this.selectedItems }];
20187
+ return;
20188
+ }
20189
+ if (this.selectedItems && this.selectedItems.length) {
20190
+ this.selecteds = __spreadArray([], __read(this.selectedItems));
20158
20191
  }
20159
20192
  };
20160
- PoDynamicFormComponent.prototype.loadDataOnInitialize = function () {
20193
+ PoLookupModalBaseComponent.prototype.setAdvancedFilterModalProperties = function () {
20161
20194
  var _this = this;
20162
- var previousFocusElement = document.activeElement;
20163
- this.disabledForm = true;
20164
- var errorOnLoad = function () { return (_this.disabledForm = false); };
20165
- this.onLoadSubscription = this.loadService
20166
- .executeLoad(this.load, this.value)
20167
- .subscribe(this.applyFormUpdatesOnLoad(previousFocusElement), errorOnLoad);
20195
+ this.advancedFilterModalTitle = this.literals.modalAdvancedSearchTitle;
20196
+ this.disclaimerGroup = {
20197
+ title: this.literals.modalDisclaimerGroupTitle,
20198
+ disclaimers: []
20199
+ };
20200
+ this.primaryActionAdvancedFilter = {
20201
+ action: function () {
20202
+ _this.destroyDynamicForm();
20203
+ _this.isAdvancedFilter = false;
20204
+ _this.createDisclaimer();
20205
+ },
20206
+ label: this.literals.modalAdvancedSearchPrimaryActionLabel
20207
+ };
20208
+ this.secondaryActionAdvancedFilter = {
20209
+ action: function () {
20210
+ _this.destroyDynamicForm();
20211
+ _this.isAdvancedFilter = false;
20212
+ },
20213
+ label: this.literals.modalAdvancedSearchSecondaryActionLabel
20214
+ };
20168
20215
  };
20169
- PoDynamicFormComponent.prototype.removeListeners = function () {
20170
- if (this.onLoadSubscription) {
20171
- this.onLoadSubscription.unsubscribe();
20216
+ PoLookupModalBaseComponent.prototype.getAdvancedFilters = function (advancedParams) {
20217
+ if (advancedParams && advancedParams.length > 0) {
20218
+ var filters_1 = {};
20219
+ var validatedAdvacendFilters_1;
20220
+ advancedParams.forEach(function (filter) {
20221
+ filters_1[filter.property] = filter.value instanceof Array ? filter.value.join() : filter.value;
20222
+ validatedAdvacendFilters_1 = Object.assign(Object.assign({}, validatedAdvacendFilters_1), filters_1);
20223
+ });
20224
+ return validatedAdvacendFilters_1;
20172
20225
  }
20173
- if (this.sendFormSubscription) {
20174
- this.sendFormSubscription.unsubscribe();
20226
+ return undefined;
20227
+ };
20228
+ PoLookupModalBaseComponent.prototype.getFilteredItems = function (filter) {
20229
+ var filteredParams = this.getFilteredParams(filter);
20230
+ return this.filterService.getFilteredItems(filteredParams);
20231
+ };
20232
+ PoLookupModalBaseComponent.prototype.getFilteredParams = function (filter) {
20233
+ var _c = this, page = _c.page, pageSize = _c.pageSize, filterParams = _c.filterParams, sort = _c.sort;
20234
+ var filteredParams = {};
20235
+ var order = this.getOrderParam(sort);
20236
+ var advancedFilters = this.getAdvancedFilters(this.disclaimerGroup.disclaimers);
20237
+ var params = { filter: filter, page: page, pageSize: pageSize, order: order, filterParams: filterParams, advancedFilters: advancedFilters };
20238
+ for (var key in params) {
20239
+ if (params.hasOwnProperty(key) && params[key] !== undefined) {
20240
+ filteredParams[key] = params[key];
20241
+ }
20175
20242
  }
20243
+ return filteredParams;
20176
20244
  };
20177
- PoDynamicFormComponent.prototype.setFocusOnFieldByProperty = function (property, previousFocusElement) {
20178
- var _this = this;
20179
- if (property) {
20180
- // precisa do timeout para que o valor seja atribuido no campo antes de setar o focus,
20181
- // para nao disparar a mudança posteriormente. Situação ocorre quando retornar campo com valor e focus atribuido a ele.
20182
- setTimeout(function () { return _this.focus(property); });
20245
+ PoLookupModalBaseComponent.prototype.getOrderParam = function (sort) {
20246
+ if (sort === void 0) { sort = { type: undefined }; }
20247
+ var column = sort.column, type = sort.type;
20248
+ if (!column) {
20249
+ return;
20183
20250
  }
20184
- else {
20185
- previousFocusElement['focus']();
20251
+ if (type === exports.PoTableColumnSortType.Descending) {
20252
+ return "-" + column.property;
20186
20253
  }
20254
+ return "" + column.property;
20187
20255
  };
20188
- PoDynamicFormComponent.prototype.updateModelOnLoad = function (loadedFormData) {
20189
- Object.assign(this.value, loadedFormData.value);
20190
- this.fields = this.loadService.createAndUpdateFieldsForm(loadedFormData.fields, this.fields);
20256
+ PoLookupModalBaseComponent.prototype.initializeData = function () {
20257
+ var _this = this;
20258
+ this.isLoading = true;
20259
+ this.filterSubscription = this.getFilteredItems('').subscribe(function (data) {
20260
+ _this.setLookupResponseProperties(data);
20261
+ });
20191
20262
  };
20192
- PoDynamicFormComponent.prototype.updateModelWithValidation = function (formData) {
20193
- Object.assign(this.value, formData.value);
20194
- this.fieldsComponent.updatePreviousValue();
20195
- this.fields = this.validationService.updateFieldsForm(formData.fields, this.fields);
20263
+ PoLookupModalBaseComponent.prototype.setLookupResponseProperties = function (data) {
20264
+ var _a, _b;
20265
+ this.items = (_a = data === null || data === void 0 ? void 0 : data.items) !== null && _a !== void 0 ? _a : [];
20266
+ this.hasNext = (_b = data === null || data === void 0 ? void 0 : data.hasNext) !== null && _b !== void 0 ? _b : false;
20267
+ this.isLoading = false;
20268
+ this.changeDetector.detectChanges();
20269
+ this.setDisclaimersItems();
20270
+ this.setSelectedItems();
20196
20271
  };
20197
- return PoDynamicFormComponent;
20198
- }(PoDynamicFormBaseComponent));
20199
- PoDynamicFormComponent.decorators = [
20200
- { type: i0.Component, args: [{
20201
- selector: 'po-dynamic-form',
20202
- template: "<ng-container *ngIf=\"groupForm; then reuseFormTemplate; else uniqueFormTemplate\"></ng-container>\n\n<ng-template #reuseFormTemplate>\n <po-dynamic-form-fields #fieldsComponent [p-auto-focus]=\"autoFocus\" [p-fields]=\"fields\" [p-value]=\"value\">\n </po-dynamic-form-fields>\n</ng-template>\n\n<ng-template #uniqueFormTemplate>\n <form #dynamicForm=\"ngForm\">\n <po-dynamic-form-fields\n #fieldsComponent\n [(p-fields)]=\"fields\"\n [p-auto-focus]=\"autoFocus\"\n [p-disabled-form]=\"disabledForm\"\n [p-validate]=\"validate\"\n [p-validate-fields]=\"validateFields\"\n [p-value]=\"value\"\n (p-object-value)=\"sendObjectValue($event)\"\n (p-form-validate)=\"validateForm($event)\"\n >\n </po-dynamic-form-fields>\n </form>\n</ng-template>\n"
20203
- },] }
20272
+ PoLookupModalBaseComponent.prototype.setTableLiterals = function () {
20273
+ this.tableLiterals = {
20274
+ 'noColumns': this.literals.modalTableNoColumns,
20275
+ 'noData': this.literals.modalTableNoData,
20276
+ 'loadingData': this.literals.modalTableLoadingData,
20277
+ 'loadMoreData': this.literals.modalTableLoadMoreData
20278
+ };
20279
+ };
20280
+ return PoLookupModalBaseComponent;
20281
+ }());
20282
+ PoLookupModalBaseComponent.decorators = [
20283
+ { type: i0.Directive }
20204
20284
  ];
20205
- PoDynamicFormComponent.ctorParameters = function () { return [
20206
- { type: i0.ChangeDetectorRef },
20207
- { type: PoDynamicFormLoadService },
20208
- { type: PoDynamicFormValidationService }
20285
+ PoLookupModalBaseComponent.ctorParameters = function () { return [
20286
+ { type: PoLanguageService },
20287
+ { type: i0.ChangeDetectorRef }
20209
20288
  ]; };
20210
- PoDynamicFormComponent.propDecorators = {
20211
- fieldsComponent: [{ type: i0.ViewChild, args: ['fieldsComponent',] }],
20212
- form: [{ type: i0.ViewChild, args: ['dynamicForm',] }]
20289
+ PoLookupModalBaseComponent.propDecorators = {
20290
+ poModal: [{ type: i0.ViewChild, args: [PoModalComponent, { static: true },] }],
20291
+ poTable: [{ type: i0.ViewChild, args: [PoTableComponent, { static: true },] }],
20292
+ advancedFilters: [{ type: i0.Input, args: ['p-advanced-filters',] }],
20293
+ columns: [{ type: i0.Input, args: ['p-columns',] }],
20294
+ items: [{ type: i0.Input, args: ['p-items',] }],
20295
+ filterService: [{ type: i0.Input, args: ['p-filter-service',] }],
20296
+ filterParams: [{ type: i0.Input, args: ['p-filter-params',] }],
20297
+ infiniteScroll: [{ type: i0.Input, args: ['p-infinite-scroll',] }],
20298
+ multiple: [{ type: i0.Input, args: ['p-multiple',] }],
20299
+ model: [{ type: i0.Output, args: ['p-change-model',] }],
20300
+ selectedItems: [{ type: i0.Input, args: ['p-selected-items',] }],
20301
+ fieldLabel: [{ type: i0.Input, args: ['p-field-label',] }],
20302
+ fieldValue: [{ type: i0.Input, args: ['p-field-value',] }],
20303
+ literals: [{ type: i0.Input, args: ['p-literals',] }],
20304
+ title: [{ type: i0.Input, args: ['p-title',] }]
20213
20305
  };
20306
+ __decorate([
20307
+ InputBoolean()
20308
+ ], PoLookupModalBaseComponent.prototype, "infiniteScroll", void 0);
20309
+ __decorate([
20310
+ InputBoolean()
20311
+ ], PoLookupModalBaseComponent.prototype, "multiple", void 0);
20214
20312
 
20215
- var poLookupLiteralsDefault = {
20216
- en: {
20217
- modalPrimaryActionLabel: 'Select',
20218
- modalSecondaryActionLabel: 'Cancel',
20219
- modalPlaceholder: 'Search',
20220
- modalTitle: 'Select a record',
20221
- modalTableNoColumns: poTableLiteralsDefault.en.noColumns,
20222
- modalTableNoData: poTableLiteralsDefault.en.noData,
20223
- modalTableLoadingData: poTableLiteralsDefault.en.loadingData,
20224
- modalTableLoadMoreData: poTableLiteralsDefault.en.loadMoreData,
20225
- modalAdvancedSearch: 'Advanced search',
20226
- modalAdvancedSearchTitle: 'Advanced search',
20227
- modalAdvancedSearchPrimaryActionLabel: 'Filter',
20228
- modalAdvancedSearchSecondaryActionLabel: 'Return',
20229
- modalDisclaimerGroupTitle: 'Presenting results filtered by:'
20230
- },
20231
- es: {
20232
- modalPrimaryActionLabel: 'Seleccionar',
20233
- modalSecondaryActionLabel: 'Cancelar',
20234
- modalPlaceholder: 'Buscar',
20235
- modalTitle: 'Seleccione un registro',
20236
- modalTableNoColumns: poTableLiteralsDefault.es.noColumns,
20237
- modalTableNoData: poTableLiteralsDefault.es.noData,
20238
- modalTableLoadingData: poTableLiteralsDefault.es.loadingData,
20239
- modalTableLoadMoreData: poTableLiteralsDefault.es.loadMoreData,
20240
- modalAdvancedSearch: 'Búsqueda Avanzada',
20241
- modalAdvancedSearchTitle: 'Búsqueda Avanzada',
20242
- modalAdvancedSearchPrimaryActionLabel: 'Filtrar',
20243
- modalAdvancedSearchSecondaryActionLabel: 'Vuelve',
20244
- modalDisclaimerGroupTitle: 'Presentar resultados filtrados por:'
20245
- },
20246
- pt: {
20247
- modalPrimaryActionLabel: 'Selecionar',
20248
- modalSecondaryActionLabel: 'Cancelar',
20249
- modalPlaceholder: 'Pesquisar',
20250
- modalTitle: 'Selecione um registro',
20251
- modalTableNoColumns: poTableLiteralsDefault.pt.noColumns,
20252
- modalTableNoData: poTableLiteralsDefault.pt.noData,
20253
- modalTableLoadingData: poTableLiteralsDefault.pt.loadingData,
20254
- modalTableLoadMoreData: poTableLiteralsDefault.pt.loadMoreData,
20255
- modalAdvancedSearch: 'Busca avançada',
20256
- modalAdvancedSearchTitle: 'Busca Avançada',
20257
- modalAdvancedSearchPrimaryActionLabel: 'Filtrar',
20258
- modalAdvancedSearchSecondaryActionLabel: 'Voltar',
20259
- modalDisclaimerGroupTitle: 'Apresentando resultados filtrados por:'
20260
- },
20261
- ru: {
20262
- modalPrimaryActionLabel: 'выбирать',
20263
- modalSecondaryActionLabel: 'отменить',
20264
- modalPlaceholder: 'поиск',
20265
- modalTitle: 'Выберите запись',
20266
- modalTableNoColumns: poTableLiteralsDefault.ru.noColumns,
20267
- modalTableNoData: poTableLiteralsDefault.ru.noData,
20268
- modalTableLoadingData: poTableLiteralsDefault.ru.loadingData,
20269
- modalTableLoadMoreData: poTableLiteralsDefault.ru.loadMoreData,
20270
- modalAdvancedSearch: 'Расширенный поиск',
20271
- modalAdvancedSearchTitle: 'Расширенный поиск',
20272
- modalAdvancedSearchPrimaryActionLabel: 'Фильтр',
20273
- modalAdvancedSearchSecondaryActionLabel: 'Вернись',
20274
- modalDisclaimerGroupTitle: 'Представление результатов отфильтровано по:'
20313
+ /**
20314
+ *
20315
+ * @description
20316
+ *
20317
+ * Componente para criação de formulários dinâmicos a partir de uma lista de objetos.
20318
+ *
20319
+ * Também é possível verificar se o formulário está válido e informar valores para a exibição de informações.
20320
+ */
20321
+ var PoDynamicFormBaseComponent = /** @class */ (function () {
20322
+ function PoDynamicFormBaseComponent() {
20323
+ /**
20324
+ * @optional
20325
+ *
20326
+ * @description
20327
+ *
20328
+ * Na inicialização do componente será repassado o objeto de formulário utilizado no componente,
20329
+ * podendo ser utilizado para validações e/ou detecção de mudança dos valores.
20330
+ *
20331
+ * Portanto existem duas maneiras de recuperar o formulário,
20332
+ * através de *template reference* e através do *output*, veja os exemplos abaixo:
20333
+ *
20334
+ * > *template reference*
20335
+ *
20336
+ * ```html
20337
+ * <po-dynamic-form #dynamicForm>
20338
+ * </po-dynamic-form>
20339
+ *
20340
+ * <po-button p-label="Adicionar" [p-disabled]="dynamicForm?.form.invalid">
20341
+ * </po-button>
20342
+ *
20343
+ * ```
20344
+ *
20345
+ * > *Output*
20346
+ *
20347
+ * ```html
20348
+ * ...
20349
+ * <po-dynamic-form (p-form)="getForm($event)">
20350
+ * </po-dynamic-form>
20351
+ *
20352
+ * <po-button p-label="Adicionar" [p-disabled]="dynamicForm?.invalid">
20353
+ * </po-button>
20354
+ * ...
20355
+ *
20356
+ * ```
20357
+ *
20358
+ * ```ts
20359
+ * ...
20360
+ *
20361
+ * export class AppComponent {
20362
+ *
20363
+ * dynamicForm: NgForm;
20364
+ *
20365
+ * getForm(form: NgForm) {
20366
+ * this.dynamicForm = form;
20367
+ * }
20368
+ *
20369
+ * }
20370
+ * ```
20371
+ *
20372
+ * > Caso a propriedade `p-group-form` for verdadeira não será repassado o formulário, pois o mesmo utilizará
20373
+ * o formulário pai.
20374
+ */
20375
+ this.formOutput = new i0.EventEmitter();
20376
+ this._groupForm = false;
20377
+ }
20378
+ Object.defineProperty(PoDynamicFormBaseComponent.prototype, "groupForm", {
20379
+ get: function () {
20380
+ return this._groupForm;
20381
+ },
20382
+ /**
20383
+ * @optional
20384
+ *
20385
+ * @description
20386
+ * Ao informar esta propriedade, o componente passará a utilizar o formulário pai para criar os `FormControl`
20387
+ * e com isso é possível recuperar o valor do formulário e suas validações a partir do formulário pai.
20388
+ *
20389
+ * ```html
20390
+ * <form #parentForm="ngForm">
20391
+ *
20392
+ * <po-dynamic-form p-group-form [p-fields]="fields"></po-dynamic-form>
20393
+ *
20394
+ * <po-button p-label="Adicionar" [p-disabled]="parentForm.invalid"></po-button>
20395
+ * </form>
20396
+ * ```
20397
+ */
20398
+ set: function (value) {
20399
+ this._groupForm = value === '' ? true : convertToBoolean(value);
20400
+ },
20401
+ enumerable: false,
20402
+ configurable: true
20403
+ });
20404
+ return PoDynamicFormBaseComponent;
20405
+ }());
20406
+ PoDynamicFormBaseComponent.decorators = [
20407
+ { type: i0.Directive }
20408
+ ];
20409
+ PoDynamicFormBaseComponent.propDecorators = {
20410
+ autoFocus: [{ type: i0.Input, args: ['p-auto-focus',] }],
20411
+ fields: [{ type: i0.Input, args: ['p-fields',] }],
20412
+ value: [{ type: i0.Input, args: ['p-value',] }],
20413
+ formOutput: [{ type: i0.Output, args: ['p-form',] }],
20414
+ load: [{ type: i0.Input, args: ['p-load',] }],
20415
+ validate: [{ type: i0.Input, args: ['p-validate',] }],
20416
+ validateFields: [{ type: i0.Input, args: ['p-validate-fields',] }],
20417
+ groupForm: [{ type: i0.Input, args: ['p-group-form',] }]
20418
+ };
20419
+
20420
+ var PoDynamicFormOperation = /** @class */ (function () {
20421
+ function PoDynamicFormOperation(http) {
20422
+ this.http = http;
20423
+ }
20424
+ PoDynamicFormOperation.prototype.execute = function (action, param) {
20425
+ return typeof action === 'string' ? this.post(action, param) : rxjs.of(action(param));
20426
+ };
20427
+ PoDynamicFormOperation.prototype.post = function (url, body) {
20428
+ return this.http.post(url, body);
20429
+ };
20430
+ PoDynamicFormOperation.prototype.setFormDefaultIfEmpty = function (validateFields) {
20431
+ return (validateFields || {
20432
+ value: {},
20433
+ fields: [],
20434
+ focus: undefined
20435
+ });
20436
+ };
20437
+ return PoDynamicFormOperation;
20438
+ }());
20439
+
20440
+ var PoDynamicFormLoadService = /** @class */ (function (_super) {
20441
+ __extends(PoDynamicFormLoadService, _super);
20442
+ function PoDynamicFormLoadService(http) {
20443
+ return _super.call(this, http) || this;
20444
+ }
20445
+ PoDynamicFormLoadService.prototype.createAndUpdateFieldsForm = function (loadedFields, fields) {
20446
+ if (loadedFields === void 0) { loadedFields = []; }
20447
+ if (fields === void 0) { fields = []; }
20448
+ return __spreadArray([], __read(loadedFields)).reduce(function (updatedFields, field) {
20449
+ var index = updatedFields.findIndex(function (updatedField) { return updatedField.property === field.property; });
20450
+ var hasProperty = index >= 0;
20451
+ if (hasProperty) {
20452
+ updatedFields[index] = Object.assign(Object.assign({}, fields[index]), field);
20453
+ }
20454
+ else {
20455
+ updatedFields.push(field);
20456
+ }
20457
+ return updatedFields;
20458
+ }, __spreadArray([], __read(fields)));
20459
+ };
20460
+ PoDynamicFormLoadService.prototype.executeLoad = function (load, value) {
20461
+ var _this = this;
20462
+ return this.execute(load, value).pipe(operators.map(function (loadedFormdData) { return _this.setFormDefaultIfEmpty(loadedFormdData); }));
20463
+ };
20464
+ return PoDynamicFormLoadService;
20465
+ }(PoDynamicFormOperation));
20466
+ PoDynamicFormLoadService.decorators = [
20467
+ { type: i0.Injectable }
20468
+ ];
20469
+ PoDynamicFormLoadService.ctorParameters = function () { return [
20470
+ { type: i1.HttpClient }
20471
+ ]; };
20472
+
20473
+ var PoDynamicFormValidationService = /** @class */ (function (_super) {
20474
+ __extends(PoDynamicFormValidationService, _super);
20475
+ function PoDynamicFormValidationService(http) {
20476
+ return _super.call(this, http) || this;
20275
20477
  }
20276
- };
20478
+ PoDynamicFormValidationService.prototype.sendFieldChange = function (field, value) {
20479
+ var _this = this;
20480
+ var changedValue = { property: field.property, value: value };
20481
+ return this.execute(field.validate, changedValue).pipe(operators.map(function (validateFields) { return _this.setFieldDefaultIfEmpty(validateFields); }));
20482
+ };
20483
+ PoDynamicFormValidationService.prototype.sendFormChange = function (validate, field, value) {
20484
+ var _this = this;
20485
+ var changedValue = { property: field.property, value: value };
20486
+ return this.execute(validate, changedValue).pipe(operators.map(function (validateFields) { return _this.setFormDefaultIfEmpty(validateFields); }));
20487
+ };
20488
+ PoDynamicFormValidationService.prototype.updateFieldsForm = function (validatedFields, fields) {
20489
+ if (validatedFields === void 0) { validatedFields = []; }
20490
+ if (fields === void 0) { fields = []; }
20491
+ return __spreadArray([], __read(validatedFields)).reduce(function (updatedFields, validatedField) {
20492
+ var index = updatedFields.findIndex(function (field) { return field.property === validatedField.property; });
20493
+ var hasProperty = index >= 0;
20494
+ if (hasProperty) {
20495
+ updatedFields[index] = Object.assign(Object.assign({}, fields[index]), validatedField);
20496
+ }
20497
+ return updatedFields;
20498
+ }, __spreadArray([], __read(fields)));
20499
+ };
20500
+ PoDynamicFormValidationService.prototype.setFieldDefaultIfEmpty = function (validateFields) {
20501
+ return (validateFields || {
20502
+ field: {}
20503
+ });
20504
+ };
20505
+ return PoDynamicFormValidationService;
20506
+ }(PoDynamicFormOperation));
20507
+ PoDynamicFormValidationService.decorators = [
20508
+ { type: i0.Injectable }
20509
+ ];
20510
+ PoDynamicFormValidationService.ctorParameters = function () { return [
20511
+ { type: i1.HttpClient }
20512
+ ]; };
20513
+
20277
20514
  /**
20278
- * @docsPrivate
20515
+ * @docsExtends PoDynamicFormBaseComponent
20279
20516
  *
20280
- * Classe base do componente Po Lookup Modal.
20517
+ * @example
20518
+ *
20519
+ * <example name="po-dynamic-form-basic" title="PO Dynamic Form Basic">
20520
+ * <file name="sample-po-dynamic-form-basic/sample-po-dynamic-form-basic.component.html"> </file>
20521
+ * <file name="sample-po-dynamic-form-basic/sample-po-dynamic-form-basic.component.ts"> </file>
20522
+ * </example>
20523
+ *
20524
+ * <example name="po-dynamic-form-register" title="PO Dynamic Form - Register">
20525
+ * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.component.html"> </file>
20526
+ * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.component.ts"> </file>
20527
+ * <file name="sample-po-dynamic-form-register/sample-po-dynamic-form-register.service.ts"> </file>
20528
+ * </example>
20281
20529
  */
20282
- var PoLookupModalBaseComponent = /** @class */ (function () {
20283
- function PoLookupModalBaseComponent(languageService) {
20284
- var _this = this;
20285
- /** Se verdadeiro, ativa a funcionalidade de scroll infinito para a tabela exibida no retorno da consulta. */
20286
- this.infiniteScroll = false;
20287
- /** Evento utilizado ao selecionar um registro da tabela. */
20288
- this.model = new i0.EventEmitter();
20289
- this.hasNext = true;
20290
- this.isLoading = false;
20291
- this.page = 1;
20292
- this.pageSize = 10;
20293
- this.searchValue = '';
20294
- // Propriedade da modal de busca avançada:
20295
- this.advancedFilterModalTitle = '';
20296
- this.dynamicFormValue = {};
20297
- this.isAdvancedFilter = false;
20298
- this.language = poLocaleDefault;
20299
- // eslint-disable-next-line @typescript-eslint/member-ordering
20300
- this.primaryAction = {
20301
- action: function () {
20302
- _this.items.forEach(function (element) {
20303
- if (element['$selected']) {
20304
- _this.model.emit(element);
20305
- _this.poModal.close();
20306
- }
20307
- });
20308
- },
20309
- label: this.literals.modalPrimaryActionLabel
20310
- };
20311
- // eslint-disable-next-line @typescript-eslint/member-ordering
20312
- this.secondaryAction = {
20313
- action: function () {
20314
- _this.model.emit(null);
20315
- _this.poModal.close();
20316
- },
20317
- label: this.literals.modalSecondaryActionLabel
20318
- };
20319
- this.language = languageService.getShortLanguage();
20530
+ var PoDynamicFormComponent = /** @class */ (function (_super) {
20531
+ __extends(PoDynamicFormComponent, _super);
20532
+ function PoDynamicFormComponent(changes, loadService, validationService) {
20533
+ var _this = _super.call(this) || this;
20534
+ _this.changes = changes;
20535
+ _this.loadService = loadService;
20536
+ _this.validationService = validationService;
20537
+ _this.comboOptionSubject = new rxjs.Subject();
20538
+ return _this;
20320
20539
  }
20321
- Object.defineProperty(PoLookupModalBaseComponent.prototype, "literals", {
20322
- get: function () {
20323
- return this._literals || poLookupLiteralsDefault[this.language];
20324
- },
20325
- /** Objeto com as literais usadas no `po-lookup-modal`. */
20326
- set: function (value) {
20327
- if (value instanceof Object && !(value instanceof Array)) {
20328
- this._literals = Object.assign(Object.assign(Object.assign({}, poLookupLiteralsDefault[poLocaleDefault]), poLookupLiteralsDefault[this.language]), value);
20329
- if (value.modalTitle) {
20330
- this.title = this.literals.modalTitle;
20331
- }
20332
- }
20333
- else {
20334
- this._literals = poLookupLiteralsDefault[this.language];
20335
- }
20336
- this.primaryAction.label = this.literals.modalPrimaryActionLabel;
20337
- this.secondaryAction.label = this.literals.modalSecondaryActionLabel;
20338
- this.setTableLiterals();
20339
- },
20340
- enumerable: false,
20341
- configurable: true
20342
- });
20343
- Object.defineProperty(PoLookupModalBaseComponent.prototype, "title", {
20540
+ Object.defineProperty(PoDynamicFormComponent.prototype, "form", {
20344
20541
  get: function () {
20345
- return this._title;
20542
+ return this._form || {};
20346
20543
  },
20347
- /** Título da modal. */
20348
20544
  set: function (value) {
20349
- this._title = isTypeof(value, 'string') ? value : this.literals.modalTitle;
20545
+ var _this = this;
20546
+ // necessario para nao ocorrer o ExpressionChangedAfterItHasBeenCheckedError
20547
+ setTimeout(function () {
20548
+ _this._form = value;
20549
+ _this.emitForm();
20550
+ });
20350
20551
  },
20351
20552
  enumerable: false,
20352
20553
  configurable: true
20353
20554
  });
20354
- PoLookupModalBaseComponent.prototype.ngOnDestroy = function () {
20355
- if (this.filterSubscription) {
20356
- this.filterSubscription.unsubscribe();
20357
- }
20358
- if (this.searchSubscription) {
20359
- this.searchSubscription.unsubscribe();
20360
- }
20361
- if (this.showMoreSubscription) {
20362
- this.showMoreSubscription.unsubscribe();
20363
- }
20364
- };
20365
- PoLookupModalBaseComponent.prototype.ngOnInit = function () {
20366
- this.setAdvancedFilterModalProperties();
20367
- this.initializeData();
20368
- this.setTableLiterals();
20555
+ PoDynamicFormComponent.prototype.ngOnDestroy = function () {
20556
+ this.removeListeners();
20369
20557
  };
20370
- PoLookupModalBaseComponent.prototype.createDisclaimer = function () {
20371
- var e_1, _c;
20372
- this.disclaimerGroup.disclaimers = [];
20373
- this.searchValue = '';
20374
- try {
20375
- for (var _d = __values(Object.entries(this.dynamicFormValue)), _e = _d.next(); !_e.done; _e = _d.next()) {
20376
- var _f = __read(_e.value, 2), key = _f[0], value = _f[1];
20377
- this.addDisclaimer(value, key);
20378
- }
20379
- }
20380
- catch (e_1_1) { e_1 = { error: e_1_1 }; }
20381
- finally {
20382
- try {
20383
- if (_e && !_e.done && (_c = _d.return)) _c.call(_d);
20384
- }
20385
- finally { if (e_1) throw e_1.error; }
20386
- }
20387
- if (!Object.values(this.dynamicFormValue).some(function (v) { return v !== null && typeof v !== 'undefined'; })) {
20388
- this.initializeData();
20558
+ PoDynamicFormComponent.prototype.ngOnInit = function () {
20559
+ if (this.load) {
20560
+ this.loadDataOnInitialize();
20389
20561
  }
20390
20562
  };
20391
- PoLookupModalBaseComponent.prototype.addDisclaimer = function (value, property) {
20392
- this.disclaimer = { property: property };
20393
- this.disclaimer.value = value;
20394
- this.disclaimerGroup.disclaimers = __spreadArray(__spreadArray([], __read(this.disclaimerGroup.disclaimers)), [this.disclaimer]);
20563
+ /**
20564
+ * Função que atribui foco ao campo desejado.
20565
+ *
20566
+ * Para utilizá-la é necessário capturar a instância do `dynamic form`, como por exemplo:
20567
+ *
20568
+ * ``` html
20569
+ * <po-dynamic-form #dynamicForm [p-fields]="fields"></po-dynamic-form>
20570
+ * ```
20571
+ *
20572
+ * ``` javascript
20573
+ * import { PoDynamicFormComponent, PoDynamicFormField } from '@po-ui/ng-components';
20574
+ *
20575
+ * ...
20576
+ *
20577
+ * @ViewChild('dynamicForm', { static: true }) dynamicForm: PoDynamicFormComponent;
20578
+ *
20579
+ * fields: Array<PoDynamicFormField> = [
20580
+ * { property: 'fieldOne' },
20581
+ * { property: 'fieldTwo' }
20582
+ * ];
20583
+ *
20584
+ * fieldFocus() {
20585
+ * this.dynamicForm.focus('fieldTwo');
20586
+ * }
20587
+ * ```
20588
+ *
20589
+ * @param {string} property Nome da propriedade atribuída ao `PoDynamicFormField.property`.
20590
+ */
20591
+ PoDynamicFormComponent.prototype.focus = function (property) {
20592
+ this.fieldsComponent.focus(property);
20395
20593
  };
20396
- PoLookupModalBaseComponent.prototype.onChangeDisclaimerGroup = function () {
20397
- if (!this.searchValue) {
20398
- this.isLoading = true;
20399
- this.searchValue = '';
20400
- this.searchFilteredItems();
20401
- }
20594
+ PoDynamicFormComponent.prototype.getObjectValue = function () {
20595
+ return this.comboOptionSubject.asObservable();
20402
20596
  };
20403
- PoLookupModalBaseComponent.prototype.search = function () {
20404
- this.page = 1;
20405
- if (this.searchValue) {
20406
- this.isLoading = true;
20407
- this.disclaimerGroup.disclaimers = [];
20408
- this.searchFilteredItems();
20409
- }
20410
- else {
20411
- this.initializeData();
20412
- }
20597
+ PoDynamicFormComponent.prototype.sendObjectValue = function (objectValue) {
20598
+ this.comboOptionSubject.next(objectValue);
20413
20599
  };
20414
- PoLookupModalBaseComponent.prototype.searchFilteredItems = function () {
20600
+ PoDynamicFormComponent.prototype.validateForm = function (field) {
20415
20601
  var _this = this;
20416
- this.searchSubscription = this.getFilteredItems(this.searchValue)
20417
- .pipe(operators.catchError(function (error) {
20418
- _this.setLookupResponseProperties();
20419
- return rxjs.throwError(error);
20420
- }))
20421
- .subscribe(function (data) { return _this.setLookupResponseProperties(data); }, function () { });
20602
+ var previousFocusElement = document.activeElement;
20603
+ this.disableForm(true);
20604
+ var errorOnValidation = function () { return _this.disableForm(false); };
20605
+ this.sendFormSubscription = this.validationService
20606
+ .sendFormChange(this.validate, field, this.value)
20607
+ .subscribe(this.applyFormValidation(previousFocusElement), errorOnValidation);
20422
20608
  };
20423
- PoLookupModalBaseComponent.prototype.showMoreEvent = function () {
20609
+ PoDynamicFormComponent.prototype.applyFormUpdatesOnLoad = function (previousFocusElement) {
20424
20610
  var _this = this;
20425
- this.page++;
20426
- this.isLoading = true;
20427
- this.showMoreSubscription = this.getFilteredItems(this.searchValue)
20428
- .pipe(operators.catchError(function (error) {
20429
- _this.hasNext = false;
20430
- _this.isLoading = false;
20431
- return rxjs.throwError(error);
20432
- }))
20433
- .subscribe(function (data) {
20434
- _this.items = __spreadArray(__spreadArray([], __read(_this.items)), __read(data.items));
20435
- _this.hasNext = data.hasNext;
20436
- _this.isLoading = false;
20437
- }, function () { });
20611
+ return function (dynamicFormData) {
20612
+ _this.updateModelOnLoad(dynamicFormData);
20613
+ _this.disableForm(false);
20614
+ _this.setFocusOnFieldByProperty(dynamicFormData.focus, previousFocusElement);
20615
+ };
20438
20616
  };
20439
- PoLookupModalBaseComponent.prototype.setAdvancedFilterModalProperties = function () {
20617
+ PoDynamicFormComponent.prototype.applyFormValidation = function (previousFocusElement) {
20440
20618
  var _this = this;
20441
- this.advancedFilterModalTitle = this.literals.modalAdvancedSearchTitle;
20442
- this.disclaimerGroup = {
20443
- title: this.literals.modalDisclaimerGroupTitle,
20444
- disclaimers: []
20445
- };
20446
- this.primaryActionAdvancedFilter = {
20447
- action: function () {
20448
- _this.destroyDynamicForm();
20449
- _this.isAdvancedFilter = false;
20450
- _this.createDisclaimer();
20451
- },
20452
- label: this.literals.modalAdvancedSearchPrimaryActionLabel
20453
- };
20454
- this.secondaryActionAdvancedFilter = {
20455
- action: function () {
20456
- _this.destroyDynamicForm();
20457
- _this.isAdvancedFilter = false;
20458
- },
20459
- label: this.literals.modalAdvancedSearchSecondaryActionLabel
20619
+ return function (dynamicFormData) {
20620
+ _this.updateModelWithValidation(dynamicFormData);
20621
+ _this.disableForm(false);
20622
+ _this.setFocusOnFieldByProperty(dynamicFormData.focus, previousFocusElement);
20460
20623
  };
20461
20624
  };
20462
- PoLookupModalBaseComponent.prototype.getAdvancedFilters = function (advancedParams) {
20463
- if (advancedParams && advancedParams.length > 0) {
20464
- var filters_1 = {};
20465
- var validatedAdvacendFilters_1;
20466
- advancedParams.forEach(function (filter) {
20467
- filters_1[filter.property] = filter.value instanceof Array ? filter.value.join() : filter.value;
20468
- validatedAdvacendFilters_1 = Object.assign(Object.assign({}, validatedAdvacendFilters_1), filters_1);
20469
- });
20470
- return validatedAdvacendFilters_1;
20471
- }
20472
- return undefined;
20473
- };
20474
- PoLookupModalBaseComponent.prototype.getFilteredItems = function (filter) {
20475
- var filteredParams = this.getFilteredParams(filter);
20476
- return this.filterService.getFilteredItems(filteredParams);
20625
+ PoDynamicFormComponent.prototype.disableForm = function (value) {
20626
+ this.disabledForm = value;
20627
+ this.changes.detectChanges();
20477
20628
  };
20478
- PoLookupModalBaseComponent.prototype.getFilteredParams = function (filter) {
20479
- var _c = this, page = _c.page, pageSize = _c.pageSize, filterParams = _c.filterParams, sort = _c.sort;
20480
- var filteredParams = {};
20481
- var order = this.getOrderParam(sort);
20482
- var advancedFilters = this.getAdvancedFilters(this.disclaimerGroup.disclaimers);
20483
- var params = { filter: filter, page: page, pageSize: pageSize, order: order, filterParams: filterParams, advancedFilters: advancedFilters };
20484
- for (var key in params) {
20485
- if (params.hasOwnProperty(key) && params[key] !== undefined) {
20486
- filteredParams[key] = params[key];
20487
- }
20629
+ PoDynamicFormComponent.prototype.emitForm = function () {
20630
+ if (!this.groupForm && this.formOutput.observers.length) {
20631
+ this.formOutput.emit(this.form);
20488
20632
  }
20489
- return filteredParams;
20490
20633
  };
20491
- PoLookupModalBaseComponent.prototype.getOrderParam = function (sort) {
20492
- if (sort === void 0) { sort = { type: undefined }; }
20493
- var column = sort.column, type = sort.type;
20494
- if (!column) {
20495
- return;
20634
+ PoDynamicFormComponent.prototype.loadDataOnInitialize = function () {
20635
+ var _this = this;
20636
+ var previousFocusElement = document.activeElement;
20637
+ this.disabledForm = true;
20638
+ var errorOnLoad = function () { return (_this.disabledForm = false); };
20639
+ this.onLoadSubscription = this.loadService
20640
+ .executeLoad(this.load, this.value)
20641
+ .subscribe(this.applyFormUpdatesOnLoad(previousFocusElement), errorOnLoad);
20642
+ };
20643
+ PoDynamicFormComponent.prototype.removeListeners = function () {
20644
+ if (this.onLoadSubscription) {
20645
+ this.onLoadSubscription.unsubscribe();
20496
20646
  }
20497
- if (type === exports.PoTableColumnSortType.Descending) {
20498
- return "-" + column.property;
20647
+ if (this.sendFormSubscription) {
20648
+ this.sendFormSubscription.unsubscribe();
20499
20649
  }
20500
- return "" + column.property;
20501
20650
  };
20502
- PoLookupModalBaseComponent.prototype.initializeData = function () {
20651
+ PoDynamicFormComponent.prototype.setFocusOnFieldByProperty = function (property, previousFocusElement) {
20503
20652
  var _this = this;
20504
- this.isLoading = true;
20505
- this.filterSubscription = this.getFilteredItems('').subscribe(function (data) {
20506
- _this.setLookupResponseProperties(data);
20507
- });
20653
+ if (property) {
20654
+ // precisa do timeout para que o valor seja atribuido no campo antes de setar o focus,
20655
+ // para nao disparar a mudança posteriormente. Situação ocorre quando retornar campo com valor e focus atribuido a ele.
20656
+ setTimeout(function () { return _this.focus(property); });
20657
+ }
20658
+ else {
20659
+ previousFocusElement['focus']();
20660
+ }
20508
20661
  };
20509
- PoLookupModalBaseComponent.prototype.setLookupResponseProperties = function (data) {
20510
- var _a, _b;
20511
- this.items = (_a = data === null || data === void 0 ? void 0 : data.items) !== null && _a !== void 0 ? _a : [];
20512
- this.hasNext = (_b = data === null || data === void 0 ? void 0 : data.hasNext) !== null && _b !== void 0 ? _b : false;
20513
- this.isLoading = false;
20662
+ PoDynamicFormComponent.prototype.updateModelOnLoad = function (loadedFormData) {
20663
+ Object.assign(this.value, loadedFormData.value);
20664
+ this.fields = this.loadService.createAndUpdateFieldsForm(loadedFormData.fields, this.fields);
20514
20665
  };
20515
- PoLookupModalBaseComponent.prototype.setTableLiterals = function () {
20516
- this.tableLiterals = {
20517
- 'noColumns': this.literals.modalTableNoColumns,
20518
- 'noData': this.literals.modalTableNoData,
20519
- 'loadingData': this.literals.modalTableLoadingData,
20520
- 'loadMoreData': this.literals.modalTableLoadMoreData
20521
- };
20666
+ PoDynamicFormComponent.prototype.updateModelWithValidation = function (formData) {
20667
+ Object.assign(this.value, formData.value);
20668
+ this.fieldsComponent.updatePreviousValue();
20669
+ this.fields = this.validationService.updateFieldsForm(formData.fields, this.fields);
20522
20670
  };
20523
- return PoLookupModalBaseComponent;
20524
- }());
20525
- PoLookupModalBaseComponent.decorators = [
20526
- { type: i0.Directive }
20671
+ return PoDynamicFormComponent;
20672
+ }(PoDynamicFormBaseComponent));
20673
+ PoDynamicFormComponent.decorators = [
20674
+ { type: i0.Component, args: [{
20675
+ selector: 'po-dynamic-form',
20676
+ template: "<ng-container *ngIf=\"groupForm; then reuseFormTemplate; else uniqueFormTemplate\"></ng-container>\n\n<ng-template #reuseFormTemplate>\n <po-dynamic-form-fields #fieldsComponent [p-auto-focus]=\"autoFocus\" [p-fields]=\"fields\" [p-value]=\"value\">\n </po-dynamic-form-fields>\n</ng-template>\n\n<ng-template #uniqueFormTemplate>\n <form #dynamicForm=\"ngForm\">\n <po-dynamic-form-fields\n #fieldsComponent\n [(p-fields)]=\"fields\"\n [p-auto-focus]=\"autoFocus\"\n [p-disabled-form]=\"disabledForm\"\n [p-validate]=\"validate\"\n [p-validate-fields]=\"validateFields\"\n [p-value]=\"value\"\n (p-object-value)=\"sendObjectValue($event)\"\n (p-form-validate)=\"validateForm($event)\"\n >\n </po-dynamic-form-fields>\n </form>\n</ng-template>\n"
20677
+ },] }
20527
20678
  ];
20528
- PoLookupModalBaseComponent.ctorParameters = function () { return [
20529
- { type: PoLanguageService }
20679
+ PoDynamicFormComponent.ctorParameters = function () { return [
20680
+ { type: i0.ChangeDetectorRef },
20681
+ { type: PoDynamicFormLoadService },
20682
+ { type: PoDynamicFormValidationService }
20530
20683
  ]; };
20531
- PoLookupModalBaseComponent.propDecorators = {
20532
- poModal: [{ type: i0.ViewChild, args: [PoModalComponent, { static: true },] }],
20533
- advancedFilters: [{ type: i0.Input, args: ['p-advanced-filters',] }],
20534
- columns: [{ type: i0.Input, args: ['p-columns',] }],
20535
- items: [{ type: i0.Input, args: ['p-items',] }],
20536
- filterService: [{ type: i0.Input, args: ['p-filter-service',] }],
20537
- filterParams: [{ type: i0.Input, args: ['p-filter-params',] }],
20538
- infiniteScroll: [{ type: i0.Input, args: ['p-infinite-scroll',] }],
20539
- model: [{ type: i0.Output, args: ['p-change-model',] }],
20540
- literals: [{ type: i0.Input, args: ['p-literals',] }],
20541
- title: [{ type: i0.Input, args: ['p-title',] }]
20684
+ PoDynamicFormComponent.propDecorators = {
20685
+ fieldsComponent: [{ type: i0.ViewChild, args: ['fieldsComponent',] }],
20686
+ form: [{ type: i0.ViewChild, args: ['dynamicForm',] }]
20542
20687
  };
20543
- __decorate([
20544
- InputBoolean()
20545
- ], PoLookupModalBaseComponent.prototype, "infiniteScroll", void 0);
20546
20688
 
20547
20689
  /**
20548
20690
  * @docsPrivate
@@ -20551,8 +20693,8 @@
20551
20693
  */
20552
20694
  var PoLookupModalComponent = /** @class */ (function (_super) {
20553
20695
  __extends(PoLookupModalComponent, _super);
20554
- function PoLookupModalComponent(componentFactory, poLanguage) {
20555
- var _this = _super.call(this, poLanguage) || this;
20696
+ function PoLookupModalComponent(componentFactory, poLanguage, changeDetector) {
20697
+ var _this = _super.call(this, poLanguage, changeDetector) || this;
20556
20698
  _this.componentFactory = componentFactory;
20557
20699
  _this.keyUpObservable = null;
20558
20700
  _this.containerHeight = 375;
@@ -20565,6 +20707,34 @@
20565
20707
  PoLookupModalComponent.prototype.ngAfterViewInit = function () {
20566
20708
  this.initializeEventInput();
20567
20709
  };
20710
+ // Seleciona um item na tabela
20711
+ PoLookupModalComponent.prototype.onSelect = function (item) {
20712
+ if (this.multiple) {
20713
+ this.selecteds = __spreadArray(__spreadArray([], __read(this.selecteds)), [Object.assign({ value: item[this.fieldValue], label: item[this.fieldLabel] }, item)]);
20714
+ }
20715
+ else {
20716
+ this.selecteds = [Object.assign({ value: item[this.fieldValue], label: item[this.fieldLabel] }, item)];
20717
+ }
20718
+ };
20719
+ // Remove a seleção de um item na tabela
20720
+ PoLookupModalComponent.prototype.onUnselect = function (unselectedItem) {
20721
+ var _this = this;
20722
+ this.selecteds = this.selecteds.filter(function (itemSelected) { return itemSelected.value !== unselectedItem[_this.fieldValue]; });
20723
+ };
20724
+ PoLookupModalComponent.prototype.onUnselectFromDisclaimer = function (removedDisclaimer) {
20725
+ var _this = this;
20726
+ this.poTable.unselectRowItem(function (item) { return item[_this.fieldValue] === removedDisclaimer.value; });
20727
+ };
20728
+ // Seleciona todos os itens visíveis na tabela
20729
+ PoLookupModalComponent.prototype.onAllSelected = function (items) {
20730
+ var _this = this;
20731
+ this.selecteds = items.map(function (item) { return (Object.assign({ value: item[_this.fieldValue], label: item[_this.fieldLabel] }, item)); });
20732
+ };
20733
+ // Remove a seleção de todos os itens visíveis na tabela
20734
+ PoLookupModalComponent.prototype.onAllUnselected = function (items) {
20735
+ this.poTable.unselectRows();
20736
+ this.selecteds = [];
20737
+ };
20568
20738
  PoLookupModalComponent.prototype.initializeEventInput = function () {
20569
20739
  var _this = this;
20570
20740
  this.keyUpObservable = rxjs.fromEvent(this.inputSearchEl.nativeElement, 'keyup').pipe(operators.filter(function (e) { return _this.validateEnterPressed(e); }), operators.debounceTime(400));
@@ -20588,6 +20758,16 @@
20588
20758
  this.createDynamicForm();
20589
20759
  };
20590
20760
  PoLookupModalComponent.prototype.setTableHeight = function () {
20761
+ var _a;
20762
+ if (this.multiple) {
20763
+ if (((_a = this.selecteds) === null || _a === void 0 ? void 0 : _a.length) !== 0) {
20764
+ this.tableHeight = 300;
20765
+ }
20766
+ else {
20767
+ this.tableHeight = 370;
20768
+ this.containerHeight = 375;
20769
+ }
20770
+ }
20591
20771
  // precisa ser 315 por as linhas terem altura de 32px (quando tela menor que 1366px).
20592
20772
  // O retorno padrão é 10 itens fazendo com que gere scroll caso houver paginação, 370 não gerava.
20593
20773
  this.tableHeight = this.infiniteScroll ? 315 : 370;
@@ -20623,14 +20803,16 @@
20623
20803
  PoLookupModalComponent.decorators = [
20624
20804
  { type: i0.Component, args: [{
20625
20805
  selector: 'po-lookup-modal',
20626
- template: "<po-modal\n p-click-out=\"false\"\n p-hide-close=\"false\"\n p-size=\"lg\"\n [p-primary-action]=\"isAdvancedFilter ? primaryActionAdvancedFilter : primaryAction\"\n [p-secondary-action]=\"isAdvancedFilter ? secondaryActionAdvancedFilter : secondaryAction\"\n [p-title]=\"isAdvancedFilter ? advancedFilterModalTitle : title\"\n>\n <div [hidden]=\"isAdvancedFilter\">\n <po-field-container class=\"po-lookup-header po-pull-right\" [p-optional]=\"false\">\n <div class=\"po-lookup-filter-content\">\n <div class=\"po-field-icon-container-right\">\n <span #iconLookup class=\"po-icon po-field-icon po-icon-search\" (click)=\"search()\"> </span>\n </div>\n\n <input\n #inpsearch\n class=\"po-input po-input-icon-right\"\n name=\"contentSearch\"\n [(ngModel)]=\"searchValue\"\n [placeholder]=\"literals.modalPlaceholder\"\n type=\"text\"\n />\n </div>\n\n <div *ngIf=\"advancedFilters && advancedFilters.length > 0\" class=\"po-lookup-advanced-search\">\n <span\n class=\"po-lookup-advanced-search-link\"\n tabindex=\"0\"\n (click)=\"onAdvancedFilter()\"\n (keydown.enter)=\"onAdvancedFilter()\"\n tabindex=\"0\"\n >\n {{ literals.modalAdvancedSearch }}\n </span>\n </div>\n </po-field-container>\n\n <!-- DISCLAIMER -->\n <po-disclaimer-group\n class=\"po-md-12\"\n *ngIf=\"!!disclaimerGroup\"\n [p-disclaimers]=\"disclaimerGroup?.disclaimers\"\n [p-title]=\"disclaimerGroup?.title\"\n (p-change)=\"onChangeDisclaimerGroup()\"\n >\n </po-disclaimer-group>\n\n <div class=\"po-row po-lookup-container-table\" [style.height.px]=\"containerHeight\">\n <po-table\n class=\"po-md-12\"\n [p-selectable]=\"true\"\n [p-hide-detail]=\"true\"\n [p-single-select]=\"true\"\n [p-sort]=\"true\"\n [p-columns]=\"columns\"\n [p-height]=\"tableHeight\"\n [p-items]=\"items\"\n [p-literals]=\"tableLiterals\"\n [p-loading]=\"isLoading\"\n [p-show-more-disabled]=\"!hasNext\"\n [p-infinite-scroll]=\"infiniteScroll\"\n (p-show-more)=\"showMoreEvent()\"\n (p-sort-by)=\"sortBy($event)\"\n >\n </po-table>\n </div>\n </div>\n <div [hidden]=\"!isAdvancedFilter\">\n <ng-container #container> </ng-container>\n </div>\n</po-modal>\n"
20806
+ template: "<po-modal\n p-click-out=\"false\"\n p-hide-close=\"false\"\n p-size=\"lg\"\n [p-primary-action]=\"isAdvancedFilter ? primaryActionAdvancedFilter : primaryAction\"\n [p-secondary-action]=\"isAdvancedFilter ? secondaryActionAdvancedFilter : secondaryAction\"\n [p-title]=\"isAdvancedFilter ? advancedFilterModalTitle : title\"\n>\n <div [hidden]=\"isAdvancedFilter\">\n <po-field-container class=\"po-lookup-header po-pull-right\" [p-optional]=\"false\">\n <div class=\"po-lookup-filter-content\">\n <div class=\"po-field-icon-container-right\">\n <span #iconLookup class=\"po-icon po-field-icon po-icon-search\" (click)=\"search()\"> </span>\n </div>\n\n <input\n #inpsearch\n class=\"po-input po-input-icon-right\"\n name=\"contentSearch\"\n [(ngModel)]=\"searchValue\"\n [placeholder]=\"literals.modalPlaceholder\"\n type=\"text\"\n />\n </div>\n\n <div *ngIf=\"advancedFilters && advancedFilters.length > 0\" class=\"po-lookup-advanced-search\">\n <span\n class=\"po-lookup-advanced-search-link\"\n tabindex=\"0\"\n (click)=\"onAdvancedFilter()\"\n (keydown.enter)=\"onAdvancedFilter()\"\n tabindex=\"0\"\n >\n {{ literals.modalAdvancedSearch }}\n </span>\n </div>\n </po-field-container>\n\n <!-- DISCLAIMER -->\n <po-disclaimer-group\n *ngIf=\"!!disclaimerGroup\"\n class=\"po-md-12\"\n [p-disclaimers]=\"disclaimerGroup?.disclaimers\"\n [p-title]=\"disclaimerGroup?.title\"\n (p-change)=\"onChangeDisclaimerGroup()\"\n >\n </po-disclaimer-group>\n\n <div class=\"po-row po-lookup-container-table\" [style.height.px]=\"containerHeight\">\n <po-table\n #poTable\n class=\"po-md-12\"\n [p-selectable]=\"true\"\n [p-hide-detail]=\"true\"\n [p-single-select]=\"!multiple\"\n [p-sort]=\"true\"\n [p-columns]=\"columns\"\n [p-height]=\"tableHeight\"\n [p-items]=\"items\"\n [p-literals]=\"tableLiterals\"\n [p-loading]=\"isLoading\"\n [p-show-more-disabled]=\"!hasNext\"\n [p-infinite-scroll]=\"infiniteScroll\"\n (p-selected)=\"onSelect($event)\"\n (p-unselected)=\"onUnselect($event)\"\n (p-all-selected)=\"onAllSelected($event)\"\n (p-all-unselected)=\"onAllUnselected($event)\"\n (p-show-more)=\"showMoreEvent()\"\n (p-sort-by)=\"sortBy($event)\"\n >\n </po-table>\n </div>\n\n <!-- DISCLAIMER -->\n <po-disclaimer-group\n *ngIf=\"multiple\"\n class=\"po-md-12\"\n [p-disclaimers]=\"selecteds\"\n (p-remove)=\"onUnselectFromDisclaimer($event.removedDisclaimer)\"\n (p-remove-all)=\"onAllUnselected($event)\"\n >\n </po-disclaimer-group>\n </div>\n <div [hidden]=\"!isAdvancedFilter\">\n <ng-container #container> </ng-container>\n </div>\n</po-modal>\n"
20627
20807
  },] }
20628
20808
  ];
20629
20809
  PoLookupModalComponent.ctorParameters = function () { return [
20630
20810
  { type: i0.ComponentFactoryResolver },
20631
- { type: PoLanguageService }
20811
+ { type: PoLanguageService },
20812
+ { type: i0.ChangeDetectorRef }
20632
20813
  ]; };
20633
20814
  PoLookupModalComponent.propDecorators = {
20815
+ poTable: [{ type: i0.ViewChild, args: [PoTableComponent, { static: true },] }],
20634
20816
  inputSearchEl: [{ type: i0.ViewChild, args: ['inpsearch',] }],
20635
20817
  container: [{ type: i0.ViewChild, args: ['container', { read: i0.ViewContainerRef },] }]
20636
20818
  };
@@ -20655,10 +20837,13 @@
20655
20837
  * @param filterParams {any} Valor que será repassado aos métodos do serviço para auxiliar no filtro dos dados.
20656
20838
  * @param title {string} Definição do título da modal.
20657
20839
  * @param literals {PoLookupLiterals} Literais utilizadas no componente.
20840
+ * @param selectedItems {any} Valor que está selecionado que será repassado para o modal para apresentar na tabela.
20841
+ * @param fieldLabel {string} Valor que será utilizado como descrição do campo.
20842
+ * @param fieldValue {string} Valor que será utilizado como valor do campo.
20658
20843
  */
20659
20844
  PoLookupModalService.prototype.openModal = function (params) {
20660
20845
  var _this = this;
20661
- var advancedFilters = params.advancedFilters, service = params.service, columns = params.columns, filterParams = params.filterParams, title = params.title, literals = params.literals, infiniteScroll = params.infiniteScroll;
20846
+ var advancedFilters = params.advancedFilters, service = params.service, columns = params.columns, filterParams = params.filterParams, title = params.title, literals = params.literals, infiniteScroll = params.infiniteScroll, multiple = params.multiple, selectedItems = params.selectedItems, fieldLabel = params.fieldLabel, fieldValue = params.fieldValue;
20662
20847
  this.componentRef = this.poComponentInjector.createComponentInApplication(PoLookupModalComponent);
20663
20848
  this.componentRef.instance.advancedFilters = advancedFilters;
20664
20849
  this.componentRef.instance.title = title;
@@ -20670,6 +20855,10 @@
20670
20855
  _this.selectValue($event);
20671
20856
  });
20672
20857
  this.componentRef.instance.infiniteScroll = infiniteScroll;
20858
+ this.componentRef.instance.multiple = multiple;
20859
+ this.componentRef.instance.selectedItems = selectedItems;
20860
+ this.componentRef.instance.fieldLabel = fieldLabel;
20861
+ this.componentRef.instance.fieldValue = fieldValue;
20673
20862
  this.componentRef.changeDetectorRef.detectChanges();
20674
20863
  this.componentRef.instance.openModal();
20675
20864
  };
@@ -20756,12 +20945,24 @@
20756
20945
  * <file name="sample-po-lookup-sw-films/sample-po-lookup-sw-films.component.ts"> </file>
20757
20946
  * <file name="sample-po-lookup-sw-films/sample-po-lookup-sw-films.service.ts"> </file>
20758
20947
  * </example>
20948
+ *
20949
+ * <example name="po-lookup-multiple" title="PO Lookup - Multiple">
20950
+ * <file name="sample-po-lookup-multiple/sample-po-lookup-multiple.component.html"> </file>
20951
+ * <file name="sample-po-lookup-multiple/sample-po-lookup-multiple.component.ts"> </file>
20952
+ * <file name="sample-po-lookup-multiple/sample-po-lookup-multiple.service.ts"> </file>
20953
+ * </example>
20759
20954
  */
20760
20955
  var PoLookupComponent = /** @class */ (function (_super) {
20761
20956
  __extends(PoLookupComponent, _super);
20762
- function PoLookupComponent(poLookupFilterService, poLookupModalService, injector) {
20957
+ function PoLookupComponent(renderer, poLookupFilterService, poLookupModalService, injector) {
20763
20958
  var _this = _super.call(this, poLookupFilterService, injector) || this;
20959
+ _this.renderer = renderer;
20764
20960
  _this.poLookupModalService = poLookupModalService;
20961
+ _this.initialized = false;
20962
+ _this.visibleElement = false;
20963
+ _this.disclaimers = [];
20964
+ _this.visibleDisclaimers = [];
20965
+ _this.isCalculateVisibleItems = true;
20765
20966
  return _this;
20766
20967
  }
20767
20968
  Object.defineProperty(PoLookupComponent.prototype, "autocomplete", {
@@ -20776,6 +20977,17 @@
20776
20977
  if (this.autoFocus) {
20777
20978
  this.focus();
20778
20979
  }
20980
+ this.initialized = true;
20981
+ };
20982
+ PoLookupComponent.prototype.ngDoCheck = function () {
20983
+ var _a;
20984
+ var inputWidth = (_a = this.inputEl) === null || _a === void 0 ? void 0 : _a.nativeElement.offsetWidth;
20985
+ // Permite que os disclaimers sejam calculados na primeira vez que o componente torna-se visível,
20986
+ // evitando com isso, problemas com Tabs ou Divs que iniciem escondidas.
20987
+ if ((inputWidth && !this.visibleElement && this.initialized) || (inputWidth && this.isCalculateVisibleItems)) {
20988
+ this.debounceResize();
20989
+ this.visibleElement = true;
20990
+ }
20779
20991
  };
20780
20992
  PoLookupComponent.prototype.ngOnDestroy = function () {
20781
20993
  if (this.modalSubscription) {
@@ -20784,6 +20996,7 @@
20784
20996
  };
20785
20997
  PoLookupComponent.prototype.ngOnInit = function () {
20786
20998
  _super.prototype.ngOnInit.call(this);
20999
+ this.initializeListeners();
20787
21000
  };
20788
21001
  /**
20789
21002
  * Função que atribui foco ao componente.
@@ -20810,7 +21023,8 @@
20810
21023
  PoLookupComponent.prototype.openLookup = function () {
20811
21024
  var _this = this;
20812
21025
  if (this.isAllowedOpenModal()) {
20813
- var _b = this, advancedFilters = _b.advancedFilters, service = _b.service, columns = _b.columns, filterParams = _b.filterParams, literals = _b.literals, infiniteScroll = _b.infiniteScroll;
21026
+ var _c = this, advancedFilters = _c.advancedFilters, service = _c.service, columns = _c.columns, filterParams = _c.filterParams, literals = _c.literals, infiniteScroll = _c.infiniteScroll, multiple = _c.multiple, fieldLabel = _c.fieldLabel, fieldValue = _c.fieldValue;
21027
+ var selectedItems = this.checkSelectedItems();
20814
21028
  this.poLookupModalService.openModal({
20815
21029
  advancedFilters: advancedFilters,
20816
21030
  service: service,
@@ -20818,20 +21032,45 @@
20818
21032
  filterParams: filterParams,
20819
21033
  title: this.label,
20820
21034
  literals: literals,
20821
- infiniteScroll: infiniteScroll
21035
+ infiniteScroll: infiniteScroll,
21036
+ multiple: multiple,
21037
+ selectedItems: selectedItems,
21038
+ fieldLabel: fieldLabel,
21039
+ fieldValue: fieldValue
20822
21040
  });
20823
21041
  if (!this.modalSubscription) {
20824
- this.modalSubscription = this.poLookupModalService.selectValueEvent.subscribe(function (element) {
20825
- _this.selectModel(element);
21042
+ this.modalSubscription = this.poLookupModalService.selectValueEvent.subscribe(function (selectedOptions) {
21043
+ if (selectedOptions.length > 1 || _this.disclaimers.length) {
21044
+ _this.setDisclaimers(selectedOptions);
21045
+ _this.updateVisibleItems();
21046
+ }
21047
+ _this.selectModel(selectedOptions);
20826
21048
  });
20827
21049
  }
20828
21050
  }
20829
21051
  };
21052
+ PoLookupComponent.prototype.checkSelectedItems = function () {
21053
+ var _a;
21054
+ if (this.multiple) {
21055
+ if (!this.disclaimers.length && ((_a = this.valueToModel) === null || _a === void 0 ? void 0 : _a.length)) {
21056
+ return [Object.assign({ value: this.valueToModel[0], label: this.oldValue }, this.selectedOptions[0])];
21057
+ }
21058
+ return this.disclaimers;
21059
+ }
21060
+ else {
21061
+ return this.valueToModel;
21062
+ }
21063
+ };
21064
+ PoLookupComponent.prototype.setDisclaimers = function (selectedOptions) {
21065
+ var _this = this;
21066
+ this.disclaimers = selectedOptions.map(function (selectedOption) { return (Object.assign({ value: selectedOption[_this.fieldValue], label: selectedOption[_this.fieldLabel] }, selectedOption)); });
21067
+ this.visibleDisclaimers = __spreadArray([], __read(this.disclaimers));
21068
+ };
20830
21069
  PoLookupComponent.prototype.setViewValue = function (value, object) {
20831
- if (this.fieldFormat) {
21070
+ if (this.inputEl && this.fieldFormat) {
20832
21071
  this.setInputValueWipoieldFormat(object);
20833
21072
  }
20834
- else {
21073
+ else if (this.inputEl) {
20835
21074
  this.inputEl.nativeElement.value = this.valueToModel || this.valueToModel === 0 ? value : '';
20836
21075
  }
20837
21076
  };
@@ -20839,13 +21078,82 @@
20839
21078
  return this.inputEl.nativeElement.value;
20840
21079
  };
20841
21080
  PoLookupComponent.prototype.searchEvent = function () {
20842
- var _a;
21081
+ var _a, _b;
20843
21082
  (_a = this.onTouched) === null || _a === void 0 ? void 0 : _a.call(this);
20844
21083
  var value = this.getViewValue();
20845
- if (this.oldValue.toString() !== value) {
21084
+ if (((_b = this.oldValue) === null || _b === void 0 ? void 0 : _b.toString()) !== value) {
20846
21085
  this.searchById(value);
20847
21086
  }
20848
21087
  };
21088
+ PoLookupComponent.prototype.closeDisclaimer = function (value) {
21089
+ this.disclaimers = this.disclaimers.filter(function (disclaimer) { return disclaimer.value !== value; });
21090
+ this.valueToModel = this.valueToModel.filter(function (model) { return model !== value; });
21091
+ this.updateVisibleItems();
21092
+ this.callOnChange(this.valueToModel.length ? this.valueToModel : undefined);
21093
+ };
21094
+ PoLookupComponent.prototype.updateVisibleItems = function () {
21095
+ if (this.disclaimers && this.disclaimers.length > 0) {
21096
+ this.visibleDisclaimers = [].concat(this.disclaimers);
21097
+ }
21098
+ this.debounceResize();
21099
+ if (!this.inputEl.nativeElement.offsetWidth) {
21100
+ this.isCalculateVisibleItems = true;
21101
+ }
21102
+ };
21103
+ PoLookupComponent.prototype.debounceResize = function () {
21104
+ var _this = this;
21105
+ if (!this.autoHeight) {
21106
+ clearTimeout(this.timeoutResize);
21107
+ this.timeoutResize = setTimeout(function () {
21108
+ _this.calculateVisibleItems();
21109
+ }, 200);
21110
+ }
21111
+ };
21112
+ PoLookupComponent.prototype.getInputWidth = function () {
21113
+ return this.inputEl.nativeElement.offsetWidth - 40;
21114
+ };
21115
+ PoLookupComponent.prototype.getDisclaimersWidth = function () {
21116
+ var disclaimers = this.inputEl.nativeElement.querySelectorAll('po-disclaimer');
21117
+ return Array.from(disclaimers).map(function (disclaimer) { return disclaimer['offsetWidth']; });
21118
+ };
21119
+ PoLookupComponent.prototype.calculateVisibleItems = function () {
21120
+ var disclaimersWidth = this.getDisclaimersWidth();
21121
+ var inputWidth = this.getInputWidth();
21122
+ var extraDisclaimerSize = 38;
21123
+ var disclaimersVisible = disclaimersWidth[0];
21124
+ var newDisclaimers = [];
21125
+ var disclaimers = this.disclaimers;
21126
+ if (inputWidth > 0) {
21127
+ var sum = 0;
21128
+ var i = 0;
21129
+ for (i = 0; i < disclaimers.length; i++) {
21130
+ sum += disclaimersWidth[i];
21131
+ newDisclaimers.push(disclaimers[i]);
21132
+ if (sum > inputWidth) {
21133
+ sum -= disclaimersWidth[i];
21134
+ this.isCalculateVisibleItems = false;
21135
+ break;
21136
+ }
21137
+ }
21138
+ if (disclaimersVisible || !disclaimers.length) {
21139
+ if (i === disclaimers.length) {
21140
+ this.isCalculateVisibleItems = false;
21141
+ return;
21142
+ }
21143
+ if (sum + extraDisclaimerSize > inputWidth) {
21144
+ newDisclaimers.splice(-2, 2);
21145
+ var label = '+' + (disclaimers.length + 1 - i).toString();
21146
+ newDisclaimers.push({ value: '', label: label });
21147
+ }
21148
+ else {
21149
+ newDisclaimers.splice(-1, 1);
21150
+ var label = '+' + (disclaimers.length - i).toString();
21151
+ newDisclaimers.push({ value: '', label: label });
21152
+ }
21153
+ }
21154
+ }
21155
+ this.visibleDisclaimers = __spreadArray([], __read(newDisclaimers));
21156
+ };
20849
21157
  PoLookupComponent.prototype.isAllowedOpenModal = function () {
20850
21158
  if (!this.service) {
20851
21159
  console.warn('No service informed');
@@ -20853,7 +21161,7 @@
20853
21161
  return !!(this.service && !this.disabled);
20854
21162
  };
20855
21163
  PoLookupComponent.prototype.formatFields = function (objectSelected, properties) {
20856
- var e_1, _b;
21164
+ var e_1, _c;
20857
21165
  var formatedField;
20858
21166
  if (Array.isArray(properties)) {
20859
21167
  try {
@@ -20872,7 +21180,7 @@
20872
21180
  catch (e_1_1) { e_1 = { error: e_1_1 }; }
20873
21181
  finally {
20874
21182
  try {
20875
- if (properties_1_1 && !properties_1_1.done && (_b = properties_1.return)) _b.call(properties_1);
21183
+ if (properties_1_1 && !properties_1_1.done && (_c = properties_1.return)) _c.call(properties_1);
20876
21184
  }
20877
21185
  finally { if (e_1) throw e_1.error; }
20878
21186
  }
@@ -20894,22 +21202,29 @@
20894
21202
  this.oldValue = isEmpty ? '' : fieldFormated;
20895
21203
  this.inputEl.nativeElement.value = isEmpty ? '' : fieldFormated;
20896
21204
  };
21205
+ PoLookupComponent.prototype.initializeListeners = function () {
21206
+ var _this = this;
21207
+ this.resizeListener = this.renderer.listen('window', 'resize', function () {
21208
+ _this.updateVisibleItems();
21209
+ });
21210
+ };
20897
21211
  return PoLookupComponent;
20898
21212
  }(PoLookupBaseComponent));
20899
21213
  PoLookupComponent.decorators = [
20900
21214
  { type: i0.Component, args: [{
20901
21215
  selector: 'po-lookup',
20902
- template: "<po-field-container [p-label]=\"label\" [p-help]=\"help\" [p-optional]=\"!required && optional\">\n <div class=\"po-field-container-content\">\n <input\n #inp\n class=\"po-input\"\n type=\"text\"\n [ngClass]=\"clean && inp.value ? 'po-input-double-icon-right' : 'po-input-icon-right'\"\n [autocomplete]=\"autocomplete\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n [required]=\"required\"\n (blur)=\"searchEvent()\"\n />\n\n <div class=\"po-field-icon-container-right\">\n <po-clean *ngIf=\"clean && !disabled\" [p-element-ref]=\"inputEl\" (p-change-event)=\"cleanModel()\"> </po-clean>\n\n <span\n #iconLookup\n class=\"po-icon po-field-icon po-icon-search\"\n tabindex=\"-1\"\n [class.po-field-icon]=\"!disabled\"\n [class.po-field-icon-disabled]=\"disabled\"\n (click)=\"openLookup()\"\n (focus)=\"inp.focus()\"\n >\n </span>\n </div>\n </div>\n\n <po-field-container-bottom></po-field-container-bottom>\n</po-field-container>\n",
21216
+ template: "<po-field-container [p-label]=\"label\" [p-help]=\"help\" [p-optional]=\"!required && optional\">\n <div class=\"po-field-container-content\" *ngIf=\"!disclaimers.length; else disclaimersTemplate\">\n <input\n #inp\n class=\"po-input\"\n type=\"text\"\n [ngClass]=\"clean && inp.value ? 'po-input-double-icon-right' : 'po-input-icon-right'\"\n [autocomplete]=\"autocomplete\"\n [disabled]=\"disabled\"\n [placeholder]=\"placeholder\"\n [required]=\"required\"\n (blur)=\"searchEvent()\"\n />\n\n <div class=\"po-field-icon-container-right\">\n <po-clean *ngIf=\"clean && !disabled\" [p-element-ref]=\"inputEl\" (p-change-event)=\"cleanModel()\"> </po-clean>\n\n <span\n #iconLookup\n class=\"po-icon po-field-icon po-icon-search\"\n tabindex=\"-1\"\n [class.po-field-icon]=\"!disabled\"\n [class.po-field-icon-disabled]=\"disabled\"\n (click)=\"openLookup()\"\n (focus)=\"inp.focus()\"\n >\n </span>\n </div>\n </div>\n <po-field-container-bottom></po-field-container-bottom>\n</po-field-container>\n\n<ng-template #disclaimersTemplate>\n <div class=\"po-field-container-content\">\n <div\n #inp\n [tabindex]=\"disabled ? -1 : 0\"\n class=\"po-input po-input-icon-right po-lookup-input\"\n [class.po-lookup-input-auto]=\"autoHeight\"\n [class.po-lookup-input-static]=\"!autoHeight\"\n [class.po-lookup-input-disabled]=\"disabled\"\n >\n <span *ngIf=\"placeholder && !disclaimers?.length\" class=\"po-lookup-input-placeholder\">\n {{ placeholder }}\n </span>\n\n <po-disclaimer\n *ngFor=\"let disclaimer of visibleDisclaimers\"\n class=\"po-lookup-input-disclaimer\"\n [p-label]=\"disclaimer.label\"\n [p-value]=\"disclaimer.value\"\n [p-hide-close]=\"disclaimer.value === '' || disabled\"\n [class.po-clickable]=\"disclaimer.value === '' && !disabled\"\n (p-close-action)=\"closeDisclaimer(disclaimer.value)\"\n >\n </po-disclaimer>\n </div>\n\n <div class=\"po-field-icon-container-right\">\n <span\n #iconLookup\n class=\"po-icon po-field-icon po-icon-search\"\n tabindex=\"-1\"\n [class.po-field-icon]=\"!disabled\"\n [class.po-field-icon-disabled]=\"disabled\"\n (click)=\"openLookup()\"\n (focus)=\"inp.focus()\"\n >\n </span>\n </div>\n </div>\n</ng-template>\n",
20903
21217
  providers: providers$2
20904
21218
  },] }
20905
21219
  ];
20906
21220
  PoLookupComponent.ctorParameters = function () { return [
21221
+ { type: i0.Renderer2 },
20907
21222
  { type: PoLookupFilterService },
20908
21223
  { type: PoLookupModalService },
20909
21224
  { type: i0.Injector }
20910
21225
  ]; };
20911
21226
  PoLookupComponent.propDecorators = {
20912
- inputEl: [{ type: i0.ViewChild, args: ['inp', { read: i0.ElementRef, static: true },] }]
21227
+ inputEl: [{ type: i0.ViewChild, args: ['inp', { read: i0.ElementRef, static: false },] }]
20913
21228
  };
20914
21229
 
20915
21230
  /**
@@ -35238,6 +35553,12 @@
35238
35553
  * <file name="sample-po-stepper-sales/sample-po-stepper-sales.component.html"> </file>
35239
35554
  * <file name="sample-po-stepper-sales/sample-po-stepper-sales.component.ts"> </file>
35240
35555
  * </example>
35556
+ *
35557
+ * <example name="po-stepper-active" title="PO Stepper - Active">
35558
+ * <file name="sample-po-stepper-active/sample-po-stepper-active.component.html"> </file>
35559
+ * <file name="sample-po-stepper-active/sample-po-stepper-active.component.ts"> </file>
35560
+ * <file name="sample-po-stepper-active/sample-po-stepper-active.service.ts"> </file>
35561
+ * </example>
35241
35562
  */
35242
35563
  var PoStepperComponent = /** @class */ (function (_super) {
35243
35564
  __extends(PoStepperComponent, _super);
@@ -35287,11 +35608,7 @@
35287
35608
  }
35288
35609
  var stepsArray = this.getPoSteps();
35289
35610
  var step = stepsArray[index];
35290
- var isDisabledStep = step.status === exports.PoStepperStatus.Disabled;
35291
- var isErrorStep = step.status === exports.PoStepperStatus.Error;
35292
- if (!isDisabledStep || isErrorStep) {
35293
- this.changeStep(index, step);
35294
- }
35611
+ this.changeStep(index, step);
35295
35612
  };
35296
35613
  /**
35297
35614
  * Ativa o primeiro *step*.
@@ -35354,8 +35671,12 @@
35354
35671
  };
35355
35672
  PoStepperComponent.prototype.onStepActive = function (step) {
35356
35673
  this.currentActiveStep = step;
35357
- this.previousActiveStep = this.poSteps.find(function (stepChild) { return stepChild.status === exports.PoStepperStatus.Active && stepChild.id !== step.id; });
35358
- this.setPreviousStepAsDone();
35674
+ var stepIndex = this.getStepsAndIndex(this.currentActiveStep).stepIndex;
35675
+ this.poSteps.forEach(function (stepChild, i) {
35676
+ if (i < stepIndex) {
35677
+ stepChild.status = exports.PoStepperStatus.Done;
35678
+ }
35679
+ });
35359
35680
  };
35360
35681
  PoStepperComponent.prototype.trackByFn = function (step) {
35361
35682
  return step.id;
@@ -35432,11 +35753,6 @@
35432
35753
  steps[nextIndex].status = exports.PoStepperStatus.Default;
35433
35754
  }
35434
35755
  };
35435
- PoStepperComponent.prototype.setPreviousStepAsDone = function () {
35436
- if (this.previousActiveStep) {
35437
- this.previousActiveStep.status = exports.PoStepperStatus.Done;
35438
- }
35439
- };
35440
35756
  return PoStepperComponent;
35441
35757
  }(PoStepperBaseComponent));
35442
35758
  PoStepperComponent.decorators = [