Permalink
Browse files

Updated spine and brought application up to speed with changes.

  • Loading branch information...
1 parent f8a1d0c commit 0ed99714f74d4ed2d7bb37956bd364d1f21f96d2 @jaitaiwan jaitaiwan committed Nov 20, 2011
Showing with 196 additions and 90 deletions.
  1. +1 −1 index.html
  2. +41 −14 lib/application.js
  3. +1 −1 lib/{spine.local.js → local.js}
  4. +86 −41 lib/spine.js
  5. +1 −1 src/application.coffee
  6. +1 −1 src/{spine.local.coffee → local.coffee}
  7. +65 −31 src/spine.coffee
View
@@ -10,7 +10,7 @@
<script src="lib/jquery.tmpl.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/spine.js" type="text/javascript" charset="utf-8"></script>
- <script src="lib/spine.local.js" type="text/javascript" charset="utf-8"></script>
+ <script src="lib/local.js" type="text/javascript" charset="utf-8"></script>
<script src="lib/application.js" type="text/javascript" charset="utf-8"></script>
<script type="text/x-jquery-tmpl" id="taskTemplate">
View
@@ -1,31 +1,33 @@
(function() {
var $, Task, TaskApp, Tasks;
- var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) {
- for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; }
- function ctor() { this.constructor = child; }
- ctor.prototype = parent.prototype;
- child.prototype = new ctor;
- child.__super__ = parent.prototype;
- return child;
- }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+ var __hasProp = Object.prototype.hasOwnProperty, __extends = function(child, parent) { for (var key in parent) { if (__hasProp.call(parent, key)) child[key] = parent[key]; } function ctor() { this.constructor = child; } ctor.prototype = parent.prototype; child.prototype = new ctor; child.__super__ = parent.prototype; return child; }, __bind = function(fn, me){ return function(){ return fn.apply(me, arguments); }; };
+
$ = jQuery;
+
Task = (function() {
+
__extends(Task, Spine.Model);
+
function Task() {
Task.__super__.constructor.apply(this, arguments);
}
+
Task.configure("Task", "name", "done");
+
Task.extend(Spine.Model.Local);
+
Task.active = function() {
return this.select(function(item) {
return !item.done;
});
};
+
Task.done = function() {
return this.select(function(item) {
return !!item.done;
});
};
+
Task.destroyDone = function() {
var rec, _i, _len, _ref, _results;
_ref = this.done();
@@ -36,67 +38,83 @@
}
return _results;
};
+
return Task;
+
})();
+
Tasks = (function() {
+
__extends(Tasks, Spine.Controller);
+
Tasks.prototype.events = {
"change input[type=checkbox]": "toggle",
"click .destroy": "remove",
"dblclick .view": "edit",
"keypress input[type=text]": "blurOnEnter",
"blur input[type=text]": "close"
};
+
Tasks.prototype.elements = {
"input[type=text]": "input"
};
+
function Tasks() {
this.render = __bind(this.render, this); Tasks.__super__.constructor.apply(this, arguments);
this.item.bind("update", this.render);
- this.item.bind("destroy", __bind(function() {
- return this.trigger('destroy');
- }, this));
+ this.item.bind("destroy", this.release);
}
+
Tasks.prototype.render = function() {
this.replace($("#taskTemplate").tmpl(this.item));
return this;
};
+
Tasks.prototype.toggle = function() {
this.item.done = !this.item.done;
return this.item.save();
};
+
Tasks.prototype.remove = function() {
return this.item.destroy();
};
+
Tasks.prototype.edit = function() {
this.el.addClass("editing");
return this.input.focus();
};
+
Tasks.prototype.blurOnEnter = function(e) {
- if (e.keyCode === 13) {
- return e.target.blur();
- }
+ if (e.keyCode === 13) return e.target.blur();
};
+
Tasks.prototype.close = function() {
this.el.removeClass("editing");
return this.item.updateAttributes({
name: this.input.val()
});
};
+
return Tasks;
+
})();
+
TaskApp = (function() {
+
__extends(TaskApp, Spine.Controller);
+
TaskApp.prototype.events = {
"submit form": "create",
"click .clear": "clear"
};
+
TaskApp.prototype.elements = {
".items": "items",
".countVal": "count",
".clear": "clear",
"form input": "input"
};
+
function TaskApp() {
this.renderCount = __bind(this.renderCount, this);
this.addAll = __bind(this.addAll, this);
@@ -106,26 +124,31 @@
Task.bind("refresh change", this.renderCount);
Task.fetch();
}
+
TaskApp.prototype.addOne = function(task) {
var view;
view = new Tasks({
item: task
});
return this.items.append(view.render().el);
};
+
TaskApp.prototype.addAll = function() {
return Task.each(this.addOne);
};
+
TaskApp.prototype.create = function(e) {
e.preventDefault();
Task.create({
name: this.input.val()
});
return this.input.val("");
};
+
TaskApp.prototype.clear = function() {
return Task.destroyDone();
};
+
TaskApp.prototype.renderCount = function() {
var active, inactive;
active = Task.active().length;
@@ -137,11 +160,15 @@
return this.clear.hide();
}
};
+
return TaskApp;
+
})();
+
$(function() {
return new TaskApp({
el: $("#tasks")
});
});
+
}).call(this);
@@ -1,6 +1,6 @@
(function() {
if (typeof Spine === "undefined" || Spine === null) {
- Spine = require("spine");
+ Spine = require('spine');
}
Spine.Model.Local = {
extended: function() {
Oops, something went wrong.

0 comments on commit 0ed9971

Please sign in to comment.