Align admin progress bars form fields with new translations interface

Add new js method to recover selected language to disable correctly default language fields.
This commit is contained in:
taitus
2019-06-01 20:17:56 +02:00
committed by Senén Rodero Rodríguez
parent c1a72e7169
commit 12089282c8
3 changed files with 34 additions and 21 deletions

View File

@@ -40,7 +40,8 @@ App.Forms =
hideOrShowFieldsAfterSelection: -> hideOrShowFieldsAfterSelection: ->
$("[name='progress_bar[kind]']").on $("[name='progress_bar[kind]']").on
change: -> change: ->
title_field = $("[name^='progress_bar'][name$='[title]']").parent() locale = App.Globalize.selected_language()
title_field = $(".translatable-fields[data-locale=#{locale}]")
if this.value == "primary" if this.value == "primary"
title_field.hide() title_field.hide()

View File

@@ -1,5 +1,8 @@
App.Globalize = App.Globalize =
selected_language: ->
$("#select_language").val()
display_locale: (locale) -> display_locale: (locale) ->
App.Globalize.enable_locale(locale) App.Globalize.enable_locale(locale)
App.Globalize.add_language(locale) App.Globalize.add_language(locale)

View File

@@ -2,30 +2,39 @@
<%= translatable_form_for [:tracking, *resource_hierarchy_for(@progress_bar)] do |f| %> <%= translatable_form_for [:tracking, *resource_hierarchy_for(@progress_bar)] do |f| %>
<div class="small-12 medium-6"> <div class="row">
<%= f.enum_select :kind %> <div class="small-12 medium-6 column">
<%= f.enum_select :kind %>
</div>
</div> </div>
<%= f.translatable_fields do |translations_form| %> <div class="row">
<div class="small-12 medium-6"> <%= f.translatable_fields do |translations_form| %>
<%= translations_form.text_field :title %> <div class="small-12 medium-6 column end">
</div> <%= translations_form.text_field :title %>
<% end %> </div>
<% end %>
</div>
<% progress_options = { min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 } %> <% progress_options = { min: ProgressBar::RANGE.min, max: ProgressBar::RANGE.max, step: 1 } %>
<div class="small-12 medium-6 large-2"> <div class="row">
<%= f.text_field :percentage, { type: :range, <div class="small-12 medium-6 large-2 column">
id: "percentage_range", <%= f.text_field :percentage, { type: :range,
class: "column" }.merge(progress_options) %> id: "percentage_range",
</div> class: "column" }.merge(progress_options) %>
<div class="small-12 medium-6 large-2"> </div>
<div class="input-group">
<%= f.text_field :percentage, { type: :number, <div class="small-12 medium-6 large-2 column">
label: false, <div class="input-group">
class: "input-group-field" }.merge(progress_options) %> <%= f.text_field :percentage, { type: :number,
<span class="input-group-label">%</span> label: false,
class: "input-group-field" }.merge(progress_options) %>
<span class="input-group-label">%</span>
</div>
</div>
<div class="column">
<%= f.submit nil, class: "button success" %>
</div> </div>
</div> </div>
<%= f.submit nil, class: "button success" %>
<% end %> <% end %>