-
Notifications
You must be signed in to change notification settings - Fork 0
/
icesheet.min.js
1 lines (1 loc) · 29 KB
/
icesheet.min.js
1
var app=angular.module("icesheet",["ngNewRouter","ui.bootstrap","ngMessages"]),MenuController=function(){function t(t){this.isActive=function(t){if(t===this.location.path()||""===this.location.path()&&"/"===t)return!0},this.location=t}return t.$inject=["$location"],t}();app.controller("MenuController",MenuController);var RESTService=function(){function t(t,e){this.http=t,this.q=e,this.baseUrl="icesheet/"}return t.prototype.callServer=function(t,e,a,s){var i=this.q.defer();switch(t){case"get":var r=null==a?this.baseUrl+e:this.baseUrl+e+"/"+a;this.http.get(r).then(function(t){return i.resolve(t.data)}).catch(function(t){return i.reject("server error")});break;case"post":this.http.post(this.baseUrl+e,s).then(function(t){return i.resolve(t.data)}).catch(function(t){return i.reject("server error")});break;case"put":this.http.put(this.baseUrl+e,s).then(function(t){return i.resolve(t.data)}).catch(function(t){return i.reject("server error")});break;case"delete":this.http.delete(this.baseUrl+e+"/"+a).then(function(t){return i.resolve(t.data)}).catch(function(t){return i.reject("server error")})}return i.promise},t.$inject=["$http","$q"],t}();app.service("RESTService",RESTService);var RoutesController=function(){function t(t){(this.$router=t).config([{path:"/",redirectTo:"/teams"},{path:"/teams",component:"teams"},{path:"/stats",component:"stats"},{path:"/standings",component:"standings"},{path:"/games",component:"games"},{path:"/game/:gameId",component:"game"}])}return t.$inject=["$router"],t}();app.controller("RoutesController",RoutesController);var GameController=function(){function t(t,e,a,s,i){this.restsvc=t,this.modal=e,this.filter=a,this.location=s,this.windowsvc=i;var r=this.location.path().split("/").filter(function(t){return 0!==t.length&&"game"!==t});r&&0<r.length&&this.loadGame(r[0])}return t.prototype.loadTeams=function(){var e=this,a=this.game.homeTeam?this.game.homeTeam.players:[],s=this.game.visitorTeam?this.game.visitorTeam.players:[];this.teams?(this.game.homeTeam=this.teams.filter(function(t){return t.teamId===e.game.homeTeam.teamId})[0],this.game.visitorTeam=this.teams.filter(function(t){return t.teamId===e.game.visitorTeam.teamId})[0],this.game.homeTeam.players=a,this.game.visitorTeam.players=s):this.restsvc.callServer("get","teams").then(function(t){t&&(e.teams=t,e.players=e.game.homeTeam&&e.game.visitorTeam?e.game.homeTeam.players.concat(e.game.visitorTeam.players):[],e.game.homeTeam=e.game.homeTeam?e.teams.filter(function(t){return t.teamId===e.game.homeTeam.teamId})[0]:e.teams[0],e.game.visitorTeam=e.game.visitorTeam?e.teams.filter(function(t){return t.teamId===e.game.visitorTeam.teamId})[0]:e.teams[1],e.game.homeTeam.players=a,e.game.visitorTeam.players=s)}).catch(function(t){return e.status="Teams not retrieved - error: "+t})},t.prototype.isPlayerOnHomeTeam=function(t){return t.teamid===this.game.homeTeam.teamId},t.prototype.buildGoalLine=function(e){var t="",a=this.game.assists.filter(function(t){return t.goalid===e.goalid}),s=this.players.filter(function(t){return t.playerid===e.player.playerid})[0];if(0<this.players.length&&null!=s){if(t=this.getPlayerTeam(s).name+" - Goal scored by: #"+s.number+" "+s.firstname+" "+s.lastname,0<a.length){t+=" assisted by: ";for(var i=0,r=a.length;i<r;i++)t+=0<i?", and ":"",t+="# "+a[i].player.number+" "+a[i].player.firstname+" "+a[i].player.lastname}else t+=" unassisted";t+=" ("+e.time+", "+this.ordinal_suffix_of(e.period)+")"}return t},t.prototype.buildPenaltyLine=function(e){var t="",a=this.players.filter(function(t){return t.playerid===e.player.playerid})[0];a&&(t+=this.getPlayerTeam(a).name+" - Penalty: #"+a.number+" "+a.firstname+" "+a.lastname+" - "+e.minutes+" minutes for "+e.penalty+" ("+e.time+", "+this.ordinal_suffix_of(e.period)+")");return t},t.prototype.getPlayerTeam=function(t){return this.game.homeTeam.teamId===t.teamid?this.game.homeTeam:this.game.visitorTeam},t.prototype.ordinal_suffix_of=function(t){var e=t%10,a=t%100;return 1==e&&11!=a?t+"st":2==e&&12!=a?t+"nd":3==e&&13!=a?t+"rd":t+"th"},t.prototype.openGameEventModal=function(t,e,a){var s=this,i={templateUrl:"components/game/gameEventModal.html",controller:GameEventModalController.Id+" as ctrlr",resolve:{gameid:function(){return s.game.gameid},player:function(){return t},players:function(){return s.players},goal:function(){return e},penalty:function(){return a},assists:function(){return e?s.game.assists.filter(function(t){return t.goalid===e.goalid}):null}}};this.modal.open(i).result.then(function(t){return s.processGameEventModal(t)}).catch(function(t){return s.status=t})},t.prototype.processGameEventModal=function(t){switch(t.operation){case"create":t.goal&&(this.game.goalToUpdate=t.goal,t.assists?this.createGoal(t.goal,t.assists):this.createGoal(t.goal)),t.penalty&&this.createPenalty(t.penalty);break;case"edit":(t.goal||t.assists)&&(this.game.goalToUpdate=t.goal,this.game.goalToUpdate.player=t.player,this.game.updateAssists=t.assists,this.updateGame()),t.penalty&&(this.game.penaltyToUpdate=t.penalty,this.game.penaltyToUpdate.player=t.player,this.game.goalToUpdate=null,this.game.updateAssists=[],this.updateGame());break;case"delete":t.goal&&this.deleteGoal(t.goal),t.penalty&&this.deletePenalty(t.penalty)}},t.prototype.loadGame=function(t){var e=this;return this.restsvc.callServer("get","game",t).then(function(t){t?(e.game=t,e.game.gameDate=new Date(e.game.gameDate).toISOString().slice(0,10),e.loadTeams(),e.status="Game retreived"):e.status="Game not retrieved"}).catch(function(t){return e.status="Game not retrieved - error: "+t})},t.prototype.startGame=function(){var e=this;return this.restsvc.callServer("post","games",null,this.game).then(function(t){t?(e.status="Game started!",e.location.path("/game/"+t)):e.status="Game not started!"}).catch(function(t){return e.status="Game not created! - "+t})},t.prototype.saveGame=function(){var e=this;return this.restsvc.callServer("put","games",this.game.gameid.toString(),this.game).then(function(t){t?(e.status="Game saved!",e.game=t):e.status="Game not saved!"}).catch(function(t){return e.status="Game not created! - "+t})},t.prototype.updateGame=function(){var e=this;return this.restsvc.callServer("put","game",this.game.gameid.toString(),this.game).then(function(t){t?(e.resetUpdateVariables(),e.game=t,e.status="Game updated"):e.status="Game not updated"}).catch(function(t){return e.status="Game not updated - error: "+t})},t.prototype.createGoal=function(t,a){var s=this;return this.restsvc.callServer("post","goal",null,t).then(function(e){e&&(s.resetUpdateVariables(),a?(a.forEach(function(t){t.goalid=e.goalid,t.gameid=s.game.gameid}),s.createAssists(a)):s.loadGame(s.game.gameid.toString()))}).catch(function(t){return s.status="Goal not created! - "+t})},t.prototype.deleteGoal=function(t){var e=this;return this.restsvc.callServer("delete","goal",t.goalid.toString()).then(function(t){t&&0<t?(e.resetUpdateVariables(),e.loadGame(e.game.gameid.toString())):e.status="Goal not deleted!"}).catch(function(t){return e.status="Goal not deleted! - "+t})},t.prototype.createAssists=function(t){var e=this;return this.restsvc.callServer("post","assists",null,t).then(function(t){t&&(e.resetUpdateVariables(),e.loadGame(e.game.gameid.toString()))}).catch(function(t){return e.status="Goal not created! - "+t})},t.prototype.createPenalty=function(t){var e=this;return this.restsvc.callServer("post","penalties",null,t).then(function(t){t&&(e.resetUpdateVariables(),e.loadGame(e.game.gameid.toString()))}).catch(function(t){return e.status="Penalty not created! - "+t})},t.prototype.deletePenalty=function(t){var e=this;return this.restsvc.callServer("delete","penalties",t.penaltyid.toString()).then(function(t){t&&0<t?(e.resetUpdateVariables(),e.loadGame(e.game.gameid.toString())):e.status="Penalty not deleted!"}).catch(function(t){return e.status="Penalty not deleted! - "+t})},t.prototype.resetUpdateVariables=function(){this.game.updateAssists=this.game.goalToUpdate=this.game.penaltyToUpdate=null},t.prototype.openGameSheet=function(){this.windowsvc.location.href="icesheet/gamesheet?game="+this.game.gameid},t.$inject=["RESTService","$modal","$filter","$location","$window"],t}();app.controller("GameController",GameController);var GameEventModalController=function(){function t(t,e,a){this.modal=t,this.gameid=e,this.player=a,this.timeRegex="^(0[0-9]|1[0-9]|2[0-1]|[0-9]):[0-5][0-9]$",this.periods=[1,2,3],this.minutes=[2,4,5,10],this.penalties=["Slashing","Tripping","Interference","Holding","High-Sticking","Roughing"],a?(this.modalTitle="Edit - ",this.todo="edit"):(this.modalTitle="Create New Game Event",this.todo="create"),this.retVal={operation:"",player:a,goal:null,penalty:null,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.retVal.operation="create",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.edit=function(){this.retVal.operation="edit",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.delete=function(){this.retVal.operation="delete",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.$inject=["$modalInstance","player","gameid"],t.Id="GameEventModalController",t}();app.controller("GameEventModalController",GameEventModalController);GameEventModalController=function(){function t(t,e,a,s,i,r,l){var o=this;if(this.modal=t,this.gameid=e,this.player=a,this.players=s,this.goal=i,this.penalty=r,this.assists=l,this.timeRegex="^(0[0-9]|1[0-9]|2[0-1]|[0-9]):[0-5][0-9]$",this.periods=[1,2,3],this.minutes=[2,4,5,10],this.penalties=["Slashing","Tripping","Interference","Holding","High Sticking","Roughing"],this.modalTitle=(i||r)&&a?"Edit ":"",this.modalTitle+=a.firstname+" "+a.lastname,this.modalTitle+=i?" Goal":r?" Penalty":"",this.todo=(i||r)&&a?"edit":a?"create":"",this.eventType=i&&a?"goal":r&&a?"penalty":"",this.time=i&&a?this.goal.time:r&&a?this.penalty.time:"",this.period=i&&a?this.goal.period:r&&a?this.penalty.period:1,this.assists)switch(l.length){case 1:this.showPrimaryAssist=!0,this.assists[0].player=this.players.filter(function(t){return t.playerid===o.assists[0].player.playerid})[0];break;case 2:this.showPrimaryAssist=!0,this.showSecondaryAssist=!0,this.assists[0].player=this.players.filter(function(t){return t.playerid===o.assists[0].player.playerid})[0],this.assists[1].player=this.players.filter(function(t){return t.playerid===o.assists[1].player.playerid})[0]}else this.assists=[];this.penalty&&(this.penalty.penalty=this.penalties.filter(function(t){return t===o.penalty.penalty})[0]),this.players&&(this.player=this.players.filter(function(t){return t.playerid===o.player.playerid})[0]),this.retVal={operation:"",player:a,goal:null,penalty:null,assists:null,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.setTimeAndPeriod(),this.retVal.operation="create",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.retVal.assists=this.assists,this.modal.close(this.retVal)},t.prototype.edit=function(){this.setTimeAndPeriod(),this.retVal.operation="edit",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.assists=0<this.assists.length?this.assists:null,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.delete=function(){this.retVal.operation="delete",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.setTimeAndPeriod=function(){switch(this.eventType){case"goal":this.goal.time=this.time,this.goal.period=this.period;break;case"penalty":this.penalty.time=this.time,this.penalty.period=this.period}},t.prototype.createGoalClicked=function(){this.modalTitle+=" - Create Goal",this.eventType="goal",this.goal={goalid:null,player:this.player,gameid:this.gameid,period:this.period,time:this.time}},t.prototype.createAssistClicked=function(){var e=this;switch(this.assists.length){case 0:this.showPrimaryAssist=!0;var t={assistid:null,goalid:this.goal.goalid,gameid:this.gameid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t);break;case 1:this.showSecondaryAssist=!0;t={assistid:null,goalid:this.goal.goalid,gameid:this.gameid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.playerid!=e.assists[0].player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t)}},t.prototype.deleteAssist=function(t){"primary"===t?(this.assists=[],this.showPrimaryAssist=!1):(this.assists.pop(),this.showSecondaryAssist=!1)},t.prototype.createPenaltyClicked=function(){this.modalTitle+=" - Create Penalty",this.eventType="penalty",this.penalty={penaltyid:null,gameid:this.gameid,player:this.player,penalty:this.penalties[0],minutes:this.minutes[0],period:this.period,time:this.time}},t.prototype.playerChanged=function(){if(this.modalTitle="Edit ".concat(this.player.firstname+" "+this.player.lastname).concat(this.goal?" Goal":" Penalty"),"goal"===this.eventType)if(this.goal.player.teamid!==this.player.teamid)this.assists=[],this.assists[0],this.showPrimaryAssist=!1,this.showSecondaryAssist=!1;else if(this.assists)switch(this.assists.length){case 1:this.assists[0].player.playerid===this.player.playerid&&(this.assists.pop(),this.showPrimaryAssist=!1);break;case 2:this.assists[1].player.playerid===this.player.playerid&&(this.showSecondaryAssist=!1,this.assists.pop()),this.assists[0].player.playerid===this.player.playerid&&(this.showSecondaryAssist=!1,this.assists[0]=this.assists[1],this.assists.pop())}"penalty"===this.eventType&&this.penalty.player.playerid!==this.player.playerid&&(this.penalty.minutes=2,this.penalty.penalty=this.penalties[0],this.penalty.time=null)},t.$inject=["$modalInstance","gameid","player","players","goal","penalty","assists"],t.Id="GameEventModalController",t}();app.controller("GameEventModalController",GameEventModalController);var GamePlayerModalController=function(){function t(t,e,a,s,i,r,l){var o=this;if(this.modal=t,this.gameid=e,this.player=a,this.players=s,this.goal=i,this.penalty=r,this.assists=l,this.timeRegex="^(0[0-9]|1[0-9]|2[0-1]|[0-9]):[0-5][0-9]$",this.periods=[1,2,3],this.minutes=[2,4,5,10],this.penalties=["Slashing","Tripping","Interference","Holding","High Sticking","Roughing"],this.modalTitle=(i||r)&&a?"Edit ":"",this.modalTitle+=a.firstname+" "+a.lastname,this.modalTitle+=i?" Goal":r?" Penalty":"",this.todo=(i||r)&&a?"edit":a?"create":"",this.eventType=i&&a?"goal":r&&a?"penalty":"",this.time=i&&a?this.goal.time:r&&a?this.penalty.time:"",this.period=i&&a?this.goal.period:r&&a?this.penalty.period:1,this.assists)switch(l.length){case 1:this.showPrimaryAssist=!0,this.assists[0].player=this.players.filter(function(t){return t.playerid===o.assists[0].player.playerid})[0];break;case 2:this.showPrimaryAssist=!0,this.showSecondaryAssist=!0,this.assists[0].player=this.players.filter(function(t){return t.playerid===o.assists[0].player.playerid})[0],this.assists[1].player=this.players.filter(function(t){return t.playerid===o.assists[1].player.playerid})[0]}else this.assists=[];this.penalty&&(this.penalty.penalty=this.penalties.filter(function(t){return t===o.penalty.penalty})[0]),this.players&&(this.player=this.players.filter(function(t){return t.playerid===o.player.playerid})[0]),this.retVal={operation:"",player:a,goal:null,penalty:null,assists:null,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.setTimeAndPeriod(),this.retVal.operation="create",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.retVal.assists=this.assists,this.modal.close(this.retVal)},t.prototype.edit=function(){this.setTimeAndPeriod(),this.retVal.operation="edit",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.assists=this.assists,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.delete=function(){this.retVal.operation="delete",this.retVal.player=this.player,this.retVal.goal=this.goal,this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.setTimeAndPeriod=function(){switch(this.eventType){case"goal":this.goal.time=this.time,this.goal.period=this.period;break;case"penalty":this.penalty.time=this.time,this.penalty.period=this.period}},t.prototype.createGoalClicked=function(){this.modalTitle+=" - Create Goal",this.eventType="goal",this.goal={goalid:null,player:this.player,gameid:this.gameid,period:this.period,time:this.time}},t.prototype.createAssistClicked=function(){var e=this;switch(this.assists.length){case 0:this.showPrimaryAssist=!0;var t={assistid:null,goalid:this.goal.goalid,gameid:this.gameid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t);break;case 1:this.showSecondaryAssist=!0;t={assistid:null,goalid:this.goal.goalid,gameid:this.gameid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.playerid!=e.assists[0].player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t)}},t.prototype.deleteAssist=function(t){"primary"===t?(this.assists=[],this.showPrimaryAssist=!1):(this.assists.pop(),this.showSecondaryAssist=!1)},t.prototype.createPenaltyClicked=function(){this.modalTitle+=" - Create Penalty",this.eventType="penalty",this.penalty={penaltyid:null,gameid:this.gameid,player:this.player,penalty:this.penalties[0],minutes:this.minutes[0],period:this.period,time:this.time}},t.prototype.playerChanged=function(){if(this.modalTitle="Edit ".concat(this.player.firstname+" "+this.player.lastname).concat(this.goal?" Goal":" Penalty"),"goal"===this.eventType&&this.assists)switch(this.assists.length){case 1:this.assists[0].player.playerid===this.player.playerid&&(this.assists.pop(),this.showPrimaryAssist=!1);break;case 2:this.assists[1].player.playerid===this.player.playerid&&(this.showSecondaryAssist=!1,this.assists.pop()),this.assists[0].player.playerid===this.player.playerid&&(this.showSecondaryAssist=!1,this.assists[0]=this.assists[1],this.assists.pop())}},t.$inject=["$modalInstance","gameid","player","players","goal","penalty","assists"],t.Id="GamePlayerModalController",t}();app.controller("GamePlayerModalController",GamePlayerModalController);var GoalModalController=function(){function t(t,e,a,s,i){var r=this;this.modal=t,this.goal=e,this.teams=a,this.players=s,this.assists=i,this.timeRegex="^(0[0-9]|1[0-9]|2[0-1]|[0-9]):[0-5][0-9]$",this.periods=[1,2,3],this.showPrimaryAssist=!1,this.showSecondaryAssist=!1,e?(this.goal=e,this.player=this.players.filter(function(t){return t.playerid===e.player.playerid})[0],this.teams=a,this.team=this.teams.filter(function(t){return t.teamId==r.player.teamid})[0],this.players=s,this.modalTitle="Edit Goal",this.todo="edit",this.assists=i,this.showPrimaryAssist=0<this.assists.length,this.showSecondaryAssist=2==this.assists.length):(this.modalTitle="Create New Goal",this.todo="create",0<a.length&&(this.team=this.teams[0]),this.player=this.players.filter(function(t){return t.teamid==r.team.teamId})[0],this.goal={goalid:null,gameid:null,player:this.player,period:1,time:null},this.assists=[]),this.retVal={operation:"",goal:e,assists:[],status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.retVal.operation="create",this.retVal.goal=this.goal,this.retVal.assists=this.assists,this.modal.close(this.retVal)},t.prototype.edit=function(){this.retVal.operation="edit",this.retVal.goal=this.goal,this.retVal.assists=this.assists,this.modal.close(this.retVal)},t.prototype.delete=function(){this.retVal.operation="delete",this.retVal.goal=this.goal,this.modal.close(this.retVal)},t.prototype.addAssist=function(){var e=this;switch(this.assists.length){case 0:this.showPrimaryAssist=!0;var t={assistid:null,goalid:this.goal.goalid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t);break;case 1:this.showSecondaryAssist=!0;t={assistid:null,goalid:this.goal.goalid,player:this.players.filter(function(t){return t.playerid!==e.goal.player.playerid&&t.playerid!=e.assists[0].player.playerid&&t.teamid===e.goal.player.teamid})[0]};this.assists.push(t)}},t.prototype.deleteAssist=function(t){"primary"===t?(this.assists=[],this.showPrimaryAssist=!1):(this.assists.pop(),this.showSecondaryAssist=!1)},t.prototype.teamChange=function(){var e=this;this.assists=[],this.showPrimaryAssist=!1,this.showSecondaryAssist=!1,this.player=this.players.filter(function(t){return t.teamid==e.team.teamId})[0],this.goal.player=this.player},t.$inject=["$modalInstance","goal","teams","players","assists"],t.Id="GoalModalController",t}();app.controller("GoalModalController",GoalModalController);var PenaltyModalController=function(){function t(t,e,a,s){var i=this;this.modal=t,this.penalty=e,this.teams=a,this.players=s,this.timeRegex="^(0[0-9]|1[0-9]|2[0-1]|[0-9]):[0-5][0-9]$",this.periods=[1,2,3],this.minutes=[2,4,5,10],this.penalties=["Slashing","Tripping","Interference","Holding","High-Sticking","Roughing"],e?(this.penalty=e,this.player=this.players.filter(function(t){return t.playerid===e.player.playerid})[0],this.teams=a,this.team=this.teams.filter(function(t){return t.teamId==i.player.teamid})[0],this.players=s,this.modalTitle="Edit Penalty",this.todo="edit"):(this.modalTitle="Create New Penalty",this.todo="create",0<a.length&&(this.team=this.teams[0]),this.player=this.players.filter(function(t){return t.teamid==i.team.teamId})[0],this.penalty={penaltyid:null,gameid:null,player:this.player,minutes:2,penalty:"",period:1,time:null}),this.retVal={operation:"",penalty:e,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.retVal.operation="create",this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.edit=function(){this.retVal.operation="edit",this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.delete=function(){this.retVal.operation="delete",this.retVal.penalty=this.penalty,this.modal.close(this.retVal)},t.prototype.teamChange=function(){var e=this;this.player=this.players.filter(function(t){return t.teamid==e.team.teamId})[0],this.penalty.player=this.player},t.$inject=["$modalInstance","penalty","teams","players"],t.Id="PenaltyModalController",t}();app.controller("PenaltyModalController",PenaltyModalController);var GameModalController=function(){function t(t,e){this.modal=t,this.game=e,this.action="game",this.modalTitle=e?"Edit Game":"Create Game",this.retVal={operation:"",retPlayer:e,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.switchAction=function(t){this.action=t},t.$inject=["$modalInstance","modalData"],t.Id="GameModalController",t}();app.controller("GameModalController",GameModalController);var GamesController=function(){function t(t,e,a){this.restsvc=t,this.filter=e,this.location=a,this.loadGames()}return t.prototype.loadGames=function(){var e=this;return this.restsvc.callServer("get","games").then(function(t){e.games=t,e.games.forEach(function(t){return t.gameDate=new Date(t.gameDate).toISOString().slice(0,10)}),e.status="Games retreived"}).catch(function(t){return e.status="Games not retrieved - error: "+t})},t.prototype.findPlayer=function(t,e){return t.playerid===e},t.prototype.newGame=function(){this.location.path("/game/-1")},t.prototype.openGame=function(t){var e=t.gameid.toString();this.location.path("/game/"+e)},t.$inject=["RESTService","$filter","$location"],t}();app.controller("GamesController",GamesController);var StandingsController=function(){function t(t,e){this.restsvc=t,this.filter=e,this.loadStandings()}return t.prototype.loadStandings=function(){var e=this;return this.restsvc.callServer("get","standings").then(function(t){e.teams=t,e.sortStandings(5,!1)}).catch(function(t){return e.status="Standings not retrieved - error: "+t})},t.prototype.sortStandings=function(t,e){console.log("sortStandings"),this.teams=this.filter("orderBy")(this.teams,t,e)},t.$inject=["RESTService","$filter"],t}();app.controller("StandingsController",StandingsController);var StatsController=function(){function t(t,e){this.restsvc=t,this.filter=e,this.loadStats()}return t.prototype.loadStats=function(){var e=this;return this.restsvc.callServer("get","stats").then(function(t){e.players=t}).catch(function(t){return e.status="Stats not retrieved - error: "+t})},t.prototype.sortStats=function(t,e){this.players=this.filter("orderBy")(this.players,t,e)},t.$inject=["RESTService","$filter"],t}();app.controller("StatsController",StatsController);var PlayerModalController=function(){function t(t,e){this.modal=t,this.player=e,this.positions=["F","D","G"],this.numberRegex="^(0?[1-9]|[1-9][0-9])$",e?(this.player=e,this.modalTitle="Edit Player - "+this.player.firstname+" "+e.lastname,this.todo="edit"):(this.modalTitle="Create New Player",this.todo="create",this.player={teamid:null,playerid:null,firstname:null,lastname:null,position:"F",shoots:"R",number:null,goals:0,assists:0,pims:0,wins:0,savepercentage:0}),this.retVal={operation:"",retPlayer:e,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.retVal.operation="create",this.retVal.player=this.player,this.modal.close(this.retVal)},t.prototype.edit=function(){this.retVal.operation="edit",this.retVal.player=this.player,this.modal.close(this.retVal)},t.$inject=["$modalInstance","modalData"],t.Id="PlayerModalController",t}();app.controller("PlayerModalController",PlayerModalController);var TeamModalController=function(){function t(t,e){this.modal=t,(this.team=e)?(this.team=e,this.modalTitle="Edit Team - "+e.name,this.todo="edit"):(this.modalTitle="Create New Team",this.todo="create"),this.retVal={operation:"",retTeam:e,status:""}}return t.prototype.cancel=function(){this.retVal.operation="cancel",this.modal.close(this.retVal)},t.prototype.create=function(){this.retVal.operation="create",this.retVal.team=this.team,this.modal.close(this.retVal)},t.prototype.edit=function(){this.retVal.operation="edit",this.retVal.team=this.team,this.modal.close(this.retVal)},t.$inject=["$modalInstance","modalData"],t.Id="TeamModalController",t}();app.controller("TeamModalController",TeamModalController);var TeamsController=function(){function t(t,e,a){this.restsvc=t,this.modal=e,this.filter=a,this.loadTeamsDropdown()}return t.prototype.loadTeamsDropdown=function(){var e=this;return this.restsvc.callServer("get","teams").then(function(t){e.teams=t,null!=e.teams&&(e.team=e.teams[0],e.loadPlayers()),e.status="Teams retreived"}).catch(function(t){return e.status="Teams not retrieved - error: "+t})},t.prototype.loadPlayers=function(){var e=this;return this.restsvc.callServer("get","players",this.team.teamId.toString()).then(function(t){e.players=t,null!=e.players&&(e.player=e.players[0]),e.status="Players retreived"}).catch(function(t){return e.status="Players not retrieved - error: "+t})},t.prototype.teamChange=function(){this.loadPlayers()},t.prototype.openTeamModal=function(t){var e=this,a={templateUrl:"components/teams/teamModal.html",controller:TeamModalController.Id+" as ctrlr",resolve:{modalData:function(){if("edit"==t&&null!=e.team)return e.team}}};this.modal.open(a).result.then(function(t){return e.processTeamModal(t)}).catch(function(t){return e.status=t})},t.prototype.openPlayerModal=function(t){var e=this,a={templateUrl:"components/teams/playerModal.html",controller:PlayerModalController.Id+" as ctrlr",resolve:{modalData:function(){return t}}};this.modal.open(a).result.then(function(t){return e.processPlayerModal(t)}).catch(function(t){return e.status=t})},t.prototype.processTeamModal=function(e){var a=this;switch(e.operation){case"cancel":this.loadTeamsDropdown;break;case"create":return this.restsvc.callServer("post","teams",e.team.teamid,e.team).then(function(t){t&&(e.team.name,a.loadTeamsDropdown())}).catch(function(t){return a.status="Team not created! - "+t});case"edit":var t=[];return t.push(e.team),this.restsvc.callServer("put","teams",null,t).then(function(t){t?t.forEach(function(t){return a.status="Team "+t.name+" not updated!"}):(a.status="Teams updated!",a.loadTeamsDropdown())}).catch(function(t){return a.status="Team Not Updated! - "+t})}this.status=e},t.prototype.processPlayerModal=function(e){var a=this;switch(e.operation){case"cancel":"Player not changed!";break;case"create":return e.player.teamid||(e.player.teamid=this.team.teamId),this.restsvc.callServer("post","players",e.player.playerId,e.player).then(function(t){t&&(e.player.firstName,e.player.lastName,a.loadPlayers())}).catch(function(t){return a.status="Player not created! - "+t});case"edit":return this.restsvc.callServer("put","players",e.player.playerid,e.player).then(function(t){1===parseInt(t,10)&&(e.player.firstName,e.player.lastName,a.loadPlayers())}).catch(function(t){return a.status="Player Not Updated! - "+t})}this.status=e},t.prototype.sortPlayers=function(t,e){console.log("sortPlayers"),this.players=this.filter("orderBy")(this.players,t,e)},t.$inject=["RESTService","$modal","$filter"],t}();app.controller("TeamsController",TeamsController);