!(function($,redirect){ /** * @class [NotificationHistoryForm description] * @author Michal.Kunikowski@gtech.com * @author santoshreddy.mogulla@gtech.com * @extends Backbone.View */ portalGGA.views.NotificationHistoryForm = Backbone.View.extend( /** @lends portalGGA.views.NotificationHistoryForm.prototype */{ currentPage : 0, events:{ "click .detailsTriger" : "showNotificationDetails", "click .close" : "closeNotificationDetails", "click .deleteTriger " : "deleteSelectedNotification", "click #deleteNotifications" : "deleteNotifications" }, /** * Rename object (add function identifier) ;) Create own notifications collection if not given * @parma {Object} options * @param {portalGGA.notifications} [options.notifications] notifications collection to be used, if not given new one will be created. * @param {Number} options.size */ constructor: function NotificationHistoryForm( options ){ Backbone.View.apply(this, arguments); this.size = options.size; this.type = options.type; this.priority = options.priority; this.selector = options.selector; this.populate = options.populate; this.successRedirectURL = options.successRedirectURL; this.notifications = options.notifications || new portalGGA.models.player.Notifications(); this.winNotifications = new portalGGA.models.player.LoginNotification(); this.winNotify; this.notificationTemplate = _.template( this.$('.'+this.selector+'ntHistory-resultTemplate').html() ); this.winnotificationTemplate = _.template( this.$('.win-resultTemplate').html() ); this.errorNotifier = new portalGGA.utils.ErrorNotifier( this.$('.errorNotifier') ); if(this.populate) this.submit(); }, /** @returns {Object} serialized search form data */ serialize: function serialize(){ if(this.priority == 0 || this.priority == 1) { var data = {priority: this.priority}; } else{ var data = {}; } return data; }, /** * Submit form or given data if any * @TODO: preloader * @param {Event} [event] * @param {Object} [data] query data if not given, #serialize() will be used. */ submit: function submit( event, data ){ var self = this; event && event.preventDefault(); portalGGA.utils.globalErrorNotifier.clear(); this.winNotifications.url = "/api/v1/second-chance/players/self/notifications?acknowledged=true"; this.winNotifications.fetch() .done(function done(result){ /* result = { "nextPageUrl":null, "previousPageUrl":null, "firstPageUrl":null, "lastPageUrl":null, "pageUrls":null, "nextItems":0, "previousItems":0, "totalItems":3, "currentPage":1, "totalPages":null, "notifications":[ { "notificationId":6859735435504045, "alternate":true, "drawName":"Bingo", "drawDate":1397752708051, "drawClaimByDate":1493870400000, "drawGroupName":"MDR", "prizeDescription":null, "prizePrice":null, "winningTickets":[ "10085861582540000001" ] }, { "notificationId":962028429872080, "alternate":false, "drawName":"Bingo", "drawDate":1397752708051, "drawClaimByDate":1493870400000, "drawGroupName":"MDR", "prizeDescription":"Trip to Tallahassee", "prizePrice":5000, "winningTickets":[ "0120411097917358888", "0120451827264568888", "0120460164978298888" ] } ] }; */ var totalPage=result.totalPages; var currentPage=result.currentPage; self.winNotify = result.notifications; if(currentPage !== totalPage && result.nextPageUrl!==null){ self.winNotifications.url=result.nextPageUrl; self._getNextWinNotifications(); } else{ self._populateWinResults(); } }) .fail(function success(reason){ console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); self.errorNotifier.show(reason,"alert-danger"); return reason; }); this.notifications.fetch( {data: data || this.serialize() , beforeSend: function(xhr){ xhr.setRequestHeader("GK-Cookie", $.cookie("GK_AUTHE")); }} ) .done( $.proxy( this._populateResults, this)) .fail(function success(reason){ console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); self.errorNotifier.show(reason,"alert-danger"); return reason; }); }, _getNextWinNotifications: function _getNextWinNotifications(){ var self=this; self.winNotifications.fetch({cache:false}).done(function success(response){ var totalPage=response.totalPages; var currentPage=response.currentPage; for(var i=0;i"+ row.SUBJECT +""; } }, css: { footer: 'pagination-container pagination-bootgrid', }, templates: { header:"", footer: "
", loading: "
\
\
\
" } }).on("loaded.rs.jquery.bootgrid", function (column, row) { $('.win-table tr').on('click',function(){ $(this).closest('tr').toggleClass('open'); }); $('.detailsWinTriger').on('click',function(event){ self.showWinNotificationDetails(event); }); }); }else{ self.$('.notify-noResults').fadeIn(); } }, _clearPopup: function clearPopup(){ $("#draw_name").html("N/A"); $("#claim_date").html("N/A"); $('#prize_amt').html("N/A"); }, /** * [_populateResults description] * @TODO return something (twytrebowicz) * @TODO scope (twytrebowicz) */ _populateResults: function _populateResults( ){ console.info('_populateResults', this, arguments); var rows = "", table; var self = this; if(self.notifications.length){ for(var not=0; not"+ row.SUBJECT +""; } else { return ""+ row.SUBJECT +""; } }, dateTime: function(col,row){ return ""; } }, css: { footer: 'pagination-container pagination-bootgrid', }, templates: { header:"", footer: "
", loading: "
\
\
\
" } }).on("loaded.rs.jquery.bootgrid", function (column, row) { $('.'+this.selector+'notificationhistory-table tr').on('click',function(){ $(this).closest('tr').toggleClass('open'); }); $('.detailsTriger').on('click',function(event){ self.showNotificationDetails(event); }); }); }else{ self.$('.'+self.selector+'ntHistory-resultsInfo') .fadeOut() .add( self.$('.'+self.selector+'.preloader_big').fadeOut() ) .promise().done(function crossFade(){ self.$('.'+self.selector+'ntHistory-noResults').fadeIn(); }); } }, showWinNotificationDetails: function showWinNotificationDetails(event,data){ var target = $(event.target); var self = this; var id = target.attr("data-uuid"); $(".modal-footer").html('
'); var obj={"subject":"","body":"Loading........", id: id}; var selector = ".notifyModal"; // $(selector).html(_.template($('#winnerNotificationModalTmpl').html())); loading('#notificationModalBody'); // $(selector).find(".modal").modal({backdrop: 'static'}); $("body").append(_.template($('#winnerNotificationModalTmpl').html())); $('#winnerNotificationModal').modal({ keyboard: false, backdrop: 'static' }); var notifArr = self.winNotify; $('#winning_tick_div').html('Your Qualifying Tickets Are:'); self._clearPopup(); var selIndex; for(var i=0; i< notifArr.length; i++){ if(notifArr[i].notificationId == id){ if(notifArr[i].drawGroupName.indexOf("MDR")!= -1 && notifArr[i].alternate == true) $("#winName").html("You're an Alternate Quarterfinalist"); else $("#winName").html("You're a Quarterfinalist"); $('#draw_name').html(notifArr[i].drawName); if(notifArr[i].drawDate != null){ } if(notifArr[i].drawClaimByDate != null) $('#claim_date').html(portalGGA.utils.formattedLongDate(notifArr[i].drawClaimByDate,true)); var winning_tick_len = notifArr[i].winningTickets.length; var winningNumbersValue; for(var j=0; j< winning_tick_len; j++){ if(j%2 ==0 && j == 0) winningNumbersValue=''; winningNumbersValue+= ''+notifArr[i].winningTickets[j]+''; if(j%2 ==0 || j== winning_tick_len-1) winningNumbersValue+=''; } $('#winning_tick_div').append(winningNumbersValue); if(notifArr[i].prizePrice!=null) $('#prize_amt').html(notifArr[i].prizeDescription); if(notifArr[i].drawGroupName.indexOf("MDR")!= -1 && notifArr[i].alternate == true) $('#prize_amt').html("Alternate Quarterfinalist"); selIndex = i; break; } } $('.claim_inst').on("click",function(){ if(notifArr[selIndex].alternate == false) window.open("/en-us/mdr-semifinalist.html"); else window.open("/en-us/mdr-alternate.html"); self._clearPopup(); }); // var textHTML = $('#winnerNotificationModal').html(); $('.print_inst').on("click",function(){ $(".mob-alert-header__close").trigger("click"); $(".modal-footer").html(""); var textHTML = $('.mob-alert-header__message').html(); textHTML += $("#winnerNotificationModalBody").html(); self.printPDF(textHTML); }); $('#notificationModal').on('hidden.bs.modal', function(event) { self.closeNotificationDetails(event); }); }, generatePDF: function generatePDF(printFlag, textHTML) { newWin = window.open('', 'PrintWindow', ''); newWin.document.write(textHTML); newWin.document.close(); newWin.print(); }, printPDF: function printPDF(html) { var self = this; self.generatePDF("true", html); }, /** * Handles showing of modal containing details of given game transaction. * @author hariprasad.pinninti@gtech.com * @TODO return something (hari) */ showNotificationDetails: function showNotificationDetails(event,data){ var target = $(event.target); var self = this; var id = target.attr("data-uuid"); var obj={"subject":"","body":"Loading........", id: id}; var selector = "."+self.selector+"messageModal"; $(selector).html(detailsTemplate(obj)); loading('#notificationModalBody'); $(selector).find(".modal").modal({backdrop: 'static'}); if(id){ this.notifiction = self.notifications.get(id); this.notifiction.fetch({beforeSend: function(xhr){ xhr.setRequestHeader("GK-Cookie", $.cookie("GK_AUTHE")); }}).done(function success(response){ if (response) { // var selector = "."+self.selector+"messageModal"; // $(selector).html(detailsTemplate(response)); // $(selector).find(".modal").modal({backdrop: 'static'}); $("#notificationModal").attr("data-uuid",response.id); $("#notificationModalHeader").html(response.subject); $('#notificationModalBody').html(response.body); $("#templateFooter a").attr("target","_blank"); $('#notificationModal').on('hidden.bs.modal', function(event) { self.closeNotificationDetails(event); }); } }) .fail(function failure(reason){ console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); self.errorNotifier.show(reason,"alert-danger"); return reason; }); } }, /** * Delete the selected notification. * @author santoshreddy.mogulla@gtech.com * @TODO return something (santosh) */ deleteSelectedNotification: function deleteSelectedNotification(event){ portalGGA.utils.globalErrorNotifier.clear(); var target = $(event.target); var self = this; var id = target.attr("data-uuid"); if(id){ self.notification = self.notifications.get(id); self.notification.set("read",true); self.notification.save().done(function success(response){ redirect.send(self.successRedirectURL,{ message:{ code:'notification-delete.success', type:'alert-success' }}); return response; }) .fail(function failure(reason){ console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); portalGGA.utils.globalErrorNotifier.show(reason,"alert-danger"); return reason; }); return false; } }, /** * Delete the checked notifications. * @author santoshreddy.mogulla@gtech.com * @TODO return something (santosh) */ deleteNotifications: function deleteNotifications(event){ var self = this; var searchIDs = $(".panel-default input:checkbox:checked").map(function(){ return { id: $(this).val(), read: true } }).get(); this.notifications.set(searchIDs); this.notifications.save().done(function success(response){ redirect.send(self.successRedirectURL,{ message:{ code:'notifications-delete.success', type:'alert-success' }}); return response; }) .fail(function failure(reason){ reason = $.parseJSON(reason.responseText); portalGGA.utils.globalErrorNotifier.show(reason,"alert-danger"); return reason; }); }, /** * Close modal and send notification acknowledgement. */ closeNotificationDetails: function closeNotificationDetails(event) { var target = $(event.target); var self = this; var id = target.attr("data-uuid"); if(id){ self.notification = self.notifications.get(id); if(self.notification.get("read") == false){ self.notification.set("read",true); self.notification.save(); } } } }); }(jQuery, portalGGA.utils.redirect));