From 29ea95b4c6817a3ac4f8ff171f374bfa3a4e5941 Mon Sep 17 00:00:00 2001 From: Harry Bomrah Date: Wed, 12 Sep 2012 14:20:32 +0800 Subject: [PATCH] event_calendar testing --- Gemfile | 2 + Gemfile.lock | 2 + app/helpers/calendar_helper.rb | 24 ++ public/javascripts/event_calendar.js | 37 +++ public/stylesheets/event_calendar.css | 237 ++++++++++++++++++ vendor/built_in_modules/calendar/Gemfile.lock | 99 ++++++++ .../calendar_categories_controller.rb | 0 .../back_end/calendar_controller.rb | 12 + .../back_end/cals_controller.rb | 0 .../orbitcalendar/back_end/calendar_helper.rb | 24 ++ .../calendar/app/models/event.rb | 4 + .../back_end/calendar/index.html.erb | 6 + .../calendar_categories/index.html.erb | 0 .../back_end/cals/index.html.erb | 0 .../calendar/config/routes.rb | 4 +- 15 files changed, 449 insertions(+), 2 deletions(-) create mode 100644 app/helpers/calendar_helper.rb create mode 100644 public/javascripts/event_calendar.js create mode 100644 public/stylesheets/event_calendar.css create mode 100644 vendor/built_in_modules/calendar/Gemfile.lock rename vendor/built_in_modules/calendar/app/controllers/panel/{calendar => orbitcalendar}/back_end/calendar_categories_controller.rb (100%) create mode 100644 vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_controller.rb rename vendor/built_in_modules/calendar/app/controllers/panel/{calendar => orbitcalendar}/back_end/cals_controller.rb (100%) create mode 100644 vendor/built_in_modules/calendar/app/helpers/panel/orbitcalendar/back_end/calendar_helper.rb create mode 100644 vendor/built_in_modules/calendar/app/models/event.rb create mode 100644 vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar/index.html.erb rename vendor/built_in_modules/calendar/app/views/panel/{calendar => orbitcalendar}/back_end/calendar_categories/index.html.erb (100%) rename vendor/built_in_modules/calendar/app/views/panel/{calendar => orbitcalendar}/back_end/cals/index.html.erb (100%) diff --git a/Gemfile b/Gemfile index b945b6352..3e45ea1c0 100644 --- a/Gemfile +++ b/Gemfile @@ -50,6 +50,8 @@ gem 'rb-readline' if RUBY_PLATFORM.downcase.include?("linux") gem "impressionist", :git => 'git://github.com/charlotte-ruby/impressionist.git' +#gem 'contacts' +gem 'event-calendar', :require => 'event_calendar' gem 'redis','>= 2.1.1' gem 'chinese_pinyin', '0.4.1' diff --git a/Gemfile.lock b/Gemfile.lock index 7be6a7e6c..c9392e1f4 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -88,6 +88,7 @@ GEM diff-lcs (1.1.3) encrypted_strings (0.3.3) erubis (2.7.0) + event-calendar (2.3.3) exception_notification (2.5.2) actionmailer (>= 3.0.4) execjs (1.3.0) @@ -322,6 +323,7 @@ DEPENDENCIES database_cleaner delorean devise (= 1.5.3) + event-calendar exception_notification execjs factory_girl_rails diff --git a/app/helpers/calendar_helper.rb b/app/helpers/calendar_helper.rb new file mode 100644 index 000000000..880acc333 --- /dev/null +++ b/app/helpers/calendar_helper.rb @@ -0,0 +1,24 @@ +module CalendarHelper + def month_link(month_date) + link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year}) + end + + # custom options for this calendar + def event_calendar_opts + { + :year => @year, + :month => @month, + :event_strips => @event_strips, + :month_name_text => I18n.localize(@shown_month, :format => "%B %Y"), + :previous_month_text => "<< " + month_link(@shown_month.prev_month), + :next_month_text => month_link(@shown_month.next_month) + " >>" } + end + + def event_calendar + # args is an argument hash containing :event, :day, and :options + calendar event_calendar_opts do |args| + event = args[:event] + %(#{h(event.name)}) + end + end +end diff --git a/public/javascripts/event_calendar.js b/public/javascripts/event_calendar.js new file mode 100644 index 000000000..e3b2885b6 --- /dev/null +++ b/public/javascripts/event_calendar.js @@ -0,0 +1,37 @@ +/* + * Smart event highlighting + * Handles when events span rows, or don't have a background color + */ +jQuery(document).ready(function($) { + var highlight_color = "#2EAC6A"; + + // highlight events that have a background color + $(".ec-event-bg").live("mouseover", function() { + event_id = $(this).attr("data-event-id"); + event_class_name = $(this).attr("data-event-class"); + $(".ec-"+event_class_name+"-"+event_id).css("background-color", highlight_color); + }); + $(".ec-event-bg").live("mouseout", function() { + event_id = $(this).attr("data-event-id"); + event_class_name = $(this).attr("data-event-class"); + event_color = $(this).attr("data-color"); + $(".ec-"+event_class_name+"-"+event_id).css("background-color", event_color); + }); + + // highlight events that don't have a background color + $(".ec-event-no-bg").live("mouseover", function() { + ele = $(this); + ele.css("color", "white"); + ele.find("a").css("color", "white"); + ele.find(".ec-bullet").css("background-color", "white"); + ele.css("background-color", highlight_color); + }); + $(".ec-event-no-bg").live("mouseout", function() { + ele = $(this); + event_color = $(this).attr("data-color"); + ele.css("color", event_color); + ele.find("a").css("color", event_color); + ele.find(".ec-bullet").css("background-color", event_color); + ele.css("background-color", "transparent"); + }); +}); \ No newline at end of file diff --git a/public/stylesheets/event_calendar.css b/public/stylesheets/event_calendar.css new file mode 100644 index 000000000..e82165342 --- /dev/null +++ b/public/stylesheets/event_calendar.css @@ -0,0 +1,237 @@ +/* + Event Calendar stylesheet + + Colors: + #d5d5d5 - border (gray) + #303030 - day names bg (gray) + #444 - number (gray) + #ecede2 - day header bg (light tan) + ##d7d7ba - today header bg (tan) + #ffffdd - today bg light (yellow) + #777 - other month number (gray) + #efefef - other month day header (gray) + #2eac6a - hover (green) +*/ + +/* Outer most container */ +.ec-calendar { + font-family: verdana, arial, helvetica, sans-serif; + font-size: 11px; + line-height: 14px; + margin: 0; + padding: 0; + border-bottom: 1px solid #d5d5d5; +} + +/* Month name header & links */ +.ec-calendar-header { + padding: 5px 0; + width: 100%; + table-layout: fixed; +} + +.ec-month-name { + font-size: 16px; + font-weight: bold; +} + +.ec-month-nav { + +} + +/* Containers */ +.ec-body { + position: relative; + border-right: 1px solid #303030; + white-space: nowrap; +} + +/* Day names */ +.ec-day-names { + position: absolute; + top: 0; + left: 0; + width: 100%; + table-layout: fixed; + padding: 2px 0; + background: #303030; + color: white; +} + +.ec-day-name { + font-weight: normal; +} + +/* Rows container and Row */ +.ec-rows { + position: absolute; + left: 0; + bottom: 0; + width: 100%; + background: white; + overflow: hidden; + border-right: 1px solid #d5d5d5; +} + +.ec-row { + position: absolute; + left: 0; + width: 100%; + overflow: hidden; +} + +/* Background */ +.ec-row-bg { + position: absolute; + top: 0; + left: 0; + height: 100%; + width: 100%; + table-layout: fixed; +} + +.ec-day-bg { + border-left: 1px solid #d5d5d5; +} + +.ec-today-bg { + background-color: #ffffdd; +} + +.ec-row-table { + position: relative; + width: 100%; + table-layout: fixed; +} + +/* Day header */ +.ec-day-header { + color: #444; + text-align: right; + padding: 0 5px; + line-height: 16px; + border-top: 1px solid #d5d5d5; + border-left: 1px solid #d5d5d5; + border-bottom: 1px dotted #bbbbbb; + background-color: #ecede2; + overflow: hidden; +} + +a.ec-day-link { + color: #444; +} + +.ec-today-header { + background-color: #d7d7ba; +} + +.ec-weekend-day-header { + +} + +.ec-other-month-header { + background-color: #efefef; + color: #777; +} + +.ec-other-month-bg { + +} + + +/* Event cell and container */ +.ec-event-cell { + cursor: pointer; + vertical-align: top; + padding-right: 1px; + padding-left: 2px; +} + +.ec-event-cell a { + text-decoration: none; + display: block; + width: 100%; + height: 100%; +} + +.ec-no-event-cell { + cursor: default; +} + +.ec-event { + color: white; + padding-right: 1px; + padding-left: 11px; + -webkit-border-radius: 3px; + -khtml-border-radius: 3px; + -moz-border-radius: 3px; + overflow: hidden; + white-space: nowrap; +} + +.ec-event :hover { + /* doesn't look as good as js highlighting */ + /* background-color: #2eac6a; */ +} + +.ec-event-bg a { + color: white; +} + +/* used to distinguish non-all_day events */ +.ec-event-no-bg { + position: relative; + /* padding-left: 5px; */ +} + +.ec-event-no-bg a { + /* isn't implemented in all browsers */ + color: inherit; +} + +.ec-event-time { + font-size: 85%; + font-weight: bold; + padding-right: 3px; +} + + +/* Left and right arrows */ +/* Doesn't work in IE6, use bg images instead */ +.ec-left-arrow, .ec-right-arrow { + position: relative; + top: 3px; + width: 0; + height: 0; + font-size: 0; + line-height: 0; + margin-bottom: -8px; + border-top: 4px solid transparent; + border-bottom: 4px solid transparent; +} + +.ec-left-arrow { + margin-left: -7px; + margin-right: auto; + border-right: 4px solid white; +} + +.ec-right-arrow { + margin-left: auto; + margin-right: 3px; + border-left: 4px solid white; +} + +/* remove this to not have a bullet */ +/* don't look as good in ie */ +.ec-bullet { + position: absolute; + top: 7px; + width: 4px; + height: 4px; + margin-left: -7px; + margin-right: auto; + -webkit-border-radius: 2px; + -khtml-border-radius: 2px; + -moz-border-radius: 2px; +} \ No newline at end of file diff --git a/vendor/built_in_modules/calendar/Gemfile.lock b/vendor/built_in_modules/calendar/Gemfile.lock new file mode 100644 index 000000000..8058d0211 --- /dev/null +++ b/vendor/built_in_modules/calendar/Gemfile.lock @@ -0,0 +1,99 @@ +PATH + remote: . + specs: + calendar (0.0.1) + rails (~> 3.1.4) + +GEM + remote: http://rubygems.org/ + specs: + actionmailer (3.1.8) + actionpack (= 3.1.8) + mail (~> 2.3.3) + actionpack (3.1.8) + activemodel (= 3.1.8) + activesupport (= 3.1.8) + builder (~> 3.0.0) + erubis (~> 2.7.0) + i18n (~> 0.6) + rack (~> 1.3.6) + rack-cache (~> 1.2) + rack-mount (~> 0.8.2) + rack-test (~> 0.6.1) + sprockets (~> 2.0.4) + activemodel (3.1.8) + activesupport (= 3.1.8) + builder (~> 3.0.0) + i18n (~> 0.6) + activerecord (3.1.8) + activemodel (= 3.1.8) + activesupport (= 3.1.8) + arel (~> 2.2.3) + tzinfo (~> 0.3.29) + activeresource (3.1.8) + activemodel (= 3.1.8) + activesupport (= 3.1.8) + activesupport (3.1.8) + multi_json (>= 1.0, < 1.3) + arel (2.2.3) + builder (3.0.3) + erubis (2.7.0) + hike (1.2.1) + i18n (0.6.1) + jquery-rails (2.1.2) + railties (>= 3.1.0, < 5.0) + thor (~> 0.14) + json (1.7.5) + mail (2.3.3) + i18n (>= 0.4.0) + mime-types (~> 1.16) + treetop (~> 1.4.8) + mime-types (1.19) + multi_json (1.2.0) + polyglot (0.3.3) + rack (1.3.6) + rack-cache (1.2) + rack (>= 0.4) + rack-mount (0.8.3) + rack (>= 1.0.0) + rack-ssl (1.3.2) + rack + rack-test (0.6.1) + rack (>= 1.0) + rails (3.1.8) + actionmailer (= 3.1.8) + actionpack (= 3.1.8) + activerecord (= 3.1.8) + activeresource (= 3.1.8) + activesupport (= 3.1.8) + bundler (~> 1.0) + railties (= 3.1.8) + railties (3.1.8) + actionpack (= 3.1.8) + activesupport (= 3.1.8) + rack-ssl (~> 1.3.2) + rake (>= 0.8.7) + rdoc (~> 3.4) + thor (~> 0.14.6) + rake (0.9.2.2) + rdoc (3.12) + json (~> 1.4) + sprockets (2.0.4) + hike (~> 1.2) + rack (~> 1.0) + tilt (~> 1.1, != 1.3.0) + sqlite3 (1.3.6) + thor (0.14.6) + tilt (1.3.3) + treetop (1.4.10) + polyglot + polyglot (>= 0.3.1) + tzinfo (0.3.33) + +PLATFORMS + ruby + +DEPENDENCIES + calendar! + jquery-rails + sqlite3 diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/calendar_categories_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_categories_controller.rb similarity index 100% rename from vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/calendar_categories_controller.rb rename to vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_categories_controller.rb diff --git a/vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_controller.rb b/vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_controller.rb new file mode 100644 index 000000000..c060a7e38 --- /dev/null +++ b/vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/calendar_controller.rb @@ -0,0 +1,12 @@ +class Panel::Orbitcalendar::BackEnd::CalendarController < ApplicationController + + def index + @month = (params[:month] || (Time.zone || Time).now.month).to_i + @year = (params[:year] || (Time.zone || Time).now.year).to_i + + @shown_month = Date.civil(@year, @month) + + @event_strips = Event.event_strips_for_month(@shown_month) + end + +end 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/orbitcalendar/back_end/cals_controller.rb similarity index 100% rename from vendor/built_in_modules/calendar/app/controllers/panel/calendar/back_end/cals_controller.rb rename to vendor/built_in_modules/calendar/app/controllers/panel/orbitcalendar/back_end/cals_controller.rb diff --git a/vendor/built_in_modules/calendar/app/helpers/panel/orbitcalendar/back_end/calendar_helper.rb b/vendor/built_in_modules/calendar/app/helpers/panel/orbitcalendar/back_end/calendar_helper.rb new file mode 100644 index 000000000..ae0c77a24 --- /dev/null +++ b/vendor/built_in_modules/calendar/app/helpers/panel/orbitcalendar/back_end/calendar_helper.rb @@ -0,0 +1,24 @@ +module Panel::Orbitcalendar::BackEnd::CalendarHelper + def month_link(month_date) + link_to(I18n.localize(month_date, :format => "%B"), {:month => month_date.month, :year => month_date.year}) + end + + # custom options for this calendar + def event_calendar_opts + { + :year => @year, + :month => @month, + :event_strips => @event_strips, + :month_name_text => I18n.localize(@shown_month, :format => "%B %Y"), + :previous_month_text => "<< " + month_link(@shown_month.prev_month), + :next_month_text => month_link(@shown_month.next_month) + " >>" } + end + + def event_calendar + # args is an argument hash containing :event, :day, and :options + calendar event_calendar_opts do |args| + event = args[:event] + %(#{h(event.name)}) + end + end +end diff --git a/vendor/built_in_modules/calendar/app/models/event.rb b/vendor/built_in_modules/calendar/app/models/event.rb new file mode 100644 index 000000000..56c344000 --- /dev/null +++ b/vendor/built_in_modules/calendar/app/models/event.rb @@ -0,0 +1,4 @@ +class Event + include Mongoid::Document + has_event_calendar +end diff --git a/vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar/index.html.erb b/vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar/index.html.erb new file mode 100644 index 000000000..c1059cbc1 --- /dev/null +++ b/vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar/index.html.erb @@ -0,0 +1,6 @@ + +<%= stylesheet_link_tag "event_calendar" %> + +

Calendar

+ +<%= raw(event_calendar) %> diff --git a/vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/calendar_categories/index.html.erb b/vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar_categories/index.html.erb similarity index 100% rename from vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/calendar_categories/index.html.erb rename to vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/calendar_categories/index.html.erb 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/orbitcalendar/back_end/cals/index.html.erb similarity index 100% rename from vendor/built_in_modules/calendar/app/views/panel/calendar/back_end/cals/index.html.erb rename to vendor/built_in_modules/calendar/app/views/panel/orbitcalendar/back_end/cals/index.html.erb diff --git a/vendor/built_in_modules/calendar/config/routes.rb b/vendor/built_in_modules/calendar/config/routes.rb index 39d9b60a5..5f9615139 100644 --- a/vendor/built_in_modules/calendar/config/routes.rb +++ b/vendor/built_in_modules/calendar/config/routes.rb @@ -1,9 +1,9 @@ Rails.application.routes.draw do namespace :panel do - namespace :calendar do + namespace :orbitcalendar do namespace :back_end do - resources :cals + match '/calendar(/:year(/:month))' => 'calendar#index', :as => :calendar, :constraints => {:year => /\d{4}/, :month => /\d{1,2}/} resources :calendar_categories end