!(function($,redirect){ /** * @class View of Eligible Games form * @view * @author santoshreddy.mogulla@gtech.com * @requires portalGGA.models.EligibleGames * @requiresDOM .eligibleGames-results, .eligibleGames-noResults */ portalGGA.views.EligibleGamesView = Backbone.View.extend( /** @lends portalGGA.views.EligibleGamesView.prototype */{ events:{ "click .eligible-games-pagination a" : "changePage", "submit" : "submit", "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.EligibleGames} [options.EligibleGames] EligibleGames 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 EligibleGamesView( options ){ Backbone.View.apply(this, arguments); this.groupName = options.groupName; this.successRedirectURL = options.successRedirectURL; this.EligibleGames = options.EligibleGames || new portalGGA.EligibleGames(); this.SCEligibleGamesTemplate = _.template( this.$('.eligibleGames-transactionTemplate').html() ); this.SCEligibleGamesHeaderTemplate = _.template( this.$('.eligibleGames-transactionHeader').html() ); this.specyficErrorNotifier = new portalGGA.utils.ErrorNotifier(this.$(".eligibleGames-error")); this.sortField = "GAME_NAME"; this.sortType = "asc"; this.fieldsMap = { 'GAME_NAME':'gameName', 'AMOUNT' : 'cost', 'GAME_ID' :'siteGameId' }, _.bindAll(this, "_populateHeader", "_populateResults", "_populatePagination", "_handleFailure"); if(options.populate) { this.submit(); } }, /** * Submit form or given data if any * @author santoshreddy.mogulla@gtech.com * @TODO: error handling * @param {Event} [event] * @param {Object} [data] query data if not given, #serialize() will be used. * @returns {Q.promise} [description] */ submit: function submit( event, data ){ event && event.preventDefault(); this.$('.pagination-container').fadeOut(); this.$('.preloader_big').fadeIn(); this.$(".eligibleGames-table").hide(); this._populateHeader(); this.$('.eligibleGames-noResults').fadeOut(); this.$('.eligibleGames-results').empty(); this.specyficErrorNotifier.clear(); this.EligibleGames.url = "/api/v1/second-chance/games"; return Q.when(this.EligibleGames.fetch({cache:false, data: this.getFilters()} )) .then(this._populateResults) .then(this._populatePagination ) .fail(this._handleFailure ); }, /** * [_populateHeader description] * @author santoshreddy.mogulla@gtech.com * @TODO return something (smogulla) * @TODO scope (smogulla) */ _populateHeader: function _populateHeader( ) { console.info('_populateHeader', this, arguments); this.$('.eligibleGames-header').html(this.SCEligibleGamesHeaderTemplate({ 'sortField': this.sortField, 'sortType': this.sortType, 'fieldsMap': this.fieldsMap })); }, /** * [_populateResults description] * @author santoshreddy.mogulla@gtech.com * @TODO return something (smogulla) * @TODO scope (smogulla) */ _populateResults: function _populateResults( ){ console.info('_populateResults', this, arguments); var rows = "", preloader = this.$('.preloader_big'), table = this.$(".eligibleGames-table"); if(this.EligibleGames.length){ for(var txNo=0; txNo