| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141 |
- using System;
- using System.Linq;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- namespace PRS.Mobile
- {
- public class DigitalFormOptionComboBox : Grid, IDigitalFormField<DFLayoutOptionField, DFLayoutOptionFieldProperties, string>
- {
- private readonly MobileCard _labelframe;
- private readonly Label _label;
- private readonly MobileCard _menuframe;
- private readonly MobileMenuButton _menu;
-
- private DFLayoutOptionField _definition;
- public DFLayoutOptionField Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutOptionField());
- }
- }
- private String _value;
- public String Value
- {
- get => _value;
- set
- {
- _value = value;
- _label.Text = String.IsNullOrWhiteSpace(value) ? "Select Value" : value;
- }
- }
- public bool IsEmpty => String.IsNullOrWhiteSpace(Value);
- private bool _readOnly;
- public bool ReadOnly
- {
- get => _readOnly;
- set
- {
- _readOnly = value;
- UpdateStatus();
- }
- }
-
- public void Deserialize(string serialized)
- {
- Value = serialized;
- }
- public string Serialize() => Value;
- public event DigitalFormViewChangedHandler ValueChanged;
- public DigitalFormOptionComboBox()
- {
- HeightRequest = 40;
-
- ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Star });
- ColumnDefinitions.Add(new ColumnDefinition() { Width = GridLength.Auto });
-
- RowDefinitions.Add(new RowDefinition() { Height = GridLength.Star });
- _labelframe = new MobileCard()
- {
- Padding = 5
- };
- Children.Add(_labelframe);
-
- _label = new Label
- {
- Text = "Select Value",
- VerticalTextAlignment = TextAlignment.Center,
- FontSize = Device.GetNamedSize(NamedSize.Small,new Label()),
- Margin = 5
- };
- _labelframe.Content = _label;
- _menuframe = new MobileCard() { Padding = 0 };
- _menuframe.SetValue(Grid.ColumnProperty,1);
- Children.Add(_menuframe);
- _menu = new MobileMenuButton
- {
- WidthRequest = 35,
- Image = ImageSource.FromFile("lines")
- };
- _menuframe.Content = _menu;
- }
- private void Initialize(DFLayoutOptionField definition)
- {
- _menu.Items.Clear();
- foreach (var option in definition.Properties.Options.Replace(",","\n").Split('\n'))
- {
- var item = new MobileMenuItem() { Text = option.Trim() };
- item.Clicked += (sender, args) =>
- {
- Value = item.Text;
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- _menu.Items.Add(item);
- }
-
- if (_menu.Items.Any())
- _menu.Items.Add(new MobileMenuSeparator());
-
- var clear = new MobileMenuItem() { Text = "Clear Value" };
- clear.Clicked += (sender, args) =>
- {
- Value = "";
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- _menu.Items.Add(clear);
- UpdateStatus();
- }
- private void UpdateStatus()
- {
- IsEnabled = !_readOnly || Definition.Properties.Secure;
-
- var labelcolors = DigitalFormUtils.GetColors(!IsEnabled, Definition.Properties.Required, false);
- _labelframe.BackgroundColor = labelcolors.Background;
- _labelframe.BorderColor = labelcolors.Border;
- _label.TextColor = labelcolors.Foreground;
-
- var menucolors = DigitalFormUtils.GetColors(!IsEnabled, Definition.Properties.Required, true);
- _menuframe.BackgroundColor = menucolors.Background;
- _menuframe.BorderColor = menucolors.Border;
-
- }
-
- }
- }
|