diff --git a/Gemfile.lock b/Gemfile.lock index c14da849..8a7c0223 100644 --- a/Gemfile.lock +++ b/Gemfile.lock @@ -17,13 +17,13 @@ GIT GIT remote: git://github.com/locomotivecms/custom_fields.git - revision: e54c3ddfce0e24668d02c372c6143a722718e215 + revision: 5b0e68859eaca41ac9d7a0231c6cd68ad66018b8 branch: 2.0.0.rc specs: - custom_fields (2.0.0.rc8) + custom_fields (2.0.0.rc9) activesupport (~> 3.2.1) carrierwave-mongoid (~> 0.1.3) - mongoid (~> 2.4.5) + mongoid (~> 2.4.7) PATH remote: . @@ -36,7 +36,7 @@ PATH carrierwave-mongoid (~> 0.1.3) cells (~> 3.8.0) codemirror-rails (~> 2.21) - custom_fields (~> 2.0.0.rc8) + custom_fields (~> 2.0.0.rc9) devise (~> 1.5.3) dragonfly (~> 0.9.8) flash_cookie_session (~> 1.1.1) @@ -112,8 +112,8 @@ GEM xpath (~> 0.1.4) carrierwave (0.5.8) activesupport (~> 3.0) - carrierwave-mongoid (0.1.3) - carrierwave (>= 0.5.6) + carrierwave-mongoid (0.1.4) + carrierwave (~> 0.5.6) mongoid (~> 2.1) cells (3.8.3) actionpack (~> 3.0) @@ -175,7 +175,7 @@ GEM formtastic (2.0.2) rails (~> 3.0) fssm (0.2.8.1) - gherkin (2.9.1) + gherkin (2.9.3) json (>= 1.4.6) haml (3.1.4) highline (1.6.11) @@ -188,7 +188,7 @@ GEM jquery-rails (1.0.19) railties (~> 3.0) thor (~> 0.14) - json (1.6.5) + json (1.6.6) kaminari (0.13.0) actionpack (>= 3.0.0) activesupport (>= 3.0.0) @@ -302,10 +302,10 @@ GEM polyglot polyglot (>= 0.3.1) tzinfo (0.3.32) - uglifier (1.2.3) + uglifier (1.2.4) execjs (>= 0.3.0) multi_json (>= 1.0.2) - unicorn (4.2.0) + unicorn (4.2.1) kgio (~> 2.6) rack raindrops (~> 0.7) diff --git a/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee b/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee index a7ca7414..11b1389c 100644 --- a/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/content_entries/_form_view.js.coffee @@ -73,18 +73,20 @@ class Locomotive.Views.ContentEntries.FormView extends Locomotive.Views.Shared.F new_entry = new Locomotive.Models.ContentEntry(@options["#{name}_new_entry"]) view = new Locomotive.Views.Shared.Fields.HasManyView model: @model, name: name, new_entry: new_entry, inverse_of: inverse_of - @_has_many_field_views.push(view) + if view.ui_enabled() + @_has_many_field_views.push(view) - @$("##{@model.paramRoot}_#{name}_input label").after(view.render().el) + @$("##{@model.paramRoot}_#{name}_input label").after(view.render().el) enable_many_to_many_fields: -> _.each @model.get('many_to_many_custom_fields'), (field) => name = field[0] view = new Locomotive.Views.Shared.Fields.ManyToManyView model: @model, name: name, all_entries: @options["all_#{name}_entries"] - @_many_to_many_field_views.push(view) + if view.ui_enabled() + @_many_to_many_field_views.push(view) - @$("##{@model.paramRoot}_#{name}_input label").after(view.render().el) + @$("##{@model.paramRoot}_#{name}_input label").after(view.render().el) slugify_label_field: -> @$('li.input.highlighted > input[type=text]').slugify(target: @$('#content_entry__slug')) diff --git a/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee index 71a328f4..1a1a7e1c 100644 --- a/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/fields/has_many_view.js.coffee @@ -34,6 +34,9 @@ class Locomotive.Views.Shared.Fields.HasManyView extends Backbone.View return @ + ui_enabled: -> + @template()? + insert_entries: -> if @collection.length > 0 @collection.each (entry) => @insert_entry(entry) diff --git a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee index 65bc982e..01c5c681 100644 --- a/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee +++ b/app/assets/javascripts/locomotive/views/shared/fields/many_to_many_view.js.coffee @@ -39,6 +39,9 @@ class Locomotive.Views.Shared.Fields.ManyToManyView extends Backbone.View return @ + ui_enabled: -> + @template()? + insert_entries: -> if @collection.length > 0 @collection.each (entry) => @insert_entry(entry) diff --git a/app/presenters/locomotive/content_entry_presenter.rb b/app/presenters/locomotive/content_entry_presenter.rb index 1b2e5722..49c38786 100644 --- a/app/presenters/locomotive/content_entry_presenter.rb +++ b/app/presenters/locomotive/content_entry_presenter.rb @@ -43,7 +43,7 @@ module Locomotive hash[meth]= (if self.source.custom_fields_methods.include?(meth.to_s) if self.source.is_a_custom_field_many_relationship?(meth.to_s) # go deeper - self.source.send(meth).map { |entry| entry.to_presenter(:depth => self.depth + 1) } + self.source.send(meth).ordered.map { |entry| entry.to_presenter(:depth => self.depth + 1) } else self.source.send(meth) rescue nil end diff --git a/features/public/many_to_many.feature b/features/public/many_to_many.feature new file mode 100644 index 00000000..fb496604 --- /dev/null +++ b/features/public/many_to_many.feature @@ -0,0 +1,52 @@ +Feature: Many to Many Association + As a designer + In order to make dealing with models easier + I want to be able to display other models that have a many to many association + + Background: + Given I have the site: "test site" set up + And I have a custom model named "Articles" with + | label | type | required | + | Title | string | true | + | Body | string | false | + And I have a custom model named "Projects" with + | label | type | required | target | + | Name | string | true | | + | Description | text | false | | + And I set up a many_to_many relationship between "Articles" and "Projects" + And I have entries for "Articles" with + | title | body | + | Hello world | Lorem ipsum | + | Lorem ipsum | Lorem ipsum... | + And I have entries for "Projects" with + | name | description | + | My sexy project | Lorem ipsum | + | Foo project | Lorem ipsum... | + | Bar project | Lorem ipsum... | + | Baz project | Lorem ipsum... | + And I attach the "My sexy project" project to the "Hello world" article + And I attach the "Baz project" project to the "Hello world" article + And I attach the "Foo project" project to the "Hello world" article + + Scenario: Displaying the entries of a many to many association + Given a page named "article-projects" with the template: + """ + {% assign article = contents.articles.first %} +