using System; using System.Linq; using Comal.Classes; using InABox.Core; using Xamarin.Forms; using Xamarin.Forms.Xaml; namespace PRS.Mobile { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class SiteForms { private JobFormModel _model; public SiteForms(JobShell job) : base(job) { _model = new JobFormModel(App.Data, () => new Filter(x => x.Parent.ID).IsEqualTo(Job.ID)); InitializeComponent(); ProgressVisible = true; Title = job?.DisplayName ?? "Site Forms"; _forms.DataModel = _model; _forms.AppliesTo = "Job"; _forms.Property = model => _model.Items.OfType().ToArray(); RefreshData(false, true); } private void RefreshData(bool force, bool async) { if (async) _model.Refresh(force, () => Device.BeginInvokeOnMainThread(RefreshScreen)); else { _model.Refresh(force); RefreshScreen(); } } private void RefreshScreen() { _forms.Refresh(); ProgressVisible = false; } private void AddForm_Clicked(object sender, EventArgs e) { var selector = new NewForms() { AppliesTo = _forms.AppliesTo }; selector.ItemSelected += CreateNewForm; Navigation.PushAsync(selector); } private async void CreateNewForm(object sender, NewFormSelectedArgs args) { var instance = _model.AddItem(); instance.ParentID = Job.ID; instance.FormID = args.Form.ID; instance.FormCode = args.Form.Code; instance.FormDescription = args.Form.Description; instance.Save("Created on Mobile Device"); Device.BeginInvokeOnMainThread(() => { _forms.RefreshData(false,false); _forms.EditForm(instance,Job.Entity); }); } private void _forms_OnFormTapped(object sender, ExistingFormTappedEventArgs args) { ProgressVisible = true; _forms.EditForm(args.Shell, Job.Entity); ProgressVisible = false; } } }