From a810312da4ae4fee566481c9d7c0bc82e76faf18 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Thu, 18 Oct 2012 22:21:13 +0800 Subject: [PATCH 1/2] 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 41c2fc128..744fc9ba4 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 8e67117bf..d70d68332 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 98d716c1e..3b2626a7e 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 461c7b01b..62b28113c 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 %> + -
+
+ \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb index 46fc0a169..709437c7b 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/day_view.html.erb @@ -3,14 +3,14 @@
<%= day %><%= day %><%= day %>
+
+ + + + <% @d.each_with_index do |dt,i| %> + <% if @today == i %> + + <% else %> + + <% end %> + <% end %> + +
+ + + +
+
+
-

Sunday 9/2

+
-
event1
-
event2
+
@@ -18,107 +18,25 @@ diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb new file mode 100644 index 000000000..9cf6b355b --- /dev/null +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/edit.html.erb @@ -0,0 +1,26 @@ +<%= form_for @calendar, :url => panel_calendar_back_end_cal_path(@calendar), :remote => true do |f| %> +

Edit

+
+
+ <%= label_tag("color", t("calendar.color")) %> + <%= f.text_field :color, :class => "color-picker miniColors", :size => "5", :maxlength => "5", :autocomplete=>"off",:value=>@calendar.color %> +
+
+ +
+ <%= f.fields_for :name_translations do |name| %> + <% @site_valid_locales.each_with_index do |locale, i| %> +
+ <%= label_tag(locale, t("calendar.name")+"-"+I18nVariable.from_locale(locale)) %> +
+ <%= name.text_field locale, :class => "input-xxlarge", :size=>"30", :value=>@calendar.name_translations[locale] %> +
+
+ <% end %> + <% end %> +
+
+ <%= f.submit t("calendar.save"), :class=>"btn btn-primary" %> + +
+<% 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 96701aaf9..791cfe190 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 @@ -64,7 +64,7 @@ - +
-
12am
-
1am
-
2am
-
3am
-
4am
-
5am
-
6am
-
7am
-
8am
-
9am
-
10am
-
11am
-
12am
-
1pm
-
2pm
-
3pm
-
4pm
-
5pm
-
6pm
-
7pm
-
8pm
-
9pm
-
10pm
-
11pm
+ <% @hours.each do |hour| %> +
<%= hour %>am
+ <% end %> + <% @hours.each do |hour| %> +
<%= hour %>pm
+ <% end %>
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
-
+ <% @hours.each do |hour| %> +
+
+
+
+
+
+ <% end %>
-
+