From 6d99ce2e07dd2b5c61769f032e41cde728799130 Mon Sep 17 00:00:00 2001 From: Alex Yatskov Date: Tue, 3 Mar 2015 19:32:02 +0900 Subject: [PATCH] Cleanup --- client/profile.html | 6 +++--- client/scripts/profile.js | 22 ++++++++++------------ server/search.js | 2 +- 3 files changed, 14 insertions(+), 16 deletions(-) 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()); }); }