Skip to content

Commit

Permalink
favorites wip
Browse files Browse the repository at this point in the history
  • Loading branch information
rmurphey committed Apr 13, 2012
1 parent e6fd4c3 commit 03c95a2
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
16 changes: 16 additions & 0 deletions app/data/favorites.js
@@ -0,0 +1,16 @@
define([
'use!backbone'
], function(B) {
var Favorite = Backbone.Model.extend({

});

var Favorites = Backbone.Collection.extend({
model : Favorite,
url : function() {
return '/favorites/' + this.user.get('name') + '/';
}
});

return Favorites;
});
19 changes: 19 additions & 0 deletions app/data/searches.js
@@ -0,0 +1,19 @@
define([
'use!backbone'
], function(B) {
var Search = B.Model.extend({
idAttribute : 'term'
});

var Searches = B.Collection.extend({
comparator : function(item) {
return item.get('time') * -1;
},
model : Search,
store : function(item) {
window.localStorage.setItem('searches', JSON.stringify(this.toJSON()));
}
});

return Searches;
});
4 changes: 2 additions & 2 deletions app/models/app.js
Expand Up @@ -11,10 +11,10 @@ define([
) )
), ),


favorites = new Favorites(),

user = new User(), user = new User(),


favorites = new Favorites({ user : user }),

search = new B.Model({ term : null }), search = new B.Model({ term : null }),


searchData = new SearchData(); searchData = new SearchData();
Expand Down
16 changes: 16 additions & 0 deletions app/models/user.js
@@ -0,0 +1,16 @@
define([
'use!backbone'
], function(B) {
var User = B.Model.extend({
initialize : function() {
this.set('name', window.localStorage.getItem('username'));
this.on('change', this._store);
},

_store : function() {
window.localStorage.setItem('username', this.get('name'));
}
});

return User;
});

0 comments on commit 03c95a2

Please sign in to comment.