fix some error

This commit is contained in:
BOYA,CHIU 2021-08-26 18:57:42 +08:00
parent 25d1187f99
commit 460d5a15f2
11 changed files with 46 additions and 44 deletions

View File

@ -19,7 +19,7 @@ var Calendar = function(dom,page_id,event_date=''){
this.initialize = function(){ this.initialize = function(){
if (event_date != ''){ if (event_date != ''){
var event_dates = event_date.split("-"); var event_dates = event_date.split("-");
var date = new Date(event_dates[0],event_dates[1],event_dates[2]); var date = new Date(Date.UTC(event_dates[0],event_dates[1],event_dates[2]));
}else{ }else{
var date = new Date(); var date = new Date();
} }
@ -358,8 +358,8 @@ var AgendaView = function(calendar){
} }
var eventsManager = function(){ var eventsManager = function(){
var url = "/xhr/calendars/agenda", var url = "/xhr/calendars/agenda",
sd = new Date(start_year,start_month,1), sd = new Date(Date.UTC(start_year,start_month,1)),
ed = new Date(end_year,end_month+1,0), ed = new Date(Date.UTC(end_year,end_month+1,0)),
usd = Math.round(sd/1000), usd = Math.round(sd/1000),
ued = Math.round(ed/1000); ued = Math.round(ed/1000);
$.ajax({ $.ajax({
@ -395,7 +395,7 @@ var AgendaView = function(calendar){
c_m = s.getMonth(), c_m = s.getMonth(),
c_d = s.getDate(), c_d = s.getDate(),
c_y = s.getFullYear(), c_y = s.getFullYear(),
end_of_c_month = new Date(s.getFullYear(),s.getMonth()+1,0).getDate(); end_of_c_month = new Date(Date.UTC(s.getFullYear(),s.getMonth()+1,0)).getDate();
for(var i = 0; i <= diffDays; i++){ for(var i = 0; i <= diffDays; i++){
var td = agenda_space.find("td[data-date-node="+c_d+"-"+c_m+"-"+c_y+"]"); var td = agenda_space.find("td[data-date-node="+c_d+"-"+c_m+"-"+c_y+"]");
@ -485,8 +485,8 @@ var AgendaView = function(calendar){
this.monthDom = $("<div class='row' data-year='"+year+"' data-month='"+month+"'></div>"); this.monthDom = $("<div class='row' data-year='"+year+"' data-month='"+month+"'></div>");
var template = $(month_template); var template = $(month_template);
var list_template = $(event_list_template); var list_template = $(event_list_template);
var firstDay = new Date(year,month,1); var firstDay = new Date(Date.UTC(year,month,1));
var lastDay = new Date(year,month+1,0); var lastDay = new Date(Date.UTC(year,month+1,0));
var last_inserted_date = 1; var last_inserted_date = 1;
var renderMonth = function(){ var renderMonth = function(){
@ -514,7 +514,7 @@ var AgendaView = function(calendar){
var day = 1, var day = 1,
sat_counter = 0, sat_counter = 0,
sunday_counter = 0, sunday_counter = 0,
date = new Date(year, month, day); date = new Date(Date.UTC(year, month, day));
while(date.getMonth() === month) { while(date.getMonth() === month) {
if(date.getDay() === 0) { if(date.getDay() === 0) {
@ -523,7 +523,7 @@ var AgendaView = function(calendar){
sat_counter++; sat_counter++;
} }
day++; day++;
date = new Date(year, month, day); date = new Date(Date.UTC(year, month, day));
} }
return (sunday_counter == 5 && sat_counter == 5 ? 6 : 5); return (sunday_counter == 5 && sat_counter == 5 ? 6 : 5);
} }

View File

@ -10,10 +10,10 @@
fetchInterval = null, fetchInterval = null,
month = date.getMonth(), month = date.getMonth(),
year = date.getFullYear(), year = date.getFullYear(),
first_target_day = new Date(year,month,1), first_target_day = new Date(Date.UTC(year,month,1)),
last_target_day = new Date(year,month+1,0), last_target_day = new Date(Date.UTC(year,month+1,0)),
firstDay = new Date(year,month,1), firstDay = new Date(Date.UTC(year,month,1)),
lastDay = new Date(year,month+1,0), lastDay = new Date(Date.UTC(year,month+1,0)),
today = date.getDate(), today = date.getDate(),
last_inserted_date = 1, last_inserted_date = 1,
monthDom = $("<div data-year='"+year+"' data-month='"+month+"'></div>"), monthDom = $("<div data-year='"+year+"' data-month='"+month+"'></div>"),
@ -337,7 +337,7 @@
if(dayDiff > 0){ if(dayDiff > 0){
var inserting_date = sd.getDate(); var inserting_date = sd.getDate();
for(var i = 0;i <= dayDiff; i++){ for(var i = 0;i <= dayDiff; i++){
var dt = inserting_date + "-" + month + "-" + year, var dt = inserting_date + "-" + sd.getMonth() + "-" + sd.getFullYear(),
td = dom.find("td[data-date-node=" + dt + "]"); td = dom.find("td[data-date-node=" + dt + "]");
if (events[dt]==undefined){ if (events[dt]==undefined){
events[dt]=[] events[dt]=[]
@ -370,7 +370,7 @@
} }
}) })
if (!toggle_data){ if (!toggle_data){
if (dom.find('td.w-calendar-event.w-calendar-today').length != 0){ if (dom.find('td.w-calendar-today').length != 0){
toggle_event(dom.find('td.w-calendar-today'),'show') toggle_event(dom.find('td.w-calendar-today'),'show')
}else{ }else{
toggle_event(dom.find('td'),'hide') toggle_event(dom.find('td'),'hide')
@ -410,8 +410,8 @@
year++; year++;
month = 0; month = 0;
} }
firstDay = new Date(year,month,1); firstDay = new Date(Date.UTC(year,month,1));
lastDay = new Date(year,month+1,0); lastDay = new Date(Date.UTC(year,month+1,0));
today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0); today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0);
last_inserted_date = 1; last_inserted_date = 1;
var toggle_type,ele; var toggle_type,ele;
@ -438,8 +438,8 @@
year--; year--;
month = 11; month = 11;
} }
firstDay = new Date(year,month,1); firstDay = new Date(Date.UTC(year,month,1));
lastDay = new Date(year,month+1,0); lastDay = new Date(Date.UTC(year,month+1,0));
today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0); today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0);
last_inserted_date = 1; last_inserted_date = 1;
var toggle_type,ele; var toggle_type,ele;

View File

@ -10,10 +10,10 @@
fetchInterval = null, fetchInterval = null,
month = date.getMonth(), month = date.getMonth(),
year = date.getFullYear(), year = date.getFullYear(),
first_target_day = new Date(year,month,1), first_target_day = new Date(Date.UTC(year,month,1)),
last_target_day = new Date(year,month+1,0), last_target_day = new Date(Date.UTC(year,month+1,0)),
firstDay = new Date(year,month,1), firstDay = new Date(Date.UTC(year,month,1)),
lastDay = new Date(year,month+1,0), lastDay = new Date(Date.UTC(year,month+1,0)),
today = date.getDate(), today = date.getDate(),
last_inserted_date = 1, last_inserted_date = 1,
monthDom = $("<div data-year='"+year+"' data-month='"+month+"'></div>"), monthDom = $("<div data-year='"+year+"' data-month='"+month+"'></div>"),
@ -476,7 +476,7 @@
if(dayDiff > 0){ if(dayDiff > 0){
var inserting_date = sd.getDate(); var inserting_date = sd.getDate();
for(var i = 0;i <= dayDiff; i++){ for(var i = 0;i <= dayDiff; i++){
var dt = inserting_date + "-" + month + "-" + year, var dt = inserting_date + "-" + sd.getMonth() + "-" + sd.getFullYear(),
td = dom.find("td[data-date-node=" + dt + "]"); td = dom.find("td[data-date-node=" + dt + "]");
if (events[dt]==undefined){ if (events[dt]==undefined){
events[dt]=[] events[dt]=[]
@ -509,7 +509,7 @@
} }
}) })
if (!toggle_data){ if (!toggle_data){
if (dom.find('td.w-calendar-event.w-calendar-today').length != 0){ if (dom.find('td.w-calendar-today').length != 0){
toggle_event(dom.find('td.w-calendar-today'),'show') toggle_event(dom.find('td.w-calendar-today'),'show')
}else{ }else{
toggle_event(dom.find('td'),'hide') toggle_event(dom.find('td'),'hide')
@ -550,8 +550,8 @@
year++; year++;
month = 0; month = 0;
} }
firstDay = new Date(year,month,1); firstDay = new Date(Date.UTC(year,month,1));
lastDay = new Date(year,month+1,0); lastDay =new Date(Date.UTC(year,month+1,0));
today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0); today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0);
last_inserted_date = 1; last_inserted_date = 1;
var toggle_type,ele; var toggle_type,ele;
@ -578,8 +578,8 @@
year--; year--;
month = 11; month = 11;
} }
firstDay = new Date(year,month,1); firstDay = new Date(Date.UTC(year,month,1));
lastDay = new Date(year,month+1,0); lastDay = new Date(Date.UTC(year,month+1,0));
today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0); today = (initialDate.getMonth() == month && initialDate.getFullYear() == year ? initialDate.getDate() : 0);
last_inserted_date = 1; last_inserted_date = 1;
var toggle_type,ele; var toggle_type,ele;

View File

@ -87,7 +87,7 @@ a.event-container{
margin-top: 2em; margin-top: 2em;
} }
.widget-calendar-1 .w-calendar-nav a { .widget-calendar-1 .w-calendar-nav a {
top: 2em; top: 0.5em;
} }
.calendar-dialog div.ui-dialog-content { .calendar-dialog div.ui-dialog-content {
max-height: 20em !important; max-height: 20em !important;

View File

@ -71,7 +71,7 @@ a.event-container-one{
padding: 0.2em; padding: 0.2em;
font-size: 1.5em; font-size: 1.5em;
} }
.widget-calendar-2 table.w-calendar-table td.w-calendar-toggle div { .widget-calendar-2 table.w-calendar-table td.w-calendar-toggle div, .widget-calendar-2 table.w-calendar-table td.w-calendar-toggle div{
background: #6f0007; background: #6f0007;
border-radius: 1.5em; border-radius: 1.5em;
color: white; color: white;

View File

@ -42,8 +42,8 @@ class CalendarsController < ApplicationController
events =[] events =[]
if !page.nil? if !page.nil?
if params[:start].present? && params[:end].present? if params[:start].present? && params[:end].present?
sdt = Time.at(params[:start].to_i) sdt = Time.at(params[:start].to_i).utc
edt = Time.at(params[:end].to_i) edt = Time.at(params[:end].to_i).utc
events = Event.monthly_event(sdt,edt).convert_front+Event.recurring_event(sdt,edt) events = Event.monthly_event(sdt,edt).convert_front+Event.recurring_event(sdt,edt)
end end
end end
@ -64,15 +64,15 @@ class CalendarsController < ApplicationController
calendar_types = [] calendar_types = []
end end
if params[:unix_start].present? && params[:unix_end].present? if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).to_s agenda_start = Time.at(params[:unix_start].to_i).utc.to_s
agenda_end = Time.at(params[:unix_end].to_i).to_s agenda_end = Time.at(params[:unix_end].to_i).utc.to_s
if !calendar_types.blank? if !calendar_types.blank?
events = Event.where(:calendar_type_id.in => calendar_types).agenda_events(agenda_start,agenda_end) events = Event.where(:calendar_type_id.in => calendar_types).agenda_events(agenda_start,agenda_end)
else else
events = Event.agenda_events(agenda_start,agenda_end) events = Event.agenda_events(agenda_start,agenda_end)
end end
end end
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i))}.to_json({"frontend" => true}) render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
end end
end end
@ -86,19 +86,19 @@ class CalendarsController < ApplicationController
calendar_types = [] calendar_types = []
end end
if params[:unix_start].present? && params[:unix_end].present? if params[:unix_start].present? && params[:unix_end].present?
agenda_start = Time.at(params[:unix_start].to_i).to_s agenda_start = Time.at(params[:unix_start].to_i).utc.to_s
agenda_end = Time.at(params[:unix_end].to_i).to_s agenda_end = Time.at(params[:unix_end].to_i).utc.to_s
if !calendar_types.blank? if !calendar_types.blank?
events = Event.where(:calendar_type_id.in => calendar_types).agenda_events(agenda_start,agenda_end) events = Event.where(:calendar_type_id.in => calendar_types).agenda_events(agenda_start,agenda_end)
else else
events = Event.agenda_events(agenda_start,agenda_end) events = Event.agenda_events(agenda_start,agenda_end)
end end
end end
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i))}.to_json({"frontend" => true}) render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
end end
end end
def get_calendar_title(now_date=nil) def get_calendar_title(now_date=nil)
now_date = Time.now if now_date.nil? now_date = Time.now.utc if now_date.nil?
month_name = I18n.locale.to_s=='zh_tw' ? now_date.month : I18n.t("calendar.month_name.#{now_date.month}") month_name = I18n.locale.to_s=='zh_tw' ? now_date.month : I18n.t("calendar.month_name.#{now_date.month}")
I18n.t("calendar.calendar_title",year: now_date.year,month: month_name) I18n.t("calendar.calendar_title",year: now_date.year,month: month_name)
end end

View File

@ -1,7 +1,7 @@
<div class="w-calendar widget-calendar-1" data-module="calendar"> <div class="w-calendar widget-calendar-1" data-module="calendar">
<div class='month_template'> <div class='month_template'>
<h4 class="widget-title "> <h4 class="widget-title ">
<span class="text"></span> <span class="text"><span style="display: none;">placeholder</span></span>
<i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i> <i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i>
</h4> </h4>
<div class="w-calendar-nav"> <div class="w-calendar-nav">

View File

@ -5,7 +5,7 @@
</div> </div>
<div class='month_template'> <div class='month_template'>
<h4 class="widget-title "> <h4 class="widget-title ">
<span class="text"></span> <span class="text"><span style="display: none;">placeholder</span></span>
<i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i> <i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i>
</h4> </h4>
<div class="w-calendar-nav"> <div class="w-calendar-nav">

View File

@ -27,7 +27,9 @@
</button> </button>
</div> </div>
<div id="view_holder"> <div id="view_holder">
<h3 id="current_title" class="current_day_title"></h3> <h3 id="current_title" class="current_day_title">
<span style="display: none;">placeholder</span>
</h3>
<div id="calendar"></div> <div id="calendar"></div>
<div id="calendar_agenda"></div> <div id="calendar_agenda"></div>
</div> </div>

View File

@ -3,7 +3,7 @@
<div class="w-calendar widget-calendar-1 index2" data-module="calendar" data-page-id="{{page_id}}"> <div class="w-calendar widget-calendar-1 index2" data-module="calendar" data-page-id="{{page_id}}">
<div class='month_template'> <div class='month_template'>
<h4 class="widget-title "> <h4 class="widget-title ">
<span class="text"></span> <span class="text"><span style="display: none;">placeholder</span></span>
<i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i> <i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i>
</h4> </h4>
<div class="w-calendar-nav"> <div class="w-calendar-nav">

View File

@ -7,7 +7,7 @@
</div> </div>
<div class='month_template'> <div class='month_template'>
<h4 class="widget-title "> <h4 class="widget-title ">
<span class="text"></span> <span class="text"><span style="display: none;">placeholder</span></span>
<i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i> <i class="fa fa-circle-o-notch fa-spin fa-fw loading hide"></i>
</h4> </h4>
<div class="w-calendar-nav"> <div class="w-calendar-nav">