Add time type setting.(12 or 24 hour clock)

This commit is contained in:
BoHung Chiu 2022-07-20 22:38:59 +08:00
parent 8d73675bc4
commit 39be2dd0e9
9 changed files with 93 additions and 22 deletions

View File

@ -28,25 +28,39 @@ if(window.calendar_variable.is_chinese){
window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
if(window.calendar_variable.date_type == 2){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd H:m' : 'dd/MM/yy H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) H:m" : "W, dd/MM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b");
}
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d H:m' : 'd MMM, y H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) H:m" : "W, d MMM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
}
}
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.time_format = "H:m";
}else{
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
}
window.calendar_variable.std_date_format = 'y-MM-d';
window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d");
$.fn.fullCalendar = function(args){
@ -348,7 +362,7 @@ var Calendar = function(dom){
windowResize : function(view){
c.calendar_dom.calendar.refetchEvents();
},
eventTimeFormat: { hour12: true, hour: '2-digit', minute: '2-digit', omitZeroMinute: true, meridiem: 'narrow' },
eventTimeFormat: { hour12: (window.calendar_variable.time_type != 1), hour: '2-digit', minute: '2-digit', omitZeroMinute: true, meridiem: 'narrow' },
eventClick: function(eventClickInfo) {
var calEvent = {"event": eventClickInfo.event},
originalEvent = eventClickInfo.jsEvent,

View File

@ -28,25 +28,39 @@ if(window.calendar_variable.is_chinese){
window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
if(window.calendar_variable.date_type == 2){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd H:m' : 'dd/MM/yy H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) H:m" : "W, dd/MM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b");
}
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d H:m' : 'd MMM, y H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) H:m" : "W, d MMM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
}
}
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.time_format = "H:m";
}else{
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
}
window.calendar_variable.std_date_format = 'y-MM-d';
window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d");
$.fn.fullCalendar = function(args){
@ -225,7 +239,7 @@ var Calendar = function(dom,page_id,event_date=''){
windowResize : function(view){
c.calendar_dom.calendar.refetchEvents();
},
eventTimeFormat: { hour12: true, hour: '2-digit', minute: '2-digit', omitZeroMinute: true, meridiem: 'narrow' },
eventTimeFormat: { hour12: (window.calendar_variable.time_type != 1), hour: '2-digit', minute: '2-digit', omitZeroMinute: true, meridiem: 'narrow' },
eventClick: function(eventClickInfo) {
var calEvent = {"event": eventClickInfo.event},
originalEvent = eventClickInfo.jsEvent,

View File

@ -27,25 +27,39 @@ if(window.calendar_variable.is_chinese){
window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
if(window.calendar_variable.date_type == 2){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd H:m' : 'dd/MM/yy H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) H:m" : "W, dd/MM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b");
}
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d H:m' : 'd MMM, y H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) H:m" : "W, d MMM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
}
}
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.time_format = "H:m";
}else{
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
}
window.calendar_variable.std_date_format = 'y-MM-d';
window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d");
var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){

View File

@ -27,25 +27,39 @@ if(window.calendar_variable.is_chinese){
window.calendar_variable.months = ['January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
}
if(window.calendar_variable.date_type == 2){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'yy/MM' : 'MM/yy';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'yy/MM/dd' : 'dd/MM/yy';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'yy/MM/dd (W)' : 'W, MM/dd/yy';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MM/dd (W)" : "W, dd/MM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd H:m' : 'dd/MM/yy H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) H:m" : "W, dd/MM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'yy/MM/dd b h:m' : 'dd/MM/yy h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MM/dd (W) b h:m" : "W, dd/MM h:m b");
}
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.month_year_format = calendar_variable.is_chinese ? 'y MMM' : 'MMM y';
window.calendar_variable.date_format = calendar_variable.is_chinese ? 'y MMM d' : 'd MMM, y';
window.calendar_variable.date_format_with_short_month = calendar_variable.is_chinese ? 'y M d' : 'd M, y';
window.calendar_variable.date_format_with_week = calendar_variable.is_chinese ? 'y MMM d (W)' : 'W, MMM d, y';
window.calendar_variable.short_date = (calendar_variable.is_chinese ? "MMM d (W)" : "W, d MMM");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d H:m' : 'd MMM, y H:m';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) H:m" : "W, d MMM H:m");
}else{
window.calendar_variable.datetime_format = calendar_variable.is_chinese ? 'y MMM d b h:m' : 'd MMM, y h:m b';
window.calendar_variable.short_date_time = (calendar_variable.is_chinese ? "MMM d (W) b h:m" : "W, d MMM h:m b");
}
}
window.calendar_variable.date_format_numeric = 'yy/MM/dd';
window.calendar_variable.short_date_numeric = (calendar_variable.is_chinese ? "MM/dd (w)" : "w MM/dd");
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
if(window.calendar_variable.time_type == 1){
window.calendar_variable.time_format = "H:m";
}else{
window.calendar_variable.time_format = (calendar_variable.is_chinese ? "b h:m" : "h:m b");
}
window.calendar_variable.std_date_format = 'y-MM-d';
window.calendar_variable.short_day = (calendar_variable.is_chinese ? "d (W)" : "W d");
var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){

View File

@ -6,6 +6,7 @@ class CalendarSetting
field :days, type: Array, default: [], localize: true
field :sunday_first, type: Boolean, localize: true
field :date_type, type: Integer, localize: true, default: 0
field :time_type, type: Integer, localize: true, default: 0
field :titleFormat, localize: true
All_days = (0...7).to_a
ModesInfo = {'day'=>'timeGridDay', 'week'=>'timeGridWeek', 'month'=>'dayGridMonth', 'agenda'=>'agenda'}
@ -14,6 +15,7 @@ class CalendarSetting
"zh_tw"=>["[LocaleString]: 2022年7月12日 (週三)", "[en-US format]: weekday, monthname dd, YYYY", "[Locale Numeric]: YYYY/mm/dd (weekday)"],
"en"=>["[LocaleString]: weekday, monthname dd, YYYY", "[en-US format]: weekday, monthname dd, YYYY", "[Locale Numeric]: weekday, mm/dd/YYYY"]
}
TimeTypes = ["12_hour_clock", "24_hour_clock"]
def week_title
if self.days.present?
self.days

View File

@ -44,6 +44,12 @@
<%= select_tag "#{f.object_name}[#{locale}]" , options_for_select(tmp.map.with_index{|t, idx| [t, idx]}, f.object.date_type_translations[locale]), {style: "width: auto;"} %>
<% end %>
</div>
<%= f.label :time_type, t("calendar.time_type"), :class => "control-label muted" %>
<div class="controls">
<%= f.fields_for :time_type_translations ,f.object do |f| %>
<%= select_tag "#{f.object_name}[#{locale}]" , options_for_select(CalendarSetting::TimeTypes.map.with_index{|type, idx| [t("calendar.#{type}"), idx]}, f.object.time_type_translations[locale]), {style: "width: auto;"} %>
<% end %>
</div>
<hr style="margin: 5px 0;border-top: 2px solid black;clear: left;">
<h4><%= t('calendar.calendar_mode') %></h4>
<% CalendarSetting::All_modes.each do |mode| %>

View File

@ -7,6 +7,7 @@
window.calendar_variable.sunday_first = <%=@calendar_setting.sunday_first%>;
window.calendar_variable.week_title = <%=@calendar_setting.week_title.to_s.html_safe%>;
window.calendar_variable.date_type = <%=@calendar_setting.date_type%>;
window.calendar_variable.time_type = <%=@calendar_setting.time_type%>;
window.calendar_variable.dayNames = <%=@calendar_setting.days.to_s.html_safe%>;
<% if I18n.locale == :zh_tw %>
window.calendar_variable.dayNamesShort = <%=@calendar_setting.days.map{|d| d[-1]}.to_s.html_safe%>;

View File

@ -1,5 +1,8 @@
en:
calendar:
"12_hour_clock": "12 hour clock"
"24_hour_clock": "24 hour clock"
time_type: "Time Type"
date_type: "Date Type"
today: "Today"
sunday_first: "Sunday First"

View File

@ -1,5 +1,8 @@
zh_tw:
calendar:
"12_hour_clock": "12小時制"
"24_hour_clock": "24小時制"
time_type: "時間格式"
date_type: "日期格式"
today: "今日"
sunday_first: "週日先"