2015-04-01 19:00:39 -04:00
|
|
|
app = require 'core/application'
|
|
|
|
AuthModal = require 'views/core/AuthModal'
|
2015-03-31 16:28:57 -04:00
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/clans/clan-details'
|
2015-04-01 14:56:48 -04:00
|
|
|
Clan = require 'models/Clan'
|
2015-03-31 16:28:57 -04:00
|
|
|
|
2015-04-01 19:00:39 -04:00
|
|
|
# TODO: join/leave mostly duped from clans view
|
|
|
|
|
2015-03-31 16:28:57 -04:00
|
|
|
module.exports = class ClanDetailsView extends RootView
|
|
|
|
id: 'clan-details-view'
|
|
|
|
template: template
|
|
|
|
|
2015-04-01 19:00:39 -04:00
|
|
|
events:
|
|
|
|
'click .join-clan-btn': 'onJoinClan'
|
|
|
|
'click .leave-clan-btn': 'onLeaveClan'
|
2015-04-02 14:01:37 -04:00
|
|
|
'click .remove-member-btn': 'onRemoveMember'
|
2015-04-01 19:00:39 -04:00
|
|
|
|
2015-03-31 16:28:57 -04:00
|
|
|
constructor: (options, @clanID) ->
|
|
|
|
super options
|
2015-04-01 14:56:48 -04:00
|
|
|
@clan = new Clan _id: @clanID
|
|
|
|
@supermodel.loadModel @clan, 'clan', cache: false
|
2015-03-31 16:28:57 -04:00
|
|
|
|
|
|
|
getRenderData: =>
|
|
|
|
context = super()
|
|
|
|
context.clan = @clan
|
2015-04-01 14:56:48 -04:00
|
|
|
context.isOwner = @clan.get('ownerID') is me.id
|
|
|
|
context.isMember = _.find(@clan.get('members'), (m) -> m.id is me.id) ? false
|
2015-03-31 16:28:57 -04:00
|
|
|
context
|
2015-04-01 19:00:39 -04:00
|
|
|
|
|
|
|
onJoinClan: (e) ->
|
|
|
|
return @openModalView(new AuthModal()) if me.isAnonymous()
|
|
|
|
if clanID = $(e.target).data('id')
|
|
|
|
options =
|
|
|
|
url: "/db/clan/#{clanID}/join"
|
|
|
|
method: 'PUT'
|
|
|
|
error: (model, response, options) =>
|
|
|
|
console.error 'Error joining clan', response
|
|
|
|
success: (model, response, options) =>
|
2015-04-02 14:01:37 -04:00
|
|
|
@listenToOnce @clan, 'sync', =>
|
|
|
|
@render?()
|
|
|
|
@clan.fetch cache: false
|
2015-04-01 19:00:39 -04:00
|
|
|
@supermodel.addRequestResource( 'join_clan', options).load()
|
|
|
|
else
|
|
|
|
console.error "No clan ID attached to join button."
|
|
|
|
|
|
|
|
onLeaveClan: (e) ->
|
|
|
|
if clanID = $(e.target).data('id')
|
|
|
|
options =
|
|
|
|
url: "/db/clan/#{clanID}/leave"
|
|
|
|
method: 'PUT'
|
|
|
|
error: (model, response, options) =>
|
|
|
|
console.error 'Error leaving clan', response
|
|
|
|
success: (model, response, options) =>
|
2015-04-02 14:01:37 -04:00
|
|
|
@listenToOnce @clan, 'sync', =>
|
|
|
|
@render?()
|
|
|
|
@clan.fetch cache: false
|
2015-04-01 19:00:39 -04:00
|
|
|
@supermodel.addRequestResource( 'leave_clan', options).load()
|
|
|
|
else
|
|
|
|
console.error "No clan ID attached to leave button."
|
2015-04-02 14:01:37 -04:00
|
|
|
|
|
|
|
onRemoveMember: (e) ->
|
|
|
|
if memberID = $(e.target).data('id')
|
|
|
|
options =
|
|
|
|
url: "/db/clan/#{@clanID}/remove/#{memberID}"
|
|
|
|
method: 'PUT'
|
|
|
|
error: (model, response, options) =>
|
|
|
|
console.error 'Error removing clan member', response
|
|
|
|
success: (model, response, options) =>
|
|
|
|
@listenToOnce @clan, 'sync', =>
|
|
|
|
@render?()
|
|
|
|
@clan.fetch cache: false
|
|
|
|
@supermodel.addRequestResource( 'remove_member', options).load()
|
|
|
|
else
|
|
|
|
console.error "No member ID attached to remove button."
|