opt-cc/static/src/app/statistic/campaign-submit/campaign-submit.component.ts

45 lines
1.2 KiB
TypeScript

import {Component, ViewChild} from '@angular/core';
import {ActivatedRoute, Router} from '@angular/router';
import {NgForm} from '@angular/forms';
import {Campaign} from '../../models/model-interfaces';
import {CampaignService} from '../../services/logs/campaign.service';
@Component({
selector: 'campaign-submit',
templateUrl: './campaign-submit.component.html',
styleUrls: ['./campaign-submit.component.css', '../../style/entry-form.css', '../../style/overview.css']
})
export class CampaignSubmitComponent {
campaign: Campaign = {};
showErrorLabel = false;
error;
@ViewChild(NgForm) form: NgForm;
constructor(private route: ActivatedRoute,
private router: Router,
private campaignService: CampaignService) {
}
saveCampaign() {
this.campaignService.submitCampaign(this.campaign)
.subscribe(campaign => {
this.router.navigate(['../overview/' + campaign._id], {relativeTo: this.route});
},
error => {
this.error = error._body.error.message;
this.showErrorLabel = true;
});
}
cancel() {
this.router.navigate(['..'], {relativeTo: this.route});
return false;
}
}