DigitalFormAddTask.cs 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687
  1. using System;
  2. using InABox.Core;
  3. using InABox.Mobile;
  4. using PRSClasses;
  5. namespace PRS.Mobile
  6. {
  7. public class DigitalFormAddTask : MobileButton, IDigitalFormField<DFLayoutAddTaskField, DFLayoutAddTaskFieldProperties, string?, string?>
  8. {
  9. private string? _value;
  10. private DFLayoutAddTaskField? _definition;
  11. public DFLayoutAddTaskField? Definition
  12. {
  13. get => _definition;
  14. set
  15. {
  16. _definition = value;
  17. Initialize(value ?? new DFLayoutAddTaskField());
  18. }
  19. }
  20. public string? Value
  21. {
  22. get => _value;
  23. set
  24. {
  25. _value = value;
  26. UpdateUI();
  27. }
  28. }
  29. public bool IsEmpty => String.IsNullOrWhiteSpace(Value);
  30. private bool _readOnly;
  31. public bool ReadOnly
  32. {
  33. get => _readOnly;
  34. set
  35. {
  36. _readOnly = value;
  37. UpdateStatus();
  38. }
  39. }
  40. public void Deserialize(DFLoadStorageEntry entry)
  41. => Value = Definition?.Properties.DeserializeValue(entry) ?? string.Empty;
  42. public void Serialize(DFSaveStorageEntry entry)
  43. => entry.SetValue(Value);
  44. public event DigitalFormViewChangedHandler? ValueChanged;
  45. public DigitalFormAddTask()
  46. {
  47. Clicked += (s, e) =>
  48. {
  49. // Create or Display the Task Here
  50. };
  51. }
  52. private void Initialize(DFLayoutAddTaskField definition)
  53. {
  54. }
  55. private void UpdateUI()
  56. {
  57. Text = String.IsNullOrWhiteSpace(_value)
  58. ? "Edit"
  59. : _value.Length > 25
  60. ? _value.Substring(0, 25) + "..."
  61. : _value;
  62. }
  63. private void UpdateStatus()
  64. {
  65. IsEnabled = !_readOnly && Definition?.Properties.Secure == false;
  66. var colors = DigitalFormUtils.GetColors(!IsEnabled, Definition?.Properties.Required ?? false, true);
  67. BackgroundColor = colors.Background;
  68. BorderColor = colors.Border;
  69. TextColor = colors.Foreground;
  70. }
  71. }
  72. }