add the UI for the belongs_to custom field
This commit is contained in:
parent
b132c3bba9
commit
e2bd55fe35
87
Gemfile.lock
87
Gemfile.lock
@ -1,16 +1,56 @@
|
|||||||
|
PATH
|
||||||
|
remote: .
|
||||||
|
specs:
|
||||||
|
locomotive_cms (2.0.0.rc1)
|
||||||
|
RedCloth (~> 4.2.8)
|
||||||
|
actionmailer-with-request (~> 0.3.0)
|
||||||
|
bson_ext (~> 1.5.2)
|
||||||
|
cancan (~> 1.6.7)
|
||||||
|
carrierwave-mongoid (~> 0.1.3)
|
||||||
|
cells (~> 3.8.0)
|
||||||
|
codemirror-rails (~> 2.21)
|
||||||
|
coffee-script (~> 2.2.0)
|
||||||
|
compass (~> 0.12.alpha.4)
|
||||||
|
custom_fields (~> 2.0.0.rc2)
|
||||||
|
devise (~> 1.5.3)
|
||||||
|
dragonfly (~> 0.9.8)
|
||||||
|
flash_cookie_session (~> 1.1.1)
|
||||||
|
fog (~> 1.0.0)
|
||||||
|
formtastic (~> 2.0.2)
|
||||||
|
haml (~> 3.1.3)
|
||||||
|
highline (~> 1.6.2)
|
||||||
|
httparty (~> 0.8.1)
|
||||||
|
jquery-rails (~> 1.0.16)
|
||||||
|
kaminari (~> 0.13.0)
|
||||||
|
locomotive-aloha-rails (~> 0.20.1)
|
||||||
|
locomotive-tinymce-rails (~> 3.4.7)
|
||||||
|
locomotive_liquid (= 2.2.2)
|
||||||
|
locomotive_mongoid_acts_as_tree (~> 0.1.5.8)
|
||||||
|
mimetype-fu (~> 0.1.2)
|
||||||
|
mongo (~> 1.5.2)
|
||||||
|
mongoid (~> 2.4.3)
|
||||||
|
rack-cache (~> 1.1)
|
||||||
|
rails (~> 3.1.3)
|
||||||
|
rails-backbone (~> 0.5.4)
|
||||||
|
rake (~> 0.9.2)
|
||||||
|
responders (~> 0.6.4)
|
||||||
|
rmagick (~> 2.12.2)
|
||||||
|
sanitize (~> 2.0.3)
|
||||||
|
sass-rails (~> 3.1.5)
|
||||||
|
uglifier (~> 1.2.2)
|
||||||
|
|
||||||
PATH
|
PATH
|
||||||
remote: ../gems/custom_fields
|
remote: ../gems/custom_fields
|
||||||
specs:
|
specs:
|
||||||
custom_fields (2.0.0.rc2)
|
custom_fields (2.0.0.rc2)
|
||||||
activesupport (~> 3.1.3)
|
activesupport (~> 3.1.3)
|
||||||
carrierwave-mongoid (~> 0.1.3)
|
carrierwave-mongoid (~> 0.1.3)
|
||||||
mongoid (~> 2.4.2)
|
mongoid (~> 2.4.3)
|
||||||
|
|
||||||
GEM
|
GEM
|
||||||
remote: http://rubygems.org/
|
remote: http://rubygems.org/
|
||||||
specs:
|
specs:
|
||||||
RedCloth (4.2.9)
|
RedCloth (4.2.9)
|
||||||
SystemTimer (1.2.3)
|
|
||||||
ZenTest (4.6.2)
|
ZenTest (4.6.2)
|
||||||
actionmailer (3.1.3)
|
actionmailer (3.1.3)
|
||||||
actionpack (= 3.1.3)
|
actionpack (= 3.1.3)
|
||||||
@ -161,7 +201,7 @@ GEM
|
|||||||
mocha (0.9.12)
|
mocha (0.9.12)
|
||||||
mongo (1.5.2)
|
mongo (1.5.2)
|
||||||
bson (= 1.5.2)
|
bson (= 1.5.2)
|
||||||
mongoid (2.4.2)
|
mongoid (2.4.3)
|
||||||
activemodel (~> 3.1)
|
activemodel (~> 3.1)
|
||||||
mongo (~> 1.3)
|
mongo (~> 1.3)
|
||||||
tzinfo (~> 0.3.22)
|
tzinfo (~> 0.3.22)
|
||||||
@ -193,7 +233,7 @@ GEM
|
|||||||
activesupport (= 3.1.3)
|
activesupport (= 3.1.3)
|
||||||
bundler (~> 1.0)
|
bundler (~> 1.0)
|
||||||
railties (= 3.1.3)
|
railties (= 3.1.3)
|
||||||
rails-backbone (0.5.4)
|
rails-backbone (0.5.5)
|
||||||
coffee-script (~> 2.2.0)
|
coffee-script (~> 2.2.0)
|
||||||
ejs (~> 1.0.0)
|
ejs (~> 1.0.0)
|
||||||
rails (~> 3.1.0)
|
rails (~> 3.1.0)
|
||||||
@ -253,7 +293,7 @@ GEM
|
|||||||
polyglot
|
polyglot
|
||||||
polyglot (>= 0.3.1)
|
polyglot (>= 0.3.1)
|
||||||
tzinfo (0.3.31)
|
tzinfo (0.3.31)
|
||||||
uglifier (1.0.4)
|
uglifier (1.2.3)
|
||||||
execjs (>= 0.3.0)
|
execjs (>= 0.3.0)
|
||||||
multi_json (>= 1.0.2)
|
multi_json (>= 1.0.2)
|
||||||
unicorn (4.1.1)
|
unicorn (4.1.1)
|
||||||
@ -269,55 +309,20 @@ PLATFORMS
|
|||||||
ruby
|
ruby
|
||||||
|
|
||||||
DEPENDENCIES
|
DEPENDENCIES
|
||||||
RedCloth (~> 4.2.8)
|
|
||||||
SystemTimer
|
|
||||||
ZenTest
|
ZenTest
|
||||||
actionmailer-with-request (~> 0.3.0)
|
|
||||||
autotest
|
autotest
|
||||||
bson_ext (~> 1.5.2)
|
|
||||||
cancan (~> 1.6.7)
|
|
||||||
capybara
|
capybara
|
||||||
carrierwave-mongoid (~> 0.1.3)
|
|
||||||
cells (~> 3.8.0)
|
|
||||||
codemirror-rails (~> 2.21)
|
|
||||||
coffee-script (~> 2.2.0)
|
|
||||||
compass (~> 0.12.alpha.4)
|
|
||||||
cucumber-rails
|
cucumber-rails
|
||||||
custom_fields!
|
custom_fields!
|
||||||
database_cleaner
|
database_cleaner
|
||||||
devise (~> 1.5.3)
|
|
||||||
dragonfly (~> 0.9.8)
|
|
||||||
factory_girl_rails (~> 1.3.0)
|
factory_girl_rails (~> 1.3.0)
|
||||||
flash_cookie_session (~> 1.1.1)
|
|
||||||
fog (~> 1.0.0)
|
|
||||||
formtastic (~> 2.0.2)
|
|
||||||
growl-glue
|
growl-glue
|
||||||
haml (~> 3.1.3)
|
|
||||||
highline (~> 1.6.2)
|
|
||||||
httparty (~> 0.8.1)
|
|
||||||
jquery-rails (~> 1.0.16)
|
|
||||||
kaminari (~> 0.13.0)
|
|
||||||
launchy
|
launchy
|
||||||
locomotive-aloha-rails (~> 0.20.1)
|
locomotive_cms!
|
||||||
locomotive-tinymce-rails (~> 3.4.7)
|
|
||||||
locomotive_liquid (= 2.2.2)
|
|
||||||
locomotive_mongoid_acts_as_tree (~> 0.1.5.8)
|
|
||||||
mimetype-fu (~> 0.1.2)
|
|
||||||
mocha (= 0.9.12)
|
mocha (= 0.9.12)
|
||||||
mongo (~> 1.5.2)
|
|
||||||
mongoid (~> 2.4.2)
|
|
||||||
pickle
|
pickle
|
||||||
rack-cache (~> 1.1)
|
|
||||||
rails (~> 3.1.3)
|
|
||||||
rails-backbone (= 0.5.4)
|
|
||||||
rake (= 0.9.2)
|
|
||||||
responders (~> 0.6.4)
|
|
||||||
rmagick (= 2.12.2)
|
|
||||||
rspec-cells
|
rspec-cells
|
||||||
rspec-rails (= 2.6.1)
|
rspec-rails (= 2.6.1)
|
||||||
sanitize (~> 2.0.3)
|
|
||||||
sass-rails (~> 3.1.5)
|
|
||||||
shoulda-matchers
|
shoulda-matchers
|
||||||
uglifier (~> 1.0.4)
|
|
||||||
unicorn
|
unicorn
|
||||||
xpath (~> 0.1.4)
|
xpath (~> 0.1.4)
|
||||||
|
@ -41,6 +41,9 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
|
|||||||
@$('li.input.select-options').show()
|
@$('li.input.select-options').show()
|
||||||
when 'text'
|
when 'text'
|
||||||
@$('li.input.text-formatting').show()
|
@$('li.input.text-formatting').show()
|
||||||
|
when 'belongs_to'
|
||||||
|
@$('li.input.localized').hide()
|
||||||
|
@$('li.input.class-name').show()
|
||||||
|
|
||||||
render_select_options_view: ->
|
render_select_options_view: ->
|
||||||
@select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView
|
@select_options_view = new Locomotive.Views.ContentTypes.SelectOptionsView
|
||||||
|
@ -83,6 +83,7 @@ class Locomotive.Views.Shared.FormView extends Backbone.View
|
|||||||
|
|
||||||
show_error: (attribute, message, html) ->
|
show_error: (attribute, message, html) ->
|
||||||
input = @$("##{@model.paramRoot}_#{attribute}")
|
input = @$("##{@model.paramRoot}_#{attribute}")
|
||||||
|
input = @$("##{@model.paramRoot}_#{attribute}_id") if input.size() == 0
|
||||||
|
|
||||||
return unless input.size() > 0
|
return unless input.size() > 0
|
||||||
|
|
||||||
|
17
app/helpers/locomotive/content_entries_helper.rb
Normal file
17
app/helpers/locomotive/content_entries_helper.rb
Normal file
@ -0,0 +1,17 @@
|
|||||||
|
module Locomotive::ContentEntriesHelper
|
||||||
|
|
||||||
|
def options_for_belongs_to_custom_field(class_name)
|
||||||
|
content_type = nil
|
||||||
|
|
||||||
|
if class_name =~ /^Locomotive::Entry(.*)/
|
||||||
|
content_type = current_site.content_types.find($1)
|
||||||
|
end
|
||||||
|
|
||||||
|
if content_type
|
||||||
|
content_type.ordered_entries.map { |entry| [entry._label, entry._id] }
|
||||||
|
else
|
||||||
|
[] # unknown content type
|
||||||
|
end
|
||||||
|
end
|
||||||
|
|
||||||
|
end
|
@ -1,7 +1,7 @@
|
|||||||
module Locomotive::CustomFieldsHelper
|
module Locomotive::CustomFieldsHelper
|
||||||
|
|
||||||
def options_for_custom_field_type
|
def options_for_custom_field_type
|
||||||
%w(string text select boolean date file).map do |type|
|
%w(string text select boolean date file belongs_to).map do |type|
|
||||||
[t("custom_fields.types.#{type}"), type]
|
[t("custom_fields.types.#{type}"), type]
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
@ -41,6 +41,14 @@ module Locomotive::CustomFieldsHelper
|
|||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
|
def options_for_content_types
|
||||||
|
current_site.content_types.map do |c|
|
||||||
|
c != @content_type ? [c.name, c.klass_with_custom_fields(:entries).to_s] : nil
|
||||||
|
end.compact
|
||||||
|
end
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
# def options_for_association_target
|
# def options_for_association_target
|
||||||
# current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] }
|
# current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] }
|
||||||
# end
|
# end
|
||||||
|
@ -30,10 +30,10 @@ module Locomotive
|
|||||||
#
|
#
|
||||||
def safe_attributes
|
def safe_attributes
|
||||||
self.source.custom_fields_recipe['rules'].map do |rule|
|
self.source.custom_fields_recipe['rules'].map do |rule|
|
||||||
case rule['type']
|
case rule['type'].to_sym
|
||||||
when 'select' then "#{rule['name']}_id"
|
when :date then "formatted_#{rule['name']}"
|
||||||
when 'date' then "formatted_#{rule['name']}"
|
when :file then [rule['name'], "remove_#{rule['name']}"]
|
||||||
when 'file' then [rule['name'], "remove_#{rule['name']}"]
|
when :select, :belongs_to then "#{rule['name']}_id"
|
||||||
else
|
else
|
||||||
rule['name']
|
rule['name']
|
||||||
end
|
end
|
||||||
@ -76,10 +76,11 @@ module Locomotive
|
|||||||
#
|
#
|
||||||
# @returns [ Object ] A string or an array of names
|
# @returns [ Object ] A string or an array of names
|
||||||
def getters_for(name, type)
|
def getters_for(name, type)
|
||||||
case type
|
case type.to_sym
|
||||||
when 'select' then [name, "#{name}_id"]
|
when :select then [name, "#{name}_id"]
|
||||||
when 'date' then "formatted_#{name}"
|
when :date then "formatted_#{name}"
|
||||||
when 'file' then "#{name}_url"
|
when :file then "#{name}_url"
|
||||||
|
when :belongs_to then "#{name}_id"
|
||||||
else
|
else
|
||||||
name
|
name
|
||||||
end
|
end
|
||||||
|
@ -38,12 +38,16 @@
|
|||||||
|
|
||||||
= g.input :hint, :input_html => { :class => 'hint' }
|
= g.input :hint, :input_html => { :class => 'hint' }
|
||||||
|
|
||||||
= g.input :localized, :as => :'Locomotive::Toggle', :input_html => { :class => 'localized' }
|
= g.input :localized, :as => :'Locomotive::Toggle', :wrapper_html => { :class => 'extra localized' }, :input_html => { :class => 'localized' }
|
||||||
|
|
||||||
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :class => 'extra select-options', :style => 'display: none' }
|
= g.input :select_options, :as => :'Locomotive::Empty', :wrapper_html => { :class => 'extra select-options', :style => 'display: none' }
|
||||||
|
|
||||||
= g.input :text_formatting, :as => :select, :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :class => 'extra text-formatting' }, :input_html => { :class => 'text_formatting' }
|
= g.input :text_formatting, :as => :select, :collection => options_for_text_formatting, :include_blank => false, :wrapper_html => { :class => 'extra text-formatting' }, :input_html => { :class => 'text_formatting' }
|
||||||
|
|
||||||
|
= g.input :class_name, :as => :select, :collection => options_for_content_types, :include_blank => false, :wrapper_html => { :class => 'extra class-name', :style => 'display: none' }, :input_html => { :class => 'class_name' }
|
||||||
|
|
||||||
|
/ = g.input :inverse_of, :input_html => { :class => 'inverse_of' }, :wrapper_html => { :style => 'display: none' }
|
||||||
|
|
||||||
%span.actions
|
%span.actions
|
||||||
= link_to 'toggle', '#', :class => 'toggle'
|
= link_to 'toggle', '#', :class => 'toggle'
|
||||||
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')
|
= link_to 'x', '#', :class => 'remove', :confirm => t('locomotive.messages.confirm')
|
||||||
|
@ -0,0 +1,5 @@
|
|||||||
|
= f.input :"#{name}_id",
|
||||||
|
:label => field.label,
|
||||||
|
:hint => field.hint,
|
||||||
|
:as => :select,
|
||||||
|
:collection => options_for_belongs_to_custom_field(field.class_name)
|
@ -1,8 +1,3 @@
|
|||||||
# require 'formtastic'
|
|
||||||
# require 'locomotive/misc_form_builder'
|
|
||||||
# Formtastic::SemanticFormHelper.builder = Locomotive::MiscFormBuilder
|
|
||||||
# Formtastic::SemanticFormBuilder.i18n_lookups_by_default = true
|
|
||||||
#
|
|
||||||
require 'formtastic'
|
require 'formtastic'
|
||||||
|
|
||||||
Formtastic::FormBuilder.i18n_lookups_by_default = true
|
Formtastic::FormBuilder.i18n_lookups_by_default = true
|
||||||
|
@ -27,7 +27,7 @@ Gem::Specification.new do |s|
|
|||||||
|
|
||||||
s.add_dependency 'mongo', '~> 1.5.2'
|
s.add_dependency 'mongo', '~> 1.5.2'
|
||||||
s.add_dependency 'bson_ext', '~> 1.5.2'
|
s.add_dependency 'bson_ext', '~> 1.5.2'
|
||||||
s.add_dependency 'mongoid', '~> 2.4.2'
|
s.add_dependency 'mongoid', '~> 2.4.3'
|
||||||
s.add_dependency 'locomotive_mongoid_acts_as_tree', '~> 0.1.5.8'
|
s.add_dependency 'locomotive_mongoid_acts_as_tree', '~> 0.1.5.8'
|
||||||
|
|
||||||
s.add_dependency 'custom_fields', '~> 2.0.0.rc2'
|
s.add_dependency 'custom_fields', '~> 2.0.0.rc2'
|
||||||
|
Loading…
Reference in New Issue
Block a user