From 19a159e8d73326e08b234ec19cf6e286e81a568f Mon Sep 17 00:00:00 2001 From: Benjamin ter Kuile Date: Wed, 8 Apr 2015 11:29:10 +0200 Subject: [PATCH] Use locale in template variables if available --- app/assets/javascripts/cmtool/collapsible.js.coffee | 6 ------ app/assets/javascripts/cmtool/html_edit.js.coffee | 13 +++++++++++-- 2 files changed, 11 insertions(+), 8 deletions(-) diff --git a/app/assets/javascripts/cmtool/collapsible.js.coffee b/app/assets/javascripts/cmtool/collapsible.js.coffee index 89baf5b..b0efe74 100644 --- a/app/assets/javascripts/cmtool/collapsible.js.coffee +++ b/app/assets/javascripts/cmtool/collapsible.js.coffee @@ -3,10 +3,4 @@ class Collapsible $('.collapsible-container').each (i, el) -> $(el).find('.collapsible-title').click -> $(el).toggleClass('collapsed') - #FIXME this is a hack for expanding on load for migration comments - $('.migration-comments .thread a').click() - - - - @collapsible = new Collapsible() diff --git a/app/assets/javascripts/cmtool/html_edit.js.coffee b/app/assets/javascripts/cmtool/html_edit.js.coffee index 2330e50..17fa1b2 100644 --- a/app/assets/javascripts/cmtool/html_edit.js.coffee +++ b/app/assets/javascripts/cmtool/html_edit.js.coffee @@ -1,6 +1,7 @@ class HtmlEdit setup: -> #ACE + locale_field = $('#page_locale') $('.html-content').each (i, el)-> text_field = $(el) template_field = $("##{text_field.attr('id')}_template") @@ -21,16 +22,24 @@ class HtmlEdit console.log "Editing handlebars" editor.getSession().setTabSize(2) editor.getSession().setUseSoftTabs(true) - editor.getSession().on 'change', (e)-> + template_vars = page_vars + if locale = locale_field.val() + template_vars = template_vars[locale] if template_vars[locale] + rebuild_html = -> value = editor.getValue() if template_field.length try template = Emblem.compile(Handlebars, value) - result_value = template(page_vars) + result_value = template(template_vars) template_field.val value text_field.val result_value else text_field.val value + editor.getSession().on 'change', rebuild_html + locale_field.change -> + locale = $(this).val() + template_vars = page_vars[locale] if page_vars[locale] + rebuild_html() text_field.hide() template_field.hide() @html_edit = new HtmlEdit()