mirror of
https://github.com/codeninjasllc/codecombat.git
synced 2024-11-23 15:48:11 -05:00
parent
0e2b919ec1
commit
2ded5ff4f0
2 changed files with 23 additions and 22 deletions
|
@ -32,8 +32,8 @@ block content
|
|||
th(data-i18n="clans.chieftain") Chieftain
|
||||
th
|
||||
tbody
|
||||
if publicClans.length
|
||||
each clan in publicClans
|
||||
if view.publicClansArray.length
|
||||
each clan in view.publicClansArray
|
||||
tr
|
||||
td
|
||||
if clan.get('ownerID') === me.id
|
||||
|
@ -42,12 +42,12 @@ block content
|
|||
a(href="/clans/#{clan.id}")= clan.get('name')
|
||||
td= clan.get('memberCount')
|
||||
td
|
||||
if idNameMap && idNameMap[clan.get('ownerID')]
|
||||
a(href="/user/#{clan.get('ownerID')}")= idNameMap[clan.get('ownerID')]
|
||||
if view.idNameMap && view.idNameMap[clan.get('ownerID')]
|
||||
a(href="/user/#{clan.get('ownerID')}")= view.idNameMap[clan.get('ownerID')]
|
||||
else
|
||||
a(href="/user/#{clan.get('ownerID')}") Anoner
|
||||
td
|
||||
if myClanIDs.indexOf(clan.id) < 0
|
||||
if view.myClanIDs.indexOf(clan.id) < 0
|
||||
button.btn.btn-success.join-clan-btn(data-id="#{clan.id}", data-i18n="clans.join_clan") Join Clan
|
||||
else if clan.get('ownerID') !== me.id
|
||||
button.btn.btn-xs.btn-warning.leave-clan-btn(data-id="#{clan.id}", data-i18n="clans.leave_clan") Leave Clan
|
||||
|
@ -62,8 +62,8 @@ block content
|
|||
th(data-i18n="clans.type") Type
|
||||
th
|
||||
tbody
|
||||
if myClans.length
|
||||
each clan in myClans
|
||||
if view.myClansArray.length
|
||||
each clan in view.myClansArray
|
||||
tr
|
||||
td
|
||||
if clan.get('ownerID') === me.id
|
||||
|
@ -72,8 +72,8 @@ block content
|
|||
a(href="/clans/#{clan.id}")= clan.get('name')
|
||||
td= clan.get('memberCount')
|
||||
td
|
||||
if idNameMap && idNameMap[clan.get('ownerID')]
|
||||
a(href="/user/#{clan.get('ownerID')}")= idNameMap[clan.get('ownerID')]
|
||||
if view.idNameMap && view.idNameMap[clan.get('ownerID')]
|
||||
a(href="/user/#{clan.get('ownerID')}")= view.idNameMap[clan.get('ownerID')]
|
||||
else
|
||||
a(href="/user/#{clan.get('ownerID')}") Anoner
|
||||
td= clan.get('type')
|
||||
|
|
|
@ -13,6 +13,7 @@ SubscribeModal = require 'views/core/SubscribeModal'
|
|||
module.exports = class ClansView extends RootView
|
||||
id: 'clans-view'
|
||||
template: template
|
||||
|
||||
|
||||
events:
|
||||
'click .create-clan-btn': 'onClickCreateClan'
|
||||
|
@ -20,28 +21,25 @@ module.exports = class ClansView extends RootView
|
|||
'click .leave-clan-btn': 'onLeaveClan'
|
||||
'click .private-clan-checkbox': 'onClickPrivateCheckbox'
|
||||
|
||||
constructor: (options) ->
|
||||
super options
|
||||
@initData()
|
||||
initialize: ->
|
||||
@publicClansArray = []
|
||||
@myClansArray = []
|
||||
@idNameMap = {}
|
||||
@loadData()
|
||||
|
||||
destroy: ->
|
||||
@stopListening?()
|
||||
|
||||
getRenderData: ->
|
||||
context = super()
|
||||
context.idNameMap = @idNameMap
|
||||
context.publicClans = _.filter(@publicClans.models, (clan) -> clan.get('type') is 'public')
|
||||
context.myClans = @myClans.models
|
||||
context.myClanIDs = me.get('clans') ? []
|
||||
context
|
||||
|
||||
afterRender: ->
|
||||
super()
|
||||
@setupPrivateInfoPopover()
|
||||
|
||||
initData: ->
|
||||
@idNameMap = {}
|
||||
onLoaded: ->
|
||||
super()
|
||||
@publicClansArray = _.filter(@publicClans.models, (clan) -> clan.get('type') is 'public')
|
||||
@myClansArray = @myClans.models
|
||||
|
||||
loadData: ->
|
||||
sortClanList = (a, b) ->
|
||||
if a.get('memberCount') isnt b.get('memberCount')
|
||||
if a.get('memberCount') < b.get('memberCount') then 1 else -1
|
||||
|
@ -52,12 +50,15 @@ module.exports = class ClansView extends RootView
|
|||
@refreshNames @publicClans.models
|
||||
@render?()
|
||||
@supermodel.loadCollection(@publicClans, 'public_clans', {cache: false})
|
||||
|
||||
@myClans = new CocoCollection([], { url: "/db/user/#{me.id}/clans", model: Clan, comparator: sortClanList })
|
||||
@listenTo @myClans, 'sync', =>
|
||||
@refreshNames @myClans.models
|
||||
@render?()
|
||||
@supermodel.loadCollection(@myClans, 'my_clans', {cache: false})
|
||||
|
||||
@listenTo me, 'sync', => @render?()
|
||||
@myClanIDs = me.get('clans') ? []
|
||||
|
||||
refreshNames: (clans) ->
|
||||
clanIDs = _.filter(clans, (clan) -> clan.get('type') is 'public')
|
||||
|
|
Loading…
Reference in a new issue