var LayoutsIndex = View.extend({ initialize: function(){ this.$templates = this.$(".templates") }, load: function(type){ this.$templates.children("span").remove() $.get(this.action, $.proxy(this.populate, this)) }, populate: function(data){ data.forEach($.proxy(function(room){ var $span = $("") // $span.html(JSON.stringify(room)) $span.data("slug", room.slug) $span.css("background-image", "url(" + room.photo + ")") this.$templates.append($span) }, this)) this.show() } }) var ProjectsModal = ModalView.extend(LayoutsIndex.prototype).extend({ el: ".mediaDrawer.projects", action: "/api/project", events: { "click .templates span": 'toggleActive', "submit form": 'newProject', }, populate: function(data){ if (! data.length) { app.router.newProject() } else { this.__super__.populate.call(this, data) } }, toggleActive: function(e){ e.preventDefault() this.$(".templates .active").removeClass("active") var $layout = $(e.currentTarget) $layout.addClass("active") // actually do window.location.pathname = "/project/" + $layout.data("slug") }, newProject: function(e){ e && e.preventDefault() window.location.pathname = "/project/new" } }) var LayoutsModal = ModalView.extend(LayoutsIndex.prototype).extend({ el: ".mediaDrawer.layouts", action: "/api/layout", events: { "click .templates span": 'toggleActive', "submit form": 'newLayout', }, toggleActive: function(e){ e.preventDefault() this.$(".templates .active").removeClass("active") var $layout = $(e.currentTarget) $layout.addClass("active") // actually do window.location.pathname = "/layout/" + $layout.data("slug") }, newLayout: function(e){ e && e.preventDefault() window.location.pathname = "/layout/new" } }) var NewProjectModal = ModalView.extend(LayoutsIndex.prototype).extend({ el: ".mediaDrawer.newProject", action: "/api/layout", events: { "click .templates span": 'toggleActive', "submit form": 'choose', }, toggleActive: function(e){ e.preventDefault() this.$(".templates .active").removeClass("active") $(e.currentTarget).addClass("active") }, choose: function(e){ e && e.preventDefault() var layout = this.$(".templates .active").data("slug") if (! layout || ! layout.length) return window.location.pathname = "/project/new/" + layout } })