diff --git a/client/profile.html b/client/profile.html index f12d612..dcf6cdc 100644 --- a/client/profile.html +++ b/client/profile.html @@ -32,13 +32,13 @@ {{description}} diff --git a/client/scripts/profile.js b/client/scripts/profile.js index eb3b518..1ebaf25 100644 --- a/client/scripts/profile.js +++ b/client/scripts/profile.js @@ -24,14 +24,11 @@ 'use strict'; function setProfileValue(id, value) { - var profile = localStorage.profile || {}; - profile[id] = value; - localStorage.profile = profile; + localStorage[id] = value; } function getProfileValue(id) { - var profile = localStorage.profile || {}; - return profile[id] || 0; + return localStorage[id] || 0; } function addCategory(description) { @@ -53,8 +50,8 @@ function displayCategories(categories) { var template = Handlebars.compile($('#template').html()); - $('#categories').append(template({categories: categories})); + $('#categories input:radio').change(function() { setProfileValue($(this).attr('categoryId'), this.value); }); @@ -66,14 +63,15 @@ function refreshCategories() { $.getJSON('/categories', function(results) { - var categories = {}; - for (var i = 0, length = results.length; i < length; ++i) { - var result = results[i]; - categories[result.id] = { + var categories = []; + + _.each(results, function(result) { + categories.push({ + id: result.id, description: result.description, value: getProfileValue(result.id) - }; - } + }); + }); clearCategories(); displayCategories(categories); diff --git a/server/search.js b/server/search.js index 1f5ac5c..4258ed4 100644 --- a/server/search.js +++ b/server/search.js @@ -220,7 +220,7 @@ function getCategories(callback) { return {id: row.id, description: row.description}; }); - callback(categories); + callback(categories.reverse()); }); }