Skip to content
This repository has been archived by the owner on Oct 5, 2021. It is now read-only.

Commit

Permalink
Can mark tasks as done and reopen them
Browse files Browse the repository at this point in the history
  • Loading branch information
meth committed Sep 28, 2012
1 parent 7c48ce5 commit ff21850
Show file tree
Hide file tree
Showing 6 changed files with 61 additions and 9 deletions.
5 changes: 4 additions & 1 deletion index.html
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,10 @@ <h2>Assigned: <span class="assigned"></span></h2>

</div> <!-- /container -->
<script type="text/template" id="tasktemplate">
<a href="#view-<%= id %>"><%= title %></a> <a href="#edit-<%= id %>">Edit</a> <a href="#remove-<%= id %>">Remove</a>
<a href="#view/<%= id %>"><%= title %></a> [<a href="#edit-<%= id %>">Edit</a>] [<a href="#remove-<%= id %>">Remove</a>] [<a href="#done">Mark as resolved</a>]
</script>
<script type="text/template" id="tasktemplate-done">
<%= title %> [<a href="#reopen">Reopen</a>]
</script>
<script data-main="js/main" src="js/libs/require.js"></script>

Expand Down
1 change: 0 additions & 1 deletion js/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ requirejs.config({
'jquery': 'https://ajax.googleapis.com/ajax/libs/jquery/1.8.2/jquery.min',
'bootstrap': 'libs/bootstrap.min',
'backbone-lib': 'libs/backbone-min',
//'backbone-lib': 'http://backbonejs.org/backbone',
'backbone-debug': 'libs/backbone.debug',
'backbone': 'libs/backbone.localStorage-min',
'underscore': 'libs/underscore-min',
Expand Down
14 changes: 14 additions & 0 deletions js/models/tasker.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,20 @@ define(['backbone', 'collections/task'], function( Backbone, TaskCollection )
defaults: {
'tasks': new TaskCollection(),
'done': new TaskCollection()
},
markAsDone: function( id )
{
var model = this.get( 'tasks' ).get( id );

this.get( 'tasks' ).remove( id );
this.get( 'done' ).add( model );
},
reopenTask: function( id )
{
var model = this.get( 'done' ).get( id );

this.get( 'done' ).remove( id );
this.get( 'tasks' ).add( model );
}
});

Expand Down
7 changes: 5 additions & 2 deletions js/script.js
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ define(['jquery', 'backbone', 'models/tasker', 'views/list', 'views/form', 'view
var AppRouter = Backbone.Router.extend( {
routes: {
'add': 'add',
'view-:id': 'view',
'view/:id': 'view',
'edit-:id': 'add',
'*home': 'home'
},
Expand All @@ -13,13 +13,16 @@ define(['jquery', 'backbone', 'models/tasker', 'views/list', 'views/form', 'view
{
this.tasks = new Tasker();
this.views.listtodo = new ListView( {collection: this.tasks.get( 'tasks' )} );
this.views.listdone = new ListView( {collection: this.tasks.get( 'done' ), el: document.getElementById( 'tasklist-done' )} );
this.views.listdone = new ListView( {collection: this.tasks.get( 'done' ), el: document.getElementById( 'tasklist-done' ), template: _.template( document.getElementById( 'tasktemplate-done' ).innerHTML ) } );
this.views.task = new TaskView();
this.views.form = new FormView( {collection: this.tasks.get( 'tasks' )} );

this.tasks.get( 'tasks' ).on( 'add remove change', this.goToHome, this );

this.tasks.get( 'tasks' ).fetch();

this.views.listtodo.on( 'task:markAsDone', this.tasks.markAsDone, this.tasks );
this.views.listdone.on( 'task:reopen', this.tasks.reopenTask, this.tasks );
},
showOnly: function ( section )
{
Expand Down
23 changes: 20 additions & 3 deletions js/views/list.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,27 @@ define(['jquery', 'underscore', 'backbone', 'views/task_list', 'views/tabs'], fu
{
var ListView = Backbone.View.extend( {
el: document.getElementById( 'tasklist' ),
template: _.template( document.getElementById( 'tasktemplate' ).innerHTML ),
template: null,
tabs: new TabsView(),
initialize: function ()
initialize: function ( options )
{
if ( options.template )
{
this.template = options.template;
}

this.collection.on( 'add', this.addOne, this );
this.collection.on( 'reset', this.render, this );
},
addOne: function ( model )
{
var view = new SingleTaskListView( {model: model} );
var view = new SingleTaskListView( {model: model, template: this.template} );

view.render();

view.on( 'task:markAsDone', this.markAsDone, this );
view.on( 'task:reopen', this.reopenTask, this );

this.$el.append( view.el );
},
render: function ( collection )
Expand All @@ -26,6 +35,14 @@ define(['jquery', 'underscore', 'backbone', 'views/task_list', 'views/tabs'], fu
showTab: function( tab )
{
this.tabs.showTab( tab );
},
markAsDone: function( model )
{
this.trigger( 'task:markAsDone', model.get( 'id' ) );
},
reopenTask: function( model )
{
this.trigger( 'task:reopen', model.get( 'id' ) );
}
} );

Expand Down
20 changes: 18 additions & 2 deletions js/views/task_list.js
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,16 @@ define(['jquery', 'underscore', 'backbone'], function( $, _, Backbone )
template: _.template( document.getElementById( 'tasktemplate' ).innerHTML ),
tagName: 'li',
events: {
'click a[href^="#remove"]': 'removeModel'
'click a[href^="#remove"]': 'removeModel',
'click a[href="#done"]': 'markAsDone',
'click a[href="#reopen"]': 'reopenTask'
},
initialize: function()
initialize: function( options )
{
if ( options.template )
{
this.template = options.template;
}
this.model.on( 'destroy remove', this.remove, this );
this.model.on( 'change', this.render, this );
},
Expand All @@ -27,6 +33,16 @@ define(['jquery', 'underscore', 'backbone'], function( $, _, Backbone )
options.id = this.model.cid
this.el.innerHTML = this.template( options );
return this;
},
markAsDone: function( e )
{
this.trigger( 'task:markAsDone', this.model );
e.preventDefault();
},
reopenTask: function( e )
{
this.trigger( 'task:reopen', this.model );
e.preventDefault();
}
});

Expand Down

0 comments on commit ff21850

Please sign in to comment.