From 6dd9f441ef44e9df723ee3dc1d14ca3f361ec046 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 29 Oct 2012 19:52:34 +0800 Subject: [PATCH] Agenda View --- .../app/assets/javascripts/calendarAPI.js.erb | 66 ++++- .../calendar/back_end/cals_controller.rb | 122 +++++++- .../panel/calendar/back_end/cals_helper.rb | 22 +- .../back_end/cals/agenda_view.html.erb | 271 +++++------------- .../calendar/back_end/cals/index.html.erb | 16 +- 5 files changed, 283 insertions(+), 214 deletions(-) diff --git a/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb b/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb index 09ef0195..31ef39ba 100644 --- a/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb +++ b/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb @@ -44,12 +44,17 @@ var calendarAPI = function(){ this.cur_week = c.today.getWeek(); this.cur_date = c.today.getDate(); this.view = null; + this.calendars = new Array(); this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"]; this.initialize = function(){ $(window).load(function(){ // c.loadMonthView(c.cur_month,c.cur_year); - c.loadWeekView(c.cur_week,c.cur_year); + // c.loadWeekView(c.cur_week,c.cur_year); // c.loadDayView(c.cur_date,c.cur_month,c.cur_year); + c.loadAgendaView(); + $(".calendar-filter-btn").each(function(){ + c.calendars.push($(this).attr("href")); + }) bindHandlers(); }) var bindHandlers = function(){ @@ -94,6 +99,16 @@ var calendarAPI = function(){ $("#create_event_btn").toggleClass("active"); e.stopPropagation(); }) + $(".calendar-filter-btn").click(function(){ + $(this).toggleClass("active"); + c.calendars = []; + $(".calendar-filter-btn").each(function(){ + if($(this).hasClass("active")) + c.calendars.push($(this).attr("href")); + }) + c.refresh(); + }) + $("#edit_event_btn").live("ajax:success",function(evt,form){ c.event_quick_view_div.empty().hide(); c.updateEvent(form); @@ -225,6 +240,10 @@ var calendarAPI = function(){ } } this.loadMonthView = function(month,year){ + $("#range_selection").hide(); + $("#navigation").show(); + $("#sec1").removeClass("span8").addClass("span3"); + $("#sec2").show(); c.view = "month"; if(!month){ var dt = new Date(); @@ -265,7 +284,7 @@ var calendarAPI = function(){ this.getEventsForMonth = function(month,year){ - $.getJSON("cals/getMonthEvents",{"month":month,"year":year},function(events){ + $.getJSON("cals/getMonthEvents",{"month":month,"year":year,"calendars":c.calendars},function(events){ makerow(events); }) var doneEventArray = new Array(); @@ -367,6 +386,10 @@ var calendarAPI = function(){ } this.loadWeekView = function(week,year){ + $("#range_selection").hide(); + $("#navigation").show(); + $("#sec1").removeClass("span8").addClass("span3"); + $("#sec2").show(); c.view = "week"; if(!week){ var dt = new Date(); @@ -383,7 +406,7 @@ var calendarAPI = function(){ }) } this.getEventsForWeek = function(week,year){ - $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ + $.getJSON("cals/getWeekEvents",{"week":week,"year":year,"calendars":c.calendars},function(events){ var height = 15; var full_day_count = 0; var rowcount = 7; @@ -487,6 +510,10 @@ var calendarAPI = function(){ }) } this.loadDayView = function(day,month,year){ + $("#range_selection").hide(); + $("#navigation").show(); + $("#sec1").removeClass("span8").addClass("span3"); + $("#sec2").show(); c.view = "day"; if(!day){ var dt = new Date(); @@ -506,7 +533,7 @@ var calendarAPI = function(){ }) } this.getEventsForDay = function(day,month,year){ - $.getJSON("cals/getDayEvents",{"date":day,"month":month,"year":year},function(events){ + $.getJSON("cals/getDayEvents",{"date":day,"month":month,"year":year,"calendars":c.calendars},function(events){ $.each(events,function(i,evnt){ if(evnt.all_day){ $(".all_day_event").append('
'+evnt.title+'
') @@ -558,10 +585,35 @@ var calendarAPI = function(){ }) } - this.loadAgendaView = function(){ - $('#view_holder').load("cals/agenda_view", function() { - $('.current_day_title').text('September 2, 2012'); + this.loadAgendaView = function(start_month,start_year,end_month,end_year){ + c.view = "agenda"; + var url = "cals/agenda_view"; + if(start_month && start_year && end_month && end_year) + var url = "cals/agenda_view?s_month="+start_month+"&s_year="+start_year+"&e_month="+end_month+"&e_year="+end_year ; + + $('#view_holder').load(url, function() { + $("#navigation").hide(); + $("#range_selection").html($("#agenda_date_range").html()).show(); + $("#sec1").removeClass("span3").addClass("span8"); + $("#sec2").hide(); + bindHandlers(); }) + var bindHandlers = function(){ + $("select[name=start_year]").change(function(){ + var x = parseInt($(this).val()) - parseInt($(this).find("option").eq(0).val()); + $("select[name=end_year] option").removeAttr("disabled"); + for(i=0;i false end def agenda_view + @start_year = params[:s_year].to_i + @start_month = params[:s_month].to_i + @end_year = params[:e_year].to_i + @end_month = params[:e_month].to_i + t = Time.now + if !params[:s_year] + @start_year = t.year + end + if !params[:s_month] + @start_month = t.month + @end_month = t.month + 3 + if @end_month > 12 + @end_month = @end_month - 12 + @end_year = @start_year + 1 + end + end + + startdt = Date.new(@start_year,@start_month,1) + temp = getMonthDays(@end_year) + enddt = Date.new(@end_year,@end_month,temp[@end_month]) + diff = enddt - startdt + diff = diff.to_i / 30 + + + @d_s_year = @start_year - 5 + @datesets = Array.new + @calendartitle = Array.new + @events = Array.new + events = Event.all.asc(:start_date).desc(:total_days) + @calevents = Array.new + y = @start_year + m = @start_month + for i in 0..diff-1 + if m == 13 + m = 1 + y = y + 1 + end + @calendartitle << [m,y] + @datesets << getDateSet(m,y,false) + e = Array.new + h = Array.new + events.each_with_index do |event,i| + # @temp = Array.new + startdt = Date.new(event.start_year,event.start_month) + enddt = Date.new(event.end_year,event.end_month) + range = startdt..enddt + dt = Date.new(y,m) + if range === dt + no_of_days = event.total_days + start_date = event.start_date + + if event.start_year < y + no_of_days = temp[m] - event.start_date + no_of_days += 1 + temp = m + 12 + if event.start_month < temp + start_date = 1 + end + end + if event.end_year > y + no_of_days = temp[m] - event.start_date + no_of_days += 1 + temp = m + 12 + end + if event.end_month > m + no_of_days = temp[m] - event.start_date + no_of_days += 1 + elsif event.end_month == m + no_of_days = event.end_date + end + + if event.start_month == m && event.end_month == m + no_of_days = event.total_days + no_of_days += 1 + end + + if event.start_month < m + start_date = 1 + end + + if event.start_date == event.end_date + display_date = getDayName(event.start_date,event.start_month,event.start_year) + ", " + Date::ABBR_MONTHNAMES[event.start_month] + " " + event.start_date.to_s + else + display_date = getDayName(event.start_date,event.start_month,event.start_year) + ", " + Date::ABBR_MONTHNAMES[event.start_month].to_s + " " + event.start_date.to_s + " - " + getDayName(event.end_date,event.end_month,event.end_year) + ", " + Date::ABBR_MONTHNAMES[event.end_month] + " " + event.end_date.to_s + end + if event.all_day + display_time = "All Day" + else + x = event.start_time.to_i + if event.start_time > x + est = x.to_s + ":30" + else + est = x.to_s + end + x = event.end_time.to_i + if event.end_time > x + eet = x.to_s + ":30" + else + eet = x.to_s + end + display_time = est + " " + event.start_am_pm + " - " + eet + " " + event.end_am_pm + end + for c in start_date..(start_date + no_of_days) + if h.index(c) == nil + h << c + end + end + color = Cal.find(event.cal_id).color + e << {"display_date"=>display_date,"show_link"=>panel_calendar_back_end_event_path(event), "display_time"=>display_time, "start_date"=>start_date,"end_date"=>event.end_date,"start_month"=>event.start_month,"end_month"=>event.end_month,"title" => event.title,"color"=>color} + end + end + @events << e + @calevents << h + m = m + 1 + end render :layout => false end def get_month_events month = params[:month].to_i year = params[:year].to_i + fromcalendars = params[:calendars] # events = Event.where(:start_month.lt => month).and(:start_year => year).and(:end_month.gte => month).asc(:start_date).desc(:total_days) @events = Array.new @@ -121,7 +237,7 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController # color = Cal.find(event.cal_id).color # @events << {"id"=>event.id,"index"=>i,"start_date"=>event.start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)} # end - events = Event.all.asc(:start_date).desc(:total_days) + events = Event.all.where(:cal_id.in=>fromcalendars).asc(:start_date).desc(:total_days) events.each_with_index do |event,i| # @temp = Array.new startdt = Date.new(event.start_year,event.start_month) diff --git a/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb b/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb index 6377debb..17760629 100644 --- a/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb +++ b/vendor/built_in_modules/calendar/app/helpers/panel/calendar/back_end/cals_helper.rb @@ -6,7 +6,7 @@ module Panel::Calendar::BackEnd::CalsHelper return startday end - def getDateSet(month,year) + def getDateSet(month,year,prepost) dateset = Array.new startday = monthStartDay(month,year) monthsdays = getMonthDays(year) @@ -20,7 +20,11 @@ module Panel::Calendar::BackEnd::CalsHelper i = prev_month_days_to_add while i > 0 do i -= 1 - dateset << prev_month_days - i + if prepost + dateset << prev_month_days - i + else + dateset << "NaN" + end end i = 0 @@ -29,11 +33,21 @@ module Panel::Calendar::BackEnd::CalsHelper i += 1 end - next_month_days_to_add = 42 - (prev_month_days_to_add + cur_month_days) + total_days = 42 + if !prepost + if (prev_month_days_to_add + cur_month_days) < 35 + total_days = 35 + end + end + next_month_days_to_add = total_days - (prev_month_days_to_add + cur_month_days) i = 0 while i < next_month_days_to_add do - dateset << i + 1 + if prepost + dateset << i + 1 + else + dateset << "NaN" + end i += 1 end diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb index 8d217587..d6761d88 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/agenda_view.html.erb @@ -1,7 +1,49 @@ +
+ <% @datesets.each_with_index do |dateset,i| %>
-

September

+

<%= Date::MONTHNAMES[@calendartitle[i][0]] + " - " + @calendartitle[i][1].to_s %>

@@ -13,51 +55,19 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + <% x = 0 %> + <% dateset.each do |date| %> + <% x = x + 1 %> + <% if x == 1 %> + + <% end %> + + <% if x == 7 %> + <% x = 0 %> + + <% end %> + <% end %> +
Fri Sat
12
3456789
10111213141516
17181920212223
24252627282930
><%= (date=="NaN"? "" : date ) %>
@@ -71,155 +81,30 @@ - - Thu, Sep 6 - 9:00am - 9:30am - -
Commuting time, from home to RD
- - - - - 9:30am - 12:00am - -
Work on Thu project, and ask ika for help if possible
- - - - - 13:30pm - 18:00pm - -
Template design, at least finish 2 template
- - - - Fri, Sep 7 - 9:00am - 18:00pm - -
Take a day off
- - - - Sat, Sep 8 - 7:00am - 7:50pm - -
Work out with Joseph
- - - - -
-
-
-
-

October

-
- tiny calendar goes here -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
Thu, Sep 69:00am - 9:30am -
Commuting time, from home to RD
-
9:30am - 12:00am -
Work on Thu project, and ask ika for help if possible
-
13:30pm - 18:00pm -
Template design, at least finish 2 template
-
Fri, Sep 79:00am - 18:00pm -
Take a day off
-
Sat, Sep 87:00am - 7:50pm -
Work out with Joseph
-
-
-
-
-
-

November

-
- tiny calendar goes here -
-
-
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - + <% lastday = "" %> + <% if @events[i].count > 0 %> + <% @events[i].each do |event| %> + + + + + + <% lastday = event['display_date'] %> + <% end %> + <% else %> + + + + <% end %>
Thu, Sep 69:00am - 9:30am -
Commuting time, from home to RD
-
9:30am - 12:00am -
Work on Thu project, and ask ika for help if possible
-
13:30pm - 18:00pm -
Template design, at least finish 2 template
-
Fri, Sep 79:00am - 18:00pm -
Take a day off
-
Sat, Sep 87:00am - 7:50pm -
Work out with Joseph
-
+ <% if event['display_date'] != lastday %> + <%= event['display_date'] %> + <% end %> + <%= event['display_time'] %> +
<%= event['title'] %>
+
No events for this month.
+ <% end %> \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb index c5d4b861..9300eaad 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb @@ -13,9 +13,9 @@
- Calendar1 - Calendar2 - Calendar3 + <% @calendars.each do |calendar| %> + <%= calendar.name %> + <% end %>
Clear @@ -25,8 +25,8 @@
-
-
+
+
+
-
+

-
+