/// <summary>
        /// Adds a button to create new time entries.
        /// </summary>
        private void addCreateNewTimeButton()
        {
            if (null == createNewTimeButton)
            {
                createNewTimeButton = ToolbarHelper.createAddTimeEntryButton();

                createNewTimeButton.Clicked += async(sender, args) =>
                {
                    msdyn_timeentry timeEntry = new msdyn_timeentry();

                    // Create a time entry using the current month and navigate to details page.
                    if (this.viewModel != null)
                    {
                        this.viewModel.DefaultDateFromCurrentFilter(timeEntry);
                    }

                    await NavigateToTimeDetailsView(timeEntry);
                };
            }

            this.ToolbarItems.Add(createNewTimeButton);
        }
Esempio n. 2
0
        protected override void SetToolbarItems()
        {
            base.SetToolbarItems();
            this.setEditableEntryToolbarItems();
            this.setSubmittedEntryToolbarItems();

            // Create new time entry from this page, applicable to all time entries.
            createTimeCommand          = ToolbarHelper.createAddTimeEntryButton();
            createTimeCommand.Clicked += async(sender, args) =>
            {
                if (await this.saveTimeEntry(false))
                {
                    msdyn_timeentry timeEntry       = new msdyn_timeentry();
                    TimeDetailsPage timeDetailsPage = new TimeDetailsPage();

                    this.Navigation.InsertPageBefore(timeDetailsPage, this);
                    await timeDetailsPage.Initialize(new TimeViewModel(timeEntry));

                    await this.Navigation.PopAsync();
                }
            };

            this.ToolbarItems.Add(createTimeCommand);
        }
Esempio n. 3
0
        /// <summary>
        /// Set all the toolbar items required for editable time entries
        /// and removed other unwanted toolbar items.
        /// </summary>
        private void setEditableEntryToolbarItems()
        {
            if (ViewModel.CanEdit())
            {
                // Delete command.
                deleteTimeCommand         = ToolbarHelper.createDeleteButton();
                deleteTimeCommand.Command = new RelayCommandAsync(async() =>
                {
                    // Since the toolbar items cannot be disabled, disable the action if
                    // there is already an action going on in the view model.
                    if (!this.ViewModel.IsBusy)
                    {
                        ViewModel.IsBusy = true;
                        this.setEditabilityOfControls(false);           // Prevent user from being able to edit while submit happens.

                        // Delete the time entry and go back to the caller page, if exists.
                        if (await this.ViewModel.Delete())
                        {
                            MessagingCenter.Send <Page>(this, Message.RefreshMainPage);
                            if (Navigation.NavigationStack.Count > 0)
                            {
                                await Navigation.PopAsync();
                            }
                        }
                        else
                        {
                            // Delete failed so stay on the page and enable controls again.
                            this.setEditabilityOfControls(true);
                        }
                        ViewModel.IsBusy = false;
                    }
                });

                // Save command.
                saveTimeCommand         = ToolbarHelper.createSaveButton();
                saveTimeCommand.Command = new RelayCommandAsync(async() =>
                {
                    await this.saveTimeEntry(true);
                });

                // Submit command.
                submitTimeCommand         = ToolbarHelper.createSubmitButton();
                submitTimeCommand.Command = new RelayCommandAsync(async() =>
                {
                    // Since the toolbar items cannot be disabled, disable the action if
                    // there is already an action going on in the view model.
                    if (!this.ViewModel.IsBusy)
                    {
                        this.ViewModel.IsBusy = true;

                        // Required because the unfocused method (binding) is triggered after submit is completed.
                        // Only if the duration is entered in the correct format do we save.
                        if (BindDurationToViewModel(this.durationEntry))
                        {
                            this.setEditabilityOfControls(false);           // Prevent user from being able to edit while submit happens.

                            // Submit the time entry and go back to the caller page.
                            if (await this.ViewModel.Submit() && this.Navigation.NavigationStack.Count > 0)
                            {
                                MessagingCenter.Send <Page>(this, Message.RefreshMainPage);
                                await this.Navigation.PopAsync();
                            }
                            else
                            {
                                // Submit failed so stay on the page and enable controls again.
                                await MessageCenter.ShowErrorMessage(AppResources.SubmitError);
                                this.setEditabilityOfControls(true);
                            }
                        }

                        // No need to reset editability of controls here since after submit this page is closed.
                        this.ViewModel.IsBusy = false;
                    }
                });

                // Clear the toolbar first to prevent double adding.
                this.ToolbarItems.Clear();
                this.ToolbarItems.Add(submitTimeCommand);
                this.ToolbarItems.Add(saveTimeCommand);
                this.ToolbarItems.Add(deleteTimeCommand);
            }
        }