From 79e0b8e383faa941ac248027da7110d1faa9066c Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 18 Oct 2012 22:21:13 +0800 Subject: [PATCH] week view updates --- .../app/assets/javascripts/calendarAPI.js.erb | 84 +++++++++++++++++-- .../calendar/back_end/cals_controller.rb | 47 ++++++++--- .../back_end/cals/agenda_view.html.erb | 2 +- .../calendar/back_end/cals/week_view.html.erb | 36 +++++--- 4 files changed, 141 insertions(+), 28 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 41c2fc12..744fc9ba 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 @@ -304,19 +304,74 @@ var calendarAPI = function(){ } this.getEventsForWeek = function(week,year){ $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ + var height = 15; + var full_day_count = 0; + var rowcount = 7; + var tr = $(""); + var pre = true; $.each(events,function(i,evnt){ + // console.log("rowcount: "+rowcount); + // console.log("start:"+evnt.start); + console.log(rowcount); + if(rowcount >= (7 - evnt.total_days)){ + if(tr.html()!=""){ + if(rowcount != 7){ + tr.append(""); + } + $("table.all_day_event_holder").append(tr); + } + tr = null; + tr = $(''); + pre = true; + } + if(evnt.all_day){ - $(".week_day_header[date="+evnt.start_date+"]").append('
'+evnt.title+'
'); + full_day_count++; + + var precountspan = 7 - evnt.total_days; + if(pre){ + height+=20; + $(".head_event_wrapper").height(height); + $(".head_event_wrapper table").eq(0).height(height); + tr.append(' '); + if(precountspan != 0){ + tr.append(''); + pre = false; + } + } + var colcount = evnt.total_days; + if(evnt.colcount != 0){ + colcount = evnt.colcount; + } + + rowcount = precountspan + colcount; + if(evnt.title == "Yeah"){ + console.log("rowcount: "+rowcount); + console.log("start:"+evnt.total_days); + } + + tr.append('
'+evnt.title+'
'); + + // $(".week_day_header[date="+evnt.start_date+"]").append('
'+evnt.title+'
'); }else{ + var starttime,endtime,displaystarttime,displayendtime; - if(evnt.start_am_pm == "AM") + if(evnt.start_am_pm == "AM"){ starttime = evnt.start_time; - else + if(starttime == 12) + starttime = 0; + if(starttime == 12.5) + starttime = 0.5; + }else starttime = evnt.start_time + 12; - if(evnt.end_am_pm == "AM") + if(evnt.end_am_pm == "AM"){ endtime = evnt.end_time; - else + if(endtime == 12) + endtime = 0; + if(endtime == 12.5) + endtime = 0.5; + }else endtime = evnt.end_time + 12; var temp = parseInt(evnt.start_time); @@ -333,12 +388,27 @@ var calendarAPI = function(){ else displayendtime = temp + ":00 " + evnt.end_am_pm; - var toppx = ((starttime * 2) * 19) + starttime; - var eventdom = $('
'+displaystarttime+' - '+displayendtime+'
'+evnt.title+'
'); + var toppx = ((starttime * 2) * 20) + 1; + var h = endtime - starttime; + var halfhour = ""; + if(h == 0.5) + halfhour = "half"; + h = 17 + 20 + (((h-1) * 2) * 20) + 1; + var eventdom = $('
'+displaystarttime+' - '+displayendtime+'
'+evnt.title+'
'); $(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom); } + if(full_day_count == 0){ + tr.append(''); + $("table.all_day_event_holder").append(tr); + } }) + if(tr.html()!=""){ + if(rowcount != 7){ + tr.append(""); + } + $("table.all_day_event_holder").append(tr); + } }) } 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 8e67117b..d70d6833 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 @@ -111,26 +111,53 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController 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 = Event.where(:start_week.lte => week).and(:start_year => year).and(:end_week.gte => week).and(:start_year => year).asc(:start_week).asc(:start_date) @events = Array.new events.each_with_index do |event,i| # @temp = Array.new - no_of_days = event.total_days + days = event.total_days.to_i + 1 + colcount = 0 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 + + if days > 1 all_day = true end + if event.end_week > week && event.start_week < week + days = 7 + end + + if event.end_week == week + days = @d.index(event.end_date.to_s).to_i + end + + if event.start_week == week + days = 7 - @d.index(event.start_date.to_s).to_i + end + + + if event.start_week == week && event.end_week == week + x = @d.index(event.end_date.to_s).to_i + y = @d.index(event.start_date.to_s).to_i + colcount = x - y + colcount+=1 + + end + + if event.start_week < week + startdt = @d[0].to_i + event.all_day = true + if event.end_week == week + colcount = 7 - @d.index(event.end_date.to_s).to_i + days = 7; + startdt = event.start_date + end + 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} + @events << {"id"=>event.id,"index"=>i,"start_date"=>startdt,"end_date"=>event.end_date ,"all_day"=>all_day, "start_week" => event.start_week, "end_week" => event.end_week, "total_days" => 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,"colcount"=>colcount} end render :json => @events.to_json 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 98d716c1..3b2626a7 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 @@ -84,7 +84,7 @@ - + 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 461c7b01..62b28113 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 @@ -3,19 +3,35 @@ - <% @dates.each do |day| %> - + <% @dates.each_with_index do |day,i| %> + <% if @today == i %> + + <% else %> + + <% end %> <% end %> - - <% @d.each_with_index do |dt,i| %> - <% if @today == i %> - - <% else %> - - <% end %> - <% end %> +
<%= day %><%= day %><%= day %>
+
+ + + + <% @d.each_with_index do |dt,i| %> + <% if @today == i %> + + <% else %> + + <% end %> + <% end %> + +
+ + + +
+
+