Quintiq file version 2.0
#parent: #root
Method OnUserUpdateUI () id:Method_DialogEditLaneLegs_OnUserUpdateUI
{
  #keys: '[139394.0.1547080492]'
  Body:
  [*
    // When user check certain checkboxes, we enable disable other checkboxes
    isbatchedit := DataHolderDialogDatas.Data().Size() > 1;
    
    CheckBoxHasUserLeadTime.Enabled( not isbatchedit or CheckboxBatchEditLeadTime.Checked(), '' );
    DurationSelectorLeadTime.Enabled( CheckBoxHasUserLeadTime.Enabled() and CheckBoxHasUserLeadTime.Checked(), '' );
    CheckboxHasStart.Enabled( not isbatchedit or CheckboxBatchEditStart.Checked(), '' );
    CheckboxHasEnd.Enabled( not isbatchedit or CheckboxBatchEditEnd.Checked(), '' );
    DateSelectorStart.Enabled( CheckboxHasStart.Enabled() and CheckboxHasStart.Checked(), '' );
    DateSelectorEnd.Enabled( CheckboxHasEnd.Enabled() and CheckboxHasEnd.Checked(), '' );
    
    // CO2 editfield is disabled when batch edit unchecked and global uom for CO2 is undefined
    hasGlobalCO2Defined := ifexpr( isnull( MacroPlan ), false, MacroPlan.GlobalParameters_MP().DefaultCO2EmissionUoM().Length() > 0 );
    tooltip := ifexpr( hasGlobalCO2Defined, '', Translations::MP_GlobalParameters_CO2GlobalDefined() );
    EditFieldCO2Emission.Enabled( ( not isbatchedit or CheckboxBatchEditCO2Emission.Checked() ) and hasGlobalCO2Defined, tooltip )
    
    // Special handling to update the start end
    // start
    dateTime := DateSelectorStart.Date();
    if( CheckboxHasStart.Checked() )
    {
      DateSelectorStart.Date( ifexpr( dateTime.IsFinite(), dateTime, MacroPlan.Start().Date() ) );
    }
    else
    {
      DateSelectorStart.Date( Date::MinDate() );
    }
    
    // end
    dateTime := DateSelectorEnd.Date();
    if( CheckboxHasEnd.Checked() )
    {
      DateSelectorEnd.Date( ifexpr( dateTime.IsFinite(), dateTime, MacroPlan.End().Date() ) );
    }
    else
    {
      DateSelectorEnd.Date( Date::MaxDate() );
    }
  *]
}
