Quintiq file version 2.0
#parent: MatrixEditorTimeCapacities
Response OnUpdateValue (
  structured[UnitPeriodTime] cell,
  String value,
  String oldvalue
) id:Response_MatrixEditorTimeCapacities_OnUpdateValue_549
{
  #keys: '[136682.1.1060472794]'
  CanBindMultiple: false
  DefinitionID: 'Responsedef_WebMatrixEditor_OnUpdateValue'
  QuillAction
  {
    Body:
    [*
      //Update shift pattern/time unit
      cond := ShiftPattern::GetHasValidShiftPattern( value, MacroPlan ) or PeriodSpecification_MP::GetHasValidTimeUnit( value );
      istimeunit := focusedattribute = typeof( UnitAvailability ).Name() + '.' + attribute( UnitAvailability, TimeUnit ).Name();
      if( cond )
      {
        data := shadow( cell.Element( 0 ).UnitAvailability() );
        if( isnull( data ) )
        {
          data := cell.Element( 0 ).Unit().UnitAvailability( relshadow );
        }
        
        shiftpattern := select( MacroPlan, ShiftPattern, s, s.Name()= value );
        
        UnitAvailability::CreateOrUpdateForUnitPeriodTimes( cell,
                                                            istimeunit,
                                                            ifexpr( istimeunit, value, data.TimeUnit() ),
                                                            data.Maintenance(),
                                                            false,
                                                            data.Efficiency(),
                                                            false,
                                                            data.Allocation(),
                                                            focusedattribute = attribute( UnitPeriodTime, ShiftPatternName ).Name(),
                                                            ifexpr( not isnull( shiftpattern ), shiftpattern, data.ShiftPattern() ),
                                                            false,
                                                            data.MaximumLoadPercentage(),
                                                            false,
                                                            data.NrOfUnitsOpen(),
                                                            false,
                                                            false,
                                                            data.MinimumLoadThreshold()
                                                          ); 
      }
      else
      {
        if( not istimeunit )
        {
          traverse( cell, Elements, e )
          { 
            e.ShiftPatternName( oldvalue );
          }
        }
      }
    *]
    GroupServerCalls: false
  }
}
