diff --git a/app/assets/javascripts/calendar_widget.js b/app/assets/javascripts/calendar_widget.js
index e059041..d89d96d 100644
--- a/app/assets/javascripts/calendar_widget.js
+++ b/app/assets/javascripts/calendar_widget.js
@@ -341,9 +341,9 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
td.find('div').html(last_inserted_date<10 ? " "+last_inserted_date+" " : last_inserted_date);
td.attr("data-date-node",last_inserted_date+"-"+firstDay.getMonth()+"-"+firstDay.getFullYear());
last_inserted_date++;
- }else{first_line_first_date
+ }else{
td.find('div').text(first_line_first_date+i)
- td.attr("data-date-node",(+i)+"-"+first_line_first_month+"-"+first_line_first_year);
+ td.attr("data-date-node",(first_line_first_date+i)+"-"+first_line_first_month+"-"+first_line_first_year);
td.addClass("w-calendar-other-month")
}
row.append(td);
@@ -368,10 +368,11 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
next_month = 0;
next_year = next_year + 1;
}
- last_target_day = new Date(next_year,next_month,6-lastDay.getDay())
+ var offset = lastDay.getDay() - (window.calendar_variable.sunday_first ? 0 : 1);
+ last_target_day = new Date(next_year,next_month , 6 - lastDay.getDay());
for(var i = 0;i < 7;i++){
var td = $("
| ");
- if(i <= lastDay.getDay()){
+ if(i <= offset){
if(today != 0 && last_inserted_date == today){
td.attr("class","w-calendar-today");
}
@@ -379,8 +380,8 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
td.attr("data-date-node",last_inserted_date+"-"+firstDay.getMonth()+"-"+firstDay.getFullYear());
last_inserted_date++;
}else{
- td.find('div').text(i-lastDay.getDay())
- td.attr("data-date-node",(i-lastDay.getDay())+"-"+next_month+"-"+next_year);
+ td.find('div').text(i - offset)
+ td.attr("data-date-node",(i - offset)+"-"+next_month+"-"+next_year);
td.addClass("w-calendar-other-month")
}
row.append(td);
@@ -439,9 +440,9 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
start_of_ed_date = get_start_of_date(ed_date),
timeDiff = start_of_ed_date.getTime() - start_of_sd_date.getTime(),
dayDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
- if(eve.allDay && dayDiff < 1){
- dayDiff = 1
- }
+ // if(eve.allDay && dayDiff < 1){
+ // dayDiff = 1
+ // }
if(dayDiff > 0){
var inserting_date = sd.getDate();
for(var i = 0;i <= dayDiff; i++){
diff --git a/app/assets/javascripts/calendar_widget2.js b/app/assets/javascripts/calendar_widget2.js
index fa65de6..c135978 100644
--- a/app/assets/javascripts/calendar_widget2.js
+++ b/app/assets/javascripts/calendar_widget2.js
@@ -508,10 +508,11 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
next_month = 0;
next_year = next_year + 1;
}
- last_target_day = new Date(next_year,next_month,6-lastDay.getDay())
+ var offset = lastDay.getDay() - (window.calendar_variable.sunday_first ? 0 : 1);
+ last_target_day = new Date(next_year,next_month , 6 - lastDay.getDay());
for(var i = 0;i < 7;i++){
var td = $(" | ");
- if(i <= lastDay.getDay()){
+ if(i <= offset){
if(today != 0 && last_inserted_date == today){
td.attr("class","w-calendar-today");
}
@@ -519,8 +520,8 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
td.attr("data-date-node",last_inserted_date+"-"+firstDay.getMonth()+"-"+firstDay.getFullYear());
last_inserted_date++;
}else{
- td.find('div').text(i-lastDay.getDay())
- td.attr("data-date-node",(i-lastDay.getDay())+"-"+next_month+"-"+next_year);
+ td.find('div').text(i - offset)
+ td.attr("data-date-node",(i - offset)+"-"+next_month+"-"+next_year);
td.addClass("w-calendar-other-month")
}
row.append(td);
@@ -579,9 +580,9 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
start_of_ed_date = get_start_of_date(ed_date),
timeDiff = start_of_ed_date.getTime() - start_of_sd_date.getTime(),
dayDiff = Math.ceil(timeDiff / (1000 * 3600 * 24));
- if(eve.allDay && dayDiff < 1){
- dayDiff = 1
- }
+ // if(eve.allDay && dayDiff < 1){
+ // dayDiff = 1
+ // }
if(dayDiff > 0){
var inserting_date = sd.getDate();
for(var i = 0;i <= dayDiff; i++){
diff --git a/app/controllers/admin/calendars_controller.rb b/app/controllers/admin/calendars_controller.rb
index ae413c8..af55243 100644
--- a/app/controllers/admin/calendars_controller.rb
+++ b/app/controllers/admin/calendars_controller.rb
@@ -1,7 +1,6 @@
class Admin::CalendarsController < OrbitAdminController
# GET /events
# GET /events.json
-
def index
@calendar_types = CalendarType.all
@calendar_setting = CalendarSetting.first
@@ -66,14 +65,16 @@ class Admin::CalendarsController < OrbitAdminController
else
@categories = CalendarType.where(:category_id.in => categories) rescue []
end
- @end_d_t = params[:endDate]
- @start_d_t = params[:startDate]
+ @end_d_t = @event.end
+ @start_d_t = @event.start
@all_day = false;
@recurring = false;
if params
case params[:allDay]
when "true"
@all_day = true
+ @event.end = @event.end - 1.day
+ @end_d_t = @event.end
when "false"
@all_day = false
case params[:recurring]
diff --git a/app/controllers/calendars_controller.rb b/app/controllers/calendars_controller.rb
index b4b7057..a431cf3 100644
--- a/app/controllers/calendars_controller.rb
+++ b/app/controllers/calendars_controller.rb
@@ -2,7 +2,6 @@ class CalendarsController < ApplicationController
# GET /events
# GET /events.json
include ActionView::Helpers::AssetTagHelper
-
def index
page = Page.where(page_id: OrbitHelper.params[:page_id]).first
style_file = page.layout=='index3' ? '/assets/calendar_widget2' : '/assets/calendar_widget1'
diff --git a/app/helpers/calendars_helper.rb b/app/helpers/calendars_helper.rb
new file mode 100644
index 0000000..ec9862e
--- /dev/null
+++ b/app/helpers/calendars_helper.rb
@@ -0,0 +1,24 @@
+module CalendarsHelper
+ def self.lighten_color(my_hex, percent)
+ if my_hex[0] == '#'
+ my_hex = my_hex[1..-1]
+ end
+ comp = ''
+ rgb = []
+ batch_size = (my_hex.length/3).ceil
+ (0...3).each do |i|
+ rgb << my_hex[batch_size*i ... batch_size*(i+1)]
+ end
+ rgb.each do |ch|
+ tmp = (ch.to_i(16) * (1+percent/100.0)).ceil
+ if tmp > 255
+ tmp = 255
+ end
+ if tmp < 0
+ tmp = 0
+ end
+ comp += format("%02x", tmp)
+ end
+ return '#'+comp
+ end
+end
\ No newline at end of file
diff --git a/app/models/event.rb b/app/models/event.rb
index 573cfd1..9bf5f81 100644
--- a/app/models/event.rb
+++ b/app/models/event.rb
@@ -165,7 +165,7 @@ class Event
:title => self.title,
:note => tmp_note,
:start => self.start.to_json.gsub('"',''),
- :end => (self.all_day ? [self.start, self.end - 1.day].max : self.end).to_json.gsub('"',''),
+ :end => self.end.to_json.gsub('"',''),
:allDay => self.all_day,
:recurring => self.recurring,
:calendar => self.calendar_type_id.to_s,
@@ -187,7 +187,7 @@ class Event
:title => self.title,
:note => tmp_note,
:start => self.start.to_json.gsub('"',''),
- :end => (self.all_day ? [self.start, self.end - 1.day].max : self.end).to_json.gsub('"',''),
+ :end => self.end.to_json.gsub('"',''),
:allDay => self.all_day,
:recurring => self.recurring,
:calendar => self.calendar_type_id.to_s,
@@ -217,6 +217,7 @@ class Event
def self.recurring_event(start_date, end_date, preserve_hide=false)
@recurring_events = self.where(:recurring => true).any_of({:recurring_end_date=>nil}, {:recurring_end_date.gte=>start_date.utc})
@recurring = []
+ start_date_utc_mjd = start_date.to_datetime.utc.mjd
@recurring_events.each do |re|
has_recurring_end_date = re.recurring_end_date.present?
data = re.as_json({}, true)
@@ -247,16 +248,21 @@ class Event
if period_str
org_start = re.start
@start_date = re.start
- @end_date = (re.all_day ? [re.start, re.end - 1.day].max : re.end)
+ @end_date = re.end
freq = re.frequency.to_i
interval = freq.send(period_str)
tmp_hide_start = re.hide_start.clone
if is_month
- add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month) - 1)
+ add_interval = ((start_date.year * 12 + start_date.month) - (@start_date.year * 12 + @start_date.month))
elsif is_year
- add_interval = (start_date.year - @start_date.year - 1)
+ add_interval = (start_date.year - @start_date.year)
else
- add_interval = (((start_date - @start_date - 1.day).to_i / 1.day) / days)
+ add_interval = (start_date_utc_mjd - @start_date.utc.mjd)
+ if add_interval < 0
+ add_interval = -(-add_interval / days)
+ else
+ add_interval = add_interval / days
+ end
end
if add_interval < 0
add_interval = add_interval % freq
diff --git a/app/views/admin/calendars/_form.html.erb b/app/views/admin/calendars/_form.html.erb
index 74d97aa..1c97a95 100644
--- a/app/views/admin/calendars/_form.html.erb
+++ b/app/views/admin/calendars/_form.html.erb
@@ -185,7 +185,7 @@
tmp_html = []
%>
<% (0...7).each do |i| %>
- <% tmp = f.check_box_tag "#{f.object_name}[weekdays][]", i, weekdays.include?(i), {:class=>"weekdays-checkbox"}
+ <% tmp = f.check_box_tag "#{f.object_name}[weekdays][]", i, weekdays.include?(i), {:class=>"weekdays-checkbox", :"data-key"=>i}
tmp += t("calendar.short_day.#{i}")
tmp_html << tmp
%>
@@ -336,8 +336,15 @@
$("#event_start").change(function(){
var _this = $(this);
var date = $.ui_datepicker.parseDate(_this.data('datepicker').settings.dateFormat, _this.val());
- $(".weekdays-checkbox").prop("checked", false);
- $(".weekdays-checkbox").eq(date.getDay()).prop("checked", true);
+ if($(".weekdays-checkbox:checked").length < 1){
+ $(".weekdays-checkbox").prop("checked", false);
+ $(".weekdays-checkbox").filter('[data-key="' + date.getDay().toString() + '"]').prop("checked", true);
+ }
+ var end_date = $('#event_end').val();
+ var start_date = _this.val();
+ if(end_date.length != 0 && end_date < start_date){
+ $('#event_end').val(start_date);
+ }
})
})
\ No newline at end of file
diff --git a/app/views/calendars/_calendar_variable.html.erb b/app/views/calendars/_calendar_variable.html.erb
index ec87e46..cbe57db 100644
--- a/app/views/calendars/_calendar_variable.html.erb
+++ b/app/views/calendars/_calendar_variable.html.erb
@@ -25,14 +25,20 @@
.widget-calendar-2.w-calendar .w-calendar-table td.w-calendar-event[data-calendar-id="<%=c.id%>"] div{
border-color: <%= c.color %>;
}
- .widget-calendar-2.w-calendar table.w-calendar-table td.w-calendar-toggle[data-calendar-id="<%=c.id%>"] div, .widget-calendar-2.w-calendar table.w-calendar-table td.w-calendar-toggle[data-calendar-id="<%=c.id%>"] div{
- background: <%= c.color %>;
- }
.has_event[data-calendar-id="<%=c.id%>"]{
background: <%= c.color %>;
}
.event[data-calendar-id="<%=c.id%>"], .event[data-calendar-id="<%=c.id%>"] a{
color: <%= c.color %>;
}
+ <% darken_color = CalendarsHelper.lighten_color(c.color, -45) %>
+ .widget-calendar-1 .w-calendar-table .w-calendar-event[data-calendar-id="<%=c.id%>"]:hover, .widget-calendar-1 .w-calendar-table .w-calendar-event[data-calendar-id="<%=c.id%>"].w-calendar-toggle
+ {
+ background: <%= darken_color %>;
+ }
+ .widget-calendar-2.w-calendar table.w-calendar-table td.w-calendar-toggle[data-calendar-id="<%=c.id%>"] div{
+ border-color: <%= darken_color %>;
+ background: <%= darken_color %>;
+ }
<% end if @calendar_types %>
\ No newline at end of file
diff --git a/config/routes.rb b/config/routes.rb
index 4ff5484..b561336 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -6,6 +6,7 @@ Rails.application.routes.draw do
s = Site.first
update_flag = s.respond_to?(:tmp_flags)
need_update = !update_flag || !(s.tmp_flags.include?('cf2'))
+ need_update2 = !update_flag || !(s.tmp_flags.include?('cf3'))
calendar_setting = CalendarSetting.first
calendar_setting = CalendarSetting.create if calendar_setting.nil?
if need_update
@@ -33,6 +34,14 @@ Rails.application.routes.draw do
end
puts "Calendar fix!"
end
+ if need_update2
+ Event.where(:recurring=>true).each do |e|
+ if e.end == e.start + 1.day
+ e.end = e.start
+ e.save
+ end
+ end
+ end
end
end
scope "(:locale)", locale: Regexp.new(locales.join("|")) do