コード例 #1
0
        private void ListItemSelected(object sender, SelectedItemChangedEventArgs e)
        {
            ListView senderLV  = (ListView)sender;
            object   tappedObj = e.SelectedItem;

            //don't allow items to be selected
            senderLV.SelectedItem = null;

            //this will be called again when we clear the SelectedItem, so this is here to skip that call
            if (tappedObj == null)
            {
                return;
            }

            if (senderLV == m_lstMembers && m_permManageMembers)
            { //member list triggered this event
                Member tappedMember = tappedObj as Member;
                //can't manage myself
                if (tappedMember == m_me)
                {
                    return;
                }
                ManageMemberPrompt p = new ManageMemberPrompt();
                if (tappedMember.Role == Role.MEMBER)
                {
                    p.State = ManageMemberPrompt.BtnState.PROMOTE;
                }
                else if (tappedMember.Role == Role.MANAGER)
                {
                    p.State = ManageMemberPrompt.BtnState.DEMOTE;
                }
                p.OnPromote += new EventHandler((o, e2) =>
                {
                    PromoteMemberCommand cmd = new PromoteMemberCommand()
                    {
                        Project = m_proj.ID, Member = tappedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        tappedMember.Role = Role.MANAGER;
                        p.State           = ManageMemberPrompt.BtnState.DEMOTE;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDemote += new EventHandler((o, e2) =>
                {
                    DemoteMemberCommand cmd = new DemoteMemberCommand()
                    {
                        Project = m_proj.ID, Member = tappedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        tappedMember.Role = Role.MEMBER;
                        p.State           = ManageMemberPrompt.BtnState.PROMOTE;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDelete += new EventHandler((o, e2) =>
                {
                    Prompt pc = new Prompt()
                    {
                        PromptTitle = "Are you sure?", PositiveButtonText = "Yes", NegativeButtonText = "No"
                    };
                    pc.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                    {
                        DeleteMemberCommand cmd = new DeleteMemberCommand()
                        {
                            Project = m_proj.ID, Member = tappedMember.ID
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            m_proj.Members.Remove(tappedMember);
                            ReloadProjectDisplay();
                            pc.Dismiss();
                            p.Dismiss();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    });
                    pc.Show(m_mdp);
                });
                p.Show(m_mdp);
            }
            else if (senderLV == m_lstMyTasks)
            { //my tasks list triggered this event
                Models.Task        tappedTask = tappedObj as Models.Task;
                ManageMyTaskPrompt p          = new ManageMyTaskPrompt(tappedTask);
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    //do nothing if nothing was changed
                    if (p.SelectedStatus == tappedTask.Status)
                    {
                        return;
                    }
                    //execute the command to set the task status
                    SetTaskStatusCommand cmd = new SetTaskStatusCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name, Status = p.SelectedStatus.str
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the status and reload the display
                        tappedTask.Status = p.SelectedStatus;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.Show(m_mdp);
            }
            else if (senderLV == m_lstAllTasks && m_permManageTasks)
            { //all tasks list triggered this event
                Models.Task      tappedTask = tappedObj as Models.Task;
                ManageTaskPrompt p          = new ManageTaskPrompt(m_proj);
                p.Date           = tappedTask.Due;
                p.Description    = tappedTask.Description;
                p.Status         = (tappedTask.Assigned == null) ? ManageTaskPrompt.BtnStatus.ASSIGN : ManageTaskPrompt.BtnStatus.DEASSIGN;
                p.AssignedMember = tappedTask.Assigned;
                p.OnAssign      += new EventHandler((o, e2) =>
                {
                    AssignTaskCommand cmd = new AssignTaskCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name, Member = p.AssignedMember.ID
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the dialog
                        p.HidePicker();
                        p.Status = ManageTaskPrompt.BtnStatus.DEASSIGN;
                        //update the task and reload the display
                        tappedTask.Assigned = p.AssignedMember;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDeassign += new EventHandler((o, e2) =>
                {
                    DeassignTaskCommand cmd = new DeassignTaskCommand()
                    {
                        Project = m_proj.ID, Task = tappedTask.Name
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //update the dialog
                        p.Status = ManageTaskPrompt.BtnStatus.ASSIGN;
                        //update the task and reload the display
                        tappedTask.Assigned = null;
                        ReloadProjectDisplay();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnDelete += new EventHandler((o, e2) =>
                {
                    DeleteTaskCommand cmd = new DeleteTaskCommand()
                    {
                        Project = m_proj.ID, Title = tappedTask.Name
                    };
                    cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                    {
                        if ((string)response.GetValue("result") != "success")
                        {
                            DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                            return;
                        }
                        //remove the task from the list
                        m_proj.Tasks.Remove(tappedTask);
                        //reload the display
                        ReloadProjectDisplay();
                        //close the prompt
                        p.Dismiss();
                    });
                    CondorAPI.getInstance().Execute(cmd);
                });
                p.OnPromptSaved += new Prompt.PromptClosedEventListener(() =>
                {
                    //update the due date if changed
                    if (p.Date.ToFileTimeUtc() != tappedTask.Due.ToFileTimeUtc())
                    {
                        SetTaskDueCommand cmd = new SetTaskDueCommand()
                        {
                            Project = m_proj.ID, Task = tappedTask.Name, Due = p.Date
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            //update the due date
                            tappedTask.Due = p.Date;
                            //reload the display
                            ReloadProjectDisplay();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    }
                    //update the description if changed
                    if (p.Description != tappedTask.Description)
                    {
                        SetTaskDescCommand cmd = new SetTaskDescCommand()
                        {
                            Project = m_proj.ID, Task = tappedTask.Name, Description = p.Description
                        };
                        cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) =>
                        {
                            if ((string)response.GetValue("result") != "success")
                            {
                                DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg"));
                                return;
                            }
                            //update the description
                            tappedTask.Description = p.Description;
                            //reload the display
                            ReloadProjectDisplay();
                        });
                        CondorAPI.getInstance().Execute(cmd);
                    }
                });
                p.Show(m_mdp);
            }
        }