week view updates
This commit is contained in:
parent
022d28e5e7
commit
bb626470e7
|
@ -1,16 +1,47 @@
|
||||||
//created on sep 14 2012
|
//created on sep 14 2012
|
||||||
|
Date.prototype.getWeek = function (dowOffset) {
|
||||||
|
/*getWeek() was developed by Nick Baicoianu at MeanFreePath: http://www.epoch-calendar.com */
|
||||||
|
|
||||||
|
dowOffset = typeof(dowOffset) == 'int' ? dowOffset : 0; //default dowOffset to zero
|
||||||
|
var newYear = new Date(this.getFullYear(),0,1);
|
||||||
|
var day = newYear.getDay() - dowOffset; //the day of week the year begins on
|
||||||
|
day = (day >= 0 ? day : day + 7);
|
||||||
|
var daynum = Math.floor((this.getTime() - newYear.getTime() -
|
||||||
|
(this.getTimezoneOffset()-newYear.getTimezoneOffset())*60000)/86400000) + 1;
|
||||||
|
var weeknum;
|
||||||
|
//if the year starts before the middle of a week
|
||||||
|
if(day < 4) {
|
||||||
|
weeknum = Math.floor((daynum+day-1)/7) + 1;
|
||||||
|
if(weeknum > 52) {
|
||||||
|
nYear = new Date(this.getFullYear() + 1,0,1);
|
||||||
|
nday = nYear.getDay() - dowOffset;
|
||||||
|
nday = nday >= 0 ? nday : nday + 7;
|
||||||
|
/*if the next year starts before the middle of
|
||||||
|
the week, it is week #1 of that year*/
|
||||||
|
weeknum = nday < 4 ? 1 : 53;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
weeknum = Math.floor((daynum+day-1)/7);
|
||||||
|
}
|
||||||
|
return weeknum;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
var calendarAPI = function(){
|
var calendarAPI = function(){
|
||||||
c = this;
|
c = this;
|
||||||
this.event_create_div = $("#event_create");
|
this.event_create_div = $("#event_create");
|
||||||
this.event_quick_view_div = $("#event_quick_view");
|
this.event_quick_view_div = $("#event_quick_view");
|
||||||
this.cur_month = null;
|
|
||||||
this.cur_year = null;
|
|
||||||
this.today = new Date();
|
this.today = new Date();
|
||||||
|
this.cur_month = c.today.getMonth()+1;
|
||||||
|
this.cur_year = c.today.getFullYear();
|
||||||
|
this.cur_week = c.today.getWeek();
|
||||||
|
this.view = null;
|
||||||
this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
|
this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
|
||||||
this.initialize = function(){
|
this.initialize = function(){
|
||||||
$(window).load(function(){
|
$(window).load(function(){
|
||||||
c.loadMonthView();
|
// c.loadMonthView(c.cur_month,c.cur_year);
|
||||||
|
c.loadWeekView(51,c.cur_year);
|
||||||
bindHandlers();
|
bindHandlers();
|
||||||
})
|
})
|
||||||
var bindHandlers = function(){
|
var bindHandlers = function(){
|
||||||
|
@ -39,7 +70,7 @@ var calendarAPI = function(){
|
||||||
c.loadMonthView(c.cur_month,c.cur_year);
|
c.loadMonthView(c.cur_month,c.cur_year);
|
||||||
break;
|
break;
|
||||||
case 'week':
|
case 'week':
|
||||||
c.loadWeekView();
|
c.loadWeekView(c.cur_week,c.cur_year);
|
||||||
break;
|
break;
|
||||||
case 'day':
|
case 'day':
|
||||||
c.loadDayView();
|
c.loadDayView();
|
||||||
|
@ -50,6 +81,8 @@ var calendarAPI = function(){
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
$("button#prev_month_btn").click(function(){
|
$("button#prev_month_btn").click(function(){
|
||||||
|
switch (c.view){
|
||||||
|
case "month":
|
||||||
var m,y;
|
var m,y;
|
||||||
if(c.cur_month == 1){
|
if(c.cur_month == 1){
|
||||||
m = 12;
|
m = 12;
|
||||||
|
@ -59,8 +92,19 @@ var calendarAPI = function(){
|
||||||
y = c.cur_year;
|
y = c.cur_year;
|
||||||
}
|
}
|
||||||
c.loadMonthView(m,y);
|
c.loadMonthView(m,y);
|
||||||
|
break;
|
||||||
|
case "week":
|
||||||
|
var w,y;
|
||||||
|
w = c.cur_week - 1;
|
||||||
|
y = c.cur_year;
|
||||||
|
c.loadWeekView(w,y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
})
|
})
|
||||||
$("button#next_month_btn").click(function(){
|
$("button#next_month_btn").click(function(){
|
||||||
|
switch (c.view){
|
||||||
|
case "month":
|
||||||
var m,y;
|
var m,y;
|
||||||
if(c.cur_month == 12){
|
if(c.cur_month == 12){
|
||||||
m = 1;
|
m = 1;
|
||||||
|
@ -70,6 +114,20 @@ var calendarAPI = function(){
|
||||||
y = c.cur_year;
|
y = c.cur_year;
|
||||||
}
|
}
|
||||||
c.loadMonthView(m,y);
|
c.loadMonthView(m,y);
|
||||||
|
break;
|
||||||
|
case "week":
|
||||||
|
var w,y;
|
||||||
|
|
||||||
|
if(c.cur_week == 52){
|
||||||
|
w = 2;
|
||||||
|
y = c.cur_year + 1;
|
||||||
|
}else{
|
||||||
|
w = c.cur_week + 1;
|
||||||
|
y = c.cur_year;
|
||||||
|
}
|
||||||
|
c.loadWeekView(w,y);
|
||||||
|
break;
|
||||||
|
}
|
||||||
})
|
})
|
||||||
$("button#today_btn").click(function(){
|
$("button#today_btn").click(function(){
|
||||||
c.loadMonthView();
|
c.loadMonthView();
|
||||||
|
@ -77,6 +135,7 @@ var calendarAPI = function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
this.loadMonthView = function(month,year){
|
this.loadMonthView = function(month,year){
|
||||||
|
c.view = "month";
|
||||||
if(!month){
|
if(!month){
|
||||||
var dt = new Date();
|
var dt = new Date();
|
||||||
month = dt.getMonth()+1;
|
month = dt.getMonth()+1;
|
||||||
|
@ -87,7 +146,7 @@ var calendarAPI = function(){
|
||||||
c.cur_month = month;
|
c.cur_month = month;
|
||||||
c.cur_year = year;
|
c.cur_year = year;
|
||||||
$('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() {
|
$('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() {
|
||||||
c.getEvents(month,year);
|
c.getEventsForMonth(month,year);
|
||||||
$('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year);
|
$('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year);
|
||||||
if($('#calendar_month').length > 0){
|
if($('#calendar_month').length > 0){
|
||||||
var $c_table = $('#calendar_month');
|
var $c_table = $('#calendar_month');
|
||||||
|
@ -114,7 +173,7 @@ var calendarAPI = function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
this.getEvents = function(month,year){
|
this.getEventsForMonth = function(month,year){
|
||||||
$.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){
|
$.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){
|
||||||
makerow(events);
|
makerow(events);
|
||||||
})
|
})
|
||||||
|
@ -214,9 +273,18 @@ var calendarAPI = function(){
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
this.loadWeekView = function(){
|
this.loadWeekView = function(week,year){
|
||||||
$('#view_holder').load("cals/week_view", function() {
|
c.view = "week";
|
||||||
$('.current_day_title').text('September 2 - 8, 2012');
|
if(!week){
|
||||||
|
var dt = new Date();
|
||||||
|
week = dt.getWeek();
|
||||||
|
year = dt.getFullYear();
|
||||||
|
}
|
||||||
|
|
||||||
|
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());
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.loadDayView = function(){
|
this.loadDayView = function(){
|
||||||
|
@ -267,6 +335,7 @@ var calendarAPI = function(){
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
|
|
||||||
c.initialize();
|
c.initialize();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -30,6 +30,10 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
|
||||||
end
|
end
|
||||||
|
|
||||||
def week_view
|
def week_view
|
||||||
|
week = params[:week]
|
||||||
|
year = params[:year]
|
||||||
|
@dates = week_dates(week,year)
|
||||||
|
@range = week_range(week,year)
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -47,7 +51,6 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
|
||||||
cur_month_days = getMonthDays(year)
|
cur_month_days = getMonthDays(year)
|
||||||
@post_disabled_days = @pre_disabled_days + cur_month_days[month]
|
@post_disabled_days = @pre_disabled_days + cur_month_days[month]
|
||||||
@dateset = getDateSet(month,year)
|
@dateset = getDateSet(month,year)
|
||||||
|
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
|
@ -60,11 +63,30 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
|
||||||
year = params[:year]
|
year = params[:year]
|
||||||
month = month.to_i
|
month = month.to_i
|
||||||
year = year.to_i
|
year = year.to_i
|
||||||
events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date).desc(:total_days)
|
events = Event.where(:start_month.lt => month).and(:start_year => year).and(:end_month.gte => month).asc(:start_date).desc(:total_days)
|
||||||
@events = Array.new
|
@events = Array.new
|
||||||
|
no_of_days_in_month = getMonthDays(year)
|
||||||
|
events.each_with_index do |event,i|
|
||||||
|
no_of_days = event.total_days
|
||||||
|
|
||||||
|
if event.end_month > month
|
||||||
|
no_of_days = no_of_days_in_month[month]
|
||||||
|
elsif event.end_month == month
|
||||||
|
no_of_days = event.end_date
|
||||||
|
end
|
||||||
|
|
||||||
|
no_of_days = no_of_days.to_i
|
||||||
|
|
||||||
|
color = Cal.find(event.cal_id).color
|
||||||
|
@events << {"id"=>event.id,"index"=>i,"start_date"=>"1", "total_days" => no_of_days, "title" => event.title,"color"=>color,"show_link"=>panel_calendar_back_end_event_path(event)}
|
||||||
|
end
|
||||||
|
events = Event.where(:start_month => month).and(:start_year => year).asc(:start_date).desc(:total_days)
|
||||||
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
|
no_of_days = event.total_days
|
||||||
|
if event.end_month > month
|
||||||
|
no_of_days = no_of_days_in_month[month] - event.start_date
|
||||||
|
end
|
||||||
no_of_days = no_of_days.to_i
|
no_of_days = no_of_days.to_i
|
||||||
no_of_days += 1
|
no_of_days += 1
|
||||||
color = Cal.find(event.cal_id).color
|
color = Cal.find(event.cal_id).color
|
||||||
|
|
|
@ -61,10 +61,56 @@ module Panel::Calendar::BackEnd::CalsHelper
|
||||||
monthsdays << 31
|
monthsdays << 31
|
||||||
return monthsdays
|
return monthsdays
|
||||||
end
|
end
|
||||||
|
|
||||||
def getDayName(date,month,year)
|
def getDayName(date,month,year)
|
||||||
|
date = date.to_i
|
||||||
|
month = month.to_i
|
||||||
|
year = year.to_i
|
||||||
dt = Date.new(year,month,date)
|
dt = Date.new(year,month,date)
|
||||||
name = Date::ABBR_DAYNAMES[dt.wday]
|
name = Date::ABBR_DAYNAMES[dt.wday]
|
||||||
return name
|
return name
|
||||||
end
|
end
|
||||||
|
|
||||||
|
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
|
||||||
|
end
|
||||||
|
dates
|
||||||
|
end
|
||||||
|
|
||||||
|
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 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
|
||||||
|
range
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -1,35 +1,32 @@
|
||||||
|
<div id="week_range" style="display:none;" ><%= @range %></div>
|
||||||
<div id="calendar_week">
|
<div id="calendar_week">
|
||||||
<table class="table header">
|
<table class="table header">
|
||||||
<tr>
|
<tr>
|
||||||
<th style="width: 44px;"></th>
|
<th style="width: 44px;"></th>
|
||||||
<th>Sun 9/11</th>
|
<% @dates.each do |day| %>
|
||||||
<th>Mon 9/12</th>
|
<th><%= day %></th>
|
||||||
<th class="today">Tue 9/13</th>
|
<% end %>
|
||||||
<th>Wed 9/14</th>
|
|
||||||
<th>Thu 9/15</th>
|
|
||||||
<th>Fri 9/16</th>
|
|
||||||
<th>Sat 9/17</th>
|
|
||||||
</tr>
|
</tr>
|
||||||
<tr>
|
<tr>
|
||||||
<td style="border: 0; background: none;"></td>
|
<td style="border: 0; background: none;"></td>
|
||||||
<td class="all_day_event week_day">
|
<td class="all_day_event week_day">
|
||||||
<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>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div> -->
|
||||||
</td>
|
</td>
|
||||||
<td class="all_day_event week_day">
|
<td class="all_day_event week_day">
|
||||||
</td>
|
</td>
|
||||||
<td class="all_day_event week_day"></td>
|
<td class="all_day_event week_day"></td>
|
||||||
<td class="all_day_event week_day">
|
<td class="all_day_event week_day">
|
||||||
<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>
|
||||||
<dd></dd>
|
<dd></dd>
|
||||||
</dl>
|
</dl>
|
||||||
</div>
|
</div> -->
|
||||||
</td>
|
</td>
|
||||||
<td class="all_day_event week_day"></td>
|
<td class="all_day_event week_day"></td>
|
||||||
<td class="all_day_event week_day"></td>
|
<td class="all_day_event week_day"></td>
|
||||||
|
|
|
@ -1,4 +1,4 @@
|
||||||
$("#event_create").empty().hide();
|
$("#event_create").empty().hide();
|
||||||
$("#create_event_btn").removeClass("active");
|
$("#create_event_btn").removeClass("active");
|
||||||
$("#calendar_month tr.event_row").remove();
|
$("#calendar_month tr.event_row").remove();
|
||||||
calendar.getEvents(<%= @m %>,<%= @y %>);
|
calendar.getEventsForMonth(<%= @m %>,<%= @y %>);
|
Reference in New Issue