formnestic 1.0.2 → 1.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/README.markdown +2 -0
- data/app/assets/javascripts/formnestic/formnestic.js +13 -11
- data/formnestic.gemspec +1 -1
- data/lib/formnestic/form_builder/base_builder.rb +18 -21
- data/lib/formnestic/form_builder/table_form_builder.rb +156 -56
- data/lib/formnestic/form_builder.rb +4 -5
- data/lib/formnestic/helpers/inputs_helper.rb +44 -38
- data/lib/formnestic/helpers.rb +3 -3
- data/lib/formnestic/inputs/base/labelling.rb +3 -3
- data/lib/formnestic/inputs/base/wrapping.rb +40 -18
- data/lib/formnestic/inputs/base.rb +2 -2
- data/lib/formnestic.rb +20 -67
- metadata +33 -62
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: ebe16f838c5cc06d26df3234123b7528acf0ca10
|
4
|
+
data.tar.gz: c27a6423ca05de992ba11853d2f0443504bb3894
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 185ff7ebc0baebb71cef55379a41814b41542b4f920b66086fbfad6f3f0ebf7100915301a4f1919908257004cfe53208b23945ecbf60038e260219981ab85a82
|
7
|
+
data.tar.gz: 936c96890416217c9ae6aac5c9834438bf1827fe36c88a15e4315d41ddc12168edb9b8109c57ecfc394cbce90aa5e0f37ccdd5118c3689f9629d8a675dd79fd4
|
data/README.markdown
CHANGED
@@ -6,6 +6,8 @@
|
|
6
6
|
|
7
7
|
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.
|
8
8
|
|
9
|
+
Checkout the the [Demo](http://formnestic-demo.herokuapp.com)
|
10
|
+
|
9
11
|
### Compatibility
|
10
12
|
|
11
13
|
- Formnestic gem requires ``formtastic`` gem version ``>= 2.2.1``
|
@@ -32,7 +32,7 @@ var Formnestic = {
|
|
32
32
|
var maxNumberOfEntries = parseInt(nestedModelContainer.attr("max_entry"), 10);
|
33
33
|
|
34
34
|
if (minNumberOfEntries !== -1 && numberOfShowingEntries <= minNumberOfEntries) {
|
35
|
-
return alert(nestedModelContainer.attr("min_entry_alert_message"));
|
35
|
+
return window.alert(nestedModelContainer.attr("min_entry_alert_message"));
|
36
36
|
}//end if
|
37
37
|
|
38
38
|
var entryContainer = deleteEntryLinkDom.parents("fieldset.inputs:first");
|
@@ -46,7 +46,7 @@ var Formnestic = {
|
|
46
46
|
addRowLinkContainer.removeClass("formnestic-hidden");
|
47
47
|
}//end else
|
48
48
|
|
49
|
-
entryContainer.fadeOut(
|
49
|
+
entryContainer.fadeOut();
|
50
50
|
},
|
51
51
|
|
52
52
|
removeATableEntry: function(deleteEntryLinkDom) {
|
@@ -57,7 +57,7 @@ var Formnestic = {
|
|
57
57
|
var minNumberOfEntries = parseInt(table.attr("min_entry"), 10);
|
58
58
|
var maxNumberOfEntries = parseInt(table.attr("max_entry"), 10);
|
59
59
|
if (minNumberOfEntries !== -1 && numberOfShowingEntries <= minNumberOfEntries) {
|
60
|
-
return alert(table.attr("min_entry_alert_message"));
|
60
|
+
return window.alert(table.attr("min_entry_alert_message"));
|
61
61
|
}//end if
|
62
62
|
|
63
63
|
var trContainer = deleteEntryLinkDom.parents("tr:first");
|
@@ -69,7 +69,7 @@ var Formnestic = {
|
|
69
69
|
} else {
|
70
70
|
addRowLink.removeClass("formnestic-hidden");
|
71
71
|
}//end else
|
72
|
-
trContainer.fadeOut(
|
72
|
+
trContainer.fadeOut();
|
73
73
|
},
|
74
74
|
|
75
75
|
addOddAndEventClassForListContainer: function(listContainer) {
|
@@ -91,7 +91,7 @@ var Formnestic = {
|
|
91
91
|
$(table).find("tbody:first").find("tr").each(function() {
|
92
92
|
var trDom = $(this);
|
93
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")
|
94
|
+
trDom.removeClass("formnestic-odd-row formnestic-even-row").addClass(counter % 2 === 0 ? "formnestic-even-row" : "formnestic-odd-row");
|
95
95
|
counter = counter + 1;
|
96
96
|
}
|
97
97
|
});
|
@@ -100,14 +100,12 @@ var Formnestic = {
|
|
100
100
|
},
|
101
101
|
|
102
102
|
addNewListEntry: function(linkDom, associationName, content) {
|
103
|
-
var newId = new Date().getTime();
|
104
|
-
var regexp = new RegExp("new_" + associationName, "g");
|
105
103
|
var linkDomContainer = $(linkDom).parent();
|
106
104
|
var listContainer = linkDomContainer.parents('div.formnestic-nested-model-container:first').find("div.formnestic-list-entries-container");
|
107
105
|
var nestedModelContainer = listContainer.parent();
|
108
106
|
var maxNumberOfEntries = parseInt(nestedModelContainer.attr('max_entry'), 10);
|
109
107
|
|
110
|
-
var entryContainer = $(
|
108
|
+
var entryContainer = $(this.formatNewAppendedContent(content, associationName)).appendTo(listContainer);
|
111
109
|
var counter = this.addOddAndEventClassForListContainer(listContainer);
|
112
110
|
if (maxNumberOfEntries !== -1 && counter >= maxNumberOfEntries) {
|
113
111
|
linkDomContainer.addClass("formnestic-hidden");
|
@@ -119,12 +117,10 @@ var Formnestic = {
|
|
119
117
|
},
|
120
118
|
|
121
119
|
addNewTableEntry: function(linkDom, associationName, content) {
|
122
|
-
var newId = new Date().getTime();
|
123
|
-
var regexp = new RegExp("new_" + associationName, "g");
|
124
120
|
var linkDomjQuery = $(linkDom);
|
125
121
|
var table = linkDomjQuery.parents('table:first');
|
126
122
|
|
127
|
-
var entryContainer = $(
|
123
|
+
var entryContainer = $(this.formatNewAppendedContent(content, associationName)).insertBefore(linkDomjQuery.parents("tr:first"));
|
128
124
|
|
129
125
|
var counter = this.addOddAndEvenClassForTable(table);
|
130
126
|
var maxNumberOfEntries = parseInt(table.attr('max_entry'), 10);
|
@@ -135,5 +131,11 @@ var Formnestic = {
|
|
135
131
|
}//end else
|
136
132
|
|
137
133
|
entryContainer.css({display: 'none'}).fadeIn();
|
134
|
+
},
|
135
|
+
|
136
|
+
formatNewAppendedContent: function(content, associationName) {
|
137
|
+
var newId = new Date().getTime();
|
138
|
+
var regexp = new RegExp("new_" + associationName, "g");
|
139
|
+
return content.replace(regexp, newId);
|
138
140
|
}
|
139
141
|
};
|
data/formnestic.gemspec
CHANGED
@@ -1,31 +1,29 @@
|
|
1
1
|
module Formnestic
|
2
2
|
module FormBuilder
|
3
3
|
module BaseBuilder
|
4
|
-
|
5
4
|
def formnestic_min_entry_alert_message(record_or_name_or_array, min_entry)
|
6
|
-
entity_name = I18n.t("activerecord.models.#{record_or_name_or_array.to_s.singularize}", default: record_or_name_or_array.to_s.
|
5
|
+
entity_name = I18n.t("activerecord.models.#{record_or_name_or_array.to_s.singularize}", default: record_or_name_or_array.to_s.tr('_', ' ').singularize.singularize)
|
7
6
|
min_entry != -1 ? (options[:min_entry_alert_message] ||
|
8
|
-
I18n.t('formnestic.labels.there_must_be_at_least_a_number_of_entries',
|
9
|
-
|
10
|
-
|
11
|
-
entity_plural: entity_name.pluralize})) : ''
|
7
|
+
I18n.t('formnestic.labels.there_must_be_at_least_a_number_of_entries', count: min_entry,
|
8
|
+
entity_singular: entity_name,
|
9
|
+
entity_plural: entity_name.pluralize)) : ''
|
12
10
|
end
|
13
|
-
|
11
|
+
|
14
12
|
def formnestic_add_rows_counter_related_attributes
|
15
13
|
instance_eval do
|
16
|
-
instance_variable_set(
|
14
|
+
instance_variable_set('@rows_counter', 0)
|
17
15
|
def rows_counter
|
18
|
-
|
16
|
+
@rows_counter
|
19
17
|
end
|
20
|
-
|
18
|
+
|
21
19
|
def increase_rows_counter
|
22
20
|
@rows_counter += 1
|
23
21
|
end
|
24
|
-
end
|
22
|
+
end
|
25
23
|
end
|
26
|
-
|
24
|
+
|
27
25
|
def formnestic_link_to_add_fields_with_content(record_or_name_or_array, *args, &block)
|
28
|
-
new_object =
|
26
|
+
new_object = object.class.reflect_on_association(record_or_name_or_array).klass.new
|
29
27
|
options = args.dup.extract_options!
|
30
28
|
options[:max_entry] ||= -1
|
31
29
|
duplicate_args = args.dup
|
@@ -34,22 +32,21 @@ module Formnestic
|
|
34
32
|
rows_counter = self.rows_counter
|
35
33
|
new_record_form_options[:child_index] = "new_#{record_or_name_or_array}"
|
36
34
|
new_record_form_content = formtastic_semantic_fields_for(record_or_name_or_array, *(duplicate_args << new_record_form_options), &block)
|
37
|
-
link_title = options[:new_record_link_label] || I18n.t(
|
35
|
+
link_title = options[:new_record_link_label] || I18n.t('formnestic.labels.add_new_entry')
|
38
36
|
javascript_fn_to_call = js_call_for_nested_model_display_type(options[:display_type])
|
39
|
-
|
37
|
+
|
40
38
|
template.link_to(link_title, '#', onclick:
|
41
39
|
"Formnestic.#{javascript_fn_to_call}(this, \"#{record_or_name_or_array}\", \"#{escape_javascript(new_record_form_content)}\"); return false;", \
|
42
|
-
|
43
|
-
|
40
|
+
'class' => ['formnestic-add-row-field-link', options[:new_record_link_class], (options[:max_entry] != -1) && (rows_counter >= options[:max_entry]) ? 'formnestic-hidden' : nil].compact.join(' '))
|
44
41
|
end
|
45
|
-
|
42
|
+
|
46
43
|
def js_call_for_nested_model_display_type(display_type)
|
47
44
|
if display_type == 'table'
|
48
|
-
|
45
|
+
'addNewTableEntry'
|
49
46
|
else
|
50
|
-
|
47
|
+
'addNewListEntry'
|
51
48
|
end
|
52
49
|
end
|
53
50
|
end
|
54
51
|
end
|
55
|
-
end
|
52
|
+
end
|
@@ -1,94 +1,194 @@
|
|
1
|
+
# rubocop:disable MethodLength, Documentation, ModuleLength, AbcSize
|
1
2
|
module Formnestic
|
2
3
|
module FormBuilder
|
3
4
|
module TableFormBuilder
|
4
5
|
include Formnestic::FormBuilder::BaseBuilder
|
5
|
-
|
6
|
-
|
7
|
-
|
6
|
+
def formnestic_table_semantic_fields_for(
|
7
|
+
record_or_name_or_array, *args, &block
|
8
|
+
)
|
9
|
+
options = args.dup.extract_options!
|
8
10
|
formnestic_add_table_headers_form_attributes
|
9
11
|
formnestic_add_rows_counter_related_attributes
|
10
|
-
|
12
|
+
|
11
13
|
child_form_builder = nil
|
12
|
-
contents = [formtastic_semantic_fields_for(
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
14
|
+
contents = [formtastic_semantic_fields_for(
|
15
|
+
record_or_name_or_array,
|
16
|
+
*args,
|
17
|
+
&lambda { |nested_form_builder|
|
18
|
+
child_form_builder = nested_form_builder
|
19
|
+
yield(nested_form_builder)
|
20
|
+
}
|
21
|
+
)]
|
22
|
+
|
23
|
+
if options[:row_addable]
|
24
|
+
contents.push(
|
25
|
+
formnestic_add_new_record_button_row_for_table(
|
26
|
+
record_or_name_or_array, *args, &block
|
27
|
+
)
|
28
|
+
)
|
29
|
+
end
|
30
|
+
options[:class] = [
|
31
|
+
'formnestic-table-inputs formnestic-nested-model',
|
32
|
+
options[:class]
|
33
|
+
].compact.join(' ')
|
19
34
|
options[:min_entry] ||= -1
|
20
|
-
options[:max_entry] ||= -1
|
21
|
-
options[:min_entry_alert_message] =
|
22
|
-
|
35
|
+
options[:max_entry] ||= -1
|
36
|
+
options[:min_entry_alert_message] =
|
37
|
+
formnestic_min_entry_alert_message(
|
38
|
+
record_or_name_or_array, options[:min_entry]
|
39
|
+
)
|
40
|
+
|
23
41
|
### Finally, wrap everything inside a table tag
|
24
42
|
template.content_tag(:table, [
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
43
|
+
formnestic_table_header(
|
44
|
+
options,
|
45
|
+
record_or_name_or_array,
|
46
|
+
child_form_builder
|
47
|
+
), # table header
|
48
|
+
template.content_tag(
|
49
|
+
:tbody,
|
50
|
+
Formtastic::Util.html_safe(contents.join)
|
51
|
+
) # table body
|
52
|
+
].join.html_safe, options.except(
|
53
|
+
:builder,
|
54
|
+
:parent,
|
55
|
+
:name,
|
56
|
+
:parent_builder,
|
57
|
+
:display_type,
|
58
|
+
:row_removable,
|
59
|
+
:new_record_link_label,
|
60
|
+
:table_headers
|
61
|
+
))
|
30
62
|
end
|
31
|
-
|
63
|
+
|
32
64
|
def formnestic_add_table_headers_form_attributes
|
33
65
|
instance_eval do
|
34
|
-
instance_variable_set(
|
66
|
+
instance_variable_set('@table_headers', [])
|
35
67
|
def table_headers
|
36
|
-
|
68
|
+
@table_headers
|
37
69
|
end
|
38
|
-
|
70
|
+
|
39
71
|
def add_table_header(column_name, class_name, label_text)
|
40
|
-
if @table_headers.detect
|
41
|
-
|
42
|
-
end
|
72
|
+
return if @table_headers.detect do |x|
|
73
|
+
x[:attr] == column_name
|
74
|
+
end.present?
|
75
|
+
@table_headers.push(
|
76
|
+
attr: column_name,
|
77
|
+
class:
|
78
|
+
class_name
|
79
|
+
.to_s
|
80
|
+
.tableize
|
81
|
+
.gsub('formtastic/inputs/', '')
|
82
|
+
.tr('_', '-')
|
83
|
+
.gsub('-inputs', ''),
|
84
|
+
label_text: label_text
|
85
|
+
)
|
43
86
|
end
|
44
87
|
end
|
45
88
|
end
|
46
|
-
|
47
|
-
def formnestic_add_new_record_button_row_for_table(
|
48
|
-
|
89
|
+
|
90
|
+
def formnestic_add_new_record_button_row_for_table(
|
91
|
+
record_or_name_or_array,
|
92
|
+
*args,
|
93
|
+
&block
|
94
|
+
)
|
95
|
+
template.content_tag(
|
96
|
+
:tr,
|
97
|
+
template.content_tag(
|
98
|
+
:td,
|
99
|
+
formnestic_link_to_add_fields_with_content(
|
100
|
+
record_or_name_or_array, *args, &block
|
101
|
+
), colspan: '100%'
|
102
|
+
), class: 'formnestic-table-no-border'
|
103
|
+
)
|
49
104
|
end
|
50
|
-
|
51
|
-
def formnestic_table_header(
|
52
|
-
|
105
|
+
|
106
|
+
def formnestic_table_header(
|
107
|
+
header_options, record_or_name_or_array, child_form_builder
|
108
|
+
)
|
53
109
|
thead_contents = if header_options[:table_headers]
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
110
|
+
formnestic_thead_contents_from_arguments(
|
111
|
+
header_options[:table_headers],
|
112
|
+
record_or_name_or_array, child_form_builder
|
113
|
+
)
|
114
|
+
else
|
115
|
+
formnestic_thead_contents_from_inputs(
|
116
|
+
header_options[:row_removable]
|
117
|
+
)
|
118
|
+
end
|
119
|
+
template.content_tag(:thead, thead_contents.join.html_safe)
|
59
120
|
end
|
60
|
-
|
121
|
+
|
61
122
|
def formnestic_thead_contents_from_inputs(row_removable)
|
62
123
|
tr_content_arr = []
|
63
124
|
table_headers.each do |header|
|
64
|
-
tr_content_arr.push(
|
125
|
+
tr_content_arr.push(
|
126
|
+
template.content_tag(
|
127
|
+
:th,
|
128
|
+
header[:label_text],
|
129
|
+
class: header[:class]
|
130
|
+
)
|
131
|
+
)
|
132
|
+
end
|
133
|
+
if row_removable
|
134
|
+
tr_content_arr.push(
|
135
|
+
template.content_tag(
|
136
|
+
:th, '', class: 'formnestic-minus-thead'
|
137
|
+
)
|
138
|
+
)
|
65
139
|
end
|
66
|
-
tr_content_arr.push(template.content_tag(:th, "", class: "formnestic-minus-thead")) if row_removable
|
67
140
|
[template.content_tag(:tr, tr_content_arr.join.html_safe)]
|
68
141
|
end
|
69
|
-
|
70
|
-
def formnestic_thead_contents_from_arguments(
|
142
|
+
|
143
|
+
def formnestic_thead_contents_from_arguments(
|
144
|
+
theads,
|
145
|
+
record_or_name_or_array,
|
146
|
+
child_form_builder
|
147
|
+
)
|
71
148
|
thead_contents = []
|
72
149
|
theads.each do |el_arr|
|
73
|
-
|
74
|
-
|
75
|
-
tr_content_arr
|
76
|
-
|
77
|
-
|
78
|
-
|
150
|
+
tr_content_arr = []
|
151
|
+
el_arr.each_with_index do |el, index|
|
152
|
+
tr_content_arr
|
153
|
+
.push(
|
154
|
+
template.content_tag(
|
155
|
+
:th,
|
156
|
+
formnestic_table_thead_th_content(
|
157
|
+
record_or_name_or_array, el, index + 1, child_form_builder
|
158
|
+
), el[:wrapper_html] || {}
|
159
|
+
)
|
160
|
+
)
|
161
|
+
end
|
162
|
+
thead_contents.push(
|
163
|
+
template.content_tag(:tr, tr_content_arr.join.html_safe)
|
164
|
+
)
|
165
|
+
end
|
79
166
|
thead_contents
|
80
167
|
end
|
81
|
-
|
82
|
-
def formnestic_table_thead_th_content(
|
168
|
+
|
169
|
+
def formnestic_table_thead_th_content(
|
170
|
+
record_or_name_or_array,
|
171
|
+
table_header_element_opts,
|
172
|
+
position,
|
173
|
+
child_form_builder
|
174
|
+
)
|
83
175
|
if table_header_element_opts[:attr].present?
|
84
|
-
input_base =
|
85
|
-
|
176
|
+
input_base =
|
177
|
+
Formtastic::Inputs::StringInput.new(
|
178
|
+
child_form_builder,
|
179
|
+
'',
|
180
|
+
record_or_name_or_array,
|
181
|
+
child_form_builder.object,
|
182
|
+
table_header_element_opts[:attr],
|
183
|
+
{}
|
184
|
+
)
|
185
|
+
input_base.label_text
|
86
186
|
elsif table_header_element_opts[:label].present?
|
87
|
-
|
187
|
+
table_header_element_opts[:label]
|
88
188
|
else
|
89
|
-
|
189
|
+
"Column #{position}"
|
90
190
|
end
|
91
191
|
end
|
92
|
-
end
|
192
|
+
end
|
93
193
|
end
|
94
|
-
end
|
194
|
+
end
|
@@ -1,13 +1,12 @@
|
|
1
1
|
module Formnestic
|
2
|
-
module FormBuilder
|
2
|
+
module FormBuilder
|
3
3
|
include ActionView::Helpers::JavaScriptHelper
|
4
|
-
|
4
|
+
|
5
5
|
autoload :BaseBuilder, File.join(File.dirname(__FILE__), 'form_builder', 'base_builder')
|
6
6
|
autoload :TableFormBuilder, File.join(File.dirname(__FILE__), 'form_builder', 'table_form_builder')
|
7
7
|
autoload :ListFormBuilder, File.join(File.dirname(__FILE__), 'form_builder', 'list_form_builder')
|
8
|
-
|
8
|
+
|
9
9
|
include Formnestic::FormBuilder::TableFormBuilder
|
10
10
|
include Formnestic::FormBuilder::ListFormBuilder
|
11
|
-
|
12
11
|
end
|
13
|
-
end
|
12
|
+
end
|
@@ -2,81 +2,87 @@ module Formnestic
|
|
2
2
|
module Helpers
|
3
3
|
module InputsHelper
|
4
4
|
def inputs(*args, &block)
|
5
|
-
if options[:display_type] == 'table'
|
6
|
-
formnestic_table_row_inputs(*args, &block)
|
7
|
-
elsif options[:row_removable]
|
5
|
+
if options[:display_type] == 'table'
|
6
|
+
formnestic_table_row_inputs(*args, &block)
|
7
|
+
elsif options[:row_removable] || options[:row_addable]
|
8
8
|
formnestic_list_row_inputs(*args, &block)
|
9
9
|
else
|
10
10
|
formtastic_inputs(*args, &block)
|
11
|
-
end
|
11
|
+
end
|
12
12
|
end
|
13
|
-
|
13
|
+
|
14
14
|
# for listing form
|
15
15
|
def formnestic_list_row_inputs(*args, &block)
|
16
|
-
html_options = args
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
rows_counter = template.content_tag(:span, self.options[:parent_builder].rows_counter, class: "formnestic-li-fieldset-for-order")
|
22
|
-
content_div_content = [formnestic_legend_for_list_form, " #".html_safe, rows_counter].join.html_safe
|
23
|
-
title_div = template.content_tag(:div, content_div_content, class: "formnestic-li-fieldset-legend")
|
16
|
+
html_options = formnestic_prepare_html_options_for_wrapper(:list, *args)
|
17
|
+
rows_counter = template.content_tag(:span, options[:parent_builder].rows_counter, class: 'formnestic-li-fieldset-for-order')
|
18
|
+
content_div_content = [formnestic_legend_for_list_form, ' #'.html_safe, rows_counter].join.html_safe
|
19
|
+
title_div = template.content_tag(:div, content_div_content, class: 'formnestic-li-fieldset-legend')
|
24
20
|
template.content_tag(:fieldset, [title_div, (options[:row_removable] ? formnestic_row_removing_content_tag(:list) : ''), template.capture(&block)].join.html_safe, html_options)
|
25
21
|
end
|
26
|
-
|
22
|
+
|
27
23
|
# For table form
|
28
24
|
def formnestic_table_row_inputs(*args, &block)
|
29
|
-
html_options = args
|
30
|
-
html_options[:name] = field_set_title_from_args(*args)
|
31
|
-
html_options[:class] = [html_options[:class] || "inputs", "formnestic-tr-fieldset", formnestic_row_class_based_on_position(options[:parent_builder].rows_counter)].join(" ")
|
32
|
-
|
33
|
-
self.options[:parent_builder].increase_rows_counter
|
25
|
+
html_options = formnestic_prepare_html_options_for_wrapper(:table, *args)
|
34
26
|
template.content_tag(:tr, [template.capture(&block), (options[:row_removable] ?
|
35
27
|
formnestic_row_removing_content_tag(:table) : '')].join.html_safe, html_options)
|
36
28
|
end
|
37
|
-
|
29
|
+
|
38
30
|
def formnestic_legend_for_list_form
|
39
|
-
record_name =
|
40
|
-
entity_name = I18n.t("activerecord.models.#{
|
41
|
-
template.content_tag(:span, record_name.titleize, class:
|
31
|
+
record_name = object.class.to_s.underscore.tr('_', ' ').singularize.downcase
|
32
|
+
entity_name = I18n.t("activerecord.models.#{object.class.to_s.underscore.downcase}", default: record_name)
|
33
|
+
template.content_tag(:span, record_name.titleize, class: 'formnestic-li-fieldset-for')
|
42
34
|
end
|
43
|
-
|
44
|
-
def formnestic_row_removing_content_tag(form_type)
|
35
|
+
|
36
|
+
def formnestic_row_removing_content_tag(form_type)
|
45
37
|
contents = []
|
46
|
-
contents.push(
|
47
|
-
contents.push(template.content_tag(:div, '', title: I18n.t(
|
38
|
+
contents.push(hidden_field(:_destroy, class: 'formnestic-destroy-input', value: false))
|
39
|
+
contents.push(template.content_tag(:div, '', title: I18n.t('formnestic.labels.remove_this_entry'), class: "#{formnestic_row_removing_cell_div_class(form_type)} icon-cancel-circled", onclick: formnestic_row_removing_cell_js_call(form_type)))
|
48
40
|
template.content_tag(form_type == :table ? :td : :div, contents.join.html_safe, class: formnestic_row_removing_cell_container_div_class(form_type))
|
49
41
|
end
|
50
|
-
|
42
|
+
|
43
|
+
def formnestic_prepare_html_options_for_wrapper(form_type, *args)
|
44
|
+
html_options = args.extract_options!
|
45
|
+
html_options[:name] = field_set_title_from_args(*args)
|
46
|
+
html_options[:class] = [html_options[:class] || 'inputs', formnestic_wrapper_class(form_type), formnestic_row_class_based_on_position(options[:parent_builder].rows_counter)].join(' ')
|
47
|
+
options[:parent_builder].increase_rows_counter
|
48
|
+
html_options
|
49
|
+
end
|
50
|
+
|
51
|
+
def formnestic_wrapper_class(form_type)
|
52
|
+
if form_type == :table
|
53
|
+
'formnestic-tr-fieldset'
|
54
|
+
else
|
55
|
+
'formnestic-li-fieldset'
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
51
59
|
def formnestic_row_removing_cell_js_call(form_type)
|
52
60
|
if form_type == :table
|
53
61
|
'Formnestic.removeATableEntry(this);'
|
54
62
|
else
|
55
63
|
'Formnestic.removeAListEntry(this);'
|
56
|
-
end
|
64
|
+
end
|
57
65
|
end
|
58
|
-
|
66
|
+
|
59
67
|
def formnestic_row_removing_cell_div_class(form_type)
|
60
68
|
if form_type == :table
|
61
69
|
'formnestic-table-minus-button'
|
62
70
|
else
|
63
71
|
'formnestic-list-item-minus-button'
|
64
|
-
end
|
72
|
+
end
|
65
73
|
end
|
66
|
-
|
74
|
+
|
67
75
|
def formnestic_row_removing_cell_container_div_class(form_type)
|
68
76
|
if form_type == :table
|
69
77
|
'formnestic-minus-button-cell'
|
70
78
|
else
|
71
79
|
'formnestic-minus-button-container'
|
72
|
-
end
|
80
|
+
end
|
73
81
|
end
|
74
|
-
|
82
|
+
|
75
83
|
def formnestic_row_class_based_on_position(position)
|
76
|
-
position
|
84
|
+
position.even? ? 'formnestic-even-row' : 'formnestic-odd-row'
|
77
85
|
end
|
78
|
-
|
79
|
-
|
80
86
|
end
|
81
87
|
end
|
82
|
-
end
|
88
|
+
end
|
data/lib/formnestic/helpers.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module Formnestic
|
2
2
|
# @private
|
3
3
|
module Helpers
|
4
|
-
autoload :InputsHelper,
|
4
|
+
autoload :InputsHelper, \
|
5
|
+
File.join(File.dirname(__FILE__), 'helpers', 'inputs_helper')
|
5
6
|
Formtastic::FormBuilder.send(:alias_method, :formtastic_inputs, :inputs)
|
6
7
|
Formtastic::FormBuilder.send(:include, Formnestic::Helpers::InputsHelper)
|
7
|
-
|
8
8
|
end
|
9
|
-
end
|
9
|
+
end
|
@@ -3,13 +3,13 @@ module Formnestic
|
|
3
3
|
module Base
|
4
4
|
module Labelling
|
5
5
|
def render_label?
|
6
|
-
if
|
6
|
+
if builder.options[:display_type] == 'table'
|
7
7
|
false
|
8
8
|
else
|
9
9
|
formtastic_render_label?
|
10
10
|
end
|
11
|
-
end
|
11
|
+
end
|
12
12
|
end
|
13
13
|
end
|
14
14
|
end
|
15
|
-
end
|
15
|
+
end
|
@@ -3,13 +3,13 @@ module Formnestic
|
|
3
3
|
module Base
|
4
4
|
module Wrapping
|
5
5
|
def input_wrapping(&block)
|
6
|
-
if
|
6
|
+
if builder.options[:display_type] == 'table'
|
7
7
|
if [
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
8
|
+
'Formtastic::Inputs::DateSelectInput',
|
9
|
+
'Formtastic::Inputs::TimeSelectInput',
|
10
|
+
'Formtastic::Inputs::DateTimeSelectInput',
|
11
|
+
'Formtastic::Inputs::TimeInput',
|
12
|
+
'Formtastic::Inputs::DateInput'
|
13
13
|
].index(self.class.to_s)
|
14
14
|
table_date_select_input_wrapping(&block)
|
15
15
|
else
|
@@ -19,24 +19,46 @@ module Formnestic
|
|
19
19
|
formtastic_input_wrapping(&block)
|
20
20
|
end
|
21
21
|
end
|
22
|
-
|
22
|
+
|
23
23
|
def table_date_select_input_wrapping(&block)
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
24
|
+
builder
|
25
|
+
.options[:parent_builder]
|
26
|
+
.add_table_header(
|
27
|
+
attributized_method_name,
|
28
|
+
self.class,
|
29
|
+
label_text
|
30
|
+
)
|
31
|
+
template.content_tag(
|
32
|
+
:td,
|
33
|
+
template.content_tag(
|
34
|
+
:div, [
|
35
|
+
template.capture(&block), error_html, hint_html
|
36
|
+
].join("\n").html_safe,
|
37
|
+
class: 'table-date-select-container'
|
38
|
+
), wrapper_html_options
|
29
39
|
)
|
30
40
|
end
|
31
|
-
|
41
|
+
|
32
42
|
def table_input_wrapping(&block)
|
33
|
-
|
34
|
-
|
35
|
-
|
43
|
+
builder
|
44
|
+
.options[:parent_builder]
|
45
|
+
.add_table_header(
|
46
|
+
attributized_method_name,
|
47
|
+
self.class,
|
48
|
+
label_text
|
49
|
+
)
|
50
|
+
|
51
|
+
template.content_tag(
|
52
|
+
:td,
|
53
|
+
[
|
54
|
+
template.capture(&block),
|
55
|
+
error_html,
|
56
|
+
hint_html
|
57
|
+
].join("\n").html_safe,
|
36
58
|
wrapper_html_options
|
37
59
|
)
|
38
|
-
end
|
60
|
+
end
|
39
61
|
end
|
40
62
|
end
|
41
63
|
end
|
42
|
-
end
|
64
|
+
end
|
data/lib/formnestic.rb
CHANGED
@@ -1,72 +1,25 @@
|
|
1
|
-
|
2
|
-
require 'formtastic/engine' if defined?(::Rails)
|
1
|
+
require 'formnestic/engine' if defined?(::Rails)
|
3
2
|
require 'formtastic/helpers'
|
4
3
|
require 'formtastic'
|
4
|
+
|
5
5
|
module Formnestic
|
6
6
|
extend ActiveSupport::Autoload
|
7
|
-
autoload :Helpers,
|
8
|
-
|
9
|
-
autoload :
|
10
|
-
|
11
|
-
|
7
|
+
autoload :Helpers,
|
8
|
+
File.join(File.dirname(__FILE__), 'formnestic', 'helpers')
|
9
|
+
autoload :FormBuilder,
|
10
|
+
File.join(File.dirname(__FILE__), 'formnestic', 'form_builder')
|
11
|
+
autoload :Inputs,
|
12
|
+
File.join(File.dirname(__FILE__), 'formnestic', 'inputs')
|
13
|
+
autoload \
|
14
|
+
:FormtasticExtensions,
|
15
|
+
File.join(File.dirname(__FILE__), 'formnestic', 'formtastic_extensions')
|
16
|
+
|
17
|
+
include Formnestic::Helpers
|
12
18
|
include Formnestic::Inputs::Base
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
Formtastic::Inputs::Base.send(:include, Formnestic::Inputs::Base::Labelling)
|
21
|
-
|
22
|
-
Formtastic::Inputs::BooleanInput.send(:alias_method, :formtastic_label_text_with_embedded_checkbox, :label_text_with_embedded_checkbox)
|
23
|
-
|
24
|
-
[
|
25
|
-
'Formtastic::Inputs::DateSelectInput',
|
26
|
-
'Formtastic::Inputs::DatetimeSelectInput',
|
27
|
-
'Formtastic::Inputs::TimeSelectInput'
|
28
|
-
].each do |date_related_subclass_str|
|
29
|
-
if defined?(date_related_subclass_str)
|
30
|
-
date_related_subclass = date_related_subclass_str.constantize
|
31
|
-
date_related_subclass.send(:alias_method, :formtastic_fragment_label_html, :fragment_label_html)
|
32
|
-
date_related_subclass.class_eval do
|
33
|
-
def fragment_label_html(fragment)
|
34
|
-
if self.builder.options[:display_type] == "table"
|
35
|
-
"".html_safe
|
36
|
-
else
|
37
|
-
formtastic_fragment_label_html(fragment)
|
38
|
-
end
|
39
|
-
end
|
40
|
-
end
|
41
|
-
end
|
42
|
-
end
|
43
|
-
|
44
|
-
Formtastic::Inputs::BooleanInput.class_eval do
|
45
|
-
def label_text_with_embedded_checkbox
|
46
|
-
if self.builder.options[:display_type] == 'table'
|
47
|
-
check_box_html
|
48
|
-
else
|
49
|
-
formtastic_label_text_with_embedded_checkbox
|
50
|
-
end
|
51
|
-
end
|
52
|
-
end
|
53
|
-
|
54
|
-
Formtastic::FormBuilder.class_eval do
|
55
|
-
def semantic_fields_for(record_or_name_or_array, *args, &block)
|
56
|
-
options = args.dup.extract_options!
|
57
|
-
if options[:display_type] == 'table'
|
58
|
-
formnestic_table_semantic_fields_for(record_or_name_or_array, *args, &block)
|
59
|
-
elsif options[:row_removable].present? or options[:row_addable].present?
|
60
|
-
formnestic_list_semantic_fields_for(record_or_name_or_array, *args, &block)
|
61
|
-
else
|
62
|
-
formtastic_semantic_fields_for(record_or_name_or_array, *args, &block)
|
63
|
-
end
|
64
|
-
end
|
65
|
-
end
|
66
|
-
|
67
|
-
if defined?(::Rails)
|
68
|
-
class Engine < Rails::Engine
|
69
|
-
end
|
70
|
-
end
|
71
|
-
|
72
|
-
end
|
19
|
+
extend Formnestic::FormtasticExtensions
|
20
|
+
|
21
|
+
extend_form_builder
|
22
|
+
extend_form_inputs
|
23
|
+
extend_datetime_related_inputs
|
24
|
+
extend_boolean_input
|
25
|
+
end
|
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: formnestic
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.0.
|
5
|
-
prerelease:
|
4
|
+
version: 1.0.3
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- James
|
@@ -14,193 +13,169 @@ dependencies:
|
|
14
13
|
- !ruby/object:Gem::Dependency
|
15
14
|
name: actionpack
|
16
15
|
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
16
|
requirements:
|
19
|
-
- -
|
17
|
+
- - ">="
|
20
18
|
- !ruby/object:Gem::Version
|
21
19
|
version: 3.2.13
|
22
20
|
type: :runtime
|
23
21
|
prerelease: false
|
24
22
|
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
23
|
requirements:
|
27
|
-
- -
|
24
|
+
- - ">="
|
28
25
|
- !ruby/object:Gem::Version
|
29
26
|
version: 3.2.13
|
30
27
|
- !ruby/object:Gem::Dependency
|
31
28
|
name: formtastic
|
32
29
|
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
30
|
requirements:
|
35
|
-
- -
|
31
|
+
- - ">="
|
36
32
|
- !ruby/object:Gem::Version
|
37
33
|
version: 2.2.1
|
38
34
|
type: :runtime
|
39
35
|
prerelease: false
|
40
36
|
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
37
|
requirements:
|
43
|
-
- -
|
38
|
+
- - ">="
|
44
39
|
- !ruby/object:Gem::Version
|
45
40
|
version: 2.2.1
|
46
41
|
- !ruby/object:Gem::Dependency
|
47
42
|
name: coveralls
|
48
43
|
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
44
|
requirements:
|
51
|
-
- -
|
45
|
+
- - ">="
|
52
46
|
- !ruby/object:Gem::Version
|
53
47
|
version: '0'
|
54
48
|
type: :runtime
|
55
49
|
prerelease: false
|
56
50
|
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
51
|
requirements:
|
59
|
-
- -
|
52
|
+
- - ">="
|
60
53
|
- !ruby/object:Gem::Version
|
61
54
|
version: '0'
|
62
55
|
- !ruby/object:Gem::Dependency
|
63
56
|
name: shoulda
|
64
57
|
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
58
|
requirements:
|
67
|
-
- -
|
59
|
+
- - ">="
|
68
60
|
- !ruby/object:Gem::Version
|
69
61
|
version: '0'
|
70
62
|
type: :development
|
71
63
|
prerelease: false
|
72
64
|
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
65
|
requirements:
|
75
|
-
- -
|
66
|
+
- - ">="
|
76
67
|
- !ruby/object:Gem::Version
|
77
68
|
version: '0'
|
78
69
|
- !ruby/object:Gem::Dependency
|
79
70
|
name: bundler
|
80
71
|
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
72
|
requirements:
|
83
|
-
- - ~>
|
73
|
+
- - "~>"
|
84
74
|
- !ruby/object:Gem::Version
|
85
75
|
version: '1.0'
|
86
76
|
type: :development
|
87
77
|
prerelease: false
|
88
78
|
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
79
|
requirements:
|
91
|
-
- - ~>
|
80
|
+
- - "~>"
|
92
81
|
- !ruby/object:Gem::Version
|
93
82
|
version: '1.0'
|
94
83
|
- !ruby/object:Gem::Dependency
|
95
84
|
name: rdoc
|
96
85
|
requirement: !ruby/object:Gem::Requirement
|
97
|
-
none: false
|
98
86
|
requirements:
|
99
|
-
- - ~>
|
87
|
+
- - "~>"
|
100
88
|
- !ruby/object:Gem::Version
|
101
89
|
version: '3.4'
|
102
90
|
type: :development
|
103
91
|
prerelease: false
|
104
92
|
version_requirements: !ruby/object:Gem::Requirement
|
105
|
-
none: false
|
106
93
|
requirements:
|
107
|
-
- - ~>
|
94
|
+
- - "~>"
|
108
95
|
- !ruby/object:Gem::Version
|
109
96
|
version: '3.4'
|
110
97
|
- !ruby/object:Gem::Dependency
|
111
98
|
name: jeweler
|
112
99
|
requirement: !ruby/object:Gem::Requirement
|
113
|
-
none: false
|
114
100
|
requirements:
|
115
|
-
- - ~>
|
101
|
+
- - "~>"
|
116
102
|
- !ruby/object:Gem::Version
|
117
103
|
version: 2.0.1
|
118
104
|
type: :development
|
119
105
|
prerelease: false
|
120
106
|
version_requirements: !ruby/object:Gem::Requirement
|
121
|
-
none: false
|
122
107
|
requirements:
|
123
|
-
- - ~>
|
108
|
+
- - "~>"
|
124
109
|
- !ruby/object:Gem::Version
|
125
110
|
version: 2.0.1
|
126
111
|
- !ruby/object:Gem::Dependency
|
127
112
|
name: rspec-rails
|
128
113
|
requirement: !ruby/object:Gem::Requirement
|
129
|
-
none: false
|
130
114
|
requirements:
|
131
|
-
- - ~>
|
115
|
+
- - "~>"
|
132
116
|
- !ruby/object:Gem::Version
|
133
117
|
version: 2.14.0
|
134
118
|
type: :development
|
135
119
|
prerelease: false
|
136
120
|
version_requirements: !ruby/object:Gem::Requirement
|
137
|
-
none: false
|
138
121
|
requirements:
|
139
|
-
- - ~>
|
122
|
+
- - "~>"
|
140
123
|
- !ruby/object:Gem::Version
|
141
124
|
version: 2.14.0
|
142
125
|
- !ruby/object:Gem::Dependency
|
143
126
|
name: rspec_tag_matchers
|
144
127
|
requirement: !ruby/object:Gem::Requirement
|
145
|
-
none: false
|
146
128
|
requirements:
|
147
|
-
- -
|
129
|
+
- - ">="
|
148
130
|
- !ruby/object:Gem::Version
|
149
131
|
version: 1.0.0
|
150
132
|
type: :development
|
151
133
|
prerelease: false
|
152
134
|
version_requirements: !ruby/object:Gem::Requirement
|
153
|
-
none: false
|
154
135
|
requirements:
|
155
|
-
- -
|
136
|
+
- - ">="
|
156
137
|
- !ruby/object:Gem::Version
|
157
138
|
version: 1.0.0
|
158
139
|
- !ruby/object:Gem::Dependency
|
159
140
|
name: tzinfo
|
160
141
|
requirement: !ruby/object:Gem::Requirement
|
161
|
-
none: false
|
162
142
|
requirements:
|
163
|
-
- -
|
143
|
+
- - ">="
|
164
144
|
- !ruby/object:Gem::Version
|
165
145
|
version: '0'
|
166
146
|
type: :development
|
167
147
|
prerelease: false
|
168
148
|
version_requirements: !ruby/object:Gem::Requirement
|
169
|
-
none: false
|
170
149
|
requirements:
|
171
|
-
- -
|
150
|
+
- - ">="
|
172
151
|
- !ruby/object:Gem::Version
|
173
152
|
version: '0'
|
174
153
|
- !ruby/object:Gem::Dependency
|
175
154
|
name: spork
|
176
155
|
requirement: !ruby/object:Gem::Requirement
|
177
|
-
none: false
|
178
156
|
requirements:
|
179
|
-
- -
|
157
|
+
- - ">="
|
180
158
|
- !ruby/object:Gem::Version
|
181
159
|
version: '0'
|
182
160
|
type: :development
|
183
161
|
prerelease: false
|
184
162
|
version_requirements: !ruby/object:Gem::Requirement
|
185
|
-
none: false
|
186
163
|
requirements:
|
187
|
-
- -
|
164
|
+
- - ">="
|
188
165
|
- !ruby/object:Gem::Version
|
189
166
|
version: '0'
|
190
167
|
- !ruby/object:Gem::Dependency
|
191
168
|
name: watchr
|
192
169
|
requirement: !ruby/object:Gem::Requirement
|
193
|
-
none: false
|
194
170
|
requirements:
|
195
|
-
- -
|
171
|
+
- - ">="
|
196
172
|
- !ruby/object:Gem::Version
|
197
173
|
version: '0'
|
198
174
|
type: :development
|
199
175
|
prerelease: false
|
200
176
|
version_requirements: !ruby/object:Gem::Requirement
|
201
|
-
none: false
|
202
177
|
requirements:
|
203
|
-
- -
|
178
|
+
- - ">="
|
204
179
|
- !ruby/object:Gem::Version
|
205
180
|
version: '0'
|
206
181
|
description: An extension of famous Formtastic Form Builder to make building nested
|
@@ -212,10 +187,10 @@ extensions: []
|
|
212
187
|
extra_rdoc_files:
|
213
188
|
- README.markdown
|
214
189
|
files:
|
215
|
-
- .document
|
216
|
-
- .rspec
|
217
|
-
- .travis.yml
|
218
|
-
- .watchr
|
190
|
+
- ".document"
|
191
|
+
- ".rspec"
|
192
|
+
- ".travis.yml"
|
193
|
+
- ".watchr"
|
219
194
|
- Gemfile
|
220
195
|
- Gemfile.lock
|
221
196
|
- MIT-LICENSE
|
@@ -259,28 +234,24 @@ files:
|
|
259
234
|
homepage: http://github.com/jameshuynh/formnestic
|
260
235
|
licenses:
|
261
236
|
- MIT
|
237
|
+
metadata: {}
|
262
238
|
post_install_message:
|
263
239
|
rdoc_options: []
|
264
240
|
require_paths:
|
265
241
|
- lib
|
266
242
|
required_ruby_version: !ruby/object:Gem::Requirement
|
267
|
-
none: false
|
268
243
|
requirements:
|
269
|
-
- -
|
244
|
+
- - ">="
|
270
245
|
- !ruby/object:Gem::Version
|
271
246
|
version: '0'
|
272
|
-
segments:
|
273
|
-
- 0
|
274
|
-
hash: -4363090041359353680
|
275
247
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
276
|
-
none: false
|
277
248
|
requirements:
|
278
|
-
- -
|
249
|
+
- - ">="
|
279
250
|
- !ruby/object:Gem::Version
|
280
251
|
version: '0'
|
281
252
|
requirements: []
|
282
253
|
rubyforge_project:
|
283
|
-
rubygems_version:
|
254
|
+
rubygems_version: 2.6.11
|
284
255
|
signing_key:
|
285
256
|
specification_version: 3
|
286
257
|
summary: An extension of formtastic form builder gem
|