|
| 1 | +// <copyright> |
| 2 | +// Copyright Southeast Christian Church |
| 3 | + |
| 4 | +// |
| 5 | +// Licensed under the Southeast Christian Church License (the "License"); |
| 6 | +// you may not use this file except in compliance with the License. |
| 7 | +// A copy of the License shoud be included with this file. |
| 8 | +// |
| 9 | +// Unless required by applicable law or agreed to in writing, software |
| 10 | +// distributed under the License is distributed on an "AS IS" BASIS, |
| 11 | +// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. |
| 12 | +// See the License for the specific language governing permissions and |
| 13 | +// limitations under the License. |
| 14 | +// </copyright> |
| 15 | +// |
| 16 | +using System.Linq; |
| 17 | +using Avalanche.Attribute; |
| 18 | +using Avalanche.Models; |
| 19 | +using Rock; |
| 20 | +using Rock.Field; |
| 21 | +using Rock.Field.Types; |
| 22 | +using Rock.Web.Cache; |
| 23 | + |
| 24 | +namespace Avalanche.Field.Converters |
| 25 | +{ |
| 26 | + [ConvertForFieldType( typeof( DefinedValueFieldType ) )] |
| 27 | + |
| 28 | + public class DefinedValueTypeConverter : FieldTypeConverter |
| 29 | + { |
| 30 | + public override FormElementItem Convert( IFieldType fieldType, AttributeCache attribute ) |
| 31 | + { |
| 32 | + |
| 33 | + string INCLUDE_INACTIVE_KEY = "includeInactive"; |
| 34 | + |
| 35 | + |
| 36 | + |
| 37 | + |
| 38 | + var element = new FormElementItem() |
| 39 | + { |
| 40 | + Type = FormElementType.Picker, |
| 41 | + Keyboard = Keyboard.Text, |
| 42 | + }; |
| 43 | + |
| 44 | + var definedTypeValue = attribute.QualifierValues.GetValueOrNull( "definedtype" ); |
| 45 | + var definedType = DefinedTypeCache.Get( definedTypeValue.AsInteger() ); |
| 46 | + if ( definedType != null ) |
| 47 | + { |
| 48 | + var values = definedType.DefinedValues; |
| 49 | + if ( !attribute.QualifierValues.GetValueOrNull( "includeInactive" ).AsBoolean() ) |
| 50 | + { |
| 51 | + values = values.Where( a => a.IsActive ).ToList(); |
| 52 | + } |
| 53 | + |
| 54 | + if ( definedTypeValue != null ) |
| 55 | + { |
| 56 | + element.Options = values.ToDictionary( dv => dv.Value, dv => dv.Guid.ToString() ); |
| 57 | + } |
| 58 | + |
| 59 | + var allowmultiple = attribute.QualifierValues.GetValueOrNull( "allowmultiple" ); |
| 60 | + if ( allowmultiple != null && allowmultiple.AsBoolean() == true ) |
| 61 | + { |
| 62 | + element.Type = FormElementType.CheckboxList; |
| 63 | + } |
| 64 | + } |
| 65 | + |
| 66 | + |
| 67 | + return element; |
| 68 | + } |
| 69 | + } |
| 70 | +} |
0 commit comments