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-left">{{description}}</td>
<td class="text-right"> <td class="text-right">
<label class="radio-inline"> <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>
<label class="radio-inline"> <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>
<label class="radio-inline"> <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> </label>
</td> </td>
</tr> </tr>

View File

@ -24,14 +24,11 @@
'use strict'; 'use strict';
function setProfileValue(id, value) { function setProfileValue(id, value) {
var profile = localStorage.profile || {}; localStorage[id] = value;
profile[id] = value;
localStorage.profile = profile;
} }
function getProfileValue(id) { function getProfileValue(id) {
var profile = localStorage.profile || {}; return localStorage[id] || 0;
return profile[id] || 0;
} }
function addCategory(description) { function addCategory(description) {
@ -53,8 +50,8 @@
function displayCategories(categories) { function displayCategories(categories) {
var template = Handlebars.compile($('#template').html()); var template = Handlebars.compile($('#template').html());
$('#categories').append(template({categories: categories})); $('#categories').append(template({categories: categories}));
$('#categories input:radio').change(function() { $('#categories input:radio').change(function() {
setProfileValue($(this).attr('categoryId'), this.value); setProfileValue($(this).attr('categoryId'), this.value);
}); });
@ -66,14 +63,15 @@
function refreshCategories() { function refreshCategories() {
$.getJSON('/categories', function(results) { $.getJSON('/categories', function(results) {
var categories = {}; var categories = [];
for (var i = 0, length = results.length; i < length; ++i) {
var result = results[i]; _.each(results, function(result) {
categories[result.id] = { categories.push({
id: result.id,
description: result.description, description: result.description,
value: getProfileValue(result.id) value: getProfileValue(result.id)
}; });
} });
clearCategories(); clearCategories();
displayCategories(categories); displayCategories(categories);

View File

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