Show mod icons in mod ballot

This commit is contained in:
Andrew Miner
2016-06-01 17:22:01 -06:00
parent b82bfea8f1
commit eba8c99ac0
5 changed files with 46 additions and 13 deletions
@@ -15,12 +15,15 @@ PageController = require '../page_controller'
module.exports = class BrowsePageController extends PageController module.exports = class BrowsePageController extends PageController
constructor: (options={})-> constructor: (options={})->
if not options.client then throw new Error 'options.client is required' if not options.client then throw new Error 'options.client is required'
if not options.modPack then throw new Error 'options.modPack is required' if not options.imageLoader then throw new Error 'options.imageLoader is required'
if not options.modPack then throw new Error 'options.modPack is required'
options.templateName = 'browse_page' options.templateName = 'browse_page'
super options super options
@_client = options.client @_client = options.client
@_imageLoader = options.imageLoader
@_modPack = options.modPack @_modPack = options.modPack
@_tileControllers = [] @_tileControllers = []
@@ -48,7 +51,10 @@ module.exports = class BrowsePageController extends PageController
# BaseController Overrides ##################################################################### # BaseController Overrides #####################################################################
onDidRender: -> onDidRender: ->
@_modBallotController = @addChild ModBallotController, '.view__mod_ballot', client:@_client, user:@_user @_modBallotController = @addChild ModBallotController, '.view__mod_ballot',
client: @_client
imageLoader: @_imageLoader
user: @_user
@$tileContainer = @$('.tile_container') @$tileContainer = @$('.tile_container')
@@ -11,6 +11,7 @@
.button.vote-now: .bezel: p Vote Now! .button.vote-now: .bezel: p Vote Now!
.status.loading .status.loading
img(src="/images/wait.gif")
.status-message .status-message
.status.loaded .status.loaded
@@ -22,10 +22,29 @@ $ballot-move-duration: 0.2s;
text-align: center; text-align: center;
} }
.status-message {
margin-bottom: $size-margin-large;
font-family: $font-family-header;
font-size: $font-size-medium;
text-align: center;
}
&.initial { &.initial {
padding: 0 15%; padding: 0 15%;
} }
&.loading {
display: flex;
flex-direction: column;
align-items: center;
img {
margin-top: $size-margin-large;
margin-bottom: $size-margin-medium;
}
}
&.loaded { &.loaded {
padding: 0 15%; padding: 0 15%;
@@ -63,14 +82,6 @@ $ballot-move-duration: 0.2s;
flex-direction: column; flex-direction: column;
align-items: center; align-items: center;
.status-message {
margin-bottom: $size-margin-large;
font-family: $font-family-header;
font-size: $font-size-medium;
text-align: center;
}
.button { .button {
width: $size-minecraft-block * 10; width: $size-minecraft-block * 10;
} }
@@ -27,12 +27,15 @@ module.exports = class ModBallotController extends BaseController
@::VOTE_ERROR = 'Sorry! Something went wrong casting your vote. Please try again.' @::VOTE_ERROR = 'Sorry! Something went wrong casting your vote. Please try again.'
constructor: (options={})-> constructor: (options={})->
if not options.client then throw new Error "options.client is required" if not options.client then throw new Error 'options.client is required'
if not options.imageLoader then throw new Error 'options.imageLoader is required'
options.model = ballot:null, votes:null options.model = ballot:null, votes:null
options.templateName = 'browse_page/mod_ballot' options.templateName = 'browse_page/mod_ballot'
super options super options
@_client = options.client @_client = options.client
@_imageLoader = options.imageLoader
@_lineControllers = {} @_lineControllers = {}
@_status = @STATUS.INITIAL @_status = @STATUS.INITIAL
@@ -184,7 +187,8 @@ module.exports = class ModBallotController extends BaseController
model = {ballotLine:line, vote:@_findVote(line.modId)} model = {ballotLine:line, vote:@_findVote(line.modId)}
if not controller? if not controller?
controller = new ModBallotLineController controller = new ModBallotLineController
model: model imageLoader: @_imageLoader
model: model
onVoteButtonClicked: (controller)=> @onVoteButtonClicked controller onVoteButtonClicked: (controller)=> @onVoteButtonClicked controller
controller.render() controller.render()
@$ballotList.append controller.$el @$ballotList.append controller.$el
@@ -12,9 +12,11 @@ BaseController = require '../../../base_controller'
module.exports = class ModBallotLineController extends BaseController module.exports = class ModBallotLineController extends BaseController
constructor: (options={})-> constructor: (options={})->
if not options.imageLoader then throw new Error 'options.imageLoader is required'
options.templateName = 'browse_page/mod_ballot/mod_ballot_line' options.templateName = 'browse_page/mod_ballot/mod_ballot_line'
super options super options
@_imageLoader = options.imageLoader
@_onVoteButtonClicked = options.onVoteButtonClicked or (controller)-> # do nothing @_onVoteButtonClicked = options.onVoteButtonClicked or (controller)-> # do nothing
# Event Methods ################################################################################ # Event Methods ################################################################################
@@ -56,6 +58,7 @@ module.exports = class ModBallotLineController extends BaseController
refresh: -> refresh: ->
@$name.html @model.ballotLine?.name or '' @$name.html @model.ballotLine?.name or ''
@$voteCount.html @model.ballotLine?.voteCount or '' @$voteCount.html @model.ballotLine?.voteCount or ''
@_refreshIcon()
@_refreshVoteButton() @_refreshVoteButton()
super super
@@ -67,6 +70,14 @@ module.exports = class ModBallotLineController extends BaseController
# Private Methods ############################################################################## # Private Methods ##############################################################################
_refreshIcon: ->
if @model.ballotLine?
modSlug = _.slugify(@model.ballotLine.name)
url = c.url.modIcon modSlug:modSlug
@_imageLoader.load url, @$image
else
@$image.attr 'src', '/images/unknown.png'
_refreshVoteButton: -> _refreshVoteButton: ->
if @isWaiting if @isWaiting
@$wait.removeClass 'hidden' @$wait.removeClass 'hidden'