Skip to content

Commit

Permalink
move model into thoughtbot structure
Browse files Browse the repository at this point in the history
  • Loading branch information
Joshua Stauter committed Apr 14, 2012
1 parent f2f514f commit 7533fe0
Show file tree
Hide file tree
Showing 4 changed files with 16 additions and 51 deletions.
Binary file added app/assets/images/destroy.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
12 changes: 10 additions & 2 deletions app/assets/javascripts/models/todo.js.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,13 @@ class App.Models.Todo extends Backbone.Model
paramRoot: 'todo'

defaults:
content: null
done: null
content: 'empty todo...'
done: false

initialize: ->
if !@get 'content'
@set "content": @defaults.content

toggle: -> @save done: !@get 'done'

clear: -> @destroy()
50 changes: 1 addition & 49 deletions app/assets/javascripts/todos.js
Original file line number Diff line number Diff line change
@@ -1,51 +1,9 @@
// An example Backbone application contributed by
// [Jérôme Gravel-Niquet](http://jgn.me/). This demo uses a simple
// [LocalStorage adapter](backbone-localstorage.js)
// to persist Backbone models within your browser.

// Load the application once the DOM is ready, using `jQuery.ready`:
$(function(){

// Todo Model
// ----------

// Our basic **Todo** model has `content`, `order`, and `done` attributes.
var Todo = Backbone.Model.extend({

// Default attributes for the todo.
defaults: {
content: "empty todo...",
done: false
},

// Ensure that each todo created has `content`.
initialize: function() {
if (!this.get("content")) {
this.set({"content": this.defaults.content});
}
},

// Toggle the `done` state of this todo item.
toggle: function() {
this.save({done: !this.get("done")});
},

// Remove this Todo from *localStorage* and delete its view.
clear: function() {
this.destroy();
}

});

// Todo Collection
// ---------------

// The collection of todos is backed by *localStorage* instead of a remote
// server.
var TodoList = Backbone.Collection.extend({

// Reference to this collection's model.
model: Todo,
model: window.App.Models.Todo,

// Save all of the todo items under the `"todos"` namespace.
localStorage: new Store("todos-backbone"),
Expand Down Expand Up @@ -77,9 +35,6 @@ $(function(){
// Create our global collection of **Todos**.
var Todos = new TodoList;

// Todo Item View
// --------------

// The DOM element for a todo item...
var TodoView = Backbone.View.extend({

Expand Down Expand Up @@ -143,9 +98,6 @@ $(function(){

});

// The Application
// ---------------

// Our overall **AppView** is the top-level piece of UI.
var AppView = Backbone.View.extend({

Expand Down
5 changes: 5 additions & 0 deletions public/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,11 @@
<script src="assets/underscore.js"></script>
<script src="assets/backbone.js"></script>
<script src="assets/backbone-localstorage.js"></script>
<script>
window.App = {};
App.Models = {};
</script>
<script src="assets/models/todo.js"></script>
<script src="assets/todos.js"></script>
</head>
<body>
Expand Down

0 comments on commit 7533fe0

Please sign in to comment.