event_cal 1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (32) hide show
  1. data/MIT-LICENSE +20 -0
  2. data/Rakefile +21 -0
  3. data/app/views/event_calendar/_calendar.html.haml +9 -0
  4. data/app/views/event_calendar/_date.html.haml +10 -0
  5. data/app/views/event_calendar/_event_details.html.haml +4 -0
  6. data/lib/event_calendar/calendar.rb +50 -0
  7. data/lib/event_calendar/calendar_helper.rb +45 -0
  8. data/lib/event_calendar/engine.rb +15 -0
  9. data/lib/event_calendar/event.rb +16 -0
  10. data/lib/event_calendar/version.rb +3 -0
  11. data/lib/event_calendar.rb +4 -0
  12. data/lib/tasks/event_calendar_tasks.rake +4 -0
  13. data/vendor/assets/images/calendar_next.png +0 -0
  14. data/vendor/assets/images/calendar_prev.png +0 -0
  15. data/vendor/assets/images/icon_config.png +0 -0
  16. data/vendor/assets/javascripts/calendarApplication.js.coffee +11 -0
  17. data/vendor/assets/javascripts/controllers/calendarDatesController.js.coffee +32 -0
  18. data/vendor/assets/javascripts/controllers/calendarEventsController.js.coffee +19 -0
  19. data/vendor/assets/javascripts/event_calendar.js +1117 -0
  20. data/vendor/assets/javascripts/event_calendar_no_libs.js +191 -0
  21. data/vendor/assets/javascripts/lib/moment.js +1 -0
  22. data/vendor/assets/javascripts/lib/spine.js.coffee +535 -0
  23. data/vendor/assets/javascripts/lib/spinelib/ajax.js.coffee +223 -0
  24. data/vendor/assets/javascripts/lib/spinelib/list.js.coffee +43 -0
  25. data/vendor/assets/javascripts/lib/spinelib/local.js.coffee +16 -0
  26. data/vendor/assets/javascripts/lib/spinelib/manager.js.coffee +83 -0
  27. data/vendor/assets/javascripts/lib/spinelib/relation.js.coffee +144 -0
  28. data/vendor/assets/javascripts/lib/spinelib/route.js.coffee +151 -0
  29. data/vendor/assets/javascripts/models/calendarDate.js.coffee +7 -0
  30. data/vendor/assets/javascripts/models/calendarEvent.js.coffee +11 -0
  31. data/vendor/assets/stylesheets/event_calendar.css.scss +251 -0
  32. metadata +274 -0
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright 2013 YOURNAME
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,21 @@
1
+ begin
2
+ require 'bundler'
3
+ require 'bundler/setup'
4
+ require 'bundler/gem_tasks'
5
+ rescue LoadError
6
+ puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
7
+ end
8
+
9
+ require 'rspec/core/rake_task'
10
+ require 'jasmine-headless-webkit'
11
+
12
+ RSpec::Core::RakeTask.new(:spec)
13
+ Jasmine::Headless::Task.new
14
+
15
+ if ENV['SKIP_JASMINE']
16
+ task :default => [:spec]
17
+ else
18
+ task :default => [:spec, 'jasmine:headless']
19
+ end
20
+
21
+ Bundler::GemHelper.install_tasks
@@ -0,0 +1,9 @@
1
+ .calendar.monthly{ :data => { :'base-date' => calendar.base_date }}
2
+ %h1= t('date.abbr_month_names')[calendar.base_date.month]
3
+ = link_to '', previous_month_path(calendar), :class => 'navigation previous'
4
+ = link_to '', next_month_path(calendar), :class => 'navigation next'
5
+ = link_to '', today_path(calendar), :class => 'navigation today'
6
+ %ul.dates
7
+ - (calendar.start_on .. calendar.start_on + 6.days).each do |date|
8
+ %li.date.wday_header= t('date.abbr_day_names')[date.wday]
9
+ = render :partial => 'event_calendar/date', :collection => calendar.dates, :locals => { :calendar => calendar }
@@ -0,0 +1,10 @@
1
+ - event_for_date = calendar.events_on(date)
2
+
3
+ %li.date{ :class => hightlight_classes(date, calendar).join(' '), :data => { :date => date }}
4
+ .header
5
+ %span{ :class => wday_class_for(date) }= date.strftime('%-d')
6
+ - if event_for_date.present?
7
+ %ul.events
8
+ - event_for_date.each do |event|
9
+ %li{ :class => "event #{event.class.to_s.underscore}" }
10
+ = render "event_calendar/#{event.class.to_s.underscore}", :event => event
@@ -0,0 +1,4 @@
1
+ %ul.event_details.calendar
2
+ - events.each do |event|
3
+ %li{ :class => "event_detail #{event.class.to_s.underscore}", :data => { :'event-date' => event.held_on }}
4
+ = render "event_calendar/#{event.class.to_s.underscore}_detail", :event => event
@@ -0,0 +1,50 @@
1
+ require 'event_calendar/event'
2
+
3
+ class EventCalendar::Calendar
4
+ attr_accessor :base_date, :start_on, :end_on, :events, :owner
5
+
6
+ def initialize(date = Date.today, options = {} )
7
+ parse_initializer_arguments(date, options)
8
+ # TODO: use beginning_of_week(:sunday) after migrates to rails 3.2
9
+ @start_on = @base_date.beginning_of_month.beginning_of_week.advance(:days => -1)
10
+ @end_on = @base_date.end_of_month.end_of_week.advance(:days => -1)
11
+
12
+ fetch_events
13
+ end
14
+
15
+ def dates
16
+ (@start_on..@end_on).to_a
17
+ end
18
+
19
+ def fetch_events
20
+ @events = ::EventCalendar::Event.subclasses.map { |klass|
21
+ klass.fetch_events(self)
22
+ }.flatten
23
+ end
24
+
25
+ def events_on(date)
26
+ @events.select{ |event| event.held_on == date }
27
+ end
28
+
29
+ private
30
+
31
+ def parse_initializer_arguments(date, options)
32
+ if date.class == Date
33
+ @base_date = date
34
+ opts = options
35
+ elsif date.class == Hash
36
+ @base_date = Date.today
37
+ opts = date
38
+ else
39
+ raise ArgumentError.new('wrong argument for initializer')
40
+ end
41
+
42
+ opts.each do |key, value|
43
+ if key == :owner
44
+ @owner = value
45
+ else
46
+ #ignore other keys
47
+ end
48
+ end
49
+ end
50
+ end
@@ -0,0 +1,45 @@
1
+ module ::EventCalendar::CalendarHelper
2
+ def wday_class_for(date)
3
+ case date.wday
4
+ when 0
5
+ 'sunday'
6
+ when 6
7
+ 'saturday'
8
+ end
9
+ end
10
+
11
+ def hightlight_classes(date, calendar)
12
+ classes = []
13
+ events = calendar.events_on(date)
14
+ classes << 'has_events' if events.present?
15
+ events.map(&:class).uniq.each {|event_class| classes << event_class.to_s.underscore }
16
+ classes
17
+ end
18
+
19
+ def previous_month_path(calendar)
20
+ end
21
+
22
+ def next_month_path(calendar)
23
+ end
24
+
25
+ def today_path(calendar)
26
+ end
27
+
28
+ def render_monthly(calendar)
29
+ render(
30
+ { :partial => 'event_calendar/calendar',
31
+ :format => :html,
32
+ :locals => { :calendar => calendar },
33
+ }
34
+ )
35
+ end
36
+
37
+ def render_event_details(events)
38
+ render(
39
+ { :partial => 'event_calendar/event_details',
40
+ :format => :html,
41
+ :locals => { :events => events }
42
+ }
43
+ )
44
+ end
45
+ end
@@ -0,0 +1,15 @@
1
+ require 'event_calendar/calendar_helper'
2
+
3
+ module EventCalendar
4
+ module Rails
5
+ class Engine < ::Rails::Engine
6
+ initializer 'event_calendar.setup_view_helpers' do |app|
7
+ app.config.to_prepare do
8
+ # after migrating to 3.2 a line below works
9
+ # ActionController::Base.send(:helper, ::EventCalendar::CalendarHelper)
10
+ ActionView::Base.send(:include, ::EventCalendar::CalendarHelper)
11
+ end
12
+ end
13
+ end
14
+ end
15
+ end
@@ -0,0 +1,16 @@
1
+ class EventCalendar::Event
2
+ attr_accessor :held_on, :name
3
+ def initialize(date = Date.today)
4
+ @held_on = date
5
+ end
6
+
7
+ def self.all
8
+ []
9
+ end
10
+
11
+ def self.fetch_events(calendar)
12
+ all.select do |event|
13
+ (calendar.start_on .. calendar.end_on).include?(event.held_on)
14
+ end
15
+ end
16
+ end
@@ -0,0 +1,3 @@
1
+ module EventCalendar
2
+ VERSION = "1.0"
3
+ end
@@ -0,0 +1,4 @@
1
+ require 'event_calendar/engine'
2
+
3
+ module EventCalendar
4
+ end
@@ -0,0 +1,4 @@
1
+ # desc "Explaining what the task does"
2
+ # task :event_calendar do
3
+ # # Task goes here
4
+ # end
@@ -0,0 +1,11 @@
1
+ class CalendarApplication
2
+ calendarElements =
3
+ 'ul.dates': CalendarDatesController
4
+ 'ul.event_details': CalendarEventsController
5
+
6
+ @initialize = () ->
7
+ for element, controller of calendarElements
8
+ for el in $(element)
9
+ new controller($(el))
10
+
11
+ window.CalendarApplication = CalendarApplication
@@ -0,0 +1,32 @@
1
+ class CalendarDatesController extends Spine.Module
2
+ constructor: (element) ->
3
+ @element = element
4
+ @initializeDates()
5
+
6
+ initializeDates: () ->
7
+ for el in @element.find('.date')
8
+ date = CalendarDate.create(
9
+ element: $(el)
10
+ date: $(el).data('date')
11
+ active: false
12
+ )
13
+ @initializeEventSelect(date)
14
+
15
+ initializeEventSelect: (date) ->
16
+ date.element.bind('click', () ->
17
+ date.trigger('activate')
18
+ CalendarDate.deactivateAllDates()
19
+ date.updateAttributes(active: true)
20
+ )
21
+ date.bind('activate', (date) ->
22
+ CalendarEvent.deactivateAllEvents()
23
+ CalendarEvent.activateAllEventsOn(date.date)
24
+ )
25
+ date.bind('change', (date) ->
26
+ if date.active == true
27
+ date.element.addClass('selected')
28
+ if date.active == false
29
+ date.element.removeClass('selected')
30
+ )
31
+
32
+ window.CalendarDatesController = CalendarDatesController
@@ -0,0 +1,19 @@
1
+ class CalendarEventsController extends Spine.Module
2
+ constructor: (element) ->
3
+ for el in element.find('.event_detail')
4
+ event = CalendarEvent.create(
5
+ element: $(el).hide()
6
+ held_on: $(el).data('event-date')
7
+ active: false
8
+ )
9
+ @initializeEventSelect(event)
10
+
11
+ initializeEventSelect: (event) ->
12
+ event.bind('change', () ->
13
+ if event.active == true
14
+ event.element.show()
15
+ if event.active == false
16
+ event.element.hide()
17
+ )
18
+
19
+ window.CalendarEventsController = CalendarEventsController