| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249 |
- using System;
- using System.Linq;
- using Comal.Classes;
- using InABox.Core;
- using InABox.Mobile;
- using Xamarin.Forms;
- using Xamarin.Forms.Xaml;
- using XF.Material.Forms.UI.Dialogs;
- using PRSSecurity = InABox.Core.Security;
- namespace PRS.Mobile
- {
-
- [XamlCompilation(XamlCompilationOptions.Compile)]
- public partial class AssignmentEditDetailsView
- {
-
- public AssignmentEditDetailsView()
- {
- InitializeComponent();
- }
- public override void Refresh()
- {
- bool open = ViewModel.Item.Completed.IsEmpty();
- Completed.Text = open
- ? "Complete"
- : Security.CanEdit<Assignment>() ? "Re-Open" : $"Completed {ViewModel.Item.Completed:dd/MM/yy}";
- Subject.IsEnabled = open && PRSSecurity.CanEdit<Assignment>();
- BookedStart.IsEnabled = open && PRSSecurity.IsAllowed<CanEditAssignmentBookings>();
- BookedFinish.IsEnabled = open && PRSSecurity.IsAllowed<CanEditAssignmentBookings>();
- ActualStart.IsEnabled = open && PRSSecurity.IsAllowed<CanEditAssignmentActualTimes>();
- ActualFinish.IsEnabled = open && PRSSecurity.IsAllowed<CanEditAssignmentActualTimes>();
- //AsBookedBtn.IsEnabled = open && PRSSecurity.IsAllowed<CanEditAssignmentActualTimes>();
- Job.IsEnabled = open && PRSSecurity.CanEdit<Assignment>();
- Task.IsEnabled = open && PRSSecurity.CanEdit<Assignment>();
- Activity.IsEnabled = open && PRSSecurity.CanEdit<Assignment>();
- Description.IsEnabled = open && PRSSecurity.CanEdit<Assignment>();
- Completed.IsEnabled = open || PRSSecurity.CanEdit<Assignment>();
- }
- private void Activity_Clicked(object sender, EventArgs e)
- {
- ShowPopup(() => CreateActivitySelection("Select Activity", (activity) =>
- {
- ViewModel.Item.ActivityID = activity.ID;
- ViewModel.Item.ActivityCode = activity.Code;
- ViewModel.Item.ActivityDescription = activity.Description;
- DoChanged("ActivityID");
- }));
- }
- private View CreateActivitySelection(String caption, Action<ActivityShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<ActivityShell>() { Column = x => x.Code, Width = GridLength.Auto })
- .Add(new MobileGridTextColumn<ActivityShell>()
- {
- Column = x => x.Description, Width = GridLength.Star, Caption = caption,
- Alignment = TextAlignment.Start
- })
- .EndUpdate();
- };
- selection.Refresh += (sender, args) =>
- {
- App.Data.Activities.Refresh(false);
- return App.Data.Activities.Search((x=>x.IsLeave == false));
- };
-
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as ActivityShell);
- DismissPopup();
- };
- selection.Load();
- return selection;
- }
- private void SelectJob_Clicked(object sender, EventArgs e)
- {
- ShowPopup(
- () => CreateJobSelection("Select Job", (job) =>
- {
- ViewModel.Item.JobID = job.ID;
- ViewModel.Item.JobNumber = job.JobNumber;
- ViewModel.Item.JobName = job.Name;
- ViewModel.Item.Latitude = job.Location.Latitude;
- ViewModel.Item.Longitude = job.Location.Longitude;
- DoChanged("JobID");
- })
- );
- }
-
- private View CreateJobSelection(String caption, Action<JobShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill,
- CanSearch = true
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.JobNumber, Width = GridLength.Auto, Caption = "#"})
- .Add(new MobileGridTextColumn<JobShell>() { Column = x=>x.Name, Width = GridLength.Star, Caption = caption, Alignment = TextAlignment.Start})
- .EndUpdate();
- args.Filters.AddRange(App.Data.Jobs.AvailableFilters().Where(x=> x != null).Select(x=>x.Name));
- };
- selection.Refresh += (sender, args) =>
- {
- var result = App.Data.Jobs.Refresh(args.Force);
- args.LastUpdated = App.Data.Jobs.LastUpdated;
- return result;
- };
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as JobShell);
- DismissPopup();
- };
- selection.Load();
- return selection;
- }
- private void Task_Clicked(object sender, EventArgs e)
- {
- ShowPopup(() => CreateTaskSelection("Select Task", (kanban) =>
- {
- ViewModel.Item.TaskID = kanban.ID;
- ViewModel.Item.TaskNumber = kanban.Number;
- ViewModel.Item.TaskName = kanban.Title;
- DoChanged("TaskID");
- }));
- }
-
- private View CreateTaskSelection(String caption, Action<KanbanShell> selected)
- {
- SelectionView selection = new SelectionView
- {
- VerticalOptions = LayoutOptions.Fill,
- HorizontalOptions = LayoutOptions.Fill
- };
- selection.Configure += (sender, args) =>
- {
- args.Columns
- .BeginUpdate()
- .Clear()
- .Add(new MobileGridIntegerColumn<KanbanShell>() { Column = x=>x.Number, Width = GridLength.Auto, Caption = "#"})
- .Add(new MobileGridTextColumn<KanbanShell>() { Column = x=>x.Title, Width = GridLength.Star, Caption = caption, Alignment = TextAlignment.Start})
- .EndUpdate();
- };
- selection.Refresh += (sender, args) => App.Data.Kanbans.Refresh(false);
- selection.SelectionChanged += (sender, args) =>
- {
- selected(args.SelectedItems.FirstOrDefault() as KanbanShell);
- DismissPopup();
- };
- selection.Load();
- return selection;
- }
- private async void Complete_Clicked(object sender, EventArgs e)
- {
- if (!ViewModel.Item.Completed.IsEmpty())
- {
- ViewModel.Item.Completed = DateTime.MinValue;
- ViewModel.Item.Save("Re-opened on Mobile Device");
- Refresh();
- return;
- }
- bool bOpenForms = ViewModel.Forms.Any(x => x.Completed.IsEmpty());
- if (bOpenForms)
- {
- await MaterialDialog.Instance.AlertAsync("Please finish all open forms before completing this assignment", "Open Forms Found");
- return;
- }
- bool bConfirm = await MaterialDialog.Instance.ConfirmAsync(message: "Complete Assignment?",
- confirmingText: "Yes",
- dismissiveText: "No") == true;
- if (bConfirm)
- {
- ViewModel.Item.Completed = DateTime.Now;
- ViewModel.Item.Save("Completed on Mobile Device");
- Navigation.PopAsync();
- }
- }
- private void Description_OnTextChanged(object sender, TextChangedEventArgs e)
- {
- if (Description.IsFocused)
- DoChanged("Description");
- }
- private void Subject_OnTextChanged(object sender, TextChangedEventArgs e)
- {
- if (Subject.IsFocused)
- DoChanged("Subject");
- }
-
- private void BookedStart_OnChanged(object sender, TimeButtonChangedArgs args)
- {
- DoChanged("BookedStart");
- if (ViewModel.Item.BookedStart > ViewModel.Item.BookedFinish)
- {
- ViewModel.Item.BookedFinish = ViewModel.Item.BookedStart;
- DoChanged("BookedFinish");
- }
- }
- private void ActualStart_OnChanged(object sender, TimeButtonChangedArgs args)
- {
- DoChanged("ActualStart");
- if (ViewModel.Item.ActualStart > ViewModel.Item.ActualFinish)
- {
- ViewModel.Item.ActualFinish = ViewModel.Item.ActualStart;
- DoChanged("ActualFinish");
- }
- }
- private void BookedFinish_OnChanged(object sender, TimeButtonChangedArgs args)
- {
- if (ViewModel.Item.BookedStart > ViewModel.Item.BookedFinish)
- ViewModel.Item.BookedFinish = ViewModel.Item.BookedStart;
- DoChanged("BookedFinish");
- }
- private void ActualFinish_OnChanged(object sender, TimeButtonChangedArgs args)
- {
- if (ViewModel.Item.ActualStart > ViewModel.Item.ActualFinish)
- ViewModel.Item.ActualFinish = ViewModel.Item.ActualStart;
- DoChanged("ActualFinish");
- }
- }
- }
|