File

src/app/sending-money/auto-complete/auto-complete-vm.model.ts

Index

Properties
Methods

Constructor

constructor(template?: Template[])
Parameters :
Name Type Optional
template Template[] yes

Methods

cancel
cancel()
Returns : void
select
select(template: Template)
Parameters :
Name Type Optional
template Template no
Returns : void
setSelected
setSelected()
Returns : void
setTemplates
setTemplates(templates: Template[])
Parameters :
Name Type Optional
templates Template[] no
Returns : void
update
update(updated: Template)
Parameters :
Name Type Optional
updated Template no
Returns : void

Properties

original
original: any
Type : any
selectedId
selectedId: string
Type : string
selectedTemplate
selectedTemplate: Template
Type : Template
templates
templates: Template[]
Type : Template[]
import { Template } from '../../models/template.model';

export class AutoCompleteVm {
  templates: Template[];
  original: any;
  selectedId: string;
  selectedTemplate: Template;

  constructor(template?: Template[]) {
    this.templates = template ? template : new Array<Template>();
  }

  select(template: Template) {
    if (template) {
      this.selectedTemplate = template;
      this.original = JSON.parse(JSON.stringify(template));
    }
  }

  update(updated: Template) {
    if (this.templates === undefined) {
      return;
    }
    this.templates = this.templates.map(template => {
      return template === this.selectedTemplate ? updated : template;
    });
    this.selectedTemplate = null;
  }
  cancel() {
    if (this.templates === undefined) {
      return;
    }
    this.templates = this.templates.map(template => {
      return template.id === this.selectedTemplate.id
        ? this.original
        : template;
    });
    this.selectedTemplate = null;
  }

  setSelected() {
    const found = this.templates.filter(t => t.id === this.selectedId);
    this.selectedTemplate = found.length > 0 ? found[0] : null;
  }

  setTemplates(templates: Template[]) {
    this.templates = templates;
    if (this.selectedId) {
      this.setSelected();
    }
  }
}

results matching ""

    No results matching ""