// vim: set tw=80 ts=2 sw=2 sts=2: import { Component, Inject, ViewChild } from '@angular/core'; import { MdDialogRef, MD_DIALOG_DATA } from '@angular/material'; import { NgbActiveModal } from '@ng-bootstrap/ng-bootstrap'; import { Schedule } from './schedule'; import { ScheduleFormComponent } from './scheduleForm.component'; @Component({ selector: 'schedule-edit-modal', template: `

{{ title() }}

` }) export class ScheduleEditModalComponent { private schedule: Schedule; @ViewChild('scheduleForm') scheduleForm: ScheduleFormComponent; constructor( @Inject(MD_DIALOG_DATA) public data: any, public dialogRef: MdDialogRef, ) { this.schedule = data.schedule; } title(): string { if(this.schedule.id) { return "Schedule #" + this.schedule.id; } else { return "New schedule"; } } submit(): void { let formModel = this.scheduleForm.form.value; let schedule = Object.assign({}, this.schedule); schedule.id = this.schedule.id; schedule.start_date = formModel.startDate; schedule.stop_date = formModel.stopDate; schedule.day = formModel.day; schedule.frequency = formModel.frequency; schedule.label = formModel.label; schedule.value = formModel.value; schedule.category = formModel.category; this.dialogRef.close(schedule); } }