/** * Returns the player profile page with the submitted info. * * @return The player profile page, which was just created/edited */ @Security.Authenticated(Secured.class) public static Result playerManageSubmit() { // adds the new player from the PlayerForm page to the database. Form<PlayerFormData> data = Form.form(PlayerFormData.class).bindFromRequest(); SearchFormData data2 = new SearchFormData(); Form<SearchFormData> dataForm = Form.form(SearchFormData.class).fill(data2); Page<Player> playerPage = Player.find("name asc", 0); User user = Secured.getUserInfo(ctx()); if (data.hasErrors()) { Map<String, Boolean> playerSkillMap = PlayerFields.getSkill(); Map<String, Boolean> playerPosition = PlayerFields.getPosition(); return badRequest( PlayerForm.render( "Bad Player Form", data, playerSkillMap, playerPosition, Secured.isLoggedIn(ctx()))); } else { PlayerFormData formData = data.get(); if (Player.getPlayer(user.getId()) == null) { // Player.addPlayer(formData); } else { Player.updatePlayer(formData, user.getId()); } return ok( PlayerList.render( playerPage, "PlayerList", dataForm, "none", "none", Secured.isLoggedIn(ctx()), Secured.getUserInfo(ctx()))); } }
/** * Returns the player form page to edit player's profiles. * * @return The player form page */ @Security.Authenticated(Secured.class) public static Result playerManage() { PlayerFormData data2 = new PlayerFormData(); Form<PlayerFormData> dataForm = Form.form(PlayerFormData.class).fill(data2); // Map of players skill levels and positions. // When user selects either their skill or position that skill or position is set as true. Map<String, Boolean> playerSkillMap = PlayerFields.getSkill(); Map<String, Boolean> playerPosition = PlayerFields.getPosition(); Page<Player> playerPage = Player.find("name asc", 1); return ok( PlayerForm.render( "Player Form", dataForm, playerSkillMap, playerPosition, Secured.isLoggedIn(ctx()))); }
@Security.Authenticated(Secured.class) public static Result playerEdit(long id) { PlayerFormData playerData = new PlayerFormData(Player.getPlayer(id)); Form<PlayerFormData> playerFormData = Form.form(PlayerFormData.class).fill(playerData); // Map of players skill levels and positions. // When user selects either their skill or position that skill or position is set as true. Map<String, Boolean> playerSkillMap = PlayerFields.getSkill(); Map<String, Boolean> playerPosition = PlayerFields.getPosition(); return ok( PlayerForm.render( "Player Form", playerFormData, playerSkillMap, playerPosition, Secured.isLoggedIn(ctx()))); }