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
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

View File

@ -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

View File

@ -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=>[]

View File

@ -239,7 +239,7 @@
</div>
<!-- Form Actions -->
<div class="form-actions">
<div class="form-actions" style="background: none;">
<%= f.submit t("submit"), :class => "btn btn-primary" %>
<%= f.submit t("cancel"), :class => "btn ", :type => 'reset' %>
</div>
@ -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);
}
});
});
});

View File

@ -79,14 +79,21 @@
<div class="control-group">
<label class="control-label muted">Phone Number</label>
<div class="controls">
<div class="textarea">
<%= 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" %>
<div id="phone_number_wrap" style="line-height: 40px;">
<% @site.phone_number.each_with_index do |phone,i| %>
<span>
<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 %>
</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 class="control-group">
<label class="control-label muted">Address</label>
@ -115,6 +122,14 @@
</fieldset>
<%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 %>
<script type="text/javascript">
@ -151,8 +166,17 @@
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>
<% end %>

View File

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

View File

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