formnestic 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (45) hide show
  1. data/.document +5 -0
  2. data/.rspec +2 -0
  3. data/.travis.yml +5 -0
  4. data/.watchr +31 -0
  5. data/Gemfile +27 -0
  6. data/Gemfile.lock +133 -0
  7. data/MIT-LICENSE +20 -0
  8. data/README.markdown +126 -0
  9. data/Rakefile +44 -0
  10. data/VERSION +1 -0
  11. data/app/assets/.DS_Store +0 -0
  12. data/app/assets/javascripts/formnestic/formnestic.js +139 -0
  13. data/app/assets/stylesheets/formnestic/entypo.css.scss +327 -0
  14. data/app/assets/stylesheets/formnestic/entypo.eot +0 -0
  15. data/app/assets/stylesheets/formnestic/entypo.svg +296 -0
  16. data/app/assets/stylesheets/formnestic/entypo.ttf +0 -0
  17. data/app/assets/stylesheets/formnestic/entypo.woff +0 -0
  18. data/app/assets/stylesheets/formnestic/formnestic.css.scss +167 -0
  19. data/config/locales/formnestic.en.yml +8 -0
  20. data/formnestic.gemspec +112 -0
  21. data/lib/formnestic/form_builder/base_builder.rb +55 -0
  22. data/lib/formnestic/form_builder/list_form_builder.rb +30 -0
  23. data/lib/formnestic/form_builder/table_form_builder.rb +94 -0
  24. data/lib/formnestic/form_builder.rb +13 -0
  25. data/lib/formnestic/helpers/inputs_helper.rb +82 -0
  26. data/lib/formnestic/helpers.rb +9 -0
  27. data/lib/formnestic/inputs/base/labelling.rb +15 -0
  28. data/lib/formnestic/inputs/base/wrapping.rb +52 -0
  29. data/lib/formnestic/inputs/base.rb +12 -0
  30. data/lib/formnestic/inputs.rb +7 -0
  31. data/lib/formnestic.rb +72 -0
  32. data/lib/generators/formnestic/install_generator.rb +36 -0
  33. data/log/development.log +0 -0
  34. data/rwatchr +1 -0
  35. data/screenshots/list_form.png +0 -0
  36. data/screenshots/table_form.png +0 -0
  37. data/spec/helpers/nested_model_helper_spec.rb +277 -0
  38. data/spec/helpers/nested_model_list_helper_spec.rb +51 -0
  39. data/spec/inputs/boolean_input_spec.rb +223 -0
  40. data/spec/spec_helper.rb +553 -0
  41. data/spec/support/custom_macros.rb +528 -0
  42. data/spec/support/deferred_garbage_collection.rb +21 -0
  43. data/spec/support/deprecation.rb +6 -0
  44. data/spec/support/test_environment.rb +31 -0
  45. metadata +271 -0
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --color
2
+ --format=progress
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ language: ruby
2
+ rvm:
3
+ - 1.9.3
4
+ - 2.0.0
5
+ script: bundle exec rake spec
data/.watchr ADDED
@@ -0,0 +1,31 @@
1
+ def run_spec(file)
2
+ unless File.exist?(file)
3
+ puts "#{file} does not exist"
4
+ return
5
+ end
6
+
7
+ puts "Running #{file}"
8
+ system "rspec #{file} --backtrace"
9
+ puts
10
+ end
11
+
12
+ watch("spec/.*/*_spec\.rb") do |match|
13
+ run_spec match[0]
14
+ end
15
+
16
+ watch("app/(.*/.*)\.rb") do |match|
17
+ # run_spec %{spec/#{match[1]}_spec.rb}
18
+ run_spec "spec/helpers/nested_model_list_helper_spec.rb"
19
+ run_spec "spec/helpers/nested_model_helper_spec.rb"
20
+ end
21
+
22
+ watch("lib/(.*/.*)\.rb") do |match|
23
+ # run_spec %{spec/#{match[1]}_spec.rb}
24
+ run_spec "spec/helpers/nested_model_list_helper_spec.rb"
25
+ run_spec "spec/helpers/nested_model_helper_spec.rb"
26
+ end
27
+
28
+ watch("lib/.*\.rb") do |match|
29
+ run_spec "spec/helpers/nested_model_list_helper_spec.rb"
30
+ run_spec "spec/helpers/nested_model_helper_spec.rb"
31
+ end
data/Gemfile ADDED
@@ -0,0 +1,27 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+
9
+ group :development, :test do
10
+ gem "shoulda", ">= 0"
11
+ gem "bundler", "~> 1.0"
12
+ gem 'rdoc', '~> 3.4'
13
+ gem "jeweler", "~> 2.0.1"
14
+ gem 'rspec-rails', '~> 2.14.0'
15
+ gem 'rspec_tag_matchers', '>= 1.0.0'
16
+ gem 'tzinfo'
17
+ gem 'spork'
18
+ gem 'watchr'
19
+ end
20
+
21
+ group :test do
22
+ gem 'rake'
23
+ end
24
+
25
+ gem 'actionpack', '>= 3.2.13'
26
+ gem 'formtastic', "~> 2.2.1"
27
+ # gem 'formtastic', path: '../formtastic'
data/Gemfile.lock ADDED
@@ -0,0 +1,133 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ actionpack (3.2.18)
5
+ activemodel (= 3.2.18)
6
+ activesupport (= 3.2.18)
7
+ builder (~> 3.0.0)
8
+ erubis (~> 2.7.0)
9
+ journey (~> 1.0.4)
10
+ rack (~> 1.4.5)
11
+ rack-cache (~> 1.2)
12
+ rack-test (~> 0.6.1)
13
+ sprockets (~> 2.2.1)
14
+ activemodel (3.2.18)
15
+ activesupport (= 3.2.18)
16
+ builder (~> 3.0.0)
17
+ activesupport (3.2.18)
18
+ i18n (~> 0.6, >= 0.6.4)
19
+ multi_json (~> 1.0)
20
+ addressable (2.3.6)
21
+ builder (3.0.4)
22
+ descendants_tracker (0.0.4)
23
+ thread_safe (~> 0.3, >= 0.3.1)
24
+ diff-lcs (1.2.5)
25
+ erubis (2.7.0)
26
+ faraday (0.9.0)
27
+ multipart-post (>= 1.2, < 3)
28
+ formtastic (2.2.1)
29
+ actionpack (>= 3.0)
30
+ git (1.2.7)
31
+ github_api (0.11.3)
32
+ addressable (~> 2.3)
33
+ descendants_tracker (~> 0.0.1)
34
+ faraday (~> 0.8, < 0.10)
35
+ hashie (>= 1.2)
36
+ multi_json (>= 1.7.5, < 2.0)
37
+ nokogiri (~> 1.6.0)
38
+ oauth2
39
+ hashie (3.0.0)
40
+ highline (1.6.21)
41
+ hike (1.2.3)
42
+ i18n (0.6.9)
43
+ jeweler (2.0.1)
44
+ builder
45
+ bundler (>= 1.0)
46
+ git (>= 1.2.5)
47
+ github_api
48
+ highline (>= 1.6.15)
49
+ nokogiri (>= 1.5.10)
50
+ rake
51
+ rdoc
52
+ journey (1.0.4)
53
+ json (1.8.1)
54
+ jwt (1.0.0)
55
+ mini_portile (0.6.0)
56
+ multi_json (1.10.1)
57
+ multi_xml (0.5.5)
58
+ multipart-post (2.0.0)
59
+ nokogiri (1.6.2.1)
60
+ mini_portile (= 0.6.0)
61
+ oauth2 (0.9.4)
62
+ faraday (>= 0.8, < 0.10)
63
+ jwt (~> 1.0)
64
+ multi_json (~> 1.3)
65
+ multi_xml (~> 0.5)
66
+ rack (~> 1.2)
67
+ rack (1.4.5)
68
+ rack-cache (1.2)
69
+ rack (>= 0.4)
70
+ rack-ssl (1.3.4)
71
+ rack
72
+ rack-test (0.6.2)
73
+ rack (>= 1.0)
74
+ railties (3.2.18)
75
+ actionpack (= 3.2.18)
76
+ activesupport (= 3.2.18)
77
+ rack-ssl (~> 1.3.2)
78
+ rake (>= 0.8.7)
79
+ rdoc (~> 3.4)
80
+ thor (>= 0.14.6, < 2.0)
81
+ rake (10.3.2)
82
+ rdoc (3.12.2)
83
+ json (~> 1.4)
84
+ rspec-core (2.14.8)
85
+ rspec-expectations (2.14.5)
86
+ diff-lcs (>= 1.1.3, < 2.0)
87
+ rspec-mocks (2.14.6)
88
+ rspec-rails (2.14.2)
89
+ actionpack (>= 3.0)
90
+ activemodel (>= 3.0)
91
+ activesupport (>= 3.0)
92
+ railties (>= 3.0)
93
+ rspec-core (~> 2.14.0)
94
+ rspec-expectations (~> 2.14.0)
95
+ rspec-mocks (~> 2.14.0)
96
+ rspec_tag_matchers (1.0.0)
97
+ nokogiri (>= 1.4.0)
98
+ rspec-rails (>= 1.2.6)
99
+ shoulda (3.5.0)
100
+ shoulda-context (~> 1.0, >= 1.0.1)
101
+ shoulda-matchers (>= 1.4.1, < 3.0)
102
+ shoulda-context (1.2.1)
103
+ shoulda-matchers (2.6.1)
104
+ activesupport (>= 3.0.0)
105
+ spork (0.9.2)
106
+ sprockets (2.2.2)
107
+ hike (~> 1.2)
108
+ multi_json (~> 1.0)
109
+ rack (~> 1.0)
110
+ tilt (~> 1.1, != 1.3.0)
111
+ thor (0.19.1)
112
+ thread_safe (0.3.4)
113
+ tilt (1.4.1)
114
+ tzinfo (1.2.1)
115
+ thread_safe (~> 0.1)
116
+ watchr (0.7)
117
+
118
+ PLATFORMS
119
+ ruby
120
+
121
+ DEPENDENCIES
122
+ actionpack (>= 3.2.13)
123
+ bundler (~> 1.0)
124
+ formtastic (~> 2.2.1)
125
+ jeweler (~> 2.0.1)
126
+ rake
127
+ rdoc (~> 3.4)
128
+ rspec-rails (~> 2.14.0)
129
+ rspec_tag_matchers (>= 1.0.0)
130
+ shoulda
131
+ spork
132
+ tzinfo
133
+ watchr
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2014 Formnestic
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,126 @@
1
+ # formnestic
2
+
3
+ [![Build Status](https://travis-ci.org/jameshuynh/formnestic.svg?branch=master)](https://travis-ci.org/jameshuynh/formnestic)
4
+ [![Code Climate](https://codeclimate.com/github/jameshuynh/formnestic.png)](https://codeclimate.com/github/jameshuynh/formnestic)
5
+
6
+ An extension of famous [Formtastic Form Builder](https://github.com/justinfrench/formtastic) to make building nested and association form with nested model addable and removable ability extremely easy and simple.
7
+
8
+ ### Compatibility
9
+
10
+ - Formnestic gem requires ``formtastic`` gem version ``2.2.1``
11
+ - Formnestic gem is Rails 3 and Rails 4 compatible
12
+
13
+ ### Installation
14
+
15
+ Add Formnestic to your Gemfile and run ``bundle install``:
16
+
17
+ ```ruby
18
+ gem "formnestic", '~> 1.0.0'
19
+ ```
20
+
21
+ then run the installation
22
+
23
+ ```bash
24
+ bundle exec rails g formnestic:install
25
+ ```
26
+
27
+ ### Features
28
+
29
+ - Table form with row addable and removable
30
+ - List form with entry addable and removable
31
+
32
+ ### Usage
33
+
34
+ Usage for rails 3 and rails 4 are almost the same, the only difference is that in Rails 4, you will need to remove all the ``attr_accessible`` in Rails 3 and use strong parameters in rails controller.
35
+
36
+ Basically, you can now add the following options into ``semantic_fields_for`` call in Formtastic
37
+
38
+ - ``display_type``: If you want your nested form to have table style, you can supply in ``table`` string
39
+ - ``row_removable``: Allow nested model entry to be removed.
40
+ - ``row_addable``: Allow nested model entry to be added.
41
+ - ``min_entry``: Minimum number of nested model entries that is allowed. An alert will be shown if user tries to delete the last entry that meets this minumum number.
42
+ - ``max_entry``: Maximum number of nested model entries that is allowed. Add button will be hidden if user has already added enough entries.
43
+ - ``new_record_link_label``: The label to be displayed in the Add button.
44
+ - ``table_headers``: A two(2) dimensional arrays, in which each array is presenting a row in table header row. For instance:
45
+
46
+ ```rb
47
+ [
48
+ [{label: 'Column 1', wrapper_html: {class: "big-column"}}, {label: 'Column 2'}],
49
+ [{attr: :name}, {attr: :description}],
50
+ ]
51
+ ```
52
+
53
+ will yield a table header with 2 rows. The first row has 2 columns labeled ``Column 1`` and ``Column 2`` respectively, the second row labelled respected attribute's name of the nested model.
54
+
55
+ The form view is the same between Rails 3 and Rails 4
56
+
57
+ ```erb
58
+ <%= semantic_form_for @quiz_pool do |quiz_pool_form| %>
59
+ <%= quiz_pool_form.inputs do %>
60
+ <%= quiz_pool_form.input :title %>
61
+ <%= quiz_pool_form.input :description %>
62
+ <li>
63
+ <%= quiz_pool_form.semantic_fields_for :quiz_pool_questions, {
64
+ row_removable: true,
65
+ row_addable: true,
66
+ min_entry: 1,
67
+ max_entry: 5,
68
+ new_record_link_label: "+ question"
69
+ } do |quiz_pool_question_builder| %>
70
+ <%= quiz_pool_question_builder.inputs do %>
71
+ <%= quiz_pool_question_builder.input :description %>
72
+ <%= quiz_pool_question_builder.input :score %>
73
+ <% end %>
74
+ <% end %>
75
+ </li>
76
+ <% end %>
77
+ <%= quiz_pool_form.submit %>
78
+ <% end %>
79
+ ```
80
+
81
+ See the usage for each of Rails version below for more details
82
+
83
+ #### Rails 3 Usage
84
+
85
+ - [Usage & Guideline](https://github.com/jameshuynh/formnestic/wiki/Rails-3-Guideline-and-Usage)
86
+ - [Sample project for Rails 3.2.18](https://github.com/jameshuynh/formnestic-sample-rails3)
87
+
88
+ #### Rails 4 Usage
89
+
90
+ - [Usage & Guideline](https://github.com/jameshuynh/formnestic/wiki/Rails-4-Guideline-and-Usage)
91
+ - [Sample project for Rails 4.1.1](https://github.com/jameshuynh/formnestic-sample-rails4)
92
+
93
+
94
+ #### Screenshots
95
+
96
+ ##### Table Form
97
+
98
+ <p align="left" >
99
+ <img src="https://raw.githubusercontent.com/jameshuynh/formnestic/master/screenshots/table_form.png" alt="Table Form" title="Table Form">
100
+ </p>
101
+
102
+ #### List Form
103
+
104
+ <p align="left" >
105
+ <img src="https://raw.githubusercontent.com/jameshuynh/formnestic/master/screenshots/list_form.png" alt="List Form" title="List Form">
106
+ </p>
107
+
108
+ ### Roadmap to version 2.0
109
+
110
+ - Sortable between nested model entry (including rows in a table)
111
+ - Delegator for alert view
112
+ - Ability to lock an entry
113
+
114
+ ## Contributing to formnestic
115
+
116
+ - Contribution, Suggestion and Issues are very much appreciated :). Please also fork and send your pull request!
117
+ - Make sure to add tests for it when sending for pull requests. This is important so I don't break it in a future version unintentionally.
118
+
119
+ ## Credits
120
+
121
+ - Big thanks to [Justin French](https://github.com/justinfrench) for bringing [Formtastic](https://github.com/justinfrench/formtastic) to our lives. It has enabled us to effectively code form much easier in rails and has enabled this gem to happen.
122
+
123
+ ## Copyright
124
+
125
+ Copyright (c) 2014 James, released under the MIT license
126
+
data/Rakefile ADDED
@@ -0,0 +1,44 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ require 'rspec/core/rake_task'
6
+ begin
7
+ Bundler.setup(:default, :development)
8
+ rescue Bundler::BundlerError => e
9
+ $stderr.puts e.message
10
+ $stderr.puts "Run `bundle install` to install missing gems"
11
+ exit e.status_code
12
+ end
13
+ require 'rake'
14
+
15
+ require 'jeweler'
16
+ Jeweler::Tasks.new do |gem|
17
+ # gem is a Gem::Specification... see http://guides.rubygems.org/specification-reference/ for more options
18
+ gem.name = "formnestic"
19
+ gem.homepage = "http://github.com/jameshuynh/formnestic"
20
+ gem.license = "MIT"
21
+ gem.summary = %Q{An extension of formtastic form builder gem}
22
+ gem.description = %Q{An extension of famous Formtastic Form Builder to make building nested and association form with nested model addable and removable ability extremely easy and simple}
23
+ gem.email = "james@rubify.com"
24
+ gem.authors = ["James"]
25
+ gem.version = File.exist?('VERSION') ? File.read('VERSION') : ""
26
+ gem.files.exclude 'screenshots'
27
+ # dependencies defined in Gemfile
28
+ end
29
+ Jeweler::RubygemsDotOrgTasks.new
30
+
31
+ desc 'Test the formtastic plugin.'
32
+ RSpec::Core::RakeTask.new('spec') do |t|
33
+ t.pattern = FileList['spec/**/*_spec.rb']
34
+ end
35
+
36
+ desc 'Test the formtastic inputs.'
37
+ RSpec::Core::RakeTask.new('spec:inputs') do |t|
38
+ t.pattern = FileList['spec/inputs/*_spec.rb']
39
+ end
40
+
41
+ desc 'Test the formtastic plugin with specdoc formatting and colors'
42
+ RSpec::Core::RakeTask.new('specdoc') do |t|
43
+ t.pattern = FileList['spec/**/*_spec.rb']
44
+ end
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 1.0.0
Binary file
@@ -0,0 +1,139 @@
1
+ var Formnestic = {
2
+ getNumberOfShowingEntriesInATable: function(table) {
3
+ var counter = 0;
4
+ table.find('tbody:first').find("tr").each(function() {
5
+ var dom = $(this);
6
+ if(!dom.hasClass("formnestic-deleted-row") && !dom.hasClass("formnestic-table-no-border")) {
7
+ counter = counter + 1;
8
+ }//end if
9
+ });
10
+ return counter;
11
+ },
12
+
13
+ getNumberOfShowingEntriesInANestedModelContainer: function(listContainer) {
14
+ var counter = 0;
15
+ listContainer.children().each(function() {
16
+ var dom = $(this);
17
+ if(!dom.hasClass("formnestic-deleted-row")) {
18
+ counter = counter + 1;
19
+ }//end if
20
+ });
21
+ return counter;
22
+ },
23
+
24
+ removeAListEntry: function(deleteEntryLinkDom) {
25
+ deleteEntryLinkDom = $(deleteEntryLinkDom);
26
+ var listContainer = deleteEntryLinkDom.parents('div.formnestic-nested-model-container:first').find("div.formnestic-list-entries-container");
27
+ var nestedModelContainer = listContainer.parent();
28
+
29
+ var addRowLinkContainer = nestedModelContainer.find("div.formnestic-list-new-entry-link-container:first");
30
+ var numberOfShowingEntries = Formnestic.getNumberOfShowingEntriesInANestedModelContainer(listContainer);
31
+ var minNumberOfEntries = parseInt(nestedModelContainer.attr("min_entry"), 10);
32
+ var maxNumberOfEntries = parseInt(nestedModelContainer.attr("max_entry"), 10);
33
+
34
+ if (minNumberOfEntries !== -1 && numberOfShowingEntries <= minNumberOfEntries) {
35
+ return alert(nestedModelContainer.attr("min_entry_alert_message"));
36
+ }//end if
37
+
38
+ var entryContainer = deleteEntryLinkDom.parents("fieldset.inputs:first");
39
+ entryContainer.addClass("formnestic-deleted-row");
40
+ entryContainer.find(".formnestic-destroy-input").val("true");
41
+
42
+ var counter = this.addOddAndEventClassForListContainer(listContainer);
43
+ if (maxNumberOfEntries !== -1 && counter >= maxNumberOfEntries) {
44
+ addRowLinkContainer.addClass("formnestic-hidden");
45
+ } else {
46
+ addRowLinkContainer.removeClass("formnestic-hidden");
47
+ }//end else
48
+
49
+ entryContainer.fadeOut(function() {});
50
+ },
51
+
52
+ removeATableEntry: function(deleteEntryLinkDom) {
53
+ deleteEntryLinkDom = $(deleteEntryLinkDom);
54
+ var table = deleteEntryLinkDom.parents("table:first");
55
+ var addRowLink = table.find("a.formnestic-add-row-field-link:first");
56
+ var numberOfShowingEntries = Formnestic.getNumberOfShowingEntriesInATable(table);
57
+ var minNumberOfEntries = parseInt(table.attr("min_entry"), 10);
58
+ var maxNumberOfEntries = parseInt(table.attr("max_entry"), 10);
59
+ if (minNumberOfEntries !== -1 && numberOfShowingEntries <= minNumberOfEntries) {
60
+ return alert(table.attr("min_entry_alert_message"));
61
+ }//end if
62
+
63
+ var trContainer = deleteEntryLinkDom.parents("tr:first");
64
+ trContainer.find(".formnestic-destroy-input").val("true");
65
+ trContainer.addClass("formnestic-deleted-row");
66
+ var counter = this.addOddAndEvenClassForTable(table);
67
+ if (maxNumberOfEntries !== -1 && counter >= maxNumberOfEntries) {
68
+ addRowLink.addClass("formnestic-hidden");
69
+ } else {
70
+ addRowLink.removeClass("formnestic-hidden");
71
+ }//end else
72
+ trContainer.fadeOut(function() {});
73
+ },
74
+
75
+ addOddAndEventClassForListContainer: function(listContainer) {
76
+ var counter = 0;
77
+ listContainer.children().each(function() {
78
+ var dom = $(this);
79
+ if(!dom.hasClass("formnestic-deleted-row")) {
80
+ dom.removeClass("formnestic-odd-row formnestic-even-row").addClass(counter % 2 === 0 ? "formnestic-even-row" : "formnestic-odd-row");
81
+ var counterDom = dom.find("span.formnestic-li-fieldset-for-order:first");
82
+ counter = counter + 1;
83
+ counterDom.html(counter);
84
+ }
85
+ });
86
+ return counter;
87
+ },
88
+
89
+ addOddAndEvenClassForTable: function(table) {
90
+ var counter = 0;
91
+ $(table).find("tbody:first").find("tr").each(function() {
92
+ var trDom = $(this);
93
+ if(!trDom.hasClass('formnestic-deleted-row') && !trDom.hasClass("formnestic-table-no-border")) {
94
+ trDom.removeClass("formnestic-odd-row formnestic-even-row").addClass(counter % 2 === 0 ? "formnestic-even-row" : "formnestic-odd-row")
95
+ counter = counter + 1;
96
+ }
97
+ });
98
+
99
+ return counter;
100
+ },
101
+
102
+ addNewListEntry: function(linkDom, associationName, content) {
103
+ var newId = new Date().getTime();
104
+ var regexp = new RegExp("new_" + associationName, "g");
105
+ var linkDomContainer = $(linkDom).parent();
106
+ var listContainer = linkDomContainer.parents('div.formnestic-nested-model-container:first').find("div.formnestic-list-entries-container");
107
+ var nestedModelContainer = listContainer.parent();
108
+ var maxNumberOfEntries = parseInt(nestedModelContainer.attr('max_entry'), 10);
109
+
110
+ var entryContainer = $(content.replace(regexp, newId)).appendTo(listContainer);
111
+ var counter = this.addOddAndEventClassForListContainer(listContainer);
112
+ if (maxNumberOfEntries !== -1 && counter >= maxNumberOfEntries) {
113
+ linkDomContainer.addClass("formnestic-hidden");
114
+ } else {
115
+ linkDomContainer.removeClass("formnestic-hidden");
116
+ }//end else
117
+
118
+ entryContainer.css({display: 'none'}).fadeIn();
119
+ },
120
+
121
+ addNewTableEntry: function(linkDom, associationName, content) {
122
+ var newId = new Date().getTime();
123
+ var regexp = new RegExp("new_" + associationName, "g");
124
+ var linkDomjQuery = $(linkDom);
125
+ var table = linkDomjQuery.parents('table:first');
126
+
127
+ var entryContainer = $(content.replace(regexp, newId)).insertBefore(linkDomjQuery.parents("tr:first"));
128
+
129
+ var counter = this.addOddAndEvenClassForTable(table);
130
+ var maxNumberOfEntries = parseInt(table.attr('max_entry'), 10);
131
+ if (maxNumberOfEntries !== -1 && counter >= maxNumberOfEntries) {
132
+ linkDomjQuery.addClass("formnestic-hidden");
133
+ } else {
134
+ linkDomjQuery.removeClass("formnestic-hidden");
135
+ }//end else
136
+
137
+ entryContainer.css({display: 'none'}).fadeIn();
138
+ }
139
+ };