src/app/sending-money/auto-complete/auto-complete-vm.model.ts
Properties |
Methods |
constructor(template?: Template[])
|
||||||
Parameters :
|
cancel |
cancel()
|
Returns :
void
|
select | ||||||
select(template: Template)
|
||||||
Parameters :
Returns :
void
|
setSelected |
setSelected()
|
Returns :
void
|
setTemplates | ||||||
setTemplates(templates: Template[])
|
||||||
Parameters :
Returns :
void
|
update | ||||||
update(updated: Template)
|
||||||
Parameters :
Returns :
void
|
original |
original:
|
Type : any
|
selectedId |
selectedId:
|
Type : string
|
selectedTemplate |
selectedTemplate:
|
Type : Template
|
templates |
templates:
|
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();
}
}
}