Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

favorites wip

  • Loading branch information...
commit 03c95a2bff0fb7327b4e16b1fe33691189754f45 1 parent e6fd4c3
@rmurphey authored
View
16 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;
+});
View
19 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;
+});
View
4 app/models/app.js
@@ -11,10 +11,10 @@ define([
)
),
- favorites = new Favorites(),
-
user = new User(),
+ favorites = new Favorites({ user : user }),
+
search = new B.Model({ term : null }),
searchData = new SearchData();
View
16 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;
+});
Please sign in to comment.
Something went wrong with that request. Please try again.