From 221ffc08dd2ac696ac610ee8c79b58f3092f20bc Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Mon, 17 Sep 2012 04:34:03 +0800 Subject: [PATCH] Some calendar updates --- .../app/assets/javascripts/calendarAPI.js.erb | 60 +++++-- .../calendar/back_end/cals_controller.rb | 21 ++- .../calendar/back_end/events_controller.rb | 51 ++++++ .../calendar/app/models/event.rb | 18 ++- .../calendar/back_end/cals/index.html.erb | 2 +- .../back_end/cals/month_view.html.erb | 37 +---- .../calendar/back_end/events/create.js.erb | 2 + .../calendar/back_end/events/new.html.erb | 147 +++++++++--------- .../calendar/config/locales/en.yml | 3 +- .../calendar/config/routes.rb | 1 + 10 files changed, 210 insertions(+), 132 deletions(-) create mode 100644 vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb 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 94a9fcb9..ad90903a 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 @@ -19,10 +19,18 @@ var calendarAPI = function(){ }) $("#create_event_btn").click(function(){ - c.newEvent($(this)); + 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(); + } $(this).toggleClass("active"); return false; }) + $("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"); + }) $('.mode_switch').click(function(){ var target = $(this).text(); @@ -79,6 +87,7 @@ var calendarAPI = function(){ c.cur_month = month; c.cur_year = year; $('#view_holder').load("cals/month_view?month="+month+"&year="+year, function() { + getEvents(month,year); $('.current_day_title').text(c.monthlist[c.cur_month]+" "+c.cur_year); if($('#calendar_month').length > 0){ var $c_table = $('#calendar_month'); @@ -102,6 +111,37 @@ var calendarAPI = function(){ }); } }) + var getEvents = function(month,year){ + $.getJSON("cals/getEvents",{"type":"monthview","month":month,"year":year},function(events){ + var $eventrow = $(""); + 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 = $(""); + }else if(pos == curpos){ + $eventrow = null; + $eventrow = $(""); + } + if(pos == 1){ + $eventrow.html('
'+evnt.title+'
'); + }else{ + if($eventrow.html()==""){ + $eventrow.append(''); + } + $eventrow.append('
'+evnt.title+'
'); + } + currow = thisrow; + curpos = pos; + curparent.append($eventrow); + }) + }) + } } this.loadWeekView = function(){ $('#view_holder').load("cals/week_view", function() { @@ -118,11 +158,11 @@ var calendarAPI = function(){ $('.current_day_title').text('September 2, 2012'); }) } - this.newEvent = function(dom){ + this.newEvent = function(url,ref,date,month,year){ var bindHandlers = function(){ c.event_create_div.find("button.btn-close").click(function(){ c.event_create_div.hide().empty(); - dom.removeClass("active"); + $("#create_event_btn").removeClass("active"); }) c.event_create_div.find("input[for=all_day][type=checkbox]").click(function(){ if($(this).is(":checked")) @@ -131,14 +171,12 @@ var calendarAPI = function(){ c.event_create_div.find("#non_all_day").show() }) } - if(!dom.hasClass("active")){ - c.event_create_div.load(dom.attr("href"),function(){ - c.event_create_div.show(); - bindHandlers(); - }) - }else{ - c.event_create_div.hide().empty(); - } + + c.event_create_div.load(url+"?ref="+ref+"&date="+date+"&month="+month+"&year="+year,function(){ + c.event_create_div.show(); + bindHandlers(); + }) + } this.newCalendars = function(){ if($('.color-picker').length > 0){ 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 27a0f484..4c42e0d4 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 @@ -54,5 +54,24 @@ class Panel::Calendar::BackEnd::CalsController < OrbitBackendController def agenda_view render :layout => false end + + def get_events + month = params[:month] + year = params[:year] + events = Event.where(:start_month => month).and(:start_year => year) + @events = Array.new + events.each do |event| + # @temp = Array.new + no_of_days = Date.new(event.end_year,event.end_month,event.end_date) - Date.new(event.start_year,event.start_month,event.start_date) + no_of_days = no_of_days.to_i + no_of_days += 1 + color = Cal.find(event.cal_id).color + @events << {"start_date"=>event.start_date, "total_days" => no_of_days, "title" => event.title,"color"=>color} + end + render :json => @events.to_json + end -end \ No newline at end of file +end + + + diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb index 6900480e..0dca026f 100644 --- a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb +++ b/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/events_controller.rb @@ -2,6 +2,57 @@ class Panel::Calendar::BackEnd::EventsController < OrbitBackendController def new @calendars = Cal.all + @event = Event.new + if params[:ref] == "add-btn" + @all_day_disabled = true + else + @all_day_disabled = false + end + @placeholder = params[:date]+"/"+params[:month]+"/"+params[:year] render :layout => false end + + def create + title = params[:event][:title] + note = params[:event][:note] + $start = params[:start_date] + $end = params[:end_date] + $starttime = params[:start_time] + $endtime = params[:end_time] + + temp = $start.split("/") + start_date = temp[0] + start_month = temp[1] + star_year = temp[2] + + temp = $end.split("/") + end_date = temp[0] + end_month = temp[1] + end_year = temp[2] + + start_am_pm = params[:start_am_pm] + end_am_pm = params[:end_am_pm] + + cal_id = params[:event][:cal_id] + + @event = Event.new + @event.title = title + @event.note = note + @event.start_year = star_year + @event.end_year = end_year + @event.start_month = start_month + @event.end_month = end_month + @event.start_date = start_date + @event.end_date = end_date + @event.start_time = $starttime + @event.start_am_pm = start_am_pm + @event.end_time = $endtime + @event.end_am_pm = end_am_pm + @event.cal_id = cal_id + @event.save! + + respond_to do |h| + h.js + end + end end \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/models/event.rb b/vendor/built_in_modules/calendar/app/models/event.rb index eb6f218d..55f37e52 100644 --- a/vendor/built_in_modules/calendar/app/models/event.rb +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -3,13 +3,17 @@ class Event include Mongoid::Timestamps field :title - field :description - field :start_year - field :end_year - field :start_month - field :end_month - field :start_date - field :end_date + field :note + field :start_year, type: Integer + field :end_year, type: Integer + field :start_month, type: Integer + field :end_month, type: Integer + field :start_date, type: Integer + field :end_date, type: Integer + field :start_time, type: Float + field :start_am_pm + field :end_time, type: Float + field :end_am_pm belongs_to :cal 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 1ebf08b2..98a237af 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 @@ -58,7 +58,7 @@
- <%= link_to "Add", new_panel_calendar_back_end_event_path, :class => "btn btn-primary pull-right", :id=>"create_event_btn" %> + <%= link_to "Add", new_panel_calendar_back_end_event_path, :class => "btn btn-primary pull-right", :id=>"create_event_btn", :ref=>"add-btn" %>
diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/month_view.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/month_view.html.erb index 8416b967..07221d48 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/month_view.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/month_view.html.erb @@ -36,7 +36,7 @@ <% end %> - +
<% x = 0 %> <% while x < 7 %> @@ -45,7 +45,7 @@ <% elsif day_count_for_title >= @post_disabled_days %> <% else %> - + <% end %> <% day_count_for_title += 1 %> <% x += 1 %> @@ -55,37 +55,4 @@ <% i += 1 %> <% end %> - diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb new file mode 100644 index 00000000..42efb25c --- /dev/null +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/create.js.erb @@ -0,0 +1,2 @@ +$("#event_create").empty().hide(); +$("#create_event_btn").removeClass("active"); \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb index 9515c57e..48e18efa 100644 --- a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb +++ b/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/events/new.html.erb @@ -1,19 +1,19 @@
<%= @dateset[day_count_for_title] %><%= @dateset[day_count_for_title] %><%= @dateset[day_count_for_title] %>