SiteForms.xaml.cs 2.3 KB

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