1

Work on storing data in local storage

This commit is contained in:
Alex Yatskov 2015-03-03 19:12:39 +09:00
parent ff099ddb1c
commit eaf9912fb5

View File

@ -23,8 +23,32 @@
(function(categories) { (function(categories) {
'use strict'; 'use strict';
function transmitCategories() { function setProfileValue(id, value) {
console.log(categories); var profile = localStorage.profile || {};
profile[id] = value;
localStorage.profile = profile;
}
function getProfileValue(id) {
var profile = localStorage.profile || {};
return profile[id] || 0;
}
function addCategory(description) {
$.getJSON('/learn', {description: description}, function(results) {
if (!results.success) {
return;
}
var categories = {};
categories[results.id] = {
description: results.description,
value: getProfileValue(results.id)
};
displayCategories(categories);
});
} }
function displayCategories(categories) { function displayCategories(categories) {
@ -32,8 +56,7 @@
$('#categories').append(template({categories: categories})); $('#categories').append(template({categories: categories}));
$('#categories input:radio').change(function() { $('#categories input:radio').change(function() {
categories[$(this).attr('categoryId')].value = parseInt(this.value); setProfileValue($(this).attr('categoryId'), this.value);
transmitCategories();
}); });
} }
@ -41,16 +64,6 @@
$('#categories').empty(); $('#categories').empty();
} }
function addCategory(description) {
$.getJSON('/learn', {description: description}, function(results) {
if (results.success) {
var categories = {};
categories[results.id] = {description: results.description, value: 0};
displayCategories(categories);
}
});
}
function refreshCategories() { function refreshCategories() {
$.getJSON('/categories', function(results) { $.getJSON('/categories', function(results) {
var categories = {}; var categories = {};
@ -58,7 +71,7 @@
var result = results[i]; var result = results[i];
categories[result.id] = { categories[result.id] = {
description: result.description, description: result.description,
value: 0 value: getProfileValue(result.id)
}; };
} }