diff --git a/app/views/play/ladder/play_modal.coffee b/app/views/play/ladder/play_modal.coffee index 2272be191..43286b1d0 100644 --- a/app/views/play/ladder/play_modal.coffee +++ b/app/views/play/ladder/play_modal.coffee @@ -11,6 +11,7 @@ module.exports = class LadderPlayModal extends View closeButton: true startsLoading: true @shownTutorialButton: false + tutorialLevelExists: null events: 'click #skip-tutorial-button': 'hideTutorialButtons' @@ -21,7 +22,7 @@ module.exports = class LadderPlayModal extends View @otherTeam = if team is 'ogres' then 'humans' else 'ogres' @startLoadingChallengersMaybe() @wizardType = ThangType.loadUniversalWizard() - + # PART 1: Load challengers from the db unless some are in the matches startLoadingChallengersMaybe: -> @@ -58,9 +59,11 @@ module.exports = class LadderPlayModal extends View # PART 4: Render finishRendering: -> - @startsLoading = false - @render() - @maybeShowTutorialButtons() + @checkTutorialLevelExists (exists) => + @tutorialLevelExists = exists + @startsLoading = false + @render() + @maybeShowTutorialButtons() getRenderData: -> ctx = super() @@ -94,7 +97,7 @@ module.exports = class LadderPlayModal extends View ctx maybeShowTutorialButtons: -> - return if @session or LadderPlayModal.shownTutorialButton + return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists @$el.find('#normal-view').addClass('secret') @$el.find('.modal-header').addClass('secret') @$el.find('#noob-view').removeClass('secret') @@ -105,6 +108,17 @@ module.exports = class LadderPlayModal extends View @$el.find('.modal-header').removeClass('secret') @$el.find('#noob-view').addClass('secret') + checkTutorialLevelExists: (cb) -> + levelID = @level.get('slug') or @level.id + tutorialLevelID = "#{levelID}-tutorial" + success = => cb true + failure = => cb false + $.ajax + type: "GET" + url: "/db/level/#{tutorialLevelID}/exists" + success: success + error: failure + # Choosing challengers getChallengers: -> diff --git a/server/levels/level_handler.coffee b/server/levels/level_handler.coffee index ad26fe0e1..abf3dfe07 100644 --- a/server/levels/level_handler.coffee +++ b/server/levels/level_handler.coffee @@ -37,7 +37,7 @@ LevelHandler = class LevelHandler extends Handler return @getLeaderboardFacebookFriends(req, res, args[0]) if args[1] is 'leaderboard_facebook_friends' return @getLeaderboardGPlusFriends(req, res, args[0]) if args[1] is 'leaderboard_gplus_friends' return @getHistogramData(req, res, args[0]) if args[1] is 'histogram_data' - + return @checkExistence(req, res, args[0]) if args[1] is 'exists' return @sendNotFoundError(res) fetchLevelByIDAndHandleErrors: (id, req, res, callback) -> @@ -130,7 +130,23 @@ LevelHandler = class LevelHandler extends Handler if err? then return @sendDatabaseError res, err valueArray = _.pluck data, "totalScore" @sendSuccess res, valueArray - + + checkExistence: (req, res, slugOrID) -> + findParameters = {} + if Handler.isID slugOrID + findParameters["_id"] = slugOrID + else + findParameters["slug"] = slugOrID + selectString = 'original version.major permissions' + query = Level.findOne(findParameters) + .select(selectString) + .lean() + + query.exec (err, level) => + return @sendDatabaseError(res, err) if err + return @sendNotFoundError(res) unless level? + res.send({"exists":true}) + res.end() getLeaderboard: (req, res, id) -> sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)