noodall-form-builder 0.0.13 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/app/models/noodall/field.rb +6 -1
- data/app/models/noodall/form_response.rb +11 -0
- data/app/models/noodall/multiselect.rb +5 -0
- data/app/views/form_mailer/_form_response_fields.html.erb +1 -1
- data/app/views/noodall/admin/fields/_multiselect.html.erb +14 -0
- data/app/views/noodall/admin/form_responses/index.html.erb +1 -1
- data/app/views/noodall/admin/forms/_field_select.html.erb +1 -0
- data/app/views/noodall/admin/forms/show.html.erb +3 -0
- data/app/views/noodall/form_responses/_form.html.erb +1 -33
- data/app/views/noodall/form_responses/fields/_checkbox.html.erb +2 -0
- data/app/views/noodall/form_responses/fields/_multiselect.html.erb +3 -0
- data/app/views/noodall/form_responses/fields/_radio.html.erb +13 -0
- data/app/views/noodall/form_responses/fields/_select.html.erb +2 -0
- data/app/views/noodall/form_responses/fields/_textfield.html.erb +6 -0
- data/lib/noodall/form_builder/version.rb +1 -1
- data/public/javascripts/admin/formbuilder.js +1 -1
- metadata +15 -8
data/app/models/noodall/field.rb
CHANGED
@@ -10,10 +10,15 @@ module Noodall
|
|
10
10
|
|
11
11
|
embedded_in :form
|
12
12
|
|
13
|
+
before_save :default_label
|
14
|
+
def default_label
|
15
|
+
self.label = self.name if self.label.blank?
|
16
|
+
end
|
17
|
+
|
13
18
|
def underscored_name
|
14
19
|
name.parameterize.gsub('-','_').to_s
|
15
20
|
end
|
16
|
-
|
21
|
+
|
17
22
|
def default_class(response)
|
18
23
|
'default-value' if response.send(underscored_name.to_sym) == default
|
19
24
|
end
|
@@ -36,6 +36,17 @@ module Noodall
|
|
36
36
|
self.approved == false
|
37
37
|
end
|
38
38
|
|
39
|
+
def string_value(name)
|
40
|
+
return '' unless self.respond_to?(name)
|
41
|
+
value = self.send(name)
|
42
|
+
|
43
|
+
if value.is_a?(Array)
|
44
|
+
"[#{value.join(', ')}]"
|
45
|
+
else
|
46
|
+
"Val: #{value}"
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
39
50
|
protected
|
40
51
|
def check_for_spam
|
41
52
|
if self.defensio_signature.blank?
|
@@ -0,0 +1,14 @@
|
|
1
|
+
<%= fields_for "form[fields][#{index}]", field do |f| %>
|
2
|
+
<tr>
|
3
|
+
<td><%= f.hidden_field :_type %><%= f.label :name, 'Name *' %><%= f.text_field :name %></td>
|
4
|
+
<td>Multi-Select box</td>
|
5
|
+
<td><%= f.label :label, 'Label' %><%= f.text_field :label %></td>
|
6
|
+
<td><%= f.label :default, 'Default Option' %><%= f.text_field :default %></td>
|
7
|
+
<td class="center">-</td>
|
8
|
+
<td><%= f.label :options, 'Options' %><%= f.text_field :options %></td>
|
9
|
+
<td><%= f.label :required, 'Required?' %><%= f.check_box :required %></td>
|
10
|
+
<td width="25" class="up"><a class="page_up" title="Move this field up">up</a></td>
|
11
|
+
<td width="30" class="down"><a class="page_down" title="Move this field down">down</a></td>
|
12
|
+
<td><%= link_to_function 'Delete', 'return delete_form_field(this);', :class => 'delete' %></td>
|
13
|
+
</tr>
|
14
|
+
<% end %>
|
@@ -20,7 +20,7 @@
|
|
20
20
|
<% @responses.sort_by(&:created_at).reverse.each do |response| %>
|
21
21
|
<tr id="form-<%= response.id %>" class="<%=cycle('odd', 'even')%>">
|
22
22
|
<td class="edit"><%= mail_to response.email, h(response.name) %></td>
|
23
|
-
<td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.
|
23
|
+
<td><%= @form.fields.collect{|f| "<strong>#{f.name}:</strong> #{response.string_value(f.underscored_name)}" }.join(", ").html_safe %></td>
|
24
24
|
<td><%= h response.created_at.to_formatted_s(:long_dot) %></td>
|
25
25
|
<td><%= link_to 'Delete', noodall_admin_form_form_response_path(@form, response), :confirm => 'Are you sure?', :method => :delete, :class => 'delete', :title => 'Delete this response' %>
|
26
26
|
<%= link_to 'Mark as Spam', mark_as_spam_noodall_admin_form_form_response_path(@form, response), :class => 'spam', :title => 'Mark this response as spam and delete' %></td>
|
@@ -4,6 +4,7 @@
|
|
4
4
|
<select id="field-type" name="field_type">
|
5
5
|
<option value="text_field">Text</option>
|
6
6
|
<option value="select">Select Box</option>
|
7
|
+
<option value="multiselect">Multi-Select Box</option>
|
7
8
|
<option value="radio">Radio Buttons</option>
|
8
9
|
<option value="check_box">Check Box</option>
|
9
10
|
</select>
|
@@ -47,6 +47,9 @@
|
|
47
47
|
<p id="select" class="field-help">
|
48
48
|
<strong>Examples:</strong> Types of Enquiry, Types of Postal Delivery
|
49
49
|
</p>
|
50
|
+
<p id="multiselect" class="field-help">
|
51
|
+
Similar to Select. <strong>Examples:</strong> Acceptable Contact Methods, Phone, Phone AND Email, Phone AND Text AND Mail
|
52
|
+
</p>
|
50
53
|
<p id="radio" class="field-help">
|
51
54
|
<strong>Examples:</strong> Yes or No Questions, Multiple Choice<br/><br/>
|
52
55
|
The radio button only allows one option to be chosen.
|
@@ -4,41 +4,9 @@
|
|
4
4
|
<p class="required"><span>*</span> Required</p>
|
5
5
|
<%= error_messages_for :object => form_response %>
|
6
6
|
<% for field in form.fields %>
|
7
|
-
<% field_label = (field.label.blank? ? field.name : field.label) %>
|
8
7
|
<div class="form-wrap">
|
9
|
-
|
10
|
-
<%= (f.label field.underscored_name, field_label) %><%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
11
|
-
<% end %>
|
12
|
-
|
13
|
-
<% case field._type.gsub(/^.*::/,'')
|
14
|
-
when 'TextField'
|
15
|
-
if field.rows > 1 %>
|
16
|
-
<%= f.text_area field.underscored_name, :cols => 20, :rows => field.rows, :class => field.default_class(form_response) %>
|
17
|
-
<% else %>
|
18
|
-
<%= f.text_field field.underscored_name, :class => field.default_class(form_response) %>
|
19
|
-
<% end
|
20
|
-
when 'Select' %>
|
21
|
-
<%= f.select field.underscored_name, options_for_select(field.options.split(',').collect{|o| o.strip!;[o,o]}, form_response.send(field.underscored_name)) %>
|
22
|
-
<% when 'Radio' %>
|
23
|
-
<fieldset>
|
24
|
-
<legend><%= field_label %></legend>
|
25
|
-
<%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
26
|
-
<span class="radio-wrapper">
|
27
|
-
<% field.options.split(',').each do |option|
|
28
|
-
option.strip! %>
|
29
|
-
<span class="radio">
|
30
|
-
<%= f.radio_button field.underscored_name, option, :checked => (option == form_response.send(field.underscored_name)) %>
|
31
|
-
<%= f.label "#{field.underscored_name}_#{option.parameterize('_')}", option %>
|
32
|
-
</span>
|
33
|
-
<% end %>
|
34
|
-
</span>
|
35
|
-
</fieldset>
|
36
|
-
<% when 'CheckBox' %>
|
37
|
-
<%= f.check_box field.underscored_name, {}, 'Yes', 'No' %>
|
38
|
-
<% end %>
|
39
|
-
|
8
|
+
<%= render :partial => "noodall/form_responses/fields/#{field._type.gsub(/^.*::/, '').downcase}", :locals => {:form_response => form_response, :f => f, :field => field} %>
|
40
9
|
</div>
|
41
|
-
|
42
10
|
<% end %>
|
43
11
|
|
44
12
|
<p class="buttons">
|
@@ -0,0 +1,3 @@
|
|
1
|
+
<%= (f.label field.underscored_name, field.label) %><%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
2
|
+
<% field_options = field.options.split(',').collect{|o| o.strip!;[o,o]} %>
|
3
|
+
<%= f.select field.underscored_name, options_for_select(field_options, form_response.send(field.underscored_name)), :multiple => nil, :size => [field_options.size, 10].min %>
|
@@ -0,0 +1,13 @@
|
|
1
|
+
<fieldset>
|
2
|
+
<legend><%= field.label %></legend>
|
3
|
+
<%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
4
|
+
<span class="radio-wrapper">
|
5
|
+
<% field.options.split(',').each do |option|
|
6
|
+
option.strip! %>
|
7
|
+
<span class="radio">
|
8
|
+
<%= f.radio_button field.underscored_name, option, :checked => (option == form_response.send(field.underscored_name)) %>
|
9
|
+
<%= f.label "#{field.underscored_name}_#{option.parameterize('_')}", option %>
|
10
|
+
</span>
|
11
|
+
<% end %>
|
12
|
+
</span>
|
13
|
+
</fieldset>
|
@@ -0,0 +1,2 @@
|
|
1
|
+
<%= (f.label field.underscored_name, field.label) %><%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
2
|
+
<%= f.select field.underscored_name, options_for_select(field.options.split(',').collect{|o| o.strip!;[o,o]}, form_response.send(field.underscored_name)) %>
|
@@ -0,0 +1,6 @@
|
|
1
|
+
<%= (f.label field.underscored_name, field.label) %><%= (field.required ? content_tag('span', ' *', :class => 'required') : '') %>
|
2
|
+
<% if field.rows > 1 %>
|
3
|
+
<%= f.text_area field.underscored_name, :cols => 20, :rows => field.rows, :class => field.default_class(form_response) %>
|
4
|
+
<% else %>
|
5
|
+
<%= f.text_field field.underscored_name, :class => field.default_class(form_response) %>
|
6
|
+
<% end %>
|
@@ -1,5 +1,5 @@
|
|
1
1
|
function new_form_field(type) {
|
2
|
-
if ($.inArray(type, ['text_field', 'select', 'radio', 'check_box']) == -1) {
|
2
|
+
if ($.inArray(type, ['text_field', 'select', 'multiselect', 'radio', 'check_box']) == -1) {
|
3
3
|
alert('Unknown field type.');
|
4
4
|
} else {
|
5
5
|
// find an index for the new form field (largest index plus one)
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: noodall-form-builder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
5
|
-
prerelease:
|
4
|
+
hash: 27
|
5
|
+
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
|
+
- 1
|
8
9
|
- 0
|
9
|
-
|
10
|
-
version: 0.0.13
|
10
|
+
version: 0.1.0
|
11
11
|
platform: ruby
|
12
12
|
authors: []
|
13
13
|
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-02-
|
18
|
+
date: 2011-02-24 00:00:00 +00:00
|
19
19
|
default_executable:
|
20
20
|
dependencies:
|
21
21
|
- !ruby/object:Gem::Dependency
|
@@ -30,10 +30,10 @@ dependencies:
|
|
30
30
|
- 0
|
31
31
|
- 0
|
32
32
|
version: 1.0.0
|
33
|
+
type: :development
|
33
34
|
name: bundler
|
34
35
|
prerelease: false
|
35
36
|
version_requirements: *id001
|
36
|
-
type: :development
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
requirement: &id002 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
@@ -44,10 +44,10 @@ dependencies:
|
|
44
44
|
segments:
|
45
45
|
- 0
|
46
46
|
version: "0"
|
47
|
+
type: :runtime
|
47
48
|
name: fastercsv
|
48
49
|
prerelease: false
|
49
50
|
version_requirements: *id002
|
50
|
-
type: :runtime
|
51
51
|
description: Functionality for building custom forms
|
52
52
|
email: []
|
53
53
|
|
@@ -75,6 +75,7 @@ files:
|
|
75
75
|
- app/models/noodall/field.rb
|
76
76
|
- app/models/noodall/form.rb
|
77
77
|
- app/models/noodall/form_response.rb
|
78
|
+
- app/models/noodall/multiselect.rb
|
78
79
|
- app/models/noodall/radio.rb
|
79
80
|
- app/models/noodall/select.rb
|
80
81
|
- app/models/noodall/text_field.rb
|
@@ -84,6 +85,7 @@ files:
|
|
84
85
|
- app/views/form_mailer/form_response.html.erb
|
85
86
|
- app/views/form_mailer/form_response_thankyou.html.erb
|
86
87
|
- app/views/noodall/admin/fields/_check_box.html.erb
|
88
|
+
- app/views/noodall/admin/fields/_multiselect.html.erb
|
87
89
|
- app/views/noodall/admin/fields/_radio.html.erb
|
88
90
|
- app/views/noodall/admin/fields/_select.html.erb
|
89
91
|
- app/views/noodall/admin/fields/_text_field.html.erb
|
@@ -94,6 +96,11 @@ files:
|
|
94
96
|
- app/views/noodall/admin/forms/show.html.erb
|
95
97
|
- app/views/noodall/form_responses/_form.html.erb
|
96
98
|
- app/views/noodall/form_responses/create.html.erb
|
99
|
+
- app/views/noodall/form_responses/fields/_checkbox.html.erb
|
100
|
+
- app/views/noodall/form_responses/fields/_multiselect.html.erb
|
101
|
+
- app/views/noodall/form_responses/fields/_radio.html.erb
|
102
|
+
- app/views/noodall/form_responses/fields/_select.html.erb
|
103
|
+
- app/views/noodall/form_responses/fields/_textfield.html.erb
|
97
104
|
- app/views/noodall/form_responses/new.html.erb
|
98
105
|
- app/views/noodall/forms/edit.html.erb
|
99
106
|
- app/views/noodall/forms/index.html.erb
|
@@ -196,7 +203,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
196
203
|
requirements: []
|
197
204
|
|
198
205
|
rubyforge_project:
|
199
|
-
rubygems_version: 1.
|
206
|
+
rubygems_version: 1.3.7
|
200
207
|
signing_key:
|
201
208
|
specification_version: 3
|
202
209
|
summary: Noodall Form Builder
|