using System; using System.Linq; using System.Linq.Expressions; using System.Text; using System.Threading.Tasks; using InABox.Core; using Xamarin.Forms.Xaml; using XF.Material.Forms.UI.Dialogs; namespace comal.timesheets { [XamlCompilation(XamlCompilationOptions.Compile)] public partial class ExistingForms { private String _currentfilter = ""; public IModel DataModel { get => _model.DataModel; set => _model.DataModel = value; } public String AppliesTo { get => _model.AppliesTo; set => _model.AppliesTo = value; } public Func Property { get => _model.Property; set => _model.Property = value; } // Event to handle new / existing form selection public ExistingForms() { InitializeComponent(); } public void RefreshData(bool force, bool async) { if (async) DataModel.Refresh(force, Refresh); else { DataModel.Refresh(true); Refresh(); } } private void Refresh() { var forms = Property(DataModel); _forms.ItemsSource = forms.Where(FilterShell); } private bool FilterShell(IDigitalFormInstanceShell shell) { if (String.IsNullOrWhiteSpace(_currentfilter)) return true; return shell.Code.ToUpper().Contains(_currentfilter.ToUpper()) || shell.Description.ToUpper().Contains(_currentfilter.ToUpper()); } private void _search_OnTextChanged(object sender, MobileSearchBarTextChangedArgs args) { _currentfilter = args.Text; Refresh(); } private void _digitalforms_OnRefresh(object sender, MobileListRefreshEventArgs args) { RefreshData(true,false); } private void AddForm_Tapped(object sender, EventArgs e) { var selector = new NewForms() { AppliesTo = this.AppliesTo }; selector.ItemSelected += CreateNewForm; Navigation.PushAsync(selector); } private async void CreateNewForm(object sender, NewFormSelectedArgs args) { await MaterialDialog.Instance.AlertAsync("Not Implemented Yet!"); return; } private async void EditForm(object sender, MobileListItemTappedEventArgs args) { await MaterialDialog.Instance.AlertAsync("Not Implemented Yet!"); return; } } }