week view updates

This commit is contained in:
Harry Bomrah 2012-10-18 22:21:13 +08:00
parent 47df69f8cf
commit a810312da4
4 changed files with 141 additions and 28 deletions

View File

@ -304,19 +304,74 @@ var calendarAPI = function(){
} }
this.getEventsForWeek = function(week,year){ this.getEventsForWeek = function(week,year){
$.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){ $.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){
var height = 15;
var full_day_count = 0;
var rowcount = 7;
var tr = $("<tr></tr>");
var pre = true;
$.each(events,function(i,evnt){ $.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("<td colspan='"+(7-rowcount)+"'></td>");
}
$("table.all_day_event_holder").append(tr);
}
tr = null;
tr = $('<tr></tr>');
pre = true;
}
if(evnt.all_day){ if(evnt.all_day){
$(".week_day_header[date="+evnt.start_date+"]").append('<div class="event half" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff;"><dl><dt>'+evnt.title+'</dt><dd></dd></dl></div>'); 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('<td rowspan="1" style="width:60px;">&nbsp;</td>');
if(precountspan != 0){
tr.append('<td colspan="'+precountspan+'"></td>');
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('<td colspan="'+colcount+'" class="all_day_event week_day" ><div class="event half" style="background-color: '+evnt.color+' ;color:#fff;" link="'+evnt.show_link+'"><dl><dt>'+evnt.title+'</dt><dd></dd></dl></div></td>');
// $(".week_day_header[date="+evnt.start_date+"]").append('<div class="event half" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff;"><dl><dt>'+evnt.title+'</dt><dd></dd></dl></div>');
}else{ }else{
var starttime,endtime,displaystarttime,displayendtime; var starttime,endtime,displaystarttime,displayendtime;
if(evnt.start_am_pm == "AM") if(evnt.start_am_pm == "AM"){
starttime = evnt.start_time; starttime = evnt.start_time;
else if(starttime == 12)
starttime = 0;
if(starttime == 12.5)
starttime = 0.5;
}else
starttime = evnt.start_time + 12; starttime = evnt.start_time + 12;
if(evnt.end_am_pm == "AM") if(evnt.end_am_pm == "AM"){
endtime = evnt.end_time; endtime = evnt.end_time;
else if(endtime == 12)
endtime = 0;
if(endtime == 12.5)
endtime = 0.5;
}else
endtime = evnt.end_time + 12; endtime = evnt.end_time + 12;
var temp = parseInt(evnt.start_time); var temp = parseInt(evnt.start_time);
@ -333,12 +388,27 @@ var calendarAPI = function(){
else else
displayendtime = temp + ":00 " + evnt.end_am_pm; displayendtime = temp + ":00 " + evnt.end_am_pm;
var toppx = ((starttime * 2) * 19) + starttime; var toppx = ((starttime * 2) * 20) + 1;
var eventdom = $('<div class="event" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff; top:'+toppx+'px;"><dl><dt>'+displaystarttime+' - '+displayendtime+'</dt><dd>'+evnt.title+'</dd></dl></div>'); var h = endtime - starttime;
var halfhour = "";
if(h == 0.5)
halfhour = "half";
h = 17 + 20 + (((h-1) * 2) * 20) + 1;
var eventdom = $('<div class="event '+halfhour+'" link="'+evnt.show_link+'" style="background-color: '+evnt.color+';color:#fff; top:'+toppx+'px; height:'+h+'px;"><dl><dt>'+displaystarttime+' - '+displayendtime+'</dt><dd>'+evnt.title+'</dd></dl></div>');
$(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom); $(".week_day_body[date="+evnt.start_date+"] .inner").append(eventdom);
} }
if(full_day_count == 0){
tr.append('<td rowspan="1" style="width:60px;">');
$("table.all_day_event_holder").append(tr);
}
}) })
if(tr.html()!=""){
if(rowcount != 7){
tr.append("<td colspan='"+(7-rowcount)+"'></td>");
}
$("table.all_day_event_holder").append(tr);
}
}) })
} }
this.loadDayView = function(){ this.loadDayView = function(){

View File

@ -111,26 +111,53 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
week = params[:week].to_i week = params[:week].to_i
year = params[:year].to_i year = params[:year].to_i
@d = getWeekDataSet(week,year) @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 = Array.new
events.each_with_index do |event,i| events.each_with_index do |event,i|
# @temp = Array.new # @temp = Array.new
no_of_days = event.total_days days = event.total_days.to_i + 1
colcount = 0
startdt = event.start_date 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 all_day = event.all_day
if no_of_days > 1
if days > 1
all_day = true all_day = true
end 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 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 end
render :json => @events.to_json render :json => @events.to_json
end end

View File

@ -84,7 +84,7 @@
</dl> </dl>
</div> </div>
</td> </td>
</tr> </tr>
<tr> <tr>
<td colspan="1"></td> <td colspan="1"></td>
<td colspan="2" class="all_day_event week_day"> <td colspan="2" class="all_day_event week_day">

View File

@ -3,19 +3,35 @@
<table class="table header"> <table class="table header">
<tr> <tr>
<th style="width: 44px;"></th> <th style="width: 44px;"></th>
<% @dates.each do |day| %> <% @dates.each_with_index do |day,i| %>
<th><%= day %></th> <% if @today == i %>
<th class='today'><%= day %></th>
<% else %>
<th><%= day %></th>
<% end %>
<% end %> <% end %>
</tr> </tr>
<tr> <tr>
<td style="border: 0; background: none;"></td> <td colspan="8" style="border:0;">
<% @d.each_with_index do |dt,i| %> <div class="event_list_wrapper head_event_wrapper" style="height:50px;">
<% if @today == i %> <table style="position: absolute; width: 100%; height: 50px; top: 0;">
<td class="all_day_event week_day week_day_header today" date='<%= dt %>'></td> <tr>
<% else %> <td style="border: 0; background: none; width: 60px;"></td>
<td class="all_day_event week_day week_day_header" date='<%= dt %>'></td> <% @d.each_with_index do |dt,i| %>
<% end %> <% if @today == i %>
<% end %> <td class="all_day_event week_day week_day_header today" date='<%= dt %>'></td>
<% else %>
<td class="all_day_event week_day week_day_header" date='<%= dt %>'></td>
<% end %>
<% end %>
</tr>
</table>
<table class="all_day_event_holder">
</table>
</div>
</td>
<!-- <div class="event half" style="background-color: #ccffee;"> <!-- <div class="event half" style="background-color: #ccffee;">
<dl> <dl>
<dt>10:30am - template</dt> <dt>10:30am - template</dt>