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
|
||||
remote: ../gems/custom_fields
|
||||
specs:
|
||||
custom_fields (2.0.0.rc2)
|
||||
activesupport (~> 3.1.3)
|
||||
carrierwave-mongoid (~> 0.1.3)
|
||||
mongoid (~> 2.4.2)
|
||||
mongoid (~> 2.4.3)
|
||||
|
||||
GEM
|
||||
remote: http://rubygems.org/
|
||||
specs:
|
||||
RedCloth (4.2.9)
|
||||
SystemTimer (1.2.3)
|
||||
ZenTest (4.6.2)
|
||||
actionmailer (3.1.3)
|
||||
actionpack (= 3.1.3)
|
||||
@ -161,7 +201,7 @@ GEM
|
||||
mocha (0.9.12)
|
||||
mongo (1.5.2)
|
||||
bson (= 1.5.2)
|
||||
mongoid (2.4.2)
|
||||
mongoid (2.4.3)
|
||||
activemodel (~> 3.1)
|
||||
mongo (~> 1.3)
|
||||
tzinfo (~> 0.3.22)
|
||||
@ -193,7 +233,7 @@ GEM
|
||||
activesupport (= 3.1.3)
|
||||
bundler (~> 1.0)
|
||||
railties (= 3.1.3)
|
||||
rails-backbone (0.5.4)
|
||||
rails-backbone (0.5.5)
|
||||
coffee-script (~> 2.2.0)
|
||||
ejs (~> 1.0.0)
|
||||
rails (~> 3.1.0)
|
||||
@ -253,7 +293,7 @@ GEM
|
||||
polyglot
|
||||
polyglot (>= 0.3.1)
|
||||
tzinfo (0.3.31)
|
||||
uglifier (1.0.4)
|
||||
uglifier (1.2.3)
|
||||
execjs (>= 0.3.0)
|
||||
multi_json (>= 1.0.2)
|
||||
unicorn (4.1.1)
|
||||
@ -269,55 +309,20 @@ PLATFORMS
|
||||
ruby
|
||||
|
||||
DEPENDENCIES
|
||||
RedCloth (~> 4.2.8)
|
||||
SystemTimer
|
||||
ZenTest
|
||||
actionmailer-with-request (~> 0.3.0)
|
||||
autotest
|
||||
bson_ext (~> 1.5.2)
|
||||
cancan (~> 1.6.7)
|
||||
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
|
||||
custom_fields!
|
||||
database_cleaner
|
||||
devise (~> 1.5.3)
|
||||
dragonfly (~> 0.9.8)
|
||||
factory_girl_rails (~> 1.3.0)
|
||||
flash_cookie_session (~> 1.1.1)
|
||||
fog (~> 1.0.0)
|
||||
formtastic (~> 2.0.2)
|
||||
growl-glue
|
||||
haml (~> 3.1.3)
|
||||
highline (~> 1.6.2)
|
||||
httparty (~> 0.8.1)
|
||||
jquery-rails (~> 1.0.16)
|
||||
kaminari (~> 0.13.0)
|
||||
launchy
|
||||
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)
|
||||
locomotive_cms!
|
||||
mocha (= 0.9.12)
|
||||
mongo (~> 1.5.2)
|
||||
mongoid (~> 2.4.2)
|
||||
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-rails (= 2.6.1)
|
||||
sanitize (~> 2.0.3)
|
||||
sass-rails (~> 3.1.5)
|
||||
shoulda-matchers
|
||||
uglifier (~> 1.0.4)
|
||||
unicorn
|
||||
xpath (~> 0.1.4)
|
||||
|
@ -41,6 +41,9 @@ class Locomotive.Views.ContentTypes.CustomFieldEntryView extends Backbone.View
|
||||
@$('li.input.select-options').show()
|
||||
when 'text'
|
||||
@$('li.input.text-formatting').show()
|
||||
when 'belongs_to'
|
||||
@$('li.input.localized').hide()
|
||||
@$('li.input.class-name').show()
|
||||
|
||||
render_select_options_view: ->
|
||||
@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) ->
|
||||
input = @$("##{@model.paramRoot}_#{attribute}")
|
||||
input = @$("##{@model.paramRoot}_#{attribute}_id") if 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
|
||||
|
||||
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]
|
||||
end
|
||||
end
|
||||
@ -41,6 +41,14 @@ module Locomotive::CustomFieldsHelper
|
||||
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
|
||||
# current_site.reload.content_types.collect { |c| [c.name, c.content_klass.to_s] }
|
||||
# end
|
||||
|
@ -30,10 +30,10 @@ module Locomotive
|
||||
#
|
||||
def safe_attributes
|
||||
self.source.custom_fields_recipe['rules'].map do |rule|
|
||||
case rule['type']
|
||||
when 'select' then "#{rule['name']}_id"
|
||||
when 'date' then "formatted_#{rule['name']}"
|
||||
when 'file' then [rule['name'], "remove_#{rule['name']}"]
|
||||
case rule['type'].to_sym
|
||||
when :date then "formatted_#{rule['name']}"
|
||||
when :file then [rule['name'], "remove_#{rule['name']}"]
|
||||
when :select, :belongs_to then "#{rule['name']}_id"
|
||||
else
|
||||
rule['name']
|
||||
end
|
||||
@ -76,10 +76,11 @@ module Locomotive
|
||||
#
|
||||
# @returns [ Object ] A string or an array of names
|
||||
def getters_for(name, type)
|
||||
case type
|
||||
when 'select' then [name, "#{name}_id"]
|
||||
when 'date' then "formatted_#{name}"
|
||||
when 'file' then "#{name}_url"
|
||||
case type.to_sym
|
||||
when :select then [name, "#{name}_id"]
|
||||
when :date then "formatted_#{name}"
|
||||
when :file then "#{name}_url"
|
||||
when :belongs_to then "#{name}_id"
|
||||
else
|
||||
name
|
||||
end
|
||||
|
@ -38,12 +38,16 @@
|
||||
|
||||
= 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 :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
|
||||
= link_to 'toggle', '#', :class => 'toggle'
|
||||
= 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'
|
||||
|
||||
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 '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 'custom_fields', '~> 2.0.0.rc2'
|
||||
|
Loading…
Reference in New Issue
Block a user