diff options
author | Hitoshi Nakashima <morygonzalez@gmail.com> | 2018-01-19 05:22:10 +0900 |
---|---|---|
committer | Rafael França <rafaelmfranca@gmail.com> | 2018-01-18 15:22:10 -0500 |
commit | 5fe603ac288d4432be77cfa851e86ad66fd48d53 (patch) | |
tree | 1466c9a625ef1a37898a2d676fbce74ea2f1b8a5 /railties/lib/rails/templates | |
parent | e0f0d717d63b7896186f40c4d389977ddba72a97 (diff) | |
download | rails-5fe603ac288d4432be77cfa851e86ad66fd48d53.tar.gz rails-5fe603ac288d4432be77cfa851e86ad66fd48d53.tar.bz2 rails-5fe603ac288d4432be77cfa851e86ad66fd48d53.zip |
Add locale selector to email preview (#31596)
- Add set_locale to detect suitable locale
- Make feature compatible with Rails 5.x
Diffstat (limited to 'railties/lib/rails/templates')
-rw-r--r-- | railties/lib/rails/templates/rails/mailers/email.html.erb | 35 |
1 files changed, 25 insertions, 10 deletions
diff --git a/railties/lib/rails/templates/rails/mailers/email.html.erb b/railties/lib/rails/templates/rails/mailers/email.html.erb index 89c1129f90..44c400a7e6 100644 --- a/railties/lib/rails/templates/rails/mailers/email.html.erb +++ b/railties/lib/rails/templates/rails/mailers/email.html.erb @@ -96,10 +96,22 @@ <% end %> <% if @email.multipart? %> + <dt>Format:</dt> <dd> - <select onchange="formatChanged(this);"> - <option <%= request.format == Mime[:html] ? 'selected' : '' %> value="?<%= part_query('text/html') %>">View as HTML email</option> - <option <%= request.format == Mime[:text] ? 'selected' : '' %> value="?<%= part_query('text/plain') %>">View as plain-text email</option> + <select id="part" onchange="refreshBody();"> + <option <%= request.format == Mime[:html] ? 'selected' : '' %> value="<%= part_query('text/html') %>">View as HTML email</option> + <option <%= request.format == Mime[:text] ? 'selected' : '' %> value="<%= part_query('text/plain') %>">View as plain-text email</option> + </select> + </dd> + <% end %> + + <% if I18n.available_locales.count > 1 %> + <dt>Locale:</dt> + <dd> + <select id="locale" onchange="refreshBody();"> + <% I18n.available_locales.each do |locale| %> + <option <%= I18n.locale == locale ? 'selected' : '' %> value="<%= locale_query(locale) %>"><%= locale %></option> + <% end %> </select> </dd> <% end %> @@ -116,15 +128,18 @@ <% end %> <script> - function formatChanged(form) { - var part_name = form.options[form.selectedIndex].value - var iframe =document.getElementsByName('messageBody')[0]; - iframe.contentWindow.location.replace(part_name); + function refreshBody() { + var part_select = document.querySelector('select#part'); + var locale_select = document.querySelector('select#locale'); + var part_param = part_select.options[part_select.selectedIndex].value; + var locale_param = locale_select.options[locale_select.selectedIndex].value; + var iframe = document.getElementsByName('messageBody')[0]; + iframe.contentWindow.location = '?' + part_param + '&' + locale_param; if (history.replaceState) { - var url = location.pathname.replace(/\.(txt|html)$/, ''); - var format = /html/.test(part_name) ? '.html' : '.txt'; - window.history.replaceState({}, '', url + format); + var url = location.pathname.replace(/\.(txt|html)$/, ''); + var format = /html/.test(part_param) ? '.html' : '.txt'; + window.history.replaceState({}, '', url + format + '?' + locale_param); } } </script> |