2018-03-07 11:56:50 +01:00
|
|
|
import {Component, ViewChild} from '@angular/core';
|
|
|
|
import {ActivatedRoute, Router} from '@angular/router';
|
|
|
|
import {NgForm} from '@angular/forms';
|
2018-04-28 10:44:52 +02:00
|
|
|
import {Subscription} from 'rxjs/Subscription';
|
2018-04-29 10:07:20 +02:00
|
|
|
import {Campaign} from '../../../models/model-interfaces';
|
|
|
|
import {CampaignService} from '../../../services/logs/campaign.service';
|
2018-07-17 10:07:12 +02:00
|
|
|
import {SnackBarService} from '../../../services/user-interface/snack-bar/snack-bar.service';
|
2017-09-14 11:47:41 +02:00
|
|
|
|
|
|
|
|
|
|
|
@Component({
|
|
|
|
selector: 'campaign-submit',
|
|
|
|
templateUrl: './campaign-submit.component.html',
|
2018-04-29 10:07:20 +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 = {};
|
|
|
|
|
2018-04-28 10:44:52 +02:00
|
|
|
subscription: Subscription;
|
|
|
|
|
2017-09-14 11:47:41 +02:00
|
|
|
@ViewChild(NgForm) form: NgForm;
|
|
|
|
|
|
|
|
constructor(private route: ActivatedRoute,
|
|
|
|
private router: Router,
|
2018-07-17 10:07:12 +02:00
|
|
|
private campaignService: CampaignService,
|
|
|
|
private snackBarService: SnackBarService) {
|
2018-04-28 10:44:52 +02:00
|
|
|
this.subscription = this.route.params
|
2018-07-17 10:07:12 +02:00
|
|
|
.map(params => params['id'])
|
|
|
|
.filter(id => id !== undefined)
|
|
|
|
.flatMap(id => this.campaignService.getCampaign(id))
|
|
|
|
.subscribe(campaign => {
|
|
|
|
this.campaign = campaign;
|
|
|
|
});
|
2017-09-14 11:47:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
saveCampaign() {
|
|
|
|
this.campaignService.submitCampaign(this.campaign)
|
2018-02-26 09:04:27 +01:00
|
|
|
.subscribe(campaign => {
|
2018-04-28 11:55:58 +02:00
|
|
|
let redirectSuccessUrl = '../overview/';
|
|
|
|
if (this.campaign._id) {
|
2018-04-29 09:51:28 +02:00
|
|
|
redirectSuccessUrl = '../' + redirectSuccessUrl;
|
2018-04-28 11:55:58 +02:00
|
|
|
}
|
2018-10-05 15:51:46 +02:00
|
|
|
this.snackBarService.showSuccess('generic.save.success');
|
2018-04-28 11:55:58 +02:00
|
|
|
this.router.navigate([redirectSuccessUrl + campaign._id], {relativeTo: this.route});
|
2018-02-26 09:04:27 +01:00
|
|
|
},
|
2018-07-17 11:34:32 +02:00
|
|
|
error => this.snackBarService.showError(error._body.error.message, 15000));
|
2017-09-14 11:47:41 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
cancel() {
|
|
|
|
this.router.navigate(['..'], {relativeTo: this.route});
|
|
|
|
return false;
|
|
|
|
}
|
|
|
|
}
|