2017-09-14 11:47:41 +02:00
|
|
|
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/campaign-service/campaign.service";
|
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'campaign-submit',
|
|
|
|
templateUrl: './campaign-submit.component.html',
|
2017-10-07 19:32:16 +02:00
|
|
|
styleUrls: ['./campaign-submit.component.css', '../../style/entry-form.css', '../../style/overview.css']
|
2017-09-14 11:47:41 +02:00
|
|
|
})
|
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|