From afb5afeceb5e975f4e015f1a5b9b07adb6407bee Mon Sep 17 00:00:00 2001 From: Manson Wang Date: Thu, 12 Dec 2013 16:07:27 +0800 Subject: [PATCH] Added multi-phone numbers in mobile setting page and fixed language setting --- app/controllers/admin/sites_controller.rb | 21 +++++++---- app/controllers/application_controller.rb | 1 + app/models/site.rb | 2 +- app/views/admin/sites/preference.html.erb | 30 +++++++++++----- .../admin/sites/responsive_setting.html.erb | 36 +++++++++++++++---- config/locales/en.yml | 1 + config/locales/zh_tw.yml | 1 + 7 files changed, 69 insertions(+), 23 deletions(-) diff --git a/app/controllers/admin/sites_controller.rb b/app/controllers/admin/sites_controller.rb index 13d64421..1883533b 100644 --- a/app/controllers/admin/sites_controller.rb +++ b/app/controllers/admin/sites_controller.rb @@ -21,20 +21,27 @@ class Admin::SitesController < OrbitBackendController end def update - - if params[:site][:default_locale] && @site.enable_language_detection.eql?(true) - Site.update_all({:enable_language_detection => false}) - elsif params[:site][:enable_language_detection] && @site.default_locale.present? - Site.update_all({:default_locale => nil}) - end - if params[:site][:default_bar_color] params[:site][:mobile_bar_color] = [] end # if params[:site][:enable_language_detection] # Site.update_all({:default_locale => nil}) # end + + if params[:site][:phone_number].nil? + params[:site][:phone_number] = [] + else + params[:site][:phone_number] = params[:site][:phone_number].values + end + @site.update_attributes(params[:site]) + + if params[:site][:enable_language_detection].eql?("0") + Site.update_all({:enable_language_detection => false}) + elsif params[:site][:enable_language_detection].eql?("1") + Site.update_all({:default_locale => nil}) + end + redirect_to :back end diff --git a/app/controllers/application_controller.rb b/app/controllers/application_controller.rb index 631b3e12..c8fcfe2f 100644 --- a/app/controllers/application_controller.rb +++ b/app/controllers/application_controller.rb @@ -163,6 +163,7 @@ class ApplicationController < ActionController::Base browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil if browser_locale.eql?("zh") condition = @site.in_use_locales.include?("zh_tw") + browser_locale = "zh_tw" else condition = @site.in_use_locales.include?(browser_locale) end diff --git a/app/models/site.rb b/app/models/site.rb index a1b043c4..a37cbbb3 100644 --- a/app/models/site.rb +++ b/app/models/site.rb @@ -44,7 +44,7 @@ class Site field :terms_of_use, localize: true field :google_analytics field :address - field :phone_number, :type => Hash,:default=>{} + field :phone_number, :type => Array,:default=>[] field :mobile_bar_color, :type => Array, :default=>[] diff --git a/app/views/admin/sites/preference.html.erb b/app/views/admin/sites/preference.html.erb index 6d96049a..a657e417 100644 --- a/app/views/admin/sites/preference.html.erb +++ b/app/views/admin/sites/preference.html.erb @@ -239,7 +239,7 @@ -
+
<%= f.submit t("submit"), :class => "btn btn-primary" %> <%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
@@ -254,20 +254,32 @@ $(".language-nav li a").click(function(){window.location.hash = $(this).attr("href")}); $(document).ready(function(){ - // Disable default language if language detection enbaled - $("#site_enable_language_detection").change(function(){ + var language_detection = $("#site_enable_language_detection"); + var default_locale = $( "input[name='site[default_locale]']" ); + + $(language_detection).click(function(){ if ( !$(this).parent().hasClass("disable") ){ - $.each($( "input[name='site[default_locale]']" ),function(){ - if ( !$(this).parent().hasClass("disable") ) $(this).parent().toggleClass('disable'); - $(this).toggleClass('disable'); + // Disable default language if language detection enbaled + $.each($(default_locale),function(){ + if ( !$(this).parent().hasClass("disable") ){ + $(this).parent().toggleClass('disable'); + $(this).toggleClass('disable'); + } + $(language_detection).val(1); }); + }else{ + // Enable a default language when language detection is disabled + $(default_locale).first().click(); } }); // Disable language detection if default language enbaled - $.each($( "input[name='site[default_locale]']" ),function(){ - $(this).click(function(){ - $("#site_enable_language_detection").parent().addClass('disable'); + $.each($(default_locale),function(){ + $(this).change(function(){ + if(!$(language_detection).parent().hasClass("disable")) { + $(language_detection).parent().toggleClass('disable'); + $(language_detection).val(0); + } }); }); }); diff --git a/app/views/admin/sites/responsive_setting.html.erb b/app/views/admin/sites/responsive_setting.html.erb index cdd25f43..eb583512 100644 --- a/app/views/admin/sites/responsive_setting.html.erb +++ b/app/views/admin/sites/responsive_setting.html.erb @@ -79,14 +79,21 @@
-
- <%= f.fields_for :phone_number do |p| %> - <%= p.text_field :title, :value => @site.phone_number["title"], :placeholder => "title" %> - <%= p.text_field :number, :value => @site.phone_number["number"], :placeholder => "number" %> +
+ <% @site.phone_number.each_with_index do |phone,i| %> + + + + <%= t(:delete) %> + <% end %>
+
+ + <%= t(:add) %> +
+
-
@@ -115,6 +122,14 @@ <%end%> +