UNPKG

sportsbet-mobile

Version:
103 lines (85 loc) 3.35 kB
///<reference path=".#ts/client.d.ts" /> interface Templates { lotteryBox: Template; } Template.lotteryBox.helpers({ counterTime: function(){ var diff = moment((<Lotteries.LotteryInstance>this).drawDate).diff(moment(), 'seconds'); if(diff <= 0) return; counterApi.dep.depend(); var days = Math.floor(diff / 86400); var hours = Math.floor((diff - days * 86400) / 3600); var minutes = Math.floor((diff - days * 86400 - hours * 3600) / 60); var seconds = Math.floor((diff - days * 86400 - hours * 3600 - minutes * 60)); if(days>0) return days + ' Days ' + ([1e2]+''+hours).slice(-2) + ':' + ([1e2]+''+minutes).slice(-2) + '<b>:' + ([1e2]+''+seconds).slice(-2) + '</b>'; if(hours>0) return hours + ' Hours ' + ([1e2]+''+minutes).slice(-2) + '<b>:' + ([1e2]+''+seconds).slice(-2) + '</b>'; if(minutes>0) return minutes + ' Minutes <b>' + ([1e2]+''+seconds).slice(-2) + '</b>'; return seconds + ' seconds'; }, totalPrizePool: function(){ var totalPrize = 0; var prefix = ' m฿'; if((<Lotteries.LotteryInstance>this).prizePoolType == Lotteries.PrizePoolType.FIXED) { totalPrize = (<Lotteries.LotteryInstance>this).prizePool; }else{ (<Lotteries.LotteryInstance>this).prize.forEach(function (p) { //if (p.type == Lotteries.PrizeType.MONETARY) totalPrize += p.amount; }); } if(totalPrize>=100000 && totalPrize<100000000 ) { totalPrize = Math.round(totalPrize / 100) /10; prefix = ' ' } else if(totalPrize>=100000000) { totalPrize = Math.round(totalPrize / 100000) /10; prefix = ' K฿' } return totalPrize + prefix; //return totalPrize.toFixed(2).replace(/(\d)(?=(\d{3})+\.)/g, '$1,') + prefix; }, usableTickets: function(){ return Session.get('usableTickets'); }, showHistory: function () { return Session.get('showHistory'); }, totalTickets: function(){ var self = <Lotteries.LotteryInstance>this; Meteor.call('lotteries-admin/Tickets/total', {lotteryInstance: self._id}, function (err, res) { Session.set('totalTickets'+self._id, res); }); return Session.get('totalTickets'+self._id); }, ticketsOwned: function(){ return Lotteries.Ticket.db.find({lotteryInstance: (<Lotteries.LotteryInstance>this)._id}).count(); }, logoUrl: function(){ if((<Lotteries.LotteryInstance>this).logoSmallUrl) return (<Lotteries.LotteryInstance>this).logoSmallUrl; if((<Lotteries.LotteryInstance>this).locked) return cdnUrl + 'images/lottery/icon-vip.png'; if((<Lotteries.LotteryInstance>this).isLotto) return cdnUrl + 'images/lottery/icon-lotto.png'; if((<Lotteries.LotteryInstance>this).isRaffle) return cdnUrl + 'images/lottery/icon-raffle.png'; } }); Template.lotteryBox.events({ 'click .buyTicket': function(e){ e.stopPropagation(); Session.set('opened-modal', 'buyTicketModal'); Modals.open('buyTicketModal', this); }, 'click .useTicket': function(e){ e.stopPropagation(); Session.set('opened-modal', 'useTicketModal'); Modals.open('useTicketModal', this); }, 'click .fillTicket': function(e){ e.stopPropagation(); Session.set('opened-modal', 'fillTicketModal'); Modals.open('fillTicketModal', this.tickets.fetch({numbers: {$exists: false}})[0]); }, 'click .lottery-box': function(){ Pages.go('/lotteries/'+this.handle+'/'+(this.drawn?'history/'+this._id:'')); } }); Template.lotteryBox.created = function () { };