var Contact = Spine.Model.setup("Contact", ["first_name", "last_name", "email"]);
Contact.extend(Spine.Model.Local);
Contact.include({
truefullName: function() {
truetrueif (!this.first_name && !this.last_name) return;
truetruereturn(this.last_name);
true},
});
$(function($) {
truewindow.Sidebar = Spine.Controller.create({
truetrueelements: {
truetruetrue".items": "items",
truetrue},
truetrueevents: {
truetruetrue"click button": "create",
truetrue},
truetruetemplate: function(items) {
truetruetruereturn($("#contactsTemplate").tmpl(items));
truetrue},
truetrueinit: function() {
truetruetruethis.list = new Spine.List({
truetruetruetrueel: this.items,
truetruetruetruetemplate: this.template,
truetruetrue});
truetruetruethis.list.bind("change", this.proxy(function(item) {
truetruetruetrueSpine.trigger(039;show:contact039;, item);
truetruetrue}));
truetruetrueSpine.bind("show:contact edit:contact", this.proxy(this.list.change));
truetruetrueContact.bind("refresh change", this.proxy(this.render));
truetrue},
truetruerender: function() {
truetruetruevar items = Contact.all();
truetruetruethis.list.render(items);
truetrue},
truetruecreate: function() {
truetruetruevar item = Contact.create();
truetruetrueconsole.log(item);
truetruetrueSpine.trigger("edit:contact", item);
truetrue},
true});
});
$(function($) {
truewindow.Contacts = Spine.Controller.create({
truetrueelements: {
truetruetrue".show": "showEl",
truetruetrue".edit": "editEl",
truetruetrue".show .content": "showContent",
truetruetrue".edit .content": "editContent",
truetrue},
truetrueevents: {
truetruetrue"click .optEdit": "edit",
truetruetrue"click .optDestroy": "destroy",
truetruetrue"click .optSave": "save",
truetrue},
truetrueinit: function() {
truetruetruethis.show();
truetruetrueContact.bind("change", this.proxy(this.render));
truetruetrueSpine.bind("show:contact", this.proxy(this.show));
truetruetrueSpine.bind("edit:contact", this.proxy(this.edit));
truetrue},
truetruechange: function(item) {
truetruetruethis.current = item;
truetruetruethis.render();
truetrue},
truetruerender: function() {
truetruetruethis.showContent.html($("#contactTemplate").tmpl(this.current));
truetruetruethis.editContent.html($("#editContactTemplate").tmpl(this.current));
truetrue},
truetrueshow: function(item) {
truetruetrueif (item && item.id) this.proxy(this.change(item));
truetruetruethis.showEl.show();
truetruetruethis.editEl.hide();
truetrue},
truetrue
truetrueedit: function(item) {
truetruetrueconsole.log(item);
truetruetrueif (item && item.id) this.proxy(this.change(item));
truetruetruethis.showEl.hide();
truetruetruethis.editEl.show();
truetrue},
truetruedestroy: function() {
truetruetruethis.current.destroy();
truetrue},
truetruesave: function() {
truetruetruevar atts = this.editEl.serializeForm();
truetruetruethis.current.updateAttributes(atts);
truetruetruethis.show();
truetrue}
true});
});
$(function($) {
truewindow.App = Spine.Controller.create({
truetrueel: $("body"),
truetrueelements: {
truetruetrue".sidebar": "sidebarEl",
truetruetrue".contacts": "contactsEl",
truetrue},
truetrueinit: function() {
truetruetruethis.sidebar = new Sidebar({el: this.sidebarEl});
truetruetruethis.contact = new Contacts({el: this.contactsEl});
truetruetrueContact.fetch();
truetrue},
true});
truenew App();
});