Skip to content

Commit

Permalink
add the ui element to select the languages for a site
Browse files Browse the repository at this point in the history
  • Loading branch information
did committed Jan 10, 2012
1 parent 4c204ef commit 01c5de3
Show file tree
Hide file tree
Showing 19 changed files with 265 additions and 75 deletions.
Expand Up @@ -14,8 +14,6 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
initialize: ->
@model = new Locomotive.Models.ContentEntry(@options.content_entry)

console.log(@model.urlRoot)

window.foo = @model

Backbone.ModelBinding.bind @
Expand Down Expand Up @@ -61,7 +59,6 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F
@$('li.input.highlighted > input[type=text]').slugify(target: @$('#content_entry__slug'))

refresh_file_fields: ->
console.log('refresh_file_fields')
_.each @_file_field_views, (view) => view.refresh()

remove: ->
Expand Down
Expand Up @@ -13,19 +13,39 @@ class Locomotive.Views.CurrentSite.EditView extends Locomotive.Views.Shared.Form
initialize: ->
@model = new Locomotive.Models.CurrentSite(@options.site)

Backbone.ModelBinding.bind @
Backbone.ModelBinding.bind @, checkbox: 'class'

window.foo = @model

render: ->
super()

@add_toggle_mode_for_locales()

@make_locales_sortable()

@render_domains()

@render_memberships()

@enable_liquid_editing()

add_toggle_mode_for_locales: ->
@$('#site_locales_input .list input[type=checkbox]').bind 'change', (event) ->
el = $(event.target)
if el.is(':checked')
el.closest('.entry').addClass('selected')
else
el.closest('.entry').removeClass('selected')

make_locales_sortable: ->
@sortable_locales_list = @$('#site_locales_input .list').sortable
items: '.entry'
tolerance: 'pointer'
update: =>
list = _.map @$('#site_locales_input .list input:checked'), (el) => $(el).val()
@model.set locales: list

render_domains: ->
@domains_view = new Locomotive.Views.Sites.DomainsView model: @model, errors: @options.errors

Expand Down
Expand Up @@ -17,7 +17,6 @@ class Locomotive.Views.Import.ShowView extends Backbone.View
@refresh_steps

refresh_steps: (data) =>
console.log 'refresh_steps: ....'
window.foo = data
window.bar = @

Expand Down
86 changes: 57 additions & 29 deletions app/assets/stylesheets/locomotive/formtastic_changes.scss
Expand Up @@ -279,6 +279,63 @@ form.formtastic {
}
} // li.string, li.password

&.locale, &.locales {
.list {
margin-left: 150px;
}

&.locales {
label {
color: #8B8D9A;
}
}

.entry {
float: left;
width: 212px;

margin-left: 10px;

&:first-child {
margin-left: 0px;
}

label {
float: none;
display: inline-block;
width: auto;
position: relative;

padding-left: 31px;
margin-left: 8px;

font-weight: normal;

img {
position: absolute;
top: 2px;
left: 0px;
}
}

&.selected {
label {
color: #585A69;
}
&:first-child {
label {
font-weight: bold;
}
}
} // .entry.selected

} // .entry

.inline-hints {
clear: both;
}
} // > li.locale, li.locales

&.code {

textarea, .CodeMirror-scroll {
Expand Down Expand Up @@ -521,35 +578,6 @@ form.formtastic {
}
} // > li#site_memberships_input

&#account_locale_input {
.entry {
float: left;
width: 212px;

margin-right: 10px;

&:nth-child(3n) {
margin-right: 0px;
}

label {
float: none;
display: inline-block;
width: auto;
position: relative;

padding-left: 31px;
margin-left: 8px;

img {
position: absolute;
top: 2px;
left: 0px;
}
}
}
} // > li#account_locale_input

&#account_sites_input {
.entry {
strong {
Expand Down
2 changes: 2 additions & 0 deletions app/controllers/locomotive/current_site_controller.rb
Expand Up @@ -7,6 +7,8 @@ class CurrentSiteController < BaseController

load_and_authorize_resource :class => 'Site'

helper 'Locomotive::Sites'

before_filter :filter_attributes

respond_to :json, :only => :update
Expand Down
10 changes: 3 additions & 7 deletions app/helpers/locomotive/sites_helper.rb
@@ -1,11 +1,7 @@
module Locomotive::SitesHelper

# def error_on_domain(site, name)
# if (error = (site.errors[:domains] || []).detect { |n| n.include?(name) })
# content_tag(:span, error, :class => 'inline-errors')
# else
# ''
# end
# end
def ordered_current_site_locales
current_site.locales + (Locomotive.config.site_locales - current_site.locales)
end

end
59 changes: 59 additions & 0 deletions app/inputs/locomotive/locales_input.rb
@@ -0,0 +1,59 @@
module Locomotive
class LocalesInput < ::Formtastic::Inputs::CheckBoxesInput

def to_html
input_wrapping do
label_html <<
choices_group_wrapping do
collection.map { |choice|
choice_wrapping(choice_wrapping_html_options(choice)) do
choice_html(choice)
end
}.join("\n").html_safe
end
end
end

def choices_group_wrapping(&block)
template.content_tag(:div,
template.capture(&block),
choices_group_wrapping_html_options
)
end

def choice_wrapping(html_options, &block)
template.content_tag(:div,
template.capture(&block),
html_options
)
end

def choice_html(choice)
check_box_without_hidden_input(choice) <<
template.content_tag(:label,
choice_label(choice),
label_html_options.merge(:for => choice_input_dom_id(choice), :class => nil)
)
end

def choice_label(choice)
text = I18n.t("locomotive.my_account.edit.#{choice}")
template.image_tag("locomotive/icons/flags/#{choice}.png", :alt => text) << text
end

def choices_group_wrapping_html_options
{ :class => 'list' }
end

def choice_wrapping_html_options(choice)
super.tap do |options|
options[:class] = "entry #{checked?(choice) ? 'selected' : ''}"
end
end

def hidden_fields?
false
end

end
end
53 changes: 53 additions & 0 deletions app/models/locomotive/extensions/site/i18n.rb
@@ -0,0 +1,53 @@
module Locomotive
module Extensions
module Site
module I18n

extend ActiveSupport::Concern

included do

## fields ##
field :locales, :type => 'RawArray', :default => []

## callbacks ##
# after_validation :add_missing_locales_for_all_pages

end

module InstanceMethods

def locales=(array)
array = [] if array.blank?; super(array)
end

def default_locale
self.locales.first || Locomotive.config.site_locales.first
end

# protected
#
# def add_missing_locales_for_all_pages
# if self.locales_changed?
# list = self.pages.to_a
#
# while !list.empty? do
# page = list.pop
# begin
# page.send(:set_slug_and_fullpath_for_all_locales, self.locales)
#
# page.save
#
# rescue TypeError => e
# list.insert(0, page)
# end
# end
# end
# end

end

end
end
end
end
5 changes: 3 additions & 2 deletions app/models/locomotive/site.rb
Expand Up @@ -4,9 +4,10 @@ class Site
include Locomotive::Mongoid::Document

## Extensions ##
extend Extensions::Site::SubdomainDomains
extend Extensions::Site::FirstInstallation
extend Extensions::Site::SubdomainDomains
extend Extensions::Site::FirstInstallation
include Extensions::Shared::Seo
include Extensions::Site::I18n

## fields ##
field :name
Expand Down
4 changes: 2 additions & 2 deletions app/presenters/locomotive/site_presenter.rb
@@ -1,7 +1,7 @@
module Locomotive
class SitePresenter < BasePresenter

delegate :name, :subdomain, :domains, :robots_txt, :seo_title, :meta_keywords, :meta_description, :domains_without_subdomain, :to => :source
delegate :name, :locales, :subdomain, :domains, :robots_txt, :seo_title, :meta_keywords, :meta_description, :domains_without_subdomain, :to => :source

def domain_name
Locomotive.config.domain
Expand All @@ -12,7 +12,7 @@ def memberships
end

def included_methods
super + %w(name domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships)
super + %w(name locales domain_name subdomain domains robots_txt seo_title meta_keywords meta_description domains_without_subdomain memberships)
end

end
Expand Down
16 changes: 9 additions & 7 deletions app/views/locomotive/current_site/_form.html.haml
Expand Up @@ -6,13 +6,9 @@
:plain
{ site: #{@site.to_json(:current_account => current_locomotive_account, :current_site => current_site)}, errors: #{@site.errors.to_json} }

= f.inputs :name => :information, :style => 'display: none' do
= f.input :name

= f.inputs :name => :seo, :class => "inputs foldable #{'folded' if inputs_folded?(@site)}" do
= f.input :seo_title
= f.input :meta_keywords
= f.input :meta_description
= f.inputs :name => :information do
= f.input :name, :wrapper_html => { :style => 'display: none' }
= f.input :locales, :as => '::Locomotive::Locales', :collection => ordered_current_site_locales, :input_html => { :class => 'locales' }

- if can?(:point, Locomotive::Site)
- if manage_subdomain_or_domains?
Expand All @@ -22,6 +18,12 @@
- if manage_domains?
= f.input :domains, :as => :'Locomotive::Empty'


= f.inputs :name => :seo, :class => "inputs foldable #{'folded' if inputs_folded?(@site)}" do
= f.input :seo_title
= f.input :meta_keywords
= f.input :meta_description

- if can?(:index, Locomotive::Membership)

= f.inputs :name => :memberships do
Expand Down
3 changes: 3 additions & 0 deletions config/locales/formtastic.en.yml
Expand Up @@ -54,6 +54,8 @@ en:
password_confirmation: New password confirmation
page:
seo_title: Title
site:
locales: Languages

hints:
page:
Expand All @@ -68,6 +70,7 @@ en:
snippet:
slug: "You need to know it in order to insert the snippet inside a page"
site:
locales: "Drag&drop a flag to the first position to make it the default one."
seo_title: "Define a global value here which should be used as the value for the title tag in the head section."
meta_keywords: "Meta keywords used within the head tag of the page. They are separated by a comma. Required for SEO."
meta_description: "Meta description used within the head tag of the page. Required for SEO."
Expand Down
4 changes: 4 additions & 0 deletions doc/TODO
Expand Up @@ -66,6 +66,10 @@ x edit my site
- use list_or_group_entries instead of ordered_entries
- bug ui with contents popup
- custom_fields: use the appropriate icon to drag select options
- i18n
x add locales a site responds to
- locale switcher
- inline editor

- disallow to click twice on the submit form button (spinner ?)
- message to notify people if their browser is too old
Expand Down

0 comments on commit 01c5de3

Please sign in to comment.