Quintiq file version 2.0
#parent: #root
Method InitializeRecurrencePeriod (
  LibCal_RecurrencePeriod recurrencePeriod_i
) id:Method_LibCal_dlgSubscription_InitializeRecurrencePeriod
{
  #keys: '[131094.1.101592847]'
  Body:
  [*
    // Take over the existing period.
    if( not isnull( recurrencePeriod_i ) )
    {
      startDate := recurrencePeriod_i.StartDate();
      datStartOfPeriod.Date( startDate );
      vhStartOfPeriod .Data( startDate );
    
      periodType := recurrencePeriod_i.PeriodType();
      
      // NoEnd
      if( periodType = LibCal_RecurrencePeriod::TYPE_WITHOUTEND() )
      {
        datEndOfPeriod.Enabled( false );
        datEndOfPeriod.Date( startDate );  // Default the EndDate to the StartDate
      }
    
      // NOTE: setting #occurrences is not supported for Subscriptions in the UI.
      //       If type 'NrOfOccurrences' is encountered, which can only be the case in importing data,
      //       the type is initialized here as 'WithEndDate', i.e. only the EndDate is used.
      else if( periodType = LibCal_RecurrencePeriod::TYPE_NROFOCCURRENCES() )
      {
        period := recurrencePeriod_i.astype( LibCal_RecurrencePeriodNrOfOccurrences );
    
        ckbEndOfPeriod.Checked( true );
        datEndOfPeriod.Date( period.EndDate() );
      }
      
      // WithEndDate
      else if( periodType = LibCal_RecurrencePeriod::TYPE_WITHENDDATE() )
      {
        period := recurrencePeriod_i.astype( LibCal_RecurrencePeriodWithEndDate );
    
        ckbEndOfPeriod.Checked( true );
        datEndOfPeriod.Date( period.EndDate() );
      }
    }
    
    // Don't shown the times, they are only for non-recurring events.
    durStartTimeOfDay.Visible( false );
    durEndTimeOfDay  .Visible( false );
  *]
}
