Quintiq file version 2.0
#parent: #root
Method OnOk () id:Method_DialogCreateEditCampaignType_OnOk
{
  #keys: '[139394.0.1555032668]'
  Body:
  [*
    // On ok
    this.ApplyChanges();
    
    data := DataHolderDialogData.Data();
    
    // Manually ApplyChanges for HasInputMaxQuantity and HasInputMaxDuration
    data.HasInputMaxQuantity( EditFieldDefaultMaxQty.ActionLinkText() = Translations::MP_WebDesigner_Disable() );
    data.HasInputMaxDuration( DurationSelectorMaxDuration.ActionLinkText() = Translations::MP_WebDesigner_Disable() );
      
    // New
    if( isnull( data.WrappedInstance() ) )
    {
      newcampaigntype := CampaignType_MP::Create( DropDownListUnit.Data(),
                                                  EditFieldName.Text(),
                                                  data.DefaultMinQuantity(),
                                                  data.DefaultMaxQuantity(),
                                                  data.DefaultMinDuration(),
                                                  data.DefaultMaxDuration(),
                                                  ColorSelectorColor.Color(),
                                                  data.HasInputMaxQuantity() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeQuantity(),
                                                  data.HasInputMaxDuration() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeDuration(),
                                                  false /*isfromdb*/ );
        
      // Access form, select the new campaign type
      DataHolderForm.Data().ListCampaignType().SelectByKey( newcampaigntype.Key() );
    }
    else
    {
      data.WrappedInstance().Update( data.Unit(),
                                     EditFieldName.Text(), // Read-only, apply changes to shadow is not taking place for read-only attribute when editing
                                     RadioButtonGroupQuantityDuration.BoundValue(),
                                     data.DefaultMinQuantity(),
                                     data.DefaultMaxQuantity(),
                                     data.DefaultMinDuration(),
                                     data.DefaultMaxDuration(),
                                     ColorSelectorColor.Color(),
                                     data.HasInputMaxQuantity() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeQuantity(),
                                     data.HasInputMaxDuration() and RadioButtonGroupQuantityDuration.BoundValue() = GlobalParameters_MP::GetCampaignTransitionsTypeDuration(),
                                     false /*isfromdb*/ );                               
    }
    this.Close();
  *]
}
