From 0971e00511ed8db1d74ecef64fd7d13d8f0a82ec Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Tue, 16 Oct 2012 21:50:46 +0800 Subject: [PATCH] calendar updated for week --- .../app/assets/javascripts/calendarAPI.js.erb | 51 ++++- .../calendar/back_end/cals_controller.rb | 44 +++- .../calendar/back_end/events_controller.rb | 14 ++ .../panel/calendar/back_end/cals_helper.rb | 49 +++++ .../calendar/app/models/event.rb | 1 + .../back_end/cals/agenda_view.html.erb | 202 +++++++++++++++++- .../calendar/back_end/cals/week_view.html.erb | 130 ++++------- .../calendar/back_end/events/new.html.erb | 50 ++--- .../calendar/back_end/events/show.html.erb | 2 +- .../gprs/back_end/locations/index.html.erb | 1 + 10 files changed, 417 insertions(+), 127 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 64eb8f8a..da3d0d32 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 @@ -135,7 +135,14 @@ var calendarAPI = function(){ } }) $("button#today_btn").click(function(){ - c.loadMonthView(); + switch (c.view){ + case "week": + c.loadWeekView(); + break; + case "month": + c.loadMonthView(); + break; + } }) } } @@ -231,13 +238,13 @@ var calendarAPI = function(){ $eventrow.html('
'+evnt.title+'
'); }else{ if($eventrow.html()==""){ - $eventrow.append(''); + $eventrow.append(''); }else{ if((lastno+1)!=thisno){ var inposition = parseInt($eventrow.find("td.main_td:last").attr("pos")); var curcolspan = $eventrow.find("td.main_td:last").attr("colspan"); var colspan = pos - (inposition+parseInt(curcolspan)); - $eventrow.append(''); + $eventrow.append(''); } } var colspan = 0; @@ -297,7 +304,41 @@ var calendarAPI = function(){ } this.getEventsForWeek = function(week,year){ $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ - + $.each(events,function(i,evnt){ + if(evnt.all_day){ + $(".week_day_header[date="+evnt.start_date+"]").append('
'+evnt.title+'
'); + }else{ + var starttime,endtime,displaystarttime,displayendtime; + if(evnt.start_am_pm == "AM") + starttime = evnt.start_time; + else + starttime = evnt.start_time + 12; + + if(evnt.end_am_pm == "AM") + endtime = evnt.end_time; + else + endtime = evnt.end_time + 12; + + var temp = parseInt(evnt.start_time); + + if (evnt.start_time > temp) + displaystarttime = temp + ":30 " + evnt.start_am_pm; + else + displaystarttime = temp + ":00 " + evnt.start_am_pm; + + temp = parseInt(evnt.end_time); + + if (evnt.end_time > temp) + displayendtime = temp + ":30 " + evnt.end_am_pm; + else + displayendtime = temp + ":00 " + evnt.end_am_pm; + + var toppx = ((starttime * 2) * 19) + starttime; + var eventdom = $('
'+displaystarttime+' - '+displayendtime+'
'+evnt.title+'
'); + $(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom); + } + + }) }) } this.loadDayView = function(){ @@ -306,7 +347,7 @@ var calendarAPI = function(){ }) } this.loadAgendaView = function(){ - $('#view_holder').load("cals/week_view", function() { + $('#view_holder').load("cals/agenda_view", function() { $('.current_day_title').text('September 2, 2012'); }) } 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 2c171895..8e67117b 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 @@ -30,10 +30,21 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController end def week_view - week = params[:week] - year = params[:year] + week = params[:week].to_i + year = params[:year].to_i @dates = week_dates(week,year) @range = week_range(week,year) + @d = getWeekDataSet(week,year) + t = Time.now + dt = Date.new(t.year,t.month,t.day) + today_cur_week = dt.strftime("%U").to_i + + if week == today_cur_week && t.year == year + @today = @d.index(t.day.to_s) + else + @today = 20 + end + @hours = getHours(12) render :layout => false end @@ -97,10 +108,31 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController 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 + week = params[:week].to_i + year = params[:year].to_i + @d = getWeekDataSet(week,year) + events = Event.where(:start_week.lte => week).and(:start_year => year).and(:end_week.gte => week).and(:start_year => year) + @events = Array.new + events.each_with_index do |event,i| + # @temp = Array.new + no_of_days = event.total_days + startdt = event.start_date + if event.start_week < week + startdt = @d[0].to_i + event.all_day = true + end + + no_of_days = no_of_days.to_i + no_of_days += 1 + all_day = event.all_day + if no_of_days > 1 + all_day = true + end + + color = Cal.find(event.cal_id).color + @events << {"id"=>event.id,"index"=>i,"start_date"=>startdt,"all_day"=>all_day, "start_week" => event.start_week, "end_week" => event.end_week, "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event),"start_time"=>event.start_time,"end_time"=>event.end_time,"start_am_pm"=>event.start_am_pm,"end_am_pm"=>event.end_am_pm} + end + render :json => @events.to_json end def week_number_test 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 519d84f4..41ffa151 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 @@ -42,6 +42,13 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController # if end_am_pm == "PM" # temp_end_time = $endtime + 12 # end + if params[:all_day] + all_day = true + $starttime = 0 + $endtime = 0 + else + all_day = false + end 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) @@ -67,6 +74,7 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @event.total_days = total_days @event.start_week = start_week @event.end_week = end_week + @event.all_day = all_day @event.save! respond_to do |h| @@ -81,6 +89,12 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController @end_day_name = getDayName(@event.end_date,@event.end_month,@event.end_year) render :layout=>false end + + def destroy + event = Event.find(params[:id]) + event.delete + render :json => {"success"=>"true"}.to_json + end end 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 8b4d61d8..fc349ecd 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 @@ -131,6 +131,55 @@ module Panel::Calendar::BackEnd::CalsHelper end range end + + def getWeekDataSet(week_num,year) + year = year.to_i + week_num = week_num.to_i + dates = Array.new + + if week_num == 1 + weekstartday = monthStartDay(1,year) + d = 31 + x = 0 + for i in d - (weekstartday - 2)..d + dates << i.to_s + x = x + 1 + end + for i in 1..8 - weekstartday + dates << 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 << d.to_s + end + end + dates + end + + def getHours(format) + hours = Array.new + if format == 12 + hours << 12 + for i in 1..11 + hours << i + end + elsif format == 24 + for i in 0..23 + hours << i + end + end + hours + 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 cff01fcc..5c53b1c1 100644 --- a/vendor/built_in_modules/calendar/app/models/event.rb +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -19,6 +19,7 @@ class Event field :final_start_time, type: Date field :final_end_time, type: Date field :total_days, type: Integer + field :all_day, type: Boolean belongs_to :cal 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 b7726e4c..a8577212 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,4 +1,4 @@ -
+ +
+ + + + + + + + + + + + + + + + + + + + + +
Sun 9/11Mon 9/12Tue 9/13Wed 9/14Thu 9/15Fri 9/16Sat 9/17
+
+
+
10:30am - template
+
+
+
+
+ +
+
+
10:30am - template
+
+
+
+
+
+ + + + + + + + + + + + + + + +
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
12am
+
1am
+
2am
+
3am
+
4am
+
5am
+
6am
+
7am
+
8am
+
9am
+
10am
+
11am
+
12am
+
1pm
+
2pm
+
3pm
+
4pm
+
5pm
+
6pm
+
7pm
+
8pm
+
9pm
+
10pm
+
11pm
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
10:30am - 11:00am
+
template
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
+
diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/week_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/week_view.html.erb index dc27b736..f7400608 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/week_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/week_view.html.erb @@ -9,28 +9,33 @@ - + <% @d.each_with_index do |dt,i| %> + <% if @today == i %> + + <% else %> + + <% end %> + <% end %> - - + +
- + -->
@@ -39,84 +44,26 @@
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ <% @hours.each do |hour| %> +
+
+
+
+
+
+ <% end %>
-
12am
+ <% @hours.each do |hour| %> +
<%= hour %>am
+ <% end %> + <% @hours.each do |hour| %> +
<%= hour %>pm
+ <% end %> + - -
-
+ <% @d.each_with_index do |dt,i| %> + <% if i == @today %> + + <% else %> + + <% end %> +
+
+ +
-
- - + + <% end %> +
diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb index 48e18efa..5fd5870e 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb @@ -11,7 +11,7 @@
<% if !@all_day_disabled %> <% end %>