;(function(Draws, _, session){ /** * @class Games * @extends Backbone.View * @requires portalGGA.models.Draws * @view */ portalGGA.views.DidiWinGames = Backbone.View.extend( /** @lends portalGGA.views.DrawResults.prototype */{ /** * Rename object, and render on init. * @author mulleti.satyanarayana@gtech.com * @param {Object} options * @param {portalGGA.models.Draws} [options.draws] Draws collection, if not given new one will be created. * @param {Object} options.betslipLinks Map of betslip links, one per each ESA game name. */ constructor: function DidiWinGames( options ){ Backbone.View.apply(this, arguments); this.gameConfig = $.parseJSON(options.gameConfig); //fetch all games info this.draws = options.draws || new Draws(); this.numberGameDraws = options.numberGameDraws || new Draws(); this.portalGameCode = $.parseJSON(options.portalGameCode); _.bindAll(this, "displayJackpotGames"); this.linkURL = $.parseJSON(options.linkURL); var esaGameName = []; var numberesaGameName = []; var gameConfigTemp = this.gameConfig; _.each(this.portalGameCode,function(gameCode){ var gameConfig = portalGGA.utils.getGameConfigByPortalGameName(gameCode,gameConfigTemp); if(gameConfig){ if(gameConfig.portalGameCode != 'PICK3' && gameConfig.portalGameCode != 'PICK4') { esaGameName.push(gameConfig.esaGameName); } else { numberesaGameName.push(gameConfig.esaGameName); } } }); var self = this; if(esaGameName && esaGameName.length > 0 && numberesaGameName && numberesaGameName.length >0) { this.draws.fetch({ "data":{ "previous-draws": 1, "next-draws": 0, "game-names":esaGameName.toString() }, error: function(reason){ }, success: function(response){ self.numberGameDraws.fetch({ "data":{ "previous-draws": 2, "next-draws": 0, "game-names":numberesaGameName.toString() }, error: function(reason){ }, success: function(response){ self.displayJackpotGames(); self.showOrHideGameTiles(); // self.$('#drawGameJackpots .game-tile').matchHeight(); } }) } }) } else if(esaGameName && esaGameName.length > 0 && numberesaGameName && numberesaGameName.length == 0) { this.draws.fetch({ "data":{ "previous-draws": 1, "next-draws": 0, "game-names":esaGameName.toString() }, error: function(reason){ }, success: function(response){ self.displayJackpotGames(); self.showOrHideGameTiles(); //self.$('#drawGameJackpots .game-tile').matchHeight(); } }) } else if(esaGameName && esaGameName.length == 0 && numberesaGameName && numberesaGameName.length > 0) { this.numberGameDraws.fetch({ "data":{ "previous-draws": 2, "next-draws": 0, "game-names":numberesaGameName.toString() }, error: function(reason){ }, success: function(response){ self.displayJackpotGames(); self.showOrHideGameTiles(); // self.$('#drawGameJackpots .game-tile').matchHeight(); } }) } }, /** * Render all games from collection, bind click. * @author mulleti.satyanarayana@gtech.com * @todo: get only opened? fileter latest? to be discussed with ESA guys (twytrebowicz) * @return {jQuery} #$el */ displayJackpotGames: function displayJackpotGames(){ var self = this, gameConfig; var games = {}; var numberGames = {}; var hasPick3GreenBall = false; var hasPick4GreenBall = false; _.each(self.numberGameDraws.toJSON(), function(game) { gameConfig = portalGGA.utils.getGameConfigByEsaGameName(game.gameName, self.gameConfig); if (game.status == 'CLOSED' && gameConfig.portalGameCode == 'PICK3') { _.each(game.results, function(result) { if (result.drawType.toLowerCase() == "bonus") { hasPick3GreenBall = true; } }); } if (game.status == 'CLOSED' && gameConfig.portalGameCode == 'PICK4') { _.each(game.results, function(result) { if (result.drawType.toLowerCase() == "bonus") { hasPick4GreenBall = true; } }); } }); self.draws.each(function composeDrawsData(draw){ var drawJSON = draw.toJSON(); if(!games[drawJSON.gameName]){ gameConfig = portalGGA.utils.getGameConfigByEsaGameName(drawJSON.gameName, self.gameConfig); if(gameConfig.esaGameName == drawJSON.gameName) { games[drawJSON.gameName] = { linkURL : self.linkURL[gameConfig.portalGameCode], cssName : gameConfig.cssName, imageName : gameConfig.imageName+".svg", gameName : drawJSON.gameName }; } if(gameConfig.portalGameCode == 'MONOPOLY') { games[gameConfig.esaGameName] = { linkURL : self.linkURL[gameConfig.portalGameCode], cssName : gameConfig.cssName, imageName : gameConfig.imageName+".svg", gameName : gameConfig.esaGameName }; } } games[drawJSON.gameName][drawJSON.status] = drawJSON; }); self.numberGameDraws.each(function composeDrawsData(game){ var drawJSON = game.toJSON(); if(!numberGames[drawJSON.gameName]){ gameConfig = portalGGA.utils.getGameConfigByEsaGameName(drawJSON.gameName, self.gameConfig); if(gameConfig.esaGameName == drawJSON.gameName) { numberGames[drawJSON.gameName] = { linkURL : self.linkURL[gameConfig.portalGameCode], cssName : gameConfig.cssName, imageName : gameConfig.imageName+".svg", gameName : drawJSON.gameName, hasGreenBall : (gameConfig.portalGameCode == 'PICK3') ? hasPick3GreenBall : hasPick4GreenBall }; } } numberGames[drawJSON.gameName][(drawJSON.status == 'CLOSED')?drawJSON.status+drawJSON.name:drawJSON.status] = drawJSON; }); self.$('#drawGameJackpots').html(jackpotGamesTemplate({games:games,numberGames:numberGames})); self.$('#drawGameJackpots .game-tile').matchHeight(); return this.$el; }, showOrHideGameTiles : function showOrHideGameTiles() { if(window.location.href.indexOf("didiwin.html") != -1) { $("#dreamsachanceDiv").hide(); $('#drawGameJackpots').append($("#instantgamesDiv").html()); } else if(window.location.href.indexOf("dailygames.html") != -1) { $("#instantgamesDiv").hide(); $('#drawGameJackpots').append($("#dreamsachanceDiv").html()); } else { $("#dreamsachanceDiv").hide(); $("#instantgamesDiv").hide(); } } }); }(portalGGA.models.Draws, _, portalGGA.utils.session))