| 1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889 |
- using System;
- using InABox.Core;
- using InABox.Mobile;
- namespace PRS.Mobile
- {
- public class DigitalFormStringPopup : MobileButton, IDigitalFormField<DFLayoutStringField, DFLayoutStringFieldProperties, string>
- {
- private DFLayoutStringField _definition;
- public DFLayoutStringField Definition
- {
- get => _definition;
- set
- {
- _definition = value;
- Initialize(value ?? new DFLayoutStringField());
- }
- }
- private string _value;
-
- public string Value
- {
- get => _value;
- set
- {
- _value = value;
- UpdateButtonText(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 DigitalFormStringPopup()
- {
- Clicked += (s, e) =>
- {
- PopupEditor edt = new PopupEditor(Value);
- edt.OnPopupEdtSaved += (text) =>
- {
- Value = text;
- ValueChanged?.Invoke(this, new DigitalFormViewChangedArgs(Definition,Value));
- };
- Navigation.PushAsync(edt);
- };
- }
-
- private void Initialize(DFLayoutStringField definition)
- {
- }
-
- private void UpdateButtonText(string value)
- {
- Text = String.IsNullOrWhiteSpace(value)
- ? "Edit"
- : value.Length > 25
- ? value.Substring(0, 25) + "..."
- : value;
- }
-
- private void UpdateStatus()
- {
- IsEnabled = !_readOnly || Definition.Properties.Secure;
-
- var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition.Properties.Required, true);
- BackgroundColor = colors.Background;
- BorderColor = colors.Border;
- TextColor = colors.Foreground;
- }
- }
- }
|