Added multi-phone numbers in mobile setting page and fixed language setting

This commit is contained in:
Manson Wang 2013-12-12 16:07:27 +08:00
parent 4c85d62866
commit afb5afeceb
7 changed files with 69 additions and 23 deletions

View File

@ -21,20 +21,27 @@ class Admin::SitesController < OrbitBackendController
end end
def update 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] if params[:site][:default_bar_color]
params[:site][:mobile_bar_color] = [] params[:site][:mobile_bar_color] = []
end end
# if params[:site][:enable_language_detection] # if params[:site][:enable_language_detection]
# Site.update_all({:default_locale => nil}) # Site.update_all({:default_locale => nil})
# end # 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]) @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 redirect_to :back
end end

View File

@ -163,6 +163,7 @@ class ApplicationController < ActionController::Base
browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil browser_locale = request.env['HTTP_ACCEPT_LANGUAGE'].scan(/^[a-z]{2}/).first rescue nil
if browser_locale.eql?("zh") if browser_locale.eql?("zh")
condition = @site.in_use_locales.include?("zh_tw") condition = @site.in_use_locales.include?("zh_tw")
browser_locale = "zh_tw"
else else
condition = @site.in_use_locales.include?(browser_locale) condition = @site.in_use_locales.include?(browser_locale)
end end

View File

@ -44,7 +44,7 @@ class Site
field :terms_of_use, localize: true field :terms_of_use, localize: true
field :google_analytics field :google_analytics
field :address field :address
field :phone_number, :type => Hash,:default=>{} field :phone_number, :type => Array,:default=>[]
field :mobile_bar_color, :type => Array, :default=>[] field :mobile_bar_color, :type => Array, :default=>[]

View File

@ -239,7 +239,7 @@
</div> </div>
<!-- Form Actions --> <!-- Form Actions -->
<div class="form-actions"> <div class="form-actions" style="background: none;">
<%= f.submit t("submit"), :class => "btn btn-primary" %> <%= f.submit t("submit"), :class => "btn btn-primary" %>
<%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %> <%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
</div> </div>
@ -254,20 +254,32 @@
$(".language-nav li a").click(function(){window.location.hash = $(this).attr("href")}); $(".language-nav li a").click(function(){window.location.hash = $(this).attr("href")});
$(document).ready(function(){ $(document).ready(function(){
// Disable default language if language detection enbaled var language_detection = $("#site_enable_language_detection");
$("#site_enable_language_detection").change(function(){ var default_locale = $( "input[name='site[default_locale]']" );
$(language_detection).click(function(){
if ( !$(this).parent().hasClass("disable") ){ if ( !$(this).parent().hasClass("disable") ){
$.each($( "input[name='site[default_locale]']" ),function(){ // Disable default language if language detection enbaled
if ( !$(this).parent().hasClass("disable") ) $(this).parent().toggleClass('disable'); $.each($(default_locale),function(){
if ( !$(this).parent().hasClass("disable") ){
$(this).parent().toggleClass('disable');
$(this).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 // Disable language detection if default language enbaled
$.each($( "input[name='site[default_locale]']" ),function(){ $.each($(default_locale),function(){
$(this).click(function(){ $(this).change(function(){
$("#site_enable_language_detection").parent().addClass('disable'); if(!$(language_detection).parent().hasClass("disable")) {
$(language_detection).parent().toggleClass('disable');
$(language_detection).val(0);
}
}); });
}); });
}); });

View File

@ -79,12 +79,19 @@
<div class="control-group"> <div class="control-group">
<label class="control-label muted">Phone Number</label> <label class="control-label muted">Phone Number</label>
<div class="controls"> <div class="controls">
<div class="textarea"> <div id="phone_number_wrap" style="line-height: 40px;">
<%= f.fields_for :phone_number do |p| %> <% @site.phone_number.each_with_index do |phone,i| %>
<%= p.text_field :title, :value => @site.phone_number["title"], :placeholder => "title" %> <span>
<%= p.text_field :number, :value => @site.phone_number["number"], :placeholder => "number" %> <input type="text" name="site[phone_number][<%= i %>][title]" value="<%= phone['title'] %>">
<input type="text" name="site[phone_number][<%= i %>][number]" value="<%= phone['number'] %>">
<a class="btn btn-small btn-danger delete_phone_number" href="#" onclick="$(this).parent().remove();"><i class="icon-trash"></i> <%= t(:delete) %></a>
</span>
<% end %> <% end %>
</div> </div>
<div class='btn btn-small btn-success' id='add_phone_number_btn'>
<i class="icon-plus"></i>
<%= t(:add) %>
</div>
</div> </div>
</div> </div>
@ -115,6 +122,14 @@
</fieldset> </fieldset>
<%end%> <%end%>
<div id="phone_number_template" style="display:none">
<span style='line-height: 40px; display: block;'>
<input id="site_phone_number_title" name="site[phone_number][][title]" placeholder="<%= t(:name) %>" size="30" type="text" value="">
<input id="site_phone_number_number" name="site[phone_number][][number]" placeholder="<%= t(:phone_number) %>" size="30" type="text" value="">
<a class="btn btn-small btn-danger delete_phone_number" href="#" onclick="$(this).parent().remove();"><i class="icon-trash"></i> <%= t(:delete) %></a>
</span>
</script>
<% content_for :page_specific_javascript do %> <% content_for :page_specific_javascript do %>
<script type="text/javascript"> <script type="text/javascript">
@ -151,8 +166,17 @@
colorboxes.removeAttr('disabled'); colorboxes.removeAttr('disabled');
} }
}) });
// Number of phones
var num = $("#phone_number_wrap input").length/2;
$('#add_phone_number_btn').click(function(){
var template = $("#phone_number_template").html();
template = template.replace(/\[]/g,"["+num+"]");
$("#phone_number_wrap").append(template);
num++;
});
}); });
</script> </script>
<% end %> <% end %>

View File

@ -338,6 +338,7 @@ en:
brief_intro : "Brief Intro." brief_intro : "Brief Intro."
complete_list : "Complete List" complete_list : "Complete List"
frontend_page : "Frontend Page" frontend_page : "Frontend Page"
phone_number: "Phone Number"
picture: Picture picture: Picture
placeholder: Field Hint placeholder: Field Hint
plugins: Plugins plugins: Plugins

View File

@ -339,6 +339,7 @@ zh_tw:
brief_intro : "摘要" brief_intro : "摘要"
complete_list : "完整列表" complete_list : "完整列表"
frontend_page : "前台呈現" frontend_page : "前台呈現"
phone_number: "電話"
picture: 圖片 picture: 圖片
placeholder: 欄位提示文字 placeholder: 欄位提示文字
plugins: 學術資訊 plugins: 學術資訊