Week View changes
This commit is contained in:
parent
e44495ac9b
commit
59f97f3fef
|
@ -41,7 +41,7 @@ var calendarAPI = function(){
|
||||||
this.initialize = function(){
|
this.initialize = function(){
|
||||||
$(window).load(function(){
|
$(window).load(function(){
|
||||||
// c.loadMonthView(c.cur_month,c.cur_year);
|
// c.loadMonthView(c.cur_month,c.cur_year);
|
||||||
c.loadWeekView(51,c.cur_year);
|
c.loadWeekView(c.cur_week,c.cur_year);
|
||||||
bindHandlers();
|
bindHandlers();
|
||||||
})
|
})
|
||||||
var bindHandlers = function(){
|
var bindHandlers = function(){
|
||||||
|
@ -95,8 +95,13 @@ var calendarAPI = function(){
|
||||||
break;
|
break;
|
||||||
case "week":
|
case "week":
|
||||||
var w,y;
|
var w,y;
|
||||||
w = c.cur_week - 1;
|
if(c.cur_week == 1){
|
||||||
y = c.cur_year;
|
w = 52;
|
||||||
|
y = c.cur_year - 1;
|
||||||
|
}else{
|
||||||
|
w = c.cur_week - 1;
|
||||||
|
y = c.cur_year;
|
||||||
|
}
|
||||||
c.loadWeekView(w,y);
|
c.loadWeekView(w,y);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -119,7 +124,7 @@ var calendarAPI = function(){
|
||||||
var w,y;
|
var w,y;
|
||||||
|
|
||||||
if(c.cur_week == 52){
|
if(c.cur_week == 52){
|
||||||
w = 2;
|
w = 1;
|
||||||
y = c.cur_year + 1;
|
y = c.cur_year + 1;
|
||||||
}else{
|
}else{
|
||||||
w = c.cur_week + 1;
|
w = c.cur_week + 1;
|
||||||
|
@ -173,8 +178,9 @@ var calendarAPI = function(){
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
this.getEventsForMonth = function(month,year){
|
this.getEventsForMonth = function(month,year){
|
||||||
$.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){
|
$.getJSON("cals/getMonthEvents",{"month":month,"year":year},function(events){
|
||||||
makerow(events);
|
makerow(events);
|
||||||
})
|
})
|
||||||
var doneEventArray = new Array();
|
var doneEventArray = new Array();
|
||||||
|
@ -283,8 +289,15 @@ var calendarAPI = function(){
|
||||||
|
|
||||||
c.cur_week = week;
|
c.cur_week = week;
|
||||||
c.cur_year = year;
|
c.cur_year = year;
|
||||||
|
|
||||||
$('#view_holder').load("cals/week_view?week="+week+"&year="+year, function() {
|
$('#view_holder').load("cals/week_view?week="+week+"&year="+year, function() {
|
||||||
$('.current_day_title').text($("#week_range").text());
|
$('.current_day_title').text($("#week_range").text());
|
||||||
|
c.getEventsForWeek(week,year);
|
||||||
|
})
|
||||||
|
}
|
||||||
|
this.getEventsForWeek = function(week,year){
|
||||||
|
$.getJSON("cals/getWeekEvents",{"week":week,"year":year},function(events){
|
||||||
|
|
||||||
})
|
})
|
||||||
}
|
}
|
||||||
this.loadDayView = function(){
|
this.loadDayView = function(){
|
||||||
|
|
|
@ -58,7 +58,7 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
|
||||||
render :layout => false
|
render :layout => false
|
||||||
end
|
end
|
||||||
|
|
||||||
def get_events
|
def get_month_events
|
||||||
month = params[:month]
|
month = params[:month]
|
||||||
year = params[:year]
|
year = params[:year]
|
||||||
month = month.to_i
|
month = month.to_i
|
||||||
|
@ -96,6 +96,30 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController
|
||||||
render :json => @events.to_json
|
render :json => @events.to_json
|
||||||
end
|
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
|
||||||
|
end
|
||||||
|
|
||||||
|
def week_number_test
|
||||||
|
events = Event.all
|
||||||
|
|
||||||
|
events.each do |event|
|
||||||
|
dt = Date.new(event.start_year,event.start_month,event.start_date)
|
||||||
|
sweeknumber = dt.strftime("%U")
|
||||||
|
dt = Date.new(event.end_year,event.end_month,event.end_date)
|
||||||
|
eweeknumber = dt.strftime("%U")
|
||||||
|
event.start_week = sweeknumber
|
||||||
|
event.end_week = eweeknumber
|
||||||
|
event.save!
|
||||||
|
end
|
||||||
|
|
||||||
|
dt = Date.new(2012,10,4)
|
||||||
|
@week = dt.strftime("%U")
|
||||||
|
render :text => @week.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -45,6 +45,8 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController
|
||||||
|
|
||||||
final_start_time = Date.new(start_year.to_i,start_month.to_i,start_date.to_i)
|
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)
|
final_end_time = Date.new(end_year.to_i,end_month.to_i,end_date.to_i)
|
||||||
|
start_week = final_start_time.strftime("%U")
|
||||||
|
end_week = final_end_time.strftime("%U")
|
||||||
total_days = final_end_time - final_start_time
|
total_days = final_end_time - final_start_time
|
||||||
@event = Event.new
|
@event = Event.new
|
||||||
@event.title = title
|
@event.title = title
|
||||||
|
@ -63,6 +65,8 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController
|
||||||
@event.final_start_time = final_start_time
|
@event.final_start_time = final_start_time
|
||||||
@event.final_end_time = final_end_time
|
@event.final_end_time = final_end_time
|
||||||
@event.total_days = total_days
|
@event.total_days = total_days
|
||||||
|
@event.start_week = start_week
|
||||||
|
@event.end_week = end_week
|
||||||
@event.save!
|
@event.save!
|
||||||
|
|
||||||
respond_to do |h|
|
respond_to do |h|
|
||||||
|
|
|
@ -74,18 +74,33 @@ module Panel::Calendar::BackEnd::CalsHelper
|
||||||
def week_dates(week_num,year)
|
def week_dates(week_num,year)
|
||||||
year = year.to_i
|
year = year.to_i
|
||||||
week_num = week_num.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
|
dates = Array.new
|
||||||
x = date.to_i
|
|
||||||
for i in 0..6
|
if week_num == 1
|
||||||
d = x + i
|
weekstartday = monthStartDay(1,year)
|
||||||
if d > month_days[month.to_i]
|
d = 31
|
||||||
d = d - month_days[month.to_i]
|
x = 0
|
||||||
end
|
for i in d - (weekstartday - 2)..d
|
||||||
dates << Date::ABBR_DAYNAMES[i] + " " + month + "/" + d.to_s
|
dates << Date::ABBR_DAYNAMES[x] + " 12/" + i.to_s
|
||||||
|
x = x + 1
|
||||||
|
end
|
||||||
|
for i in 1..8 - weekstartday
|
||||||
|
dates << Date::ABBR_DAYNAMES[x] + " 1/" + 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 << Date::ABBR_DAYNAMES[i] + " " + month + "/" + d.to_s
|
||||||
|
end
|
||||||
end
|
end
|
||||||
dates
|
dates
|
||||||
end
|
end
|
||||||
|
@ -93,19 +108,27 @@ module Panel::Calendar::BackEnd::CalsHelper
|
||||||
def week_range(week_num,year)
|
def week_range(week_num,year)
|
||||||
year = year.to_i
|
year = year.to_i
|
||||||
week_num = week_num.to_i
|
week_num = week_num.to_i
|
||||||
week_start = Date.commercial(year, week_num-1, 7)
|
if week_num == 1
|
||||||
week_end = Date.commercial(year, week_num, 7)
|
weekstartday = monthStartDay(1,year)
|
||||||
week_end = week_end - 1
|
start_date = 31 - (weekstartday - 2)
|
||||||
start_date = week_start.strftime("%d")
|
start_year = year - 1
|
||||||
end_date = week_end.strftime("%d")
|
end_date = 8 - weekstartday
|
||||||
start_month = week_start.strftime("%m")
|
range = "Dec " + start_date.to_s + ", " + start_year.to_s + " - " + "Jan " + end_date.to_s + ", " + year.to_s
|
||||||
end_month = week_end.strftime("%m")
|
else
|
||||||
|
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
|
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
|
range = Date::ABBR_MONTHNAMES[start_month.to_i] + " " + start_date.to_s + " - " + end_date.to_s + ", " + week_start.strftime("%Y").to_s
|
||||||
else
|
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
|
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
|
end
|
||||||
|
end
|
||||||
range
|
range
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -14,6 +14,8 @@ class Event
|
||||||
field :start_am_pm
|
field :start_am_pm
|
||||||
field :end_time, type: Float
|
field :end_time, type: Float
|
||||||
field :end_am_pm
|
field :end_am_pm
|
||||||
|
field :start_week, type: Integer
|
||||||
|
field :end_week, type: Integer
|
||||||
field :final_start_time, type: Date
|
field :final_start_time, type: Date
|
||||||
field :final_end_time, type: Date
|
field :final_end_time, type: Date
|
||||||
field :total_days, type: Integer
|
field :total_days, type: Integer
|
||||||
|
|
|
@ -7,7 +7,9 @@ Rails.application.routes.draw do
|
||||||
match 'cals/month_view' => 'cals#month_view', :via => :get
|
match 'cals/month_view' => 'cals#month_view', :via => :get
|
||||||
match 'cals/day_view' => 'cals#day_view', :via => :get
|
match 'cals/day_view' => 'cals#day_view', :via => :get
|
||||||
match 'cals/week_view' => 'cals#week_view', :via => :get
|
match 'cals/week_view' => 'cals#week_view', :via => :get
|
||||||
match 'cals/getEvents' => 'cals#get_events', :via => :get
|
match 'cals/getMonthEvents' => 'cals#get_month_events', :via => :get
|
||||||
|
match 'cals/getWeekEvents' => 'cals#get_week_events', :via => :get
|
||||||
|
|
||||||
resources :cals
|
resources :cals
|
||||||
resources :events
|
resources :events
|
||||||
|
|
||||||
|
|
Reference in New Issue