beforeRender: function() { var App = require('app'); var thiz = this; App.players.each(function(item) { thiz.insertView("ul.items", new Player.ListItem({ uuid: item.uuid(), collection: App.players })); }, thiz); return true; },
editPlayer: function(uuid) { this.updateSection("players"); var thiz = this; var App = require('app'); if (!App.players) { App.players = new Player.Collection(); App.players.fetch().done(function() { App.players.sort(); thiz.editPlayerAsync(uuid); }); } else { thiz.editPlayerAsync(uuid); } },
initialize: function(options) { Storkar.ListLayout.prototype.initialize.call(this, options); var thiz = this; var App = require('app'); if (!App.players) { App.players = new Player.Collection(); this.collection = App.players; App.players.fetch().done(function() { App.players.sort(); thiz.render(); }); } else { this.collection = App.players; this.render(); } this.listenTo(this.collection, 'change', thiz.render); this.listenTo(this.collection, 'update', thiz.render); },
saveModel: function() { var attrs = {}; attrs['uuid'] = this.model.uuid(); var fullname = $('#fullname').val(); if (fullname != this.model.fullname()) attrs['fullname'] = fullname; var name = $('#name').val(); if (name != this.model.name()) attrs['name'] = name; var shortname = $('#shortname').val(); if (shortname != this.model.shortname()) attrs['shortname'] = shortname; var aliases = this.model.aliases(); var aliasesstr = $('#aliases').val(); if (aliasesstr) aliases = aliasesstr.split(','); if (aliases != this.model.aliases()) // FIXME: does not work attrs['aliases'] = aliases; var numberstr = $('#number').val(); var number = this.model.number(); if (numberstr) number = parseInt(numberstr, 10); if (number != this.model.number()) attrs['number'] = number; var country = $('#country').val(); if (country != this.model.country()) attrs['country'] = country; var headshot30 = $('#headshot30').val(); if (headshot30 != this.model.headshot_20x30_url()) attrs['headshot-20x30-url'] = headshot30; var headshot60 = $('#headshot60').val(); if (headshot60 != this.model.headshot_40x60_url()) attrs['headshot-40x60-url'] = headshot60; var headshot120 = $('#headshot120').val(); if (headshot120 != this.model.headshot_80x120_url()) attrs['headshot-80x120-url'] = headshot120; var headshot240 = $('#headshot240').val(); if (headshot240 != this.model.headshot_160x240_url()) attrs['headshot-160x240-url'] = headshot240; var teamid = $('#team').val(); if (teamid !== this.model.teamid()) attrs['teamid'] = teamid; var active = $('#active').is(':checked'); if (active !== this.model.active()) attrs['active'] = active; var links = []; var linktext = null; for (var i = 1; ; i = i + 1) { var $linkinput = this.$('#link'+i); if ($linkinput.length) { linktext = $linkinput.val(); if (linktext !== "") { links.push(linktext); } } else { break; } } linktext = $('#newlink').val(); if (linktext !== "") { links.push(linktext); } if (links != this.model.links()) { // FIXME: does not work attrs['links'] = links; } this.model.save(attrs, {patch: true}); this.render(); var App = require('app'); if (!App.players.findWhere({uuid: this.model.uuid()})) { App.players.add(this.model); } },
App.players.fetch().done(function() { App.players.sort(); thiz.render(); });
App.players.fetch().done(function() { App.players.sort(); thiz.editPlayerAsync(uuid); });