Quintiq file version 2.0
#parent: #root
Method UpdateCheckboxState () id:Method_DialogCreateEditCampaignType_UpdateCheckboxState
{
  #keys: '[143600.0.1238445040]'
  Body:
  [*
    // Update checkbox state based on the default quantity, default min quantity and default max quantity
    
    data := DataHolderDialogData.Data();
    ischeckedmaxqty := EditFieldDefaultMaxQty.ActionLinkText() = Translations::MP_WebDesigner_Disable();
    ischeckedmaxdur := ifexpr( isnull( data.WrappedInstance() ), data.HasInputMaxDuration(), data.WrappedInstance().HasInputMaxDuration() );
    
    // Determine whether campaign type is in duration or quantity
    quantitybased := RadioButtonGroupQuantityDuration.BoundValue().TrimBoth() = GlobalParameters_MP::GetCampaignTransitionsTypeQuantity();
    durationbased := RadioButtonGroupQuantityDuration.BoundValue().TrimBoth() = GlobalParameters_MP::GetCampaignTransitionsTypeDuration();
    
    // Show/hide durations
    PanelMinimumDuration.Visible( durationbased );
    PanelMaximumDuration.Visible( durationbased );
    
    // Show/hide quantity
    PanelMinimumQuantity.Visible( quantitybased );
    PanelMaximumQuantity.Visible( quantitybased );
    
    // Enable/disable
    isMaxQty := quantitybased and ischeckedmaxqty;
    isMaxDur := durationbased and ischeckedmaxdur;
    
    EditFieldDefaultMaxQty.Enabled( quantitybased and ischeckedmaxqty, "Max quantity is not selected" );
    DurationSelectorMaxDuration.Enabled( durationbased and ischeckedmaxdur, "Max duration is not selected" );
    
    // Reset fields values when not applicable
    EditFieldDefaultMinQty.Text( ApplicationMacroPlanner.FormatRealToString( ifexpr( quantitybased, data.DefaultMinQuantity(), 0 ) ) );
    EditFieldDefaultMaxQty.Text( ApplicationMacroPlanner.FormatRealToString( ifexpr( isMaxQty, data.DefaultMaxQuantity(), 0 ) ) );
    DurationSelectorMinDuration.Duration( ifexpr( durationbased, data.DefaultMinDuration(), Duration::Zero() ) );
    DurationSelectorMaxDuration.Duration( ifexpr( isMaxDur, data.DefaultMaxDuration(), Duration::Zero() ) );
  *]
}
