@WidgetComponent

nm-add-content-text-popup

File

src/app/shared/widgets/apps/ipim-content-object/add-content-text/add-content-text-popup.component.ts

Implements

OnDestroy

Metadata

selector nm-add-content-text-popup
styleUrls add-content-text-popup.component.scss
templateUrl ./add-content-text-popup.component.html

Index

Widget inputs
Widget outputs
Properties
Methods

Constructor

constructor(langSwitcherService: LangSwitcherService, currentLocaleService: CurrentLocaleService, dialogRef: MatDialogRef, _widgetFrameService: WidgetframeService, authHttp: HttpClient, _notificationService: NotificationsService, _translateService: TranslateService)
Parameters :
Name Type Optional
langSwitcherService LangSwitcherService no
currentLocaleService CurrentLocaleService no
dialogRef MatDialogRef<AddContentTextPopupComponent> no
_widgetFrameService WidgetframeService no
authHttp HttpClient no
_notificationService NotificationsService no
_translateService TranslateService no

Methods

closePopup
closePopup()
Returns : void
ngOnDestroy
ngOnDestroy()
Returns : void
ngOnInit
ngOnInit()
Returns : void
onExternalModelChange
onExternalModelChange(value: )
Parameters :
Name Optional
value no
Returns : void
saveText
saveText()
Returns : void
updateTypesLocale
updateTypesLocale()
Returns : void

Properties

Public _widgetFrameService
_widgetFrameService: WidgetframeService
Type : WidgetframeService
Public defaultLocale
defaultLocale: string
Type : string
Public dialogRef
dialogRef: MatDialogRef<AddContentTextPopupComponent>
Type : MatDialogRef<AddContentTextPopupComponent>
Public identifier
identifier: string
Type : string
Public isTypesEmpty
isTypesEmpty: boolean
Type : boolean
Default value : false
Public langSwitcherService
langSwitcherService: LangSwitcherService
Type : LangSwitcherService
Public locales
locales: Locale[]
Type : Locale[]
Public text
text: any
Type : any
Public textLocale
textLocale: string
Type : string
Public textOrder
textOrder: any
Type : any
Public textType
textType: any
Type : any
Public textTypes
textTypes: any[]
Type : any[]
Private textTypesUri
textTypesUri: string
Type : string
Public uiLocale
uiLocale: string
Type : string
Private unsubscribe
unsubscribe:
Default value : NgUnsubscribe.create()
Public uri
uri: string
Type : string
import { OnDestroy, Component, OnInit } from "@angular/core";
import { MatDialogRef } from "@angular/material/dialog";
import { NgUnsubscribe } from "../../../../ng-unsubscribe";
import { LangSwitcherService } from "../../../../components/i18n/lang-switcher.service";
import { CurrentLocaleService, Locale } from "../../../../components/i18n";
import { HttpClient, HttpHeaders } from "@angular/common/http";
import { map } from "rxjs/operators";
import { NotificationsService } from "../../../../components/notifications/services/notifications.service";
import { WidgetframeService } from "../../../../widgets/widgetframe/widgetframe.service";
import { TranslateService } from "@ngx-translate/core";
import * as uriTemplates_ from "uri-templates";

const uriTemplates = uriTemplates_;

@Component({
  selector: "nm-add-content-text-popup",
  templateUrl: "./add-content-text-popup.component.html",
  styleUrls: ["./add-content-text-popup.component.scss"],
})
export class AddContentTextPopupComponent implements OnDestroy {
  private unsubscribe = NgUnsubscribe.create();

  public uri: string;
  public identifier: string;
  public textLocale: string;
  public uiLocale: string;
  public textOrder: any;
  public textType: any;
  public text: any;
  public defaultLocale: string;
  public textTypes: any[];
  public locales: Locale[];
  private textTypesUri: string;
  public isTypesEmpty: boolean = false;

  constructor(
    public langSwitcherService: LangSwitcherService,
    private currentLocaleService: CurrentLocaleService,
    public dialogRef: MatDialogRef<AddContentTextPopupComponent>,
    public _widgetFrameService: WidgetframeService,
    private authHttp: HttpClient,
    private _notificationService: NotificationsService,
    private _translateService: TranslateService
  ) {}

  ngOnInit(): void {
    this.langSwitcherService
      .getSupportedLanguages("/api/public/locales?type=ipim&sort=description")
      .subscribe((data: any) => {
        this.locales = data._embedded["locales"];
        this.textLocale = this.locales[0].id;
      });

    this.currentLocaleService.getCurrentLocale().subscribe((local: any) => {
      this.uiLocale = local;
      this.updateTypesLocale();
    });
  }

  onExternalModelChange(value) {
    this.text = value;
  }

  saveText() {
    let body = JSON.stringify([
      {
        locale: this.textLocale,
        order: this.textOrder,
        type: this.textType,
        text: this.text,
      },
    ]);
    let headers = new HttpHeaders();
    headers.append("Content-Type", "application/json");
    headers.append("Accept", "application/json");

    this.authHttp
      .post(this.uri, body, { headers: headers })
      .pipe(map((res) => <any>res))
      .subscribe((response) => {
        if (response.level !== "ERROR") {
          this._notificationService.success(
            this._translateService.instant(response.title),
            this._translateService.instant(response.message)
          );
          this.dialogRef.close(response.level);
        } else {
          this._notificationService.error(
            this._translateService.instant(response.title),
            this._translateService.instant(response.message)
          );
          this.dialogRef.close();
        }
      });
  }

  updateTypesLocale() {
    if (!this.uiLocale) {
      return;
    }

    let textTypesLink = uriTemplates(this.textTypesUri).fill({
      "data-locale": this.uiLocale,
      content: this.identifier,
    });

    this._widgetFrameService.getData(textTypesLink).subscribe((data: any) => {
      if (data._embedded !== undefined) {
        this.textTypes = data._embedded["content-text"];
        this.isTypesEmpty = this.textTypes.length == 0;
      }
    });
  }

  closePopup() {
    this.dialogRef.close();
  }

  ngOnDestroy() {
    this.unsubscribe.destroy();
  }
}
<nm-dialog [dialogRef]="dialogRef" class="nm-dialog">
  <ng-container slot="title">
    {{ "app.iPimContentMGT.frontend.add.text.title" | translate }}
  </ng-container>

  <ng-container slot="content">
    <div class="nm-add-text__form">
      <mat-form-field class="full-width">
        <mat-select
          class="full-width mat-body"
          required
          [(ngModel)]="textLocale"
          (selectionChange)="updateTypesLocale()"
          placeholder="{{ 'table.head.language' | translate }}"
        >
          <mat-option *ngFor="let locale of locales" [value]="locale.id">
            {{ locale.description | translate }}
          </mat-option>
        </mat-select>
      </mat-form-field>

      <mat-form-field>
        <mat-select
          class="full-width"
          [disabled]="isTypesEmpty"
          [value]=""
          #textTypeField="ngModel"
          [(ngModel)]="textType"
          required
          placeholder="{{
            'app.iPimContentMGT.frontend.content-text.type' | translate
          }}"
        >
          <mat-option></mat-option>
          <mat-option *ngFor="let type of textTypes" [value]="type.identifier">
            {{ type.description }}
          </mat-option>
        </mat-select>
      </mat-form-field>
      <mat-error class="customer-error-message" *ngIf="isTypesEmpty">{{
        "app.iPimContentMGT.frontend.error.empty-content-types" | translate
      }}</mat-error>

      <mat-form-field class="full-width">
        <input
          type="number"
          min="0"
          matInput
          [(ngModel)]="textOrder"
          placeholder="{{
            'app.iPimContentMGT.frontend.content-text.order' | translate
          }}"
        />
      </mat-form-field>
    </div>
    <div class="full-width">
      <nm-tiny-text-editor
        (valueChanged)="onExternalModelChange($event)"
        [value]="text"
      >
      </nm-tiny-text-editor>
    </div>
  </ng-container>

  <ng-container slot="actions">
    <button type="button" mat-button (click)="closePopup()">
      {{ "button.cancel" | translate }}
    </button>
    <button
      type="button"
      mat-raised-button
      color="primary"
      [disabled]="!text || !textTypeField.valid || isTypesEmpty"
      (click)="saveText()"
    >
      {{ "button.save" | translate }}
    </button>
  </ng-container>
</nm-dialog>
Legend
Html element
Component
Html element with directive

results matching ""

    No results matching ""