From f76253f51245f3f931795a8a2db317d0b8b041ad Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 8 Oct 2012 16:47:56 +0800 Subject: [PATCH] Week View changes --- .../app/assets/javascripts/calendarAPI.js.erb | 23 +++++-- .../calendar/back_end/cals_controller.rb | 26 ++++++- .../calendar/back_end/events_controller.rb | 4 ++ .../panel/calendar/back_end/cals_helper.rb | 69 ++++++++++++------- .../calendar/app/models/event.rb | 2 + .../calendar/config/routes.rb | 4 +- 6 files changed, 98 insertions(+), 30 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 aca68f07..64eb8f8a 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 @@ -41,7 +41,7 @@ var calendarAPI = function(){ this.initialize = function(){ $(window).load(function(){ // c.loadMonthView(c.cur_month,c.cur_year); - c.loadWeekView(51,c.cur_year); + c.loadWeekView(c.cur_week,c.cur_year); bindHandlers(); }) var bindHandlers = function(){ @@ -95,8 +95,13 @@ var calendarAPI = function(){ break; case "week": var w,y; - w = c.cur_week - 1; - y = c.cur_year; + if(c.cur_week == 1){ + w = 52; + y = c.cur_year - 1; + }else{ + w = c.cur_week - 1; + y = c.cur_year; + } c.loadWeekView(w,y); break; } @@ -119,7 +124,7 @@ var calendarAPI = function(){ var w,y; if(c.cur_week == 52){ - w = 2; + w = 1; y = c.cur_year + 1; }else{ w = c.cur_week + 1; @@ -173,8 +178,9 @@ var calendarAPI = function(){ } + this.getEventsForMonth = function(month,year){ - $.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){ + $.getJSON("cals/getMonthEvents",{"month":month,"year":year},function(events){ makerow(events); }) var doneEventArray = new Array(); @@ -283,8 +289,15 @@ var calendarAPI = function(){ c.cur_week = week; c.cur_year = year; + $('#view_holder').load("cals/week_view?week="+week+"&year="+year, function() { $('.current_day_title').text($("#week_range").text()); + c.getEventsForWeek(week,year); + }) + } + this.getEventsForWeek = function(week,year){ + $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ + }) } this.loadDayView = function(){ diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb index f6f128ef..2c171895 100644 --- a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb +++ b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb @@ -58,7 +58,7 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController render :layout => false end - def get_events + def get_month_events month = params[:month] year = params[:year] month = month.to_i @@ -96,6 +96,30 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController render :json => @events.to_json end + def get_week_events + week = params[:week] + year = params[:year] + events = Event.where(:start_week => week).and(:start_year => year) + render :json => events.to_json + end + + def week_number_test + events = Event.all + + events.each do |event| + dt = Date.new(event.start_year,event.start_month,event.start_date) + sweeknumber = dt.strftime("%U") + dt = Date.new(event.end_year,event.end_month,event.end_date) + eweeknumber = dt.strftime("%U") + event.start_week = sweeknumber + event.end_week = eweeknumber + event.save! + end + + dt = Date.new(2012,10,4) + @week = dt.strftime("%U") + render :text => @week.to_s + end end diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb index a23a6c4c..519d84f4 100644 --- a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb +++ b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb @@ -45,6 +45,8 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController final_start_time = Date.new(start_year.to_i,start_month.to_i,start_date.to_i) final_end_time = Date.new(end_year.to_i,end_month.to_i,end_date.to_i) + start_week = final_start_time.strftime("%U") + end_week = final_end_time.strftime("%U") total_days = final_end_time - final_start_time @event = Event.new @event.title = title @@ -63,6 +65,8 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @event.final_start_time = final_start_time @event.final_end_time = final_end_time @event.total_days = total_days + @event.start_week = start_week + @event.end_week = end_week @event.save! respond_to do |h| 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 38063265..8b4d61d8 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 @@ -74,18 +74,33 @@ module Panel::Calendar::BackEnd::CalsHelper def week_dates(week_num,year) year = year.to_i week_num = week_num.to_i - week_start = Date.commercial(year, week_num-1, 7) - month = week_start.strftime("%m") - month_days = getMonthDays(year) - date = week_start.strftime("%d") dates = Array.new - x = date.to_i - for i in 0..6 - d = x + i - if d > month_days[month.to_i] - d = d - month_days[month.to_i] - end - dates << Date::ABBR_DAYNAMES[i] + " " + month + "/" + d.to_s + + if week_num == 1 + weekstartday = monthStartDay(1,year) + d = 31 + x = 0 + for i in d - (weekstartday - 2)..d + dates << Date::ABBR_DAYNAMES[x] + " 12/" + i.to_s + x = x + 1 + end + for i in 1..8 - weekstartday + dates << Date::ABBR_DAYNAMES[x] + " 1/" + i.to_s + x = x + 1 + end + else + week_start = Date.commercial(year, week_num-1, 7) + month = week_start.strftime("%m") + month_days = getMonthDays(year) + date = week_start.strftime("%d") + x = date.to_i + for i in 0..6 + d = x + i + if d > month_days[month.to_i] + d = d - month_days[month.to_i] + end + dates << Date::ABBR_DAYNAMES[i] + " " + month + "/" + d.to_s + end end dates end @@ -93,19 +108,27 @@ module Panel::Calendar::BackEnd::CalsHelper def week_range(week_num,year) year = year.to_i week_num = week_num.to_i - week_start = Date.commercial(year, week_num-1, 7) - week_end = Date.commercial(year, week_num, 7) - week_end = week_end - 1 - start_date = week_start.strftime("%d") - end_date = week_end.strftime("%d") - start_month = week_start.strftime("%m") - end_month = week_end.strftime("%m") + if week_num == 1 + weekstartday = monthStartDay(1,year) + start_date = 31 - (weekstartday - 2) + start_year = year - 1 + end_date = 8 - weekstartday + range = "Dec " + start_date.to_s + ", " + start_year.to_s + " - " + "Jan " + end_date.to_s + ", " + year.to_s + else + week_start = Date.commercial(year, week_num-1, 7) + week_end = Date.commercial(year, week_num, 7) + week_end = week_end - 1 + start_date = week_start.strftime("%d") + end_date = week_end.strftime("%d") + start_month = week_start.strftime("%m") + end_month = week_end.strftime("%m") - if end_month == start_month - range = Date::ABBR_MONTHNAMES[start_month.to_i] + " " + start_date.to_s + " - " + end_date.to_s + ", " + week_start.strftime("%Y").to_s - else - range = Date::ABBR_MONTHNAMES[start_month.to_i] + " " + start_date.to_s + " - " + Date::ABBR_MONTHNAMES[end_month.to_i] + " " + end_date.to_s + ", " + week_start.strftime("%Y").to_s - end + if end_month == start_month + range = Date::ABBR_MONTHNAMES[start_month.to_i] + " " + start_date.to_s + " - " + end_date.to_s + ", " + week_start.strftime("%Y").to_s + else + range = Date::ABBR_MONTHNAMES[start_month.to_i] + " " + start_date.to_s + " - " + Date::ABBR_MONTHNAMES[end_month.to_i] + " " + end_date.to_s + ", " + week_start.strftime("%Y").to_s + end + end range end end diff --git a/vendor/built_in_modules/calendar/app/models/event.rb b/vendor/built_in_modules/calendar/app/models/event.rb index 5d0bc3f3..cff01fcc 100644 --- a/vendor/built_in_modules/calendar/app/models/event.rb +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -14,6 +14,8 @@ class Event field :start_am_pm field :end_time, type: Float field :end_am_pm + field :start_week, type: Integer + field :end_week, type: Integer field :final_start_time, type: Date field :final_end_time, type: Date field :total_days, type: Integer diff --git a/vendor/built_in_modules/calendar/config/routes.rb b/vendor/built_in_modules/calendar/config/routes.rb index 79e33107..469a7b20 100644 --- a/vendor/built_in_modules/calendar/config/routes.rb +++ b/vendor/built_in_modules/calendar/config/routes.rb @@ -7,7 +7,9 @@ Rails.application.routes.draw do match 'cals/month_view' => 'cals#month_view', :via => :get match 'cals/day_view' => 'cals#day_view', :via => :get match 'cals/week_view' => 'cals#week_view', :via => :get - match 'cals/getEvents' => 'cals#get_events', :via => :get + match 'cals/getMonthEvents' => 'cals#get_month_events', :via => :get + match 'cals/getWeekEvents' => 'cals#get_week_events', :via => :get + resources :cals resources :events