SiteForms.xaml.cs 2.4 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677
  1. using System;
  2. using System.Linq;
  3. using System.Threading.Tasks;
  4. using Comal.Classes;
  5. using InABox.Core;
  6. using InABox.Mobile.Shared;
  7. using Syncfusion.XForms.RichTextEditor;
  8. using Xamarin.Forms;
  9. using Xamarin.Forms.Xaml;
  10. using XF.Material.Forms.UI.Dialogs;
  11. namespace PRS.Mobile
  12. {
  13. [XamlCompilation(XamlCompilationOptions.Compile)]
  14. public partial class SiteForms
  15. {
  16. private JobFormModel _model;
  17. public SiteForms(JobShell job) : base(job)
  18. {
  19. _model = new JobFormModel(App.Data, () => new Filter<JobForm>(x => x.Parent.ID).IsEqualTo(Job.ID));
  20. InitializeComponent();
  21. ProgressVisible = true;
  22. _forms.DataModel = _model;
  23. _forms.AppliesTo = "Job";
  24. _forms.Property = model => _model.Items.OfType<IDigitalFormInstanceShell>().ToArray();
  25. RefreshData(false, true);
  26. }
  27. private void RefreshData(bool force, bool async)
  28. {
  29. if (async)
  30. _model.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshScreen));
  31. else
  32. {
  33. _model.Refresh(force);
  34. RefreshScreen();
  35. }
  36. }
  37. private void RefreshScreen()
  38. {
  39. _forms.Refresh();
  40. ProgressVisible = false;
  41. }
  42. private void AddForm_Clicked(object sender, EventArgs e)
  43. {
  44. var selector = new NewForms() { AppliesTo = _forms.AppliesTo };
  45. selector.ItemSelected += CreateNewForm;
  46. Navigation.PushAsync(selector);
  47. }
  48. private async void CreateNewForm(object sender, NewFormSelectedArgs args)
  49. {
  50. var instance = _model.AddItem();
  51. instance.ParentID = Job.ID;
  52. instance.FormID = args.Form.ID;
  53. instance.FormCode = args.Form.Code;
  54. instance.FormDescription = args.Form.Description;
  55. instance.Save("Created on Mobile Device");
  56. Device.BeginInvokeOnMainThread(() =>
  57. {
  58. _forms.RefreshData(false,false);
  59. _forms.EditForm<Job,JobLink,JobForm>(instance,Job.Entity);
  60. });
  61. }
  62. private void _forms_OnFormTapped(object sender, ExistingFormTappedEventArgs args)
  63. {
  64. ProgressVisible = true;
  65. _forms.EditForm<Job, JobLink, JobForm>(args.Shell, Job.Entity);
  66. ProgressVisible = false;
  67. }
  68. }
  69. }