Fixed tutorial modal for nonexistent tutorials

This commit is contained in:
Michael Schmatz 2014-04-10 11:42:22 -07:00
parent 42bf2996af
commit a796d88967
2 changed files with 37 additions and 7 deletions

View file

@ -11,6 +11,7 @@ module.exports = class LadderPlayModal extends View
closeButton: true closeButton: true
startsLoading: true startsLoading: true
@shownTutorialButton: false @shownTutorialButton: false
tutorialLevelExists: null
events: events:
'click #skip-tutorial-button': 'hideTutorialButtons' 'click #skip-tutorial-button': 'hideTutorialButtons'
@ -58,6 +59,8 @@ module.exports = class LadderPlayModal extends View
# PART 4: Render # PART 4: Render
finishRendering: -> finishRendering: ->
@checkTutorialLevelExists (exists) =>
@tutorialLevelExists = exists
@startsLoading = false @startsLoading = false
@render() @render()
@maybeShowTutorialButtons() @maybeShowTutorialButtons()
@ -94,7 +97,7 @@ module.exports = class LadderPlayModal extends View
ctx ctx
maybeShowTutorialButtons: -> maybeShowTutorialButtons: ->
return if @session or LadderPlayModal.shownTutorialButton return if @session or LadderPlayModal.shownTutorialButton or not @tutorialLevelExists
@$el.find('#normal-view').addClass('secret') @$el.find('#normal-view').addClass('secret')
@$el.find('.modal-header').addClass('secret') @$el.find('.modal-header').addClass('secret')
@$el.find('#noob-view').removeClass('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('.modal-header').removeClass('secret')
@$el.find('#noob-view').addClass('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 # Choosing challengers
getChallengers: -> getChallengers: ->

View file

@ -37,7 +37,7 @@ LevelHandler = class LevelHandler extends Handler
return @getLeaderboardFacebookFriends(req, res, args[0]) if args[1] is 'leaderboard_facebook_friends' 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 @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 @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) return @sendNotFoundError(res)
fetchLevelByIDAndHandleErrors: (id, req, res, callback) -> fetchLevelByIDAndHandleErrors: (id, req, res, callback) ->
@ -131,6 +131,22 @@ LevelHandler = class LevelHandler extends Handler
valueArray = _.pluck data, "totalScore" valueArray = _.pluck data, "totalScore"
@sendSuccess res, valueArray @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) -> getLeaderboard: (req, res, id) ->
sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id) sessionsQueryParameters = @makeLeaderboardQueryParameters(req, id)