public MainPage() { InitializeComponent(); MasterPage.ListView.ItemSelected += ListView_ItemSelected; m_lblCurTeam = MasterPage.RootView.FindByName <Label>("txt_cur_team"); m_lblCurUserId = MasterPage.RootView.FindByName <Label>("txt_cur_userid"); m_mnuAdminTitle = MasterPage.RootView.FindByName <StackLayout>("mnu_admin_title"); m_cellMemberPerms = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_perms_table"); m_cellCreateProject = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_create_project"); m_cellLogin = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_login"); m_cellAddr = MasterPage.RootView.FindByName <ClickableStackLayout>("mnu_addr"); //get the config class (will be different based on the platform we built) m_config = ConfigFactory.GetInstance(); //set up the login clicked event listener m_cellLogin.Clicked += (o, e) => { this.IsPresented = false; //hide the sidebar thing if (m_cellLogin.Text == "Logout") { //if logout button, do logout and skip the login actions LogoutCommand cmd = new LogoutCommand(); cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) => { if (((string)response.GetValue("msg") != "" && response.GetValue("msg") != null) || !(bool)response.GetValue("result")) { DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg")); return; } CompleteLogout(); }); CondorAPI.getInstance().Execute(cmd); return; } //execute the login command CredsPrompt p = new CredsPrompt() { PromptTitle = "Login" }; p.OnPromptSaved += new Prompt.PromptClosedEventListener(() => { LoginCommand cmd = new LoginCommand() { Username = p.Username, Password = p.Password }; cmd.OnResponseReceived += new APICommand.ResponseReceivedHandler((response) => { if ((string)response.GetValue("msg") != "" && response.GetValue("msg") != null) { //check if an error was thrown when contacting the server DependencyService.Get <INotification>().ShortAlert("ERROR: " + (string)response.GetValue("msg")); return; } if (response.GetValue("token") == null) { //if token is null then assume the login failed DependencyService.Get <INotification>().ShortAlert("ERROR: Invalid Credentials"); return; } m_config.Token = (string)response.GetValue("token"); CondorAPI.getInstance().Token = m_config.Token; m_myusername = (string)response.GetValue("username"); CompleteLogin(); }); CondorAPI.getInstance().Execute(cmd); }); p.Show(this); }; //set up the server address menu event listener m_cellAddr.Clicked += new EventHandler((o, e) => { this.IsPresented = false; AskServerAddress(); }); //set up the member permissions menu event listener m_cellMemberPerms.Clicked += new EventHandler((o, e) => { ((NavigationPage)Detail).PushAsync(new MemberPermsPage(this)); //hide the sidebar this.IsPresented = false; }); //set up the create project menu event listener m_cellCreateProject.Clicked += new EventHandler((o, e) => { ManageTaskPrompt p = new ManageTaskPrompt(null) { PromptTitle = "Create Project", CanAssign = false, CanDelete = false, CanSetTitle = true, CanSetDate = false, PositiveButtonText = "Create" }; p.OnPromptSaved += new Prompt.PromptClosedEventListener(() => { CreateCommand cmd = new CreateCommand() { Creator = m_myusername, Title = p.TaskTitle, 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; } //add the new project Project newProject = new Project(p.PromptTitle.Replace(' ', '_').ToLower()); newProject.Title = p.PromptTitle; newProject.Description = p.Description; //add the creator as a member of the project Member newProjectCreator = new Member(); newProjectCreator.ID = m_myusername; newProjectCreator.Role = Role.MANAGER; newProject.Members.Add(newProjectCreator); //add the project to the project list m_projects.AppendProject(newProject); //reload the projects list in the sidebar FillProjectsList(); }); CondorAPI.getInstance().Execute(cmd); }); p.Show(this); //hide the sidebar this.IsPresented = false; }); if (m_config.Address != null && !m_config.Address.Equals("")) { //if a server address is specified, initialize the app Initialize(); } else { //otherwise ask for a server address AskServerAddress(); } }