API access for the current site + easy way to specify the localization of any controllers + fix a minor bug about adding/removing domains

This commit is contained in:
Didier Lafforgue 2012-02-09 11:36:10 +01:00
parent a5e9e52996
commit 39d9c354da
17 changed files with 65 additions and 15 deletions

View File

@ -23,7 +23,8 @@ class Locomotive.Models.Site extends Backbone.Model
_.tap super, (hash) =>
delete hash.memberships
hash.memberships_attributes = @get('memberships').toJSONForSave() if @get('memberships')? && @get('memberships').length > 0
hash.domains = _.map(@get('domains'), (domain) -> domain.get('name'))
delete hash.domains
hash.domains = _.map(@get('domains'), (domain) -> domain.get('name')) if @get('domains')? && @get('domains').length > 0
class Locomotive.Models.CurrentSite extends Locomotive.Models.Site

View File

@ -80,6 +80,6 @@ class Locomotive.Views.ApplicationView extends Backbone.View
picker.toggle()
picker.find('li').bind 'click', (event) ->
locale = $(event.target).html()
locale = $(@).attr('data-locale')
window.addParameterToURL 'content_locale', locale

View File

@ -81,7 +81,7 @@
@mixin locomotive-blue-submenu {
@include background-image(linear-gradient(#2478ac, #1c5d86));
& > ul > li > a {
& > ul > li > a, & > .actions .button {
@include background-image(linear-gradient(#1f6ea1, #135179));
&.on, &:active {
@ -92,7 +92,7 @@
@mixin locomotive-green-submenu {
@include background-image(linear-gradient(#2e9a7d, #2e9a7d)); // TODO (#2e9a7d)
& > ul > li > a {
& > ul > li > a, & > .actions .button {
@include background-image(linear-gradient(#258c70, #13604b));
&.on, &:active {
@ -103,7 +103,7 @@
@mixin locomotive-orange-submenu {
@include background-image(linear-gradient(#ed8102, #ed8102)); // TODO (#ed8102)
& > ul > li > a {
& > ul > li > a, & > .actions .button {
@include background-image(linear-gradient(#e07a02, #a25804));
&.on, &:active {
@ -114,7 +114,7 @@
@mixin locomotive-red-submenu {
@include background-image(linear-gradient(#d23c45, #d23c45)); // TODO (#d23c45)
& > ul > li > a {
& > ul > li > a, & > .actions .button {
@include background-image(linear-gradient(#b63e45, #89272d));
&.on, &:active {

View File

@ -1,7 +1,7 @@
#content-locale-picker
%ul
- @locales.each do |locale|
%li
%li{ :'data-locale' => locale }
= image_tag "locomotive/icons/flags/#{locale}.png", :class => 'flag'
%span.text= locale

View File

@ -0,0 +1,11 @@
module Locomotive
module Api
class CurrentSiteController < BaseController
def show
respond_with(current_site)
end
end
end
end

View File

@ -3,6 +3,8 @@ module Locomotive
sections 'contents'
localized
before_filter :back_to_default_site_locale, :only => %w(new create)
before_filter :set_content_type

View File

@ -3,9 +3,11 @@ module Locomotive
sections 'contents'
localized
before_filter :back_to_default_site_locale, :only => %w(new create)
respond_to :json, :only => [:show, :create, :update, :sort, :get_path]
respond_to :json, :only => [:show, :create, :update, :sort, :get_path]
def index
@pages = current_site.all_pages_in_once

View File

@ -3,6 +3,10 @@ module Locomotive
sections 'settings', 'theme_assets'
localized
before_filter :back_to_default_site_locale, :only => %w(new create)
respond_to :json, :only => [:create, :update, :destroy]
def new

View File

@ -37,6 +37,14 @@ module Locomotive
end
end
def locale_picker_link
if current_site.locales.size > 1 && localized?
content_tag :div, render('locomotive/shared/locale_picker_link'), :class => 'action'
else
nil
end
end
def flash_message
if not flash.empty?
first_key = flash.keys.first

View File

@ -7,7 +7,7 @@ module Locomotive
included do
referenced_in :content_type, :class_name => 'Locomotive::ContentType'
belongs_to :content_type, :class_name => 'Locomotive::ContentType'
field :templatized, :type => Boolean, :default => false

View File

@ -6,7 +6,7 @@ module Locomotive
## fields ##
field :name
field :slug
field :template
field :template, :localize => true
## associations ##
referenced_in :site, :class_name => 'Locomotive::Site'

View File

@ -6,4 +6,5 @@
- if multi_sites? && current_locomotive_account.sites.size > 1
= render 'locomotive/shared/site_picker'
= render_cell 'locomotive/content_locale_picker', :show, :site => current_site, :locale => current_content_locale
- if localized?
= render_cell 'locomotive/content_locale_picker', :show, :site => current_site, :locale => current_content_locale

View File

@ -2,6 +2,4 @@
.action
= link_to content_tag(:em) + content_tag(:span, t('locomotive.content_types.index.new')), new_content_type_url, :class => 'button'
- if current_site.locales.size > 1
.action
= render 'locomotive/shared/locale_picker_link'
= locale_picker_link

View File

@ -3,6 +3,9 @@
- content_for :submenu do
= render_cell 'locomotive/settings_menu', :show
- content_for :actions do
= locale_picker_link
- content_for :buttons do
= local_action_button t('locomotive.snippets.index.new'), new_snippet_url, :class => 'new'

View File

@ -3,6 +3,9 @@
- content_for :submenu do
= render_cell 'locomotive/settings_menu', :show
- content_for :actions do
= locale_picker_link
%p!= t('.help')
= semantic_form_for @snippet, :url => snippets_url do |form|

View File

@ -68,6 +68,8 @@ Rails.application.routes.draw do
resources :content_entries, :path => 'content_types/:slug/entries'
resource :current_site, :controller => 'current_site'
end
end

View File

@ -5,7 +5,7 @@ module Locomotive
extend ActiveSupport::Concern
included do
helper_method :current_content_locale
helper_method :current_content_locale, :localized?
end
def current_content_locale
@ -42,6 +42,21 @@ module Locomotive
end
end
def localized?
Rails.logger.debug "localized? #{@locomotive_localized.inspect}"
!!@locomotive_localized
end
module ClassMethods
def localized(enable_it = true)
before_filter do |c|
c.instance_variable_set(:@locomotive_localized, enable_it)
end
end
end
end
end
end