!(function($,redirect){ /** * @class Model of My Submissions form * @view * @author santoshreddy.mogulla@gtech.com * @author hariprasad.pinninti@gtech.com * @requires portalGGA.models.MySubmissions * @requiresDOM .mySubmissions-results, .mySubmissions-noResults, .mySubmissions-query */ portalGGA.views.MySubmissionsView = Backbone.View.extend( /** @lends portalGGA.views.MySubmissionsView.prototype */{ events:{ "click .detailsTriger" : "showSCPlayerDrawDetails", "click .pagination a" : "changePage", "submit" : "submit", "click .deleteSubmission" : "deleteConfirmation", //"click .deleteSubmission" : "deleteSubmission", "click .sortable" : "sortData" }, /** * Rename object (add function identifier) ;) Create own transactions collection if not given * @author santoshreddy.mogulla@gtech.com * @param {Object} options * @param {portalGGA.MySubmissions} [options.MySubmissions] MySubmissions collection to be used, if not given new one will be created. * @param {Boolean} [options.populate=false] Should table be populated by default? */ constructor: function MySubmissionsView( options ){ Backbone.View.apply(this, arguments); this.groupName = options.groupName; this.successRedirectURL = options.successRedirectURL; this.MySubmissions = options.MySubmissions || new portalGGA.MySubmissions(); this.allSCDrawsForDropdown = options.SCDrawsSubmissions || new portalGGA.SCDrawsSubmissions(); this.games=[]; this.mdrGames = new portalGGA.EligibleMDRGames(); this.SCPlayerDrawTemplate = _.template( this.$('.mySubmissions-transactionTemplate').html() ); this.SCMySubmissionsHeaderTemplate = _.template( this.$('.mySubmissions-transactionHeader').html() ); this.SCDrawNamesTemplate = _.template( this.$('.drawNames-Template').html() ); this.drawNamesForSubmission = []; this.specyficErrorNotifier = new portalGGA.utils.ErrorNotifier(this.$(".mySubmissions-error")); this.getGames(); this._getMDRGames(); this.mdrgamesArray=[]; this.getMonthlySubmission(); this.gameNames = []; this.sortField = "DATE_SUBMITTED"; this.sortType = "desc"; this.fieldsMap = { 'DATE_SUBMITTED' : 'dateSubmitted' }, _.bindAll(this, "_populateHeader", "_populateResults", "_populatePagination", "_populateDropdown", "_handleFailure","getFilters", "deleteSubmission"); if(options.populate) { this._populateDropdown(); this.$('.preloader_big').hide(); // this.submit(); } }, /** * Retrieve games * @TODO: error handling * @param {Event} [event] * @param {Object} [data] query data if not given, #serialize() will be used. * @returns {Q.promise} [description] */ getGames: function getGames(){ var self =this; $.ajax({ url: '/api/v1/second-chance/games?group-name=MDR', type: 'GET', success: function(result) { self.games=result.games; }, error: function(reason) { reason = $.parseJSON(reason.responseText); } }); }, getMonthlySubmission: function getMonthlySubmission(){ var self =this; $.ajax({ url: '/api/v1/second-chance/players/self/current-month-submissions-count', type: 'GET', success: function(result) { console.log("result value ---->"+result); $(".mdrMonthlyCount").html(result.count); }, error: function(reason) { reason = $.parseJSON(reason.responseText); } }); }, /** * get current elligible games * @author santoshreddy.mogulla@gtech.com * @param {Event} [event] * */ _getMDRGames: function _getMDRGames(event) { var self = this; self.mdrGames.fetch({ cache:false,data:{'group-name':'MDR','sort-columns':'gameName','sort-orders':'asc'}}).done( function success(response){ var totalPage=response.totalPages; var currentPage=response.currentPage; self.mdrgamesArray=response.games; if(currentPage !== totalPage && response.nextPageUrl!==null){ self.mdrGames.url=response.nextPageUrl; self._getNextMDRGames(); } return response.games; }) .fail(function error(reason){ console.warn("Error", this, arguments); reason = $.parseJSON(reason.responseText); portalGGA.utils.globalErrorNotifier.show(reason,"alert-danger"); return reason; }); }, /** * get next set of elligible games * @author santoshreddy.mogulla@gtech.com * @param {Event} [event] * */ _getNextMDRGames: function _getNextMDRGames(){ var self = this; self.mdrGames.fetch({cache:false}).done(function success(response){ var totalPage=response.totalPages; var currentPage=response.currentPage; for(var i=0;i