"use strict";


var SiteView = Backbone.View.extend({

	$template: $($.parseHTML($("#site-template").text())),


	events: {
		"click .delete-button": "deleteSite",
		"click": "selectSite"
	},


	initialize: function(options) {

		this.model.on("change", this.updateSite, this);

		applyModelToElement(this.model, this.$el);
	},


	updateSite: function(site){

		applyModelToElement(site, this.$el);
	},


	deleteSite: function(e) {

		this.collection.remove(this.model);
		this.el.remove();
	},


	selectSite: function(e) {

		this.model.trigger('select', this.model);
	}
});

@@ -8,16 +8,356 @@
 rict%22;%0A%0A
+// TODO: Unify with CurrenSiteView, using common base views.%0Avar SiteElementView = Backbone.View.extend(%7B%0A%0A%09initialize: function(options) %7B%0A%0A%09%09this.listenTo(this.model, 'change', this.applyModel, this);%0A%09%09this.applyModel();%0A%09%7D,%0A%0A%09applyModel: function(model) %7B%0A%0A%09%09var css = this.model.toJSON();%0A%09%09delete css.id;%0A%0A%09%09this.$el.css(css);%0A%09%7D%0A%7D);%0A
 %0Avar Sit
@@ -567,174 +567,369 @@
 %0A%0A%09%09
-this.model.on(%22change%22, this.updateS
+// TODO: Leaking subviews?%0A%09%09// Build the subviews. Each DOM node in the s
 ite
-,
  t
-his);%0A%0A%09%09applyModelToElement(this.model, this.$el);%0A%09%7D,%0A%0A%0A%09updateSite: function(site)%7B%0A%0A%09%09applyModelToElement(site, this.$el
+emplate knows%0A%09%09// what selector it uses, through the %60rel%60 attribute.%0A%09%09this.subViews = this.$el.find('%5Brel%5D').get()%0A%09%09%09.map(function (el) %7B%0A%0A%09%09%09%09return new SiteElementView(%7B%0A%09%09%09%09%09el: el,%0A%09%09%09%09%09model: this.model.get('styles').get(el.attributes%5B'rel'%5D.value)%0A%09%09%09%09%7D);%0A%0A%09%09%09%7D.bind(this)
 );%0A%09

Split the SiteView functionality just like CurrentSiteView.