/** Angular Imports */ import { Component , ViewChild } from '@angular/core' ; import { ActivatedRoute , Router } from '@angular/router' ; import { DatePipe } from '@angular/common' ; /** Custom Services */ import { OrganizationService } from 'app/organization/organization.service' ; import { SettingsService } from 'app/settings/settings.service' ; /** Custom Components */ import { CampaignMessageStepComponent } from '../sms-campaign-stepper/campaign-message-step/campaign-message-step.component' ; /**
 * Edit Campaign Component
 */ @ Component ( { selector : 'mifosx-edit-campaign' , templateUrl : './edit-campaign.component.html' , styleUrls : [ './edit-campaign.component.scss' ] } ) export class EditCampaignComponent { /** smsCampaign */ smsCampaign : any ; /** SMS Campaign Template */ smsCampaignTemplate : any ; /** Run report headers */ templateParameters : any ; /** Campaign Message Step */ @ ViewChild ( CampaignMessageStepComponent , { static : true } ) campaignMessageStep : CampaignMessageStepComponent ; param { ActivatedRoute } route param { Router } router param { DatePipe } datePipe param { OrganizationService } organizationService param { SettingsService } settingsService constructor ( private route , private router , private datePipe , private organizationService , private settingsService ) { this . route . data . subscribe ( ( data ) => { this . smsCampaignTemplate = data . smsCampaignTemplate ; this . smsCampaign = data . smsCampaign ; this . smsCampaign . editFlag = true ; } ) ; } /**
     * Retrieves edited campaign message.
     */ get campaignMessage ( ) { return this . campaignMessageStep . campaignMessage . message ; } param { any } $event setParameters ( $event ) { this . templateParameters = $event ; } /**
     * Updates SMS Campaign.
     */ submit ( ) { const locale = this . settingsService . language . code ; const dateFormat = this . settingsService . dateFormat ; const dateTimeFormat = 'dd MMMM yyyy HH:mm:ss' ; const smsCampaign = { campaignName : this . smsCampaign . campaignName , campaignType : this . smsCampaign . isNotification ? 2 : 1 , isNotification : this . smsCampaign . isNotification , triggerType : this . smsCampaign . triggerType . id , providerId : this . smsCampaign . providerId === 0 ? null : this . smsCampaign . providerId , runReportId : this . smsCampaign . runReportId , message : this . campaignMessage , paramValue : JSON . parse ( this . smsCampaign . paramValue ) , dateTimeFormat , dateFormat , locale } ; if ( this . smsCampaign . triggerType . id === 2 ) { smsCampaign . recurrenceStartDate = this . datePipe . transform ( new Date ( this . smsCampaign . recurrenceStartDate ) , dateTimeFormat ) ; } this . organizationService . updateSmsCampaign ( smsCampaign , this . smsCampaign . id ) . subscribe ( ( response ) => { this . router . navigate ( [ '../' ] , { relativeTo : this . route } ) ; } ) ; } }