Add repeat week setting feature.
Fix bug. Apply color setting to all calendar templates. Add recurring note.
This commit is contained in:
parent
876434e6a5
commit
4d0925767b
|
@ -902,6 +902,7 @@ var AgendaView = function(calendar){
|
|||
});
|
||||
$.each(data,function(i,e){
|
||||
var ed = eventDom(e),
|
||||
calendar_id = e.calendar,
|
||||
s = new Date(e.start),
|
||||
e = new Date(e.end),
|
||||
e_m = ((e.getMonth() > s.getMonth() || s.getMonth() == e.getMonth()) && s.getFullYear() == e.getFullYear() ? e.getMonth() : e.getMonth() + 12)
|
||||
|
@ -921,7 +922,7 @@ var AgendaView = function(calendar){
|
|||
}
|
||||
if(s.getDate() == e.getDate() && s.getMonth() == s.getMonth() && e.getFullYear() == e.getFullYear()){
|
||||
var td = agenda_space.find("td[data-date-node="+s.getDate()+"-"+s.getMonth()+"-"+s.getFullYear()+"]");
|
||||
td.addClass("has_event");
|
||||
td.addClass("has_event").attr("data-calendar-id", calendar_id);
|
||||
}else{
|
||||
var timeDiff = Math.abs(e.getTime() - s.getTime()),
|
||||
diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)),
|
||||
|
@ -929,10 +930,9 @@ var AgendaView = function(calendar){
|
|||
c_d = s.getDate(),
|
||||
c_y = s.getFullYear(),
|
||||
end_of_c_month = new Date(s.getFullYear(),s.getMonth()+1,0).getDate();
|
||||
|
||||
for(var i = 0; i <= diffDays; i++){
|
||||
var td = agenda_space.find("td[data-date-node="+c_d+"-"+c_m+"-"+c_y+"]");
|
||||
td.addClass("has_event");
|
||||
td.addClass("has_event").attr("data-calendar-id", calendar_id);
|
||||
c_d++;
|
||||
if(c_d > end_of_c_month){
|
||||
c_d = 1;
|
||||
|
@ -949,6 +949,11 @@ var AgendaView = function(calendar){
|
|||
if($(this).find("tr").length > 1)
|
||||
$(this).find("td.no_events").parent().remove();
|
||||
})
|
||||
$(".edit_event_btn").on("click", function(){
|
||||
var _this = $(this);
|
||||
_calendar.editEvent(_this.data('edit-url'), _this.data('allDay'));
|
||||
return false;
|
||||
});
|
||||
// nano scroller here
|
||||
|
||||
}
|
||||
|
@ -971,7 +976,11 @@ var AgendaView = function(calendar){
|
|||
}
|
||||
}
|
||||
e_t.find("td.event_datetime").text(datetimeFormat);
|
||||
e_t.find("div.event").html(event.title).css("color",event.color);
|
||||
var tmp_html = event.title;
|
||||
if(event.edit_url){
|
||||
tmp_html = '<a href="javascript:void(0)" class="edit_event_btn" data-edit-url="'+event.edit_url+'" data-allDay="'+event.allDay+'">' + tmp_html + '</a>';
|
||||
}
|
||||
e_t.find("div.event").html(tmp_html).css("color",event.color).attr("data-calendar-id", event.calendar);
|
||||
return e_t;
|
||||
}
|
||||
|
||||
|
|
|
@ -734,6 +734,7 @@ var AgendaView = function(calendar){
|
|||
});
|
||||
$.each(data,function(i,e){
|
||||
var ed = eventDom(e),
|
||||
calendar_id = e.calendar,
|
||||
s = new Date(e.start),
|
||||
e = new Date(e.end),
|
||||
e_m = ((e.getMonth() > s.getMonth() || s.getMonth() == e.getMonth()) && s.getFullYear() == e.getFullYear() ? e.getMonth() : e.getMonth() + 12)
|
||||
|
@ -753,7 +754,7 @@ var AgendaView = function(calendar){
|
|||
}
|
||||
if(s.getDate() == e.getDate() && s.getMonth() == s.getMonth() && e.getFullYear() == e.getFullYear()){
|
||||
var td = agenda_space.find("td[data-date-node="+s.getDate()+"-"+s.getMonth()+"-"+s.getFullYear()+"]");
|
||||
td.addClass("has_event");
|
||||
td.addClass("has_event").attr("data-calendar-id", calendar_id);
|
||||
}else{
|
||||
var timeDiff = Math.abs(e.getTime() - s.getTime()),
|
||||
diffDays = Math.ceil(timeDiff / (1000 * 3600 * 24)),
|
||||
|
@ -764,7 +765,7 @@ var AgendaView = function(calendar){
|
|||
|
||||
for(var i = 0; i <= diffDays; i++){
|
||||
var td = agenda_space.find("td[data-date-node="+c_d+"-"+c_m+"-"+c_y+"]");
|
||||
td.addClass("has_event");
|
||||
td.addClass("has_event").attr("data-calendar-id", calendar_id);
|
||||
c_d++;
|
||||
if(c_d > end_of_c_month){
|
||||
c_d = 1;
|
||||
|
|
|
@ -451,7 +451,7 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
|
|||
events[dt]=[]
|
||||
}
|
||||
events[dt].push(eve)
|
||||
td.addClass("w-calendar-event");
|
||||
td.addClass("w-calendar-event").attr("data-calendar-id", eve.calendar);
|
||||
if(events[dt] && events[dt].length==1){
|
||||
td.click(function(){
|
||||
toggle_event(this,'show')
|
||||
|
@ -474,7 +474,7 @@ var CalendarModuleMonth1 = function(date,dom,subpart,url,index_flag){
|
|||
toggle_event(this,'show')
|
||||
})
|
||||
}
|
||||
td.addClass("w-calendar-event");
|
||||
td.addClass("w-calendar-event").attr("data-calendar-id", eve.calendar);
|
||||
}
|
||||
})
|
||||
if (!toggle_data){
|
||||
|
|
|
@ -591,7 +591,7 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
|
|||
events[dt]=[]
|
||||
}
|
||||
events[dt].push(eve)
|
||||
td.addClass("w-calendar-event");
|
||||
td.addClass("w-calendar-event").attr("data-calendar-id", eve.calendar);
|
||||
if(events[dt] && events[dt].length==1){
|
||||
td.click(function(){
|
||||
toggle_event(this,'show')
|
||||
|
@ -614,7 +614,7 @@ var CalendarModuleMonth2 = function(date,dom,subpart,url,index_flag){
|
|||
toggle_event(this,'show')
|
||||
})
|
||||
}
|
||||
td.addClass("w-calendar-event");
|
||||
td.addClass("w-calendar-event").attr("data-calendar-id", eve.calendar);
|
||||
}
|
||||
})
|
||||
if (!toggle_data){
|
||||
|
|
|
@ -3,6 +3,7 @@ class Admin::CalendarsController < OrbitAdminController
|
|||
# GET /events.json
|
||||
|
||||
def index
|
||||
@calendar_types = CalendarType.all
|
||||
@calendar_setting = CalendarSetting.first
|
||||
@events = []
|
||||
tags = @module_app.tags
|
||||
|
@ -17,7 +18,7 @@ class Admin::CalendarsController < OrbitAdminController
|
|||
@monthly_events = Event.monthly_event(sdt,edt).with_categories(filters("category"))
|
||||
.with_tags(filters("tag")).convert_front
|
||||
@re = Event.with_categories(filters("category")).with_tags(filters("tag")).recurring_event(sdt,edt)
|
||||
allevents = @monthly_events.inject(@re, :<<)
|
||||
allevents = @monthly_events.inject(@re, :<<).sort_by{|e| e[:start]}
|
||||
events = allevents.to_json
|
||||
events = JSON.parse(events)
|
||||
events.each_with_index do |e,i|
|
||||
|
@ -51,7 +52,7 @@ class Admin::CalendarsController < OrbitAdminController
|
|||
def agenda
|
||||
agenda_start = Time.at(params[:unix_start].to_i).utc
|
||||
agenda_end = Time.at(params[:unix_end].to_i).utc
|
||||
@events = Event.agenda_events(agenda_start,agenda_end)
|
||||
@events = Event.agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
|
||||
# re = Event.recurring_event(Time.at(params[:unix_start].to_i), Time.at(params[:unix_end].to_i))
|
||||
# @events = @events.inject(re, :<<)
|
||||
render :json=>@events.to_json
|
||||
|
|
|
@ -6,6 +6,11 @@ class CalendarsController < ApplicationController
|
|||
def index
|
||||
page = Page.where(page_id: OrbitHelper.params[:page_id]).first
|
||||
style_file = page.layout=='index3' ? '/assets/calendar_widget2' : '/assets/calendar_widget1'
|
||||
cat_ids = page.categories
|
||||
if cat_ids.include?('all')
|
||||
cat_ids = []
|
||||
end
|
||||
@calendar_types = cat_ids.blank? ? CalendarType.all : CalendarType.where(:id.in => cat_ids)
|
||||
@calendar_setting = CalendarSetting.first
|
||||
{
|
||||
"modes_info" => @calendar_setting.get_modes_info.map.with_index{|(trans, mode),i| {trans: trans, mode: mode, active_class: (i ==
|
||||
|
@ -34,12 +39,9 @@ class CalendarsController < ApplicationController
|
|||
def widget
|
||||
part = OrbitHelper.get_current_widget
|
||||
@calendar_setting = CalendarSetting.first
|
||||
begin
|
||||
extra_before_html = render_to_string(partial: 'calendars/calendar_variable', locals: {:@calendar_setting=>@calendar_setting})
|
||||
rescue => e
|
||||
extra_before_html = ""
|
||||
puts e, e.backtrace
|
||||
end
|
||||
cat_ids = part.custom_array_field
|
||||
@calendar_types = cat_ids.blank? ? CalendarType.all : CalendarType.where(:id.in => cat_ids)
|
||||
extra_before_html = render_to_string(partial: 'calendars/calendar_variable', locals: {:@calendar_setting=>@calendar_setting,:@calendar_types=>@calendar_types})
|
||||
{
|
||||
"modes_info" => @calendar_setting.get_modes_info.map.with_index{|(trans, mode),i| {trans: trans, mode: mode, active_class: (i ==
|
||||
2 ? 'active' : '')}},
|
||||
|
@ -97,7 +99,7 @@ class CalendarsController < ApplicationController
|
|||
agenda_start = Time.at(params[:unix_start].to_i).utc
|
||||
agenda_end = Time.at(params[:unix_end].to_i).utc
|
||||
event = Event.where("title_translations.#{locale}".to_sym.ne=>"")
|
||||
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end)
|
||||
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
|
||||
end
|
||||
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
|
||||
end
|
||||
|
@ -118,7 +120,7 @@ class CalendarsController < ApplicationController
|
|||
agenda_start = Time.at(params[:unix_start].to_i).utc
|
||||
agenda_end = Time.at(params[:unix_end].to_i).utc
|
||||
event = Event.where("title_translations.#{locale}".to_sym.ne=>"")
|
||||
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end)
|
||||
events = event.with_categories(calendar_types).agenda_events(agenda_start,agenda_end).sort_by{|e| e[:start]}
|
||||
end
|
||||
render json: {"events" => events,"calendar_title"=>get_calendar_title(Time.at(params[:month_start].to_i).utc)}.to_json({"frontend" => true})
|
||||
end
|
||||
|
|
|
@ -109,13 +109,53 @@ class Event
|
|||
]
|
||||
|
||||
def as_json(options = {})
|
||||
tmp_note = self.note || ""
|
||||
if self.recurring
|
||||
freq = self.frequency.to_i
|
||||
if @week_titles.nil?
|
||||
@week_titles = CalendarSetting.first.week_title
|
||||
@weekdayst = I18n.t("calendar.weekdays")
|
||||
@dailyt = I18n.t("calendar.daily")
|
||||
@weeklyt = I18n.t("calendar.weekly")
|
||||
@monthlyt = I18n.t("calendar.monthly")
|
||||
@yearlyt = I18n.t("calendar.yearly")
|
||||
@conjt = I18n.t('calendar.conj')
|
||||
@andt = I18n.t('calendar.and')
|
||||
end
|
||||
case self.period
|
||||
when 'Daily'
|
||||
every_n_days = (freq == 1 ? @dailyt : I18n.t("calendar.every_n_days", {:num=>self.frequency}))
|
||||
tmp_note = every_n_days + "<br>" + tmp_note
|
||||
when 'Weekly'
|
||||
if self.is_weekdays
|
||||
days = @weekdayst
|
||||
elsif self.weekdays.present?
|
||||
days = self.weekdays.map{|i| @week_titles[i]}
|
||||
if days.count > 1
|
||||
days = days[0...-1].join(@conjt) + @andt + days[-1]
|
||||
else
|
||||
days = days[0]
|
||||
end
|
||||
end
|
||||
every_n_weeks = (freq == 1 ? @weeklyt : I18n.t("calendar.every_n_weeks", {:num=>self.frequency}))
|
||||
tmp_note = I18n.t("calendar.every_week_day", {:every_n_weeks=>every_n_weeks,:days=>days}) + "<br>" + tmp_note
|
||||
when 'Monthly'
|
||||
days = self.start.day
|
||||
every_n_months = (freq == 1 ? @monthlyt : I18n.t("calendar.every_n_months", {:num=>self.frequency}))
|
||||
tmp_note = I18n.t("calendar.every_month_day", {:every_n_months=>every_n_months,:days=>days}) + "<br>" + tmp_note
|
||||
when 'Yearly'
|
||||
date = self.start.strftime('%m/%d')
|
||||
every_n_years = (freq == 1 ? @yearlyt : I18n.t("calendar.every_n_years", {:num=>self.frequency}))
|
||||
tmp_note = I18n.t("calendar.every_year_day", {:every_n_years=>every_n_years,:date=>date}) + "<br>" + tmp_note
|
||||
end
|
||||
end
|
||||
if options["frontend"]
|
||||
{
|
||||
:id => self.id.to_s,
|
||||
:title => self.title,
|
||||
:note => self.note || "",
|
||||
:note => tmp_note,
|
||||
:start => self.start.to_json.gsub('"',''),
|
||||
:end => self.end.to_json.gsub('"',''),
|
||||
:end => (self.all_day ? [self.start, self.end - 1.day].max : self.end).to_json.gsub('"',''),
|
||||
:allDay => self.all_day,
|
||||
:recurring => self.recurring,
|
||||
:calendar => self.calendar_type_id.to_s,
|
||||
|
@ -126,9 +166,9 @@ class Event
|
|||
{
|
||||
:id => self.id.to_s,
|
||||
:title => self.title,
|
||||
:note => self.note || "",
|
||||
:note => tmp_note,
|
||||
:start => self.start.to_json.gsub('"',''),
|
||||
:end => self.end.to_json.gsub('"',''),
|
||||
:end => (self.all_day ? [self.start, self.end - 1.day].max : self.end).to_json.gsub('"',''),
|
||||
:allDay => self.all_day,
|
||||
:recurring => self.recurring,
|
||||
:calendar => self.calendar_type_id.to_s,
|
||||
|
@ -146,9 +186,7 @@ class Event
|
|||
end
|
||||
def self.convert_front
|
||||
self.all.collect do |re|
|
||||
edit_url = Rails.application.routes.url_helpers.edit_admin_calendar_path(:locale=>I18n.locale, :id=>re.id)
|
||||
delete_url = Rails.application.routes.url_helpers.admin_calendar_path(:locale=>I18n.locale, :id=>re.id)
|
||||
{:id => re.id.to_s, :title=>re.title, :note=>re.note || "", :allDay => re.all_day, :recurring => re.recurring, :calendar => re.calendar_type.id.to_s, :color => (re.calendar_type.color rescue nil), :edit_url => edit_url, :delete_url => delete_url, :url_linked => re.url_to_fronted, :start => re.start, :end => re.end}
|
||||
re.as_json
|
||||
end
|
||||
end
|
||||
def self.get_diff_month(date1,date2)
|
||||
|
@ -187,7 +225,7 @@ class Event
|
|||
if period_str
|
||||
org_start = re.start
|
||||
@start_date = re.start
|
||||
@end_date = re.end
|
||||
@end_date = (re.all_day ? [re.start, re.end - 1.day].max : re.end)
|
||||
freq = re.frequency.to_i
|
||||
interval = freq.send(period_str)
|
||||
if is_month
|
||||
|
|
|
@ -3,7 +3,7 @@
|
|||
window.calendar_variable = {};
|
||||
window.calendar_variable.from = "<%=t('calendar.from')%>";
|
||||
window.calendar_variable.to = "<%=t('calendar.to')%>";
|
||||
<% if @calendar_setting && @calendar_setting.enable %>
|
||||
<% if @calendar_setting && (@calendar_setting.enable rescue false) %>
|
||||
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%>;
|
||||
|
@ -17,3 +17,22 @@
|
|||
<% end %>
|
||||
}
|
||||
</script>
|
||||
<style>
|
||||
<% @calendar_types.each do |c| %>
|
||||
.widget-calendar-1 .w-calendar-table .w-calendar-event[data-calendar-id="<%=c.id%>"]:not(:hover){
|
||||
background: <%= c.color %>;
|
||||
}
|
||||
.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 %>;
|
||||
}
|
||||
<% end if @calendar_types %>
|
||||
</style>
|
|
@ -1,5 +1,14 @@
|
|||
en:
|
||||
calendar:
|
||||
conj: ", "
|
||||
and: " and "
|
||||
every_n_years: "Every %{num} years"
|
||||
every_n_months: "Every %{num} months"
|
||||
every_n_weeks: "Every %{num} weeks"
|
||||
every_n_days: "Every %{num} days"
|
||||
every_year_day: "%{every_n_years} on %{date}"
|
||||
every_month_day: "%{every_n_months} on day %{days}"
|
||||
every_week_day: "%{every_n_weeks} on %{days}"
|
||||
type: Type
|
||||
custom: Custom
|
||||
weekdays: Weekdays
|
||||
|
|
|
@ -1,5 +1,14 @@
|
|||
zh_tw:
|
||||
calendar:
|
||||
conj: "、"
|
||||
and: "與"
|
||||
every_n_years: "每%{num}年"
|
||||
every_n_months: "每%{num}個月"
|
||||
every_n_weeks: "每%{num}週"
|
||||
every_n_days: "每%{num}天"
|
||||
every_year_day: "%{every_n_years}的%{date}"
|
||||
every_month_day: "%{every_n_months}的第%{days}天"
|
||||
every_week_day: "%{every_n_weeks}的%{days}"
|
||||
type: 類型
|
||||
custom: 自訂
|
||||
weekdays: 平日
|
||||
|
|
Loading…
Reference in New Issue