Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions Gemfile
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ source "http://rubygems.org"
gemspec

gem 'refinerycms', '~> 2.0.0'
gem 'refinerycms-i18n', :git => 'git://github.com/parndt/refinerycms-i18n.git'

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I no longer own the repo - this is better as:

gem 'refinerycms-i18n', '~> 2.0.0'

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ooops, we'll fix it as soon as we can


# Refinery/rails should pull in the proper versions of these
group :assets do
Expand Down
26 changes: 21 additions & 5 deletions Gemfile.lock
Original file line number Diff line number Diff line change
@@ -1,7 +1,16 @@
GIT
remote: git://github.com/parndt/refinerycms-i18n.git
revision: 2a6d35554421d4e0a2ebeba6eb291bcd0ade9291
specs:
refinerycms-i18n (2.1.0.dev)
rails-i18n (~> 0.6.5)
refinerycms-core (~> 2.0)
routing-filter (~> 0.3.0)

PATH
remote: .
specs:
refinerycms-calendar (2.0.1)
refinerycms-calendar (2.0.2)
refinerycms-core (~> 2.0.3)

GEM
Expand Down Expand Up @@ -84,7 +93,6 @@ GEM
activemodel (>= 3.0.0)
activerecord (>= 3.0.0)
paper_trail (~> 2)
growl (1.0.3)
guard (1.0.3)
ffi (>= 0.5.0)
thor (>= 0.14.6)
Expand All @@ -98,6 +106,8 @@ GEM
railties (>= 3.2.0, < 5.0)
thor (~> 0.14)
json (1.7.3)
libnotify (0.1.4)
ffi (>= 0.6.2)
libwebsocket (0.1.3)
addressable
mail (2.4.4)
Expand Down Expand Up @@ -129,6 +139,8 @@ GEM
activesupport (= 3.2.3)
bundler (~> 1.0)
railties (= 3.2.3)
rails-i18n (0.6.5)
i18n (~> 0.5)
railties (3.2.3)
actionpack (= 3.2.3)
activesupport (= 3.2.3)
Expand All @@ -137,7 +149,8 @@ GEM
rdoc (~> 3.4)
thor (~> 0.14.6)
rake (0.9.2.2)
rb-fsevent (0.9.1)
rb-inotify (0.8.8)
ffi (>= 0.5.0)
rdoc (3.12)
json (~> 1.4)
refinerycms (2.0.3)
Expand Down Expand Up @@ -186,6 +199,8 @@ GEM
rack-test (~> 0.6.0)
refinerycms-core (= 2.0.3)
rspec-rails (~> 2.8.1)
routing-filter (0.3.1)
actionpack
rspec (2.8.0)
rspec-core (~> 2.8.0)
rspec-expectations (~> 2.8.0)
Expand Down Expand Up @@ -245,17 +260,18 @@ DEPENDENCIES
coffee-rails
factory_girl_rails
generator_spec
growl (~> 1.0.3)
guard-spork
jquery-rails
jruby-openssl
libnotify (~> 0.1.3)
mysql2
pg
rb-fchange (~> 0.0.5)
rb-fsevent (>= 0.3.9)
rb-inotify (>= 0.5.1)
rb-notifu (~> 0.0.4)
refinerycms (~> 2.0.0)
refinerycms-calendar!
refinerycms-i18n!
refinerycms-testing (~> 2.0.0)
sass-rails
spork (= 0.9.0.rc9)
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/refinery/calendar/admin/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class EventsController < ::Refinery::AdminController
crudify :'refinery/calendar/event',
:xhr_paging => true,
:sortable => false,
:order => "'from' DESC"
:order => "'from' DESC",
:include => [:translations]

private
def find_venues
Expand Down
3 changes: 2 additions & 1 deletion app/controllers/refinery/calendar/admin/venues_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ class VenuesController < ::Refinery::AdminController
:title_attribute => 'name',
:xhr_paging => true,
:sortable => false,
:order => 'created_at DESC'
:order => 'created_at DESC',
:include => [:translations]
end
end
end
Expand Down
32 changes: 27 additions & 5 deletions app/models/refinery/calendar/event.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,11 @@
module Refinery
module Calendar
class Event < Refinery::Core::BaseModel
extend FriendlyId

friendly_id :title, :use => :slugged
translates :title, :excerpt, :description, :slug

extend FriendlyId
friendly_id :title, :use => [:slugged, :globalize]

belongs_to :venue

Expand All @@ -13,23 +15,43 @@ class Event < Refinery::Core::BaseModel
:venue_id, :excerpt, :description,
:featured, :position

attr_accessor :locale

delegate :name, :address,
:to => :venue,
:prefix => true,
:allow_nil => true

class Translation
attr_accessible :locale
end

class << self
def upcoming
where('refinery_calendar_events.from >= ?', Time.now)
where('refinery_calendar_events.from >= ?', Time.now).with_globalize
end

def featured
where(:featured => true)
where(:featured => true).with_globalize
end

def archive
where('refinery_calendar_events.from < ?', Time.now)
where('refinery_calendar_events.from < ?', Time.now).with_globalize
end

# Wrap up the logic of finding the events based on the translations table.
def with_globalize(conditions = {})
conditions = {:locale => ::Globalize.locale}.merge(conditions)
globalized_conditions = {}
conditions.keys.each do |key|
if (translated_attribute_names.map(&:to_s) | %w(locale)).include?(key.to_s)
globalized_conditions["#{self.translation_class.table_name}.#{key}"] = conditions.delete(key)
end
end
# A join implies readonly which we don't really want.
joins(:translations).where(globalized_conditions).where(conditions).readonly(false)
end

end
end
end
Expand Down
8 changes: 8 additions & 0 deletions app/models/refinery/calendar/venue.rb
Original file line number Diff line number Diff line change
@@ -1,9 +1,17 @@
module Refinery
module Calendar
class Venue < Refinery::Core::BaseModel
translates :name
has_many :events
validates :name, :presence => true, :uniqueness => true
attr_accessible :name, :address, :url, :phone, :position

attr_accessor :locale

class Translation
attr_accessible :locale
end

end
end
end
12 changes: 10 additions & 2 deletions app/views/refinery/calendar/admin/events/_event.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(event) -%>">
<span class='title'>
<%= event.title %>

<%= event.title.presence || event.translations.detect {|t| t.title.present?}.title %>
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
<span class='preview'>
<% event.translations.each do |translation| %>
<%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
refinery.edit_calendar_admin_event_path(event, :switch_locale => translation.locale),
:class => 'locale' if translation.title.present? %>
<% end %>
</span>
<% end %>
</span>
<span class='actions'>

Expand Down
1 change: 1 addition & 0 deletions app/views/refinery/calendar/admin/events/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:object => @event,
:include_object_name => true %>

<%= render '/refinery/calendar/admin/shared/locale_picker', :current_locale => Globalize.locale if Refinery.i18n_enabled? %>

<div class='field'>
<%= f.label :title -%>
Expand Down
11 changes: 11 additions & 0 deletions app/views/refinery/calendar/admin/shared/_locale_picker.html.erb
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<input type='hidden' name='switch_locale' id='switch_locale' value='<%= local_assigns[:current_locale] %>' />
<% if (locales ||= (Refinery::I18n.frontend_locales if Refinery.i18n_enabled?)).present? && locales.many? %>
<ul id='switch_locale_picker' class='clearfix'>
<% locales.each do |locale| %>
<li<%= " class='selected'" if locale.to_s == local_assigns[:current_locale].to_s %>>
<%= link_to refinery_icon_tag("flags/#{locale}.png", :size => "32x22"),
refinery.url_for(:switch_locale => locale) %>
</li>
<% end %>
</ul>
<% end %>
1 change: 1 addition & 0 deletions app/views/refinery/calendar/admin/venues/_form.html.erb
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
:object => @venue,
:include_object_name => true %>

<%= render '/refinery/calendar/admin/shared/locale_picker', :current_locale => Globalize.locale if Refinery.i18n_enabled? %>

<div class='field'>
<%= f.label :name -%>
Expand Down
12 changes: 10 additions & 2 deletions app/views/refinery/calendar/admin/venues/_venue.html.erb
Original file line number Diff line number Diff line change
@@ -1,7 +1,15 @@
<li class='clearfix record <%= cycle("on", "on-hover") %>' id="<%= dom_id(venue) -%>">
<span class='title'>
<%= venue.name %>

<%= venue.name.presence || venue.translations.detect {|t| t.name.present?}.name %>
<% if Refinery.i18n_enabled? and Refinery::I18n.frontend_locales.many? %>
<span class='preview'>
<% venue.translations.each do |translation| %>
<%= link_to refinery_icon_tag("flags/#{translation.locale}.png", :size => '16x11'),
refinery.edit_calendar_admin_venue_path(venue, :switch_locale => translation.locale),
:class => 'locale' if translation.name.present? %>
<% end %>
</span>
<% end %>
</span>
<span class='actions'>
<%= link_to refinery_icon_tag("application_edit.png"), refinery.edit_calendar_admin_venue_path(venue),
Expand Down
16 changes: 16 additions & 0 deletions db/migrate/3_create_calendar_events_translations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
class CreateCalendarEventsTranslations < ActiveRecord::Migration
def up
Refinery::Calendar::Event.create_translation_table!({
:title => :string,
:excerpt => :string,
:description => :text,
:slug => :string
}, {
:migrate_data => true
})
end

def down
Refinery::Calendar::Event.drop_translation_table! :migrate_data => true
end
end
13 changes: 13 additions & 0 deletions db/migrate/4_create_calendar_venues_translations.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
class CreateCalendarVenuesTranslations < ActiveRecord::Migration
def up
Refinery::Calendar::Venue.create_translation_table!({
:name => :string
}, {
:migrate_data => true
})
end

def down
Refinery::Calendar::Venue.drop_translation_table! :migrate_data => true
end
end
Loading