From b5fa2c761aadc2df9b519918dece5295871e7641 Mon Sep 17 00:00:00 2001 From: did Date: Thu, 26 Jan 2012 07:51:32 -0800 Subject: [PATCH] change the location url for the API responses + force the use of the default site locale when creating a new entry, content type or page --- Gemfile | 4 ++-- Gemfile.lock | 6 ++---- .../locomotive/api/content_assets_controller.rb | 4 ++-- .../locomotive/api/content_entries_controller.rb | 6 +++--- .../locomotive/api/content_types_controller.rb | 9 ++------- .../locomotive/api/pages_controller.rb | 4 ++-- .../locomotive/api/snippets_controller.rb | 4 ++-- .../locomotive/api/theme_assets_controller.rb | 4 ++-- .../locomotive/content_entries_controller.rb | 2 ++ .../locomotive/content_types_controller.rb | 2 ++ .../cross_domain_sessions_controller.rb | 4 ++-- app/controllers/locomotive/pages_controller.rb | 2 ++ .../locomotive/sessions_controller.rb | 6 ++++++ app/models/locomotive/editable_file.rb | 4 ++-- app/models/locomotive/site.rb | 16 +++++++++------- doc/TODO | 5 ++--- doc/changelogs/version_2.txt | 3 ++- .../action_controller/locale_helpers.rb | 4 ++++ 18 files changed, 50 insertions(+), 39 deletions(-) diff --git a/Gemfile b/Gemfile index d9b34196..530d332c 100644 --- a/Gemfile +++ b/Gemfile @@ -13,8 +13,8 @@ gem 'mongo', '~> 1.5.2' gem 'bson_ext', '~> 1.5.2' gem 'mongoid', '~> 2.4.2' gem 'locomotive_mongoid_acts_as_tree', '~> 0.1.5.8' -# gem 'custom_fields', :path => '../gems/custom_fields' # DEV -gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' +gem 'custom_fields', :path => '../gems/custom_fields' # DEV +# gem 'custom_fields', :git => 'git://github.com/locomotivecms/custom_fields.git', :branch => '2.0.0.rc' gem 'kaminari' gem 'haml', '~> 3.1.3' diff --git a/Gemfile.lock b/Gemfile.lock index 12caf85c..eea9a812 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -1,7 +1,5 @@ -GIT - remote: git://github.com/locomotivecms/custom_fields.git - revision: 65c451abfc849dd665a556c68c8976c405e57b10 - branch: 2.0.0.rc +PATH + remote: ../gems/custom_fields specs: custom_fields (2.0.0.rc2) activesupport (~> 3.1.3) diff --git a/app/controllers/locomotive/api/content_assets_controller.rb b/app/controllers/locomotive/api/content_assets_controller.rb index 00296527..abde5f8c 100644 --- a/app/controllers/locomotive/api/content_assets_controller.rb +++ b/app/controllers/locomotive/api/content_assets_controller.rb @@ -9,13 +9,13 @@ module Locomotive def create @content_asset = current_site.content_assets.create(params[:content_asset]) - respond_with @content_asset, :location => locomotive_api_content_asset_url(@content_asset._id) + respond_with @content_asset, :location => main_app.locomotive_api_content_assets_url end def update @content_asset = current_site.content_assets.find(params[:id]) @content_asset.update_attributes(params[:content_asset]) - respond_with @content_asset, :location => locomotive_api_content_asset_url(@content_asset._id) + respond_with @content_asset, :location => main_app.locomotive_api_content_assets_url end end diff --git a/app/controllers/locomotive/api/content_entries_controller.rb b/app/controllers/locomotive/api/content_entries_controller.rb index b61423fb..058769da 100644 --- a/app/controllers/locomotive/api/content_entries_controller.rb +++ b/app/controllers/locomotive/api/content_entries_controller.rb @@ -11,19 +11,19 @@ module Locomotive def create @content_entry = @content_type.entries.create(params[:content_entry]) - respond_with @content_entry, :location => edit_locomotive_api_content_entry_url(@content_type.slug, @content_entry._id) + respond_with @content_entry, :location => main_app.locomotive_api_content_entries_url(@content_type.slug) end def update @content_entry = @content_type.entries.find(params[:id]) @content_entry.update_attributes(params[:content_entry]) - respond_with @content_entry, :location => edit_locomotive_api_content_entry_url(@content_type.slug, @content_entry._id) + respond_with @content_entry, :location => main_app.locomotive_api_content_entries_url(@content_type.slug) end def destroy @content_entry = @content_type.entries.find(params[:id]) @content_entry.destroy - respond_with @content_entry, :location => locomotive_api_content_entries_url(@content_type.slug) + respond_with @content_entry, :location => main_app.locomotive_api_content_entries_url(@content_type.slug) end protected diff --git a/app/controllers/locomotive/api/content_types_controller.rb b/app/controllers/locomotive/api/content_types_controller.rb index a58838b4..afd4ed6a 100644 --- a/app/controllers/locomotive/api/content_types_controller.rb +++ b/app/controllers/locomotive/api/content_types_controller.rb @@ -9,18 +9,13 @@ module Locomotive def create @content_type = current_site.content_types.create(params[:content_type]) - respond_with @content_type, :location => edit_locomotive_api_content_type_url(@content_type._id) - end - - def edit - @content_type = current_site.content_types.find(params[:id]) - respond_with @content_type + respond_with @content_type, :location => main_app.locomotive_api_content_types_url end def update @content_type = current_site.content_types.find(params[:id]) @content_type.update_attributes(params[:content_type]) - respond_with @content_type, :location => edit_locomotive_api_content_type_url(@content_type._id) + respond_with @content_type, :location => main_app.locomotive_api_content_types_url end end diff --git a/app/controllers/locomotive/api/pages_controller.rb b/app/controllers/locomotive/api/pages_controller.rb index dea546c4..df7734d8 100644 --- a/app/controllers/locomotive/api/pages_controller.rb +++ b/app/controllers/locomotive/api/pages_controller.rb @@ -9,13 +9,13 @@ module Locomotive def create @page = current_site.pages.create(params[:page]) - respond_with @page, :location => edit_locomotive_api_page_url(@page._id) + respond_with @page, :location => main_app.locomotive_api_pages_url end def update @page = current_site.pages.find(params[:id]) @page.update_attributes(params[:page]) - respond_with @page, :location => edit_locomotive_api_page_url(@page._id) + respond_with @page, :location => main_app.locomotive_api_pages_url end end diff --git a/app/controllers/locomotive/api/snippets_controller.rb b/app/controllers/locomotive/api/snippets_controller.rb index 110ccf84..b7479745 100644 --- a/app/controllers/locomotive/api/snippets_controller.rb +++ b/app/controllers/locomotive/api/snippets_controller.rb @@ -9,13 +9,13 @@ module Locomotive def create @snippet = current_site.snippets.create(params[:snippet]) - respond_with @snippet, :location => edit_locomotive_api_snippet_url(@snippet._id) + respond_with @snippet, :location => main_app.locomotive_api_snippets_url end def update @snippet = current_site.snippets.find(params[:id]) @snippet.update_attributes(params[:snippet]) - respond_with @snippet, :location => edit_locomotive_api_snippet_url(@snippet._id) + respond_with @snippet, :location => main_app.locomotive_api_snippets_url end end diff --git a/app/controllers/locomotive/api/theme_assets_controller.rb b/app/controllers/locomotive/api/theme_assets_controller.rb index de8d29f6..c1cfae8d 100644 --- a/app/controllers/locomotive/api/theme_assets_controller.rb +++ b/app/controllers/locomotive/api/theme_assets_controller.rb @@ -9,13 +9,13 @@ module Locomotive def create @theme_asset = current_site.theme_assets.create(params[:theme_asset]) - respond_with @theme_asset, :location => edit_locomotive_api_theme_asset_url(@theme_asset._id) + respond_with @theme_asset, :location => main_app.locomotive_api_theme_assets_url end def update @theme_asset = current_site.theme_assets.find(params[:id]) @theme_asset.update_attributes(params[:theme_asset]) - respond_with @theme_asset, :location => edit_locomotive_api_theme_asset_url(@theme_asset._id) + respond_with @theme_asset, :location => main_app.locomotive_api_theme_assets_url end end diff --git a/app/controllers/locomotive/content_entries_controller.rb b/app/controllers/locomotive/content_entries_controller.rb index 36b10ffe..1ef5ce4d 100644 --- a/app/controllers/locomotive/content_entries_controller.rb +++ b/app/controllers/locomotive/content_entries_controller.rb @@ -3,6 +3,8 @@ module Locomotive sections 'contents' + before_filter :back_to_default_site_locale, :only => %w(new create) + before_filter :set_content_type respond_to :json, :only => [:edit, :create, :update, :sort] diff --git a/app/controllers/locomotive/content_types_controller.rb b/app/controllers/locomotive/content_types_controller.rb index e3cc8af3..d10b93c3 100644 --- a/app/controllers/locomotive/content_types_controller.rb +++ b/app/controllers/locomotive/content_types_controller.rb @@ -3,6 +3,8 @@ module Locomotive sections 'contents' + before_filter :back_to_default_site_locale, :only => %w(new create) + respond_to :json, :only => [:create, :update, :destroy] helper 'Locomotive::Accounts', 'Locomotive::CustomFields' diff --git a/app/controllers/locomotive/cross_domain_sessions_controller.rb b/app/controllers/locomotive/cross_domain_sessions_controller.rb index 4231dcc4..7e30cde4 100644 --- a/app/controllers/locomotive/cross_domain_sessions_controller.rb +++ b/app/controllers/locomotive/cross_domain_sessions_controller.rb @@ -29,9 +29,9 @@ module Locomotive if account = Account.find_using_switch_site_token(params[:token]) account.reset_switch_site_token! sign_in(account) - redirect_to admin_pages_path + redirect_to pages_path else - redirect_to new_admin_session_path, :alert => t('flash.locomotive.cross_domain_sessions.create.alert') + redirect_to new_locomotive_account_session_path, :alert => t('flash.locomotive.cross_domain_sessions.create.alert') end end diff --git a/app/controllers/locomotive/pages_controller.rb b/app/controllers/locomotive/pages_controller.rb index 364912b0..390fb8f3 100644 --- a/app/controllers/locomotive/pages_controller.rb +++ b/app/controllers/locomotive/pages_controller.rb @@ -3,6 +3,8 @@ module Locomotive sections 'contents' + before_filter :back_to_default_site_locale, :only => %w(new create) + respond_to :json, :only => [:show, :create, :update, :sort, :get_path] def index diff --git a/app/controllers/locomotive/sessions_controller.rb b/app/controllers/locomotive/sessions_controller.rb index 33960271..874fe001 100644 --- a/app/controllers/locomotive/sessions_controller.rb +++ b/app/controllers/locomotive/sessions_controller.rb @@ -7,6 +7,8 @@ module Locomotive before_filter :require_site + before_filter :set_locale + helper 'locomotive/base' protected @@ -19,5 +21,9 @@ module Locomotive request.protocol + request.host_with_port end + def set_locale + I18n.locale = current_site.accounts.first.locale + end + end end diff --git a/app/models/locomotive/editable_file.rb b/app/models/locomotive/editable_file.rb index d4589d26..b2eb43fd 100644 --- a/app/models/locomotive/editable_file.rb +++ b/app/models/locomotive/editable_file.rb @@ -1,9 +1,9 @@ module Locomotive class EditableFile < EditableElement - mount_uploader :source, EditableFileUploader, :mount_on => :source_filename + mount_uploader :source, EditableFileUploader - replace_field :source_filename, ::String, true + replace_field :source, ::String, true def content self.source? ? self.source.url : self.default_content diff --git a/app/models/locomotive/site.rb b/app/models/locomotive/site.rb index 3dc75e54..30d9450b 100644 --- a/app/models/locomotive/site.rb +++ b/app/models/locomotive/site.rb @@ -61,13 +61,15 @@ module Locomotive # namespaced ::I18n should be changed to just I18n when the t() # method is available def create_default_pages! - %w{index 404}.each do |slug| - self.pages.create({ - :slug => slug, - :title => ::I18n.t("attributes.defaults.pages.#{slug}.title"), - :raw_template => ::I18n.t("attributes.defaults.pages.#{slug}.body"), - :published => true - }) + ::Mongoid::Fields::I18n.with_locale(self.default_locale) do + %w{index 404}.each do |slug| + self.pages.create({ + :slug => slug, + :title => ::I18n.t("attributes.defaults.pages.#{slug}.title"), + :raw_template => ::I18n.t("attributes.defaults.pages.#{slug}.body"), + :published => true + }) + end end end diff --git a/doc/TODO b/doc/TODO index 32eb3dbe..d2b46d59 100644 --- a/doc/TODO +++ b/doc/TODO @@ -103,17 +103,18 @@ x deployment x data ? x script to migrate existing site x i18n +- heroku module for locomotive - refactoring - remove the import / export scripts - remove the cross domain authentication (use auth_token instead) - upgrade to rails 3.2 (https://github.com/locomotivecms/engine/pull/281/files) -- heroku module for locomotive - bugs: x unable to toggle the "required" check_boxes for content types x unable to sign out x unable to remove a field x "back to admin" link does not work if inline editor disabled + - display by categories does not work when localized - disallow to click twice on the submit form button (spinner ?) - message to notify people if their browser is too old @@ -121,8 +122,6 @@ x script to migrate existing site - where to put Locomotive::InlineEditorMiddleware ? - - BACKLOG: - custom_fields: diff --git a/doc/changelogs/version_2.txt b/doc/changelogs/version_2.txt index 7dae9bb5..9c670b3f 100644 --- a/doc/changelogs/version_2.txt +++ b/doc/changelogs/version_2.txt @@ -14,7 +14,8 @@ - api_contents: - url => entry_submissions - params[:content] => params[:entries] - + - editable_file: + - source_filename => source collection, selector = Locomotive::ContentType.collection, Locomotive::ContentType.criteria.selector collection.update selector, { '$rename' => { 'contents_custom_fields' => 'entries_custom_fields' } } diff --git a/lib/locomotive/action_controller/locale_helpers.rb b/lib/locomotive/action_controller/locale_helpers.rb index f8e74394..3834fe34 100644 --- a/lib/locomotive/action_controller/locale_helpers.rb +++ b/lib/locomotive/action_controller/locale_helpers.rb @@ -34,6 +34,10 @@ module Locomotive ::I18n.locale = current_locomotive_account.locale rescue Locomotive.config.default_locale end + def back_to_default_site_locale + session[:content_locale] = ::Mongoid::Fields::I18n.locale = current_site.default_locale + end + def setup_i18n_fallbacks (current_site.locales || []).each do |locale| ::Mongoid::Fields::I18n.fallbacks_for(locale, current_site.locale_fallbacks(locale))