bcms_event-with_location 1.0.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.
@@ -0,0 +1,42 @@
1
+ # Event Module for BrowserCMS
2
+
3
+ An Event Module for BrowserCMS. Allows contributors to create and post new upcoming events.
4
+
5
+ ## Features
6
+
7
+ * Events - Contributors can create Event content that represent Single or Multiday Events.
8
+ * Events Lists - Allows a complete listing of all published events in a reverse chronological order along with names and descriptions.
9
+ * Event Details - Allows visitors to see the complete details for each Event, including the ability link to external Event Registration pages.
10
+ * SEO Friendly URLs - Each event will have its own custom URL to display itself.
11
+ * Customizable Views - Event listings and detail pages can be styled using editable Portlet views.
12
+
13
+ ## Installation
14
+
15
+ The Event module installs like other BrowserCMS modules.
16
+
17
+ gem install bcms_event
18
+
19
+ See http://guides.browsercms.org/installing_modules.html for further details.
20
+
21
+ ### What's installed
22
+
23
+ When installing this module, it will create the following new pages/blocks.
24
+
25
+ * Events Page - A new Page 'Event' will be created at the root of the site, with an 'Event' portlet added. (Allows this page to display any Event)
26
+ * Events Route - A dynamic route to allow specific events to be shown by the Event page using a route like /events/:year/:month/:day/:slug
27
+
28
+ ## Event Details
29
+
30
+ This module includes a new Event Content Type, with the following fields:
31
+
32
+ * Name
33
+ * Start and End Dates
34
+ * Location
35
+ * Contact Email
36
+ * Description - Used on the Event listing to summarize the Event.
37
+ * More Info URL
38
+ * Registration URL - Allows a link to external sites for registration.
39
+ * Category
40
+ * Tags
41
+ * Body - For the detailed view page.
42
+
@@ -0,0 +1,2 @@
1
+ class Cms::EventsController < Cms::ContentBlockController
2
+ end
@@ -0,0 +1,53 @@
1
+ class Event < ActiveRecord::Base
2
+ acts_as_content_block :taggable => true
3
+ belongs_to_category
4
+
5
+ before_validation :set_slug
6
+ validates_presence_of :name, :slug, :starts_on
7
+
8
+ named_scope :starts_on, lambda {|date|
9
+ d = if date.kind_of?(Hash)
10
+ Date.new(date[:year].to_i, date[:month].to_i, date[:day].to_i)
11
+ else
12
+ date
13
+ end
14
+
15
+ {:conditions => ["events.starts_on = ?", d]}
16
+ }
17
+
18
+ named_scope :with_slug, lambda{|slug| {:conditions => ["events.slug = ?",slug]}}
19
+
20
+ def self.default_order
21
+ "starts_on desc"
22
+ end
23
+
24
+ def self.columns_for_index
25
+ [ {:label => "Name", :method => :name, :order => "name" },
26
+ {:label => "Starts On", :method => :starts_on_label, :order => "starts_on" } ]
27
+ end
28
+
29
+ def starts_on_label
30
+ starts_on ? starts_on.to_s(:long) : nil
31
+ end
32
+
33
+ def set_slug
34
+ self.slug = name.to_slug
35
+ end
36
+
37
+ def route_params
38
+ {:year => year, :month => month, :day => day, :slug => slug}
39
+ end
40
+
41
+ def year
42
+ starts_on.strftime("%Y")
43
+ end
44
+
45
+ def month
46
+ starts_on.strftime("%m")
47
+ end
48
+
49
+ def day
50
+ starts_on.strftime("%d")
51
+ end
52
+
53
+ end
@@ -0,0 +1,10 @@
1
+ class EventPortlet < Portlet
2
+
3
+ def render
4
+ # @event should already be set by the page route
5
+ if !@event && params[:event_id]
6
+ @event = Event.published.find(params[:event_id])
7
+ end
8
+ end
9
+
10
+ end
@@ -0,0 +1,11 @@
1
+ class EventsPortlet < Portlet
2
+
3
+ def render
4
+ if self.category_id.blank?
5
+ @events = Event.published.all
6
+ else
7
+ @events = Event.published.all(:conditions => {:category_id => self.category_id})
8
+ end
9
+ end
10
+
11
+ end
@@ -0,0 +1,74 @@
1
+ <script type="text/javascript" src="http://maps.googleapis.com/maps/api/js?sensor=false"></script>
2
+ <script type="text/javascript">
3
+ var geocoder;
4
+ var map;
5
+ var marker;
6
+ $(document).ready(function(){
7
+ $("#event_location").after('<span class="f_locate" style="display: inline-block; padding: 5px; border: solid 1px #ccc; margin-left: 10px; cursor: pointer;">Locate</span>');
8
+
9
+ var center = new google.maps.LatLng(<%= @block.lattitude || 0 %>, <%= @block.longitude || 0 %>);
10
+ geocoder = new google.maps.Geocoder();
11
+ var mapOptions = {
12
+ zoom: 13,
13
+ mapTypeId: google.maps.MapTypeId.ROADMAP,
14
+ center: center
15
+ };
16
+ map = new google.maps.Map(document.getElementById("map_canvas"), mapOptions);
17
+
18
+ marker = new google.maps.Marker({
19
+ map: map,
20
+ position: center,
21
+ animation: google.maps.Animation.DROP,
22
+ });
23
+
24
+ $(".location .instructions").text(center.toString());
25
+ $(".f_watch_location").blur(locate);
26
+ $(".f_locate").click(locate);
27
+ locate();
28
+ });
29
+
30
+ function locate(event){
31
+ var query = $("#event_location").val();
32
+ if(query != ""){
33
+ geocoder.geocode( { 'address': query}, function(results, status) {
34
+ if (status == google.maps.GeocoderStatus.OK) {
35
+ console.log(results[0].geometry.location);
36
+ $("#event_lattitude").val(results[0].geometry.location.Na);
37
+ $("#event_longitude").val(results[0].geometry.location.Oa);
38
+ marker.setPosition(results[0].geometry.location);
39
+ marker.setMap(map);
40
+ map.panTo(results[0].geometry.location);
41
+ $(".location .instructions").fadeOut('fast', function(){
42
+ $(".location .instructions").text(results[0].formatted_address);
43
+ $(".location .instructions").fadeIn('fast');
44
+ });
45
+ } else {
46
+ $("#event_lattitude").val("");
47
+ $("#event_longitude").val("");
48
+ marker.setMap(null);
49
+ $(".location .instructions").text("Unable to geocode location.");
50
+ }
51
+ });
52
+ }
53
+ }
54
+ </script>
55
+
56
+ <%= f.cms_text_field :name %>
57
+ <%= f.cms_date_picker :starts_on %>
58
+ <%= f.cms_date_picker :ends_on %>
59
+ <div class="text_fields">
60
+ <label></label>
61
+ <div id="map_canvas" style="width: 455px; height: 200px;"></div>
62
+ </div>
63
+ <div class="location">
64
+ <%= f.cms_text_field :location, :class => "f_watch_location", :instructions => "", :style => "overflow:hidden;" %>
65
+ </div>
66
+ <%= f.hidden_field :lattitude %>
67
+ <%= f.hidden_field :longitude %>
68
+ <%= f.cms_text_field :contact_email %>
69
+ <%= f.cms_text_area :description %>
70
+ <%= f.cms_text_field :more_info_url %>
71
+ <%= f.cms_text_field :registration_url %>
72
+ <%= f.cms_drop_down :category_id, categories_for('Event').map{|c| [c.path, c.id]}, :include_blank => true %>
73
+ <%= f.cms_tag_list %>
74
+ <%= f.cms_text_editor :body %>
@@ -0,0 +1,12 @@
1
+ <p><b>Name:</b> <%= @content_block.name %></p>
2
+ <p><b>Starts On:</b> <%= @content_block.starts_on %></p>
3
+ <p><b>Ends On:</b> <%= @content_block.ends_on %></p>
4
+ <p><b>Location:</b> <%= @content_block.location %></p>
5
+ <p><b>Lattitude:</b> <%= @content_block.lattitude %></p>
6
+ <p><b>Longitude:</b> <%= @content_block.longitude %></p>
7
+ <p><b>Contact Email:</b> <%= @content_block.contact_email %></p>
8
+ <p><b>Description:</b> <%= simple_format h(@content_block.description) %></p>
9
+ <p><b>More Info Url:</b> <%= @content_block.more_info_url %></p>
10
+ <p><b>Registration Url:</b> <%= @content_block.registration_url %></p>
11
+ <p><b>Category:</b> <%= @content_block.category_name %></p>
12
+ <p><b>Body:</b> <%= @content_block.body %></p>
@@ -0,0 +1,2 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,12 @@
1
+ <p><b>Name:</b> <%= @event.name %></p>
2
+ <p><b>Starts On:</b> <%= @event.starts_on %></p>
3
+ <p><b>Ends On:</b> <%= @event.ends_on %></p>
4
+ <p><b>Location:</b> <%= @event.location %></p>
5
+ <p><b>Lattitude:</b> <%= @content_block.lattitude %></p>
6
+ <p><b>Longitude:</b> <%= @content_block.longitude %></p>
7
+ <p><b>Contact Email:</b> <%= @event.contact_email %></p>
8
+ <p><b>Description:</b> <%= simple_format h(@event.description) %></p>
9
+ <p><b>More Info Url:</b> <%= @event.more_info_url %></p>
10
+ <p><b>Registration Url:</b> <%= @event.registration_url %></p>
11
+ <p><b>Category:</b> <%= @event.category_name %></p>
12
+ <p><b>Body:</b> <%= @event.body %></p>
@@ -0,0 +1,3 @@
1
+ <%= f.cms_text_field :name %>
2
+ <%= f.cms_drop_down :category_id, categories_for('Event').map{|c| [c.path, c.id]}, :include_blank => true %>
3
+ <%= f.cms_text_area :template, :default_value => @block.class.default_template %>
@@ -0,0 +1,18 @@
1
+ <div>
2
+ <% @events.group_by{|e| e.starts_on.year}.sort_by(&:first).reverse.each do |year, events_grouped_by_year| %>
3
+ <!-- <%= year %> -->
4
+ <% events_grouped_by_year.group_by{|e| e.starts_on.month}.sort_by(&:first).reverse.each do |month, events_grouped_by_month| %>
5
+ <b class="month"><%= Date::MONTHNAMES[month] %></b>
6
+ <% for event in events_grouped_by_month.sort_by(&:starts_on).reverse %>
7
+ <div id="event_<%= event.id %>" class="event">
8
+ <span class="event_starts_on"><b><%= event.starts_on.to_s(:long) %></b></span>
9
+ <br/>
10
+ <%= link_to "<b>#{h(event.name)}</b>", event_path(event.route_params) %><br/>
11
+ <% unless event.description.blank? -%>
12
+ <p><%= simple_format h(event.description) %></p>
13
+ <% end %>
14
+ </div>
15
+ <% end %>
16
+ <% end %>
17
+ <% end %>
18
+ </div>
@@ -0,0 +1,60 @@
1
+ class CreateEvents < ActiveRecord::Migration
2
+ def self.up
3
+ create_versioned_table :events do |t|
4
+ t.string :name
5
+ t.string :slug
6
+ t.date :starts_on
7
+ t.date :ends_on
8
+ t.string :location
9
+ t.string :contact_email
10
+ t.text :description
11
+ t.string :more_info_url
12
+ t.string :registration_url
13
+ t.belongs_to :category
14
+ t.text :body, :size => (64.kilobytes + 1)
15
+ end
16
+ unless CategoryType.named('Event').exists?
17
+ CategoryType.create!(:name => "Event")
18
+ end
19
+
20
+ ContentType.create!(:name => "Event", :group_name => "Event")
21
+
22
+ event_page = Page.create!(
23
+ :name => "Event",
24
+ :path => "/event",
25
+ :section => Section.root.first,
26
+ :template_file_name => "default.html.erb")
27
+
28
+ EventPortlet.create!(
29
+ :name => "Event Details",
30
+ :template => EventPortlet.default_template,
31
+ :connect_to_page_id => event_page.id,
32
+ :connect_to_container => "main",
33
+ :publish_on_save => true)
34
+
35
+ EventsPortlet.create!(
36
+ :name => "Event List",
37
+ :template => EventsPortlet.default_template,
38
+ :connect_to_page_id => event_page.id,
39
+ :connect_to_container => "main",
40
+ :publish_on_save => true)
41
+
42
+ route = event_page.page_routes.build(
43
+ :name => "Event",
44
+ :pattern => "/events/:year/:month/:day/:slug",
45
+ :code => "@event = Event.published.starts_on(params).with_slug(params[:slug]).first")
46
+ route.add_condition(:method, "get")
47
+ route.add_requirement(:year, '\d{4,}')
48
+ route.add_requirement(:month, '\d{2,}')
49
+ route.add_requirement(:day, '\d{2,}')
50
+ route.save!
51
+
52
+ end
53
+
54
+ def self.down
55
+ ContentType.delete_all(['name = ?', 'Event'])
56
+ CategoryType.all(:conditions => ['name = ?', 'Event']).each(&:destroy)
57
+ drop_table :event_versions
58
+ drop_table :events
59
+ end
60
+ end
@@ -0,0 +1 @@
1
+ require 'bcms_event/routes'
@@ -0,0 +1,7 @@
1
+ module Cms::Routes
2
+ def routes_for_bcms_event
3
+ namespace(:cms) do |cms|
4
+ cms.content_blocks :events
5
+ end
6
+ end
7
+ end
@@ -0,0 +1,3 @@
1
+ gem_root = File.expand_path(File.join(File.dirname(__FILE__), ".."))
2
+ Cms.add_to_rails_paths gem_root
3
+ Cms.add_generator_paths gem_root, "db/migrate/[0-9]*_*.rb"
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: bcms_event-with_location
3
+ version: !ruby/object:Gem::Version
4
+ hash: 23
5
+ prerelease:
6
+ segments:
7
+ - 1
8
+ - 0
9
+ - 0
10
+ version: 1.0.0
11
+ platform: ruby
12
+ authors:
13
+ - BrowserMedia
14
+ autorequire:
15
+ bindir: bin
16
+ cert_chain: []
17
+
18
+ date: 2011-08-11 00:00:00 -05:00
19
+ default_executable:
20
+ dependencies: []
21
+
22
+ description:
23
+ email: github@browsermedia.com
24
+ executables: []
25
+
26
+ extensions: []
27
+
28
+ extra_rdoc_files:
29
+ - README.markdown
30
+ files:
31
+ - app/controllers/cms/events_controller.rb
32
+ - app/models/event.rb
33
+ - app/portlets/event_portlet.rb
34
+ - app/portlets/events_portlet.rb
35
+ - app/views/cms/events/_form.html.erb
36
+ - app/views/cms/events/render.html.erb
37
+ - app/views/portlets/event/_form.html.erb
38
+ - app/views/portlets/event/render.html.erb
39
+ - app/views/portlets/events/_form.html.erb
40
+ - app/views/portlets/events/render.html.erb
41
+ - db/migrate/20090504174621_create_events.rb
42
+ - lib/bcms_event.rb
43
+ - lib/bcms_event/routes.rb
44
+ - rails/init.rb
45
+ - README.markdown
46
+ has_rdoc: true
47
+ homepage: http://www.browsercms.org
48
+ licenses: []
49
+
50
+ post_install_message:
51
+ rdoc_options: []
52
+
53
+ require_paths:
54
+ - lib
55
+ required_ruby_version: !ruby/object:Gem::Requirement
56
+ none: false
57
+ requirements:
58
+ - - ">="
59
+ - !ruby/object:Gem::Version
60
+ hash: 3
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ hash: 3
70
+ segments:
71
+ - 0
72
+ version: "0"
73
+ requirements: []
74
+
75
+ rubyforge_project: bcms_event-with_location
76
+ rubygems_version: 1.4.2
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: The Event Module for BrowserCMS
80
+ test_files: []
81
+