Commit 7f841196a627ab5e4304bbc8a05c409995dfb6dd
1 parent
76bd741e
Exists in
master
and in
10 other branches
List in selection only topics that belongs to a category
Showing
2 changed files
with
22 additions
and
7 deletions
Show diff stats
index.html
| @@ -77,16 +77,11 @@ | @@ -77,16 +77,11 @@ | ||
| 77 | {{#each categories}} | 77 | {{#each categories}} |
| 78 | <li class='category proposal-category' data-category="{{slug}}"> | 78 | <li class='category proposal-category' data-category="{{slug}}"> |
| 79 | {{#link name id}}{{/link}} | 79 | {{#link name id}}{{/link}} |
| 80 | - <select class='proposal-selection'> | ||
| 81 | - <option value='{{../id}}' selected> {{../title}}</option> | ||
| 82 | - {{#each ../../article.children}} | ||
| 83 | - <option value='{{id}}'> {{title}}</option> | ||
| 84 | - {{/each}} | ||
| 85 | - </select> | 80 | + {{#select_proposal ../../article.children slug ../id}}{{/select_proposal}} |
| 86 | </li> | 81 | </li> |
| 87 | {{/each}} | 82 | {{/each}} |
| 88 | </ul> | 83 | </ul> |
| 89 | - | 84 | + |
| 90 | <div class='proposal-header'> | 85 | <div class='proposal-header'> |
| 91 | <div class='abstract'> | 86 | <div class='abstract'> |
| 92 | <img src="{{../host}}{{image.url}}"/> | 87 | <img src="{{../host}}{{image.url}}"/> |
js/handlebars-helpers.js
| @@ -52,3 +52,23 @@ Handlebars.registerHelper('replace', function(string, to_replace, replacement) { | @@ -52,3 +52,23 @@ Handlebars.registerHelper('replace', function(string, to_replace, replacement) { | ||
| 52 | Handlebars.registerHelper('score', function(article) { | 52 | Handlebars.registerHelper('score', function(article) { |
| 53 | return article.votes_for - article.votes_against; | 53 | return article.votes_for - article.votes_against; |
| 54 | }); | 54 | }); |
| 55 | + | ||
| 56 | +Handlebars.registerHelper('select_proposal', function(proposals, category_slug, selected_id) { | ||
| 57 | + var ret = '<select class="proposal-selection">'; | ||
| 58 | + | ||
| 59 | + for(var i=0; i<proposals.length; i++) { | ||
| 60 | + if(!proposal_has_category(proposals[i], category_slug)) continue; | ||
| 61 | + var selected = proposals[i].id===selected_id ? "selected" : ""; | ||
| 62 | + ret += '<option value="'+proposals[i].id+'" '+selected+'>'+proposals[i].title+'</option>'; | ||
| 63 | + } | ||
| 64 | + ret += '</select>'; | ||
| 65 | + return ret; | ||
| 66 | +}); | ||
| 67 | + | ||
| 68 | +function proposal_has_category(proposal, category_slug) { | ||
| 69 | + for(var i=0; i<proposal.categories.length; i++) { | ||
| 70 | + if(proposal.categories[i].slug == category_slug) | ||
| 71 | + return true; | ||
| 72 | + } | ||
| 73 | + return false; | ||
| 74 | +} |