1
This commit is contained in:
Alex Yatskov 2015-03-03 19:32:02 +09:00
parent eaf9912fb5
commit 6d99ce2e07
3 changed files with 14 additions and 16 deletions

View File

@ -32,13 +32,13 @@
<td class="text-left">{{description}}</td>
<td class="text-right">
<label class="radio-inline">
<input type="radio" name="category_{{@key}}" categoryId="{{@key}}" value="1" {{checkMatch 1}}> Agree
<input type="radio" name="category_{{id}}" categoryId="{{id}}" value="1" {{checkMatch 1}}> Agree
</label>
<label class="radio-inline">
<input type="radio" name="category_{{@key}}" categoryId="{{@key}}" value="0" {{checkMatch 0}}> Neither
<input type="radio" name="category_{{id}}" categoryId="{{id}}" value="-1" {{checkMatch -1}}> Disagree
</label>
<label class="radio-inline">
<input type="radio" name="category_{{@key}}" categoryId="{{@key}}" value="-1" {{checkMatch -1}}> Disagree
<input type="radio" name="category_{{id}}" categoryId="{{id}}" value="0" {{checkMatch 0}}> Neither
</label>
</td>
</tr>

View File

@ -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);

View File

@ -220,7 +220,7 @@ function getCategories(callback) {
return {id: row.id, description: row.description};
});
callback(categories);
callback(categories.reverse());
});
}