orbit-basic/vendor/built_in_modules/calendar/app/assets/javascripts/calendarAPI.js.erb

203 lines
5.5 KiB
Plaintext
Raw Normal View History

2012-09-14 13:59:20 +00:00
//created on sep 14 2012
2012-09-14 07:20:01 +00:00
2012-09-14 13:59:20 +00:00
var calendarAPI = function(){
c = this;
this.event_create_div = $("#event_create");
this.event_quick_view_div = $("#event_quick_view");
2012-09-15 21:59:20 +00:00
this.cur_month = null;
this.cur_year = null;
this.today = new Date();
this.monthlist = ["","January","February","March","April","May","June","July","August","September","October","November","December"];
2012-09-14 13:59:20 +00:00
this.initialize = function(){
$(window).load(function(){
c.loadMonthView();
bindHandlers();
})
var bindHandlers = function(){
$(".event").live("click",function(){
c.displayEvent();
})
$("#create_event_btn").click(function(){
2012-09-16 20:34:03 +00:00
if(!$(this).hasClass("active")){
c.newEvent($(this).attr("href"),$(this).attr("ref"),c.today.getDate(),c.today.getMonth()+1,c.today.getFullYear());
}else{
c.event_create_div.hide().empty();
}
2012-09-14 13:59:20 +00:00
$(this).toggleClass("active");
return false;
})
2012-09-16 20:34:03 +00:00
$("td.click_event").live("click",function(){
c.newEvent($(this).attr("link"),$(this).attr("ref"),$(this).attr("date"),c.cur_month,c.cur_year);
$("#create_event_btn").toggleClass("active");
})
2012-09-14 13:59:20 +00:00
$('.mode_switch').click(function(){
var target = $(this).text();
switch(target){
case 'month':
2012-09-15 21:59:20 +00:00
c.loadMonthView(c.cur_month,c.cur_year);
2012-09-14 13:59:20 +00:00
break;
case 'week':
c.loadWeekView();
break;
case 'day':
c.loadDayView();
break;
case 'agenda':
c.loadAgendaView();
break;
}
2012-09-15 21:59:20 +00:00
})
$("button#prev_month_btn").click(function(){
var m,y;
if(c.cur_month == 1){
m = 12;
y = c.cur_year-1;
}else{
m = c.cur_month-1;
y = c.cur_year;
}
c.loadMonthView(m,y);
})
$("button#next_month_btn").click(function(){
var m,y;
if(c.cur_month == 12){
m = 1;
y = c.cur_year+1;
}else{
m = c.cur_month+1;
y = c.cur_year;
}
c.loadMonthView(m,y);
})
$("button#today_btn").click(function(){
c.loadMonthView();
})
2012-09-14 13:59:20 +00:00
}
}
2012-09-15 21:59:20 +00:00
this.loadMonthView = function(month,year){
if(!month){
var dt = new Date();
month = dt.getMonth()+1;
year = dt.getFullYear();
}
// month = 2;
// year = 2008;
c.cur_month = month;
c.cur_year = year;
$('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() {
2012-09-16 20:34:03 +00:00
getEvents(month,year);
2012-09-15 21:59:20 +00:00
$('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year);
2012-09-14 13:59:20 +00:00
if($('#calendar_month').length > 0){
var $c_table = $('#calendar_month');
var sum_h = 0;
var context_h = $('#main-sidebar').outerHeight();
$('#main-wrap > *').not('#orbit_calendar, .modal').each(function(){
sum_h += $(this).outerHeight();
});
2012-09-12 08:16:01 +00:00
2012-09-14 07:20:01 +00:00
$c_table
2012-09-14 13:59:20 +00:00
// .height(context_h-sum_h-64)
2012-09-14 07:20:01 +00:00
.find('.month_row')
.not('.month_row.header')
2012-09-14 13:59:20 +00:00
.height((context_h-sum_h-92) / 6);
$(window).resize(function(){
$c_table
.find('.month_row')
.not('.month_row.header')
.height(($('#main-sidebar').outerHeight()-sum_h-92) / 6);
});
}
})
2012-09-16 20:34:03 +00:00
var getEvents = function(month,year){
$.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){
var $eventrow = $("<tr></tr>");
var currow = 1;
var curpos = 1;
$.each(events,function(i,evnt){
var daydom = $("#calendar_month td[date="+evnt.start_date+"]");
var curparent = daydom.parent().parent().parent();
var thisrow = curparent.attr("row");
var pos = daydom.attr("position");
if(thisrow != currow){
$eventrow = null;
$eventrow = $("<tr></tr>");
}else if(pos == curpos){
$eventrow = null;
$eventrow = $("<tr></tr>");
}
if(pos == 1){
$eventrow.html('<td colspan="'+evnt.total_days+'"><div class="event" style="background-color: '+evnt.color+';">'+evnt.title+'</div></td>');
}else{
if($eventrow.html()==""){
$eventrow.append('<td colspan="'+(pos-1)+'">');
}
$eventrow.append('<td colspan="'+evnt.total_days+'"><div class="event" style="background-color: '+evnt.color+';">'+evnt.title+'</div></td>');
}
currow = thisrow;
curpos = pos;
curparent.append($eventrow);
})
})
}
2012-09-14 13:59:20 +00:00
}
this.loadWeekView = function(){
$('#view_holder').load("cals/week_view", function() {
$('.current_day_title').text('September 2 - 8, 2012');
})
}
this.loadDayView = function(){
$('#view_holder').load("cals/day_view", function() {
$('.current_day_title').text('September 2, 2012');
})
}
this.loadAgendaView = function(){
$('#view_holder').load("cals/week_view", function() {
$('.current_day_title').text('September 2, 2012');
})
}
2012-09-16 20:34:03 +00:00
this.newEvent = function(url,ref,date,month,year){
2012-09-14 13:59:20 +00:00
var bindHandlers = function(){
c.event_create_div.find("button.btn-close").click(function(){
c.event_create_div.hide().empty();
2012-09-16 20:34:03 +00:00
$("#create_event_btn").removeClass("active");
2012-09-14 13:59:20 +00:00
})
c.event_create_div.find("input[for=all_day][type=checkbox]").click(function(){
if($(this).is(":checked"))
c.event_create_div.find("#non_all_day").hide()
else
c.event_create_div.find("#non_all_day").show()
})
}
2012-09-16 20:34:03 +00:00
c.event_create_div.load(url+"?ref="+ref+"&date="+date+"&month="+month+"&year="+year,function(){
c.event_create_div.show();
bindHandlers();
})
2012-09-12 08:16:01 +00:00
}
2012-09-14 13:59:20 +00:00
this.newCalendars = function(){
if($('.color-picker').length > 0){
$('.color-picker').miniColors(); // just in category view
}
2012-09-15 21:59:20 +00:00
$(".btn-del-a").live("ajax:success",function(){
var domfor = $(this).attr("data-content");
$("tr[for="+domfor+"]").remove();
})
2012-09-14 07:20:01 +00:00
}
2012-09-14 13:59:20 +00:00
this.displayEvent = function(){
c.event_quick_view_div.show()
2012-09-14 07:20:01 +00:00
}
2012-09-14 13:59:20 +00:00
c.initialize();
}
2012-09-14 07:20:01 +00:00