2015-03-31 16:28:57 -04:00
|
|
|
app = require 'core/application'
|
|
|
|
RootView = require 'views/core/RootView'
|
|
|
|
template = require 'templates/clans/clans'
|
2015-04-01 14:56:48 -04:00
|
|
|
CocoCollection = require 'collections/CocoCollection'
|
|
|
|
Clan = require 'models/Clan'
|
2015-03-31 16:28:57 -04:00
|
|
|
|
|
|
|
module.exports = class MainAdminView extends RootView
|
|
|
|
id: 'clans-view'
|
|
|
|
template: template
|
|
|
|
|
|
|
|
events:
|
2015-04-01 14:56:48 -04:00
|
|
|
'click .create-clan-btn': 'onClickCreateClan'
|
2015-03-31 16:28:57 -04:00
|
|
|
|
|
|
|
constructor: (options) ->
|
|
|
|
super options
|
2015-04-01 14:56:48 -04:00
|
|
|
@publicClans = new CocoCollection([], { url: '/db/clan', model: Clan, comparator:'_id' })
|
|
|
|
@supermodel.loadCollection(@publicClans, 'public_clans', {cache: false})
|
2015-03-31 16:28:57 -04:00
|
|
|
|
|
|
|
getRenderData: ->
|
|
|
|
context = super()
|
2015-04-01 14:56:48 -04:00
|
|
|
context.publicClans = @publicClans.models
|
|
|
|
context.myClans = @publicClans.where({ownerID: me.get('_id')})
|
|
|
|
context.myClanIDs = _.map context.myClans, (c) -> c.id
|
2015-03-31 16:28:57 -04:00
|
|
|
context
|
|
|
|
|
2015-04-01 14:56:48 -04:00
|
|
|
onClickCreateClan: (e) ->
|
|
|
|
if name = $('.create-clan-name').val()
|
|
|
|
# TODO: async creating message
|
|
|
|
clan = new Clan()
|
|
|
|
clan.set 'type', 'public'
|
|
|
|
clan.set 'name', name
|
|
|
|
clan.save {},
|
|
|
|
error: (model, response, options) =>
|
|
|
|
console.error 'Error saving clan', response
|
|
|
|
success: (model, response, options) =>
|
|
|
|
app.router.navigate "/clans/#{model.id}"
|
|
|
|
window.location.reload()
|
2015-03-31 16:28:57 -04:00
|
|
|
else
|
2015-04-01 14:56:48 -04:00
|
|
|
# TODO: Invalid name message
|
|
|
|
console.log 'Invalid name'
|