2015-06-13 19:36:02 +00:00
|
|
|
var Backbone = require("backbone");
|
|
|
|
var Handlebars = require("handlebars");
|
|
|
|
var $ = require("jquery");
|
|
|
|
|
|
|
|
var Lobby = Backbone.View.extend({
|
|
|
|
defaults: {
|
|
|
|
id: ""
|
|
|
|
},
|
|
|
|
className: "container",
|
|
|
|
|
|
|
|
template: Handlebars.compile($("#matchmaker-template").html()),
|
|
|
|
initialize: function(){
|
|
|
|
this.app = app;
|
|
|
|
this.listenTo(app.user, "change", this.render);
|
|
|
|
$(this.el).prependTo('body');
|
|
|
|
this.render();
|
|
|
|
},
|
|
|
|
events: {
|
|
|
|
"click .create-room": "createRoom",
|
|
|
|
"click .join-room": "joinRoom",
|
2015-06-19 12:14:37 +00:00
|
|
|
"blur .name-input": "changeName",
|
|
|
|
"change #deckChoice": "setDeck"
|
2015-06-13 19:36:02 +00:00
|
|
|
},
|
|
|
|
render: function(){
|
|
|
|
this.$el.html(this.template(this.app.user.attributes));
|
2015-06-19 12:14:37 +00:00
|
|
|
//this.$el.find("#deckChoice option[value='" + this.app.user.get("setDeck") + "']").attr("selected", "selected")
|
2015-06-13 19:36:02 +00:00
|
|
|
return this;
|
|
|
|
},
|
|
|
|
createRoom: function(){
|
|
|
|
this.app.send("request:createRoom");
|
|
|
|
},
|
|
|
|
joinRoom: function(){
|
|
|
|
this.app.send("request:joinRoom");
|
|
|
|
},
|
2015-06-19 12:14:37 +00:00
|
|
|
setDeck: function(e){
|
|
|
|
var val = $(e.target).val();
|
|
|
|
this.app.user.setDeck(val);
|
|
|
|
},
|
2015-06-13 19:36:02 +00:00
|
|
|
changeName: function(e){
|
|
|
|
var name = $(e.target).val();
|
|
|
|
this.app.user.setName(name);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
|
|
|
|
|
|
|
module.exports = Lobby;
|