formbuilder-rb 0.0.1
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.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/Rakefile +24 -0
- data/app/controllers/formbuilder/forms_controller.rb +53 -0
- data/app/models/formbuilder/entry_attachment.rb +15 -0
- data/app/models/formbuilder/form.rb +12 -0
- data/app/models/formbuilder/response_field.rb +85 -0
- data/app/models/formbuilder/response_field_address.rb +349 -0
- data/app/models/formbuilder/response_field_checkboxes.rb +68 -0
- data/app/models/formbuilder/response_field_date.rb +46 -0
- data/app/models/formbuilder/response_field_dropdown.rb +30 -0
- data/app/models/formbuilder/response_field_email.rb +26 -0
- data/app/models/formbuilder/response_field_file.rb +44 -0
- data/app/models/formbuilder/response_field_number.rb +33 -0
- data/app/models/formbuilder/response_field_paragraph.rb +21 -0
- data/app/models/formbuilder/response_field_price.rb +47 -0
- data/app/models/formbuilder/response_field_radio.rb +52 -0
- data/app/models/formbuilder/response_field_section_break.rb +17 -0
- data/app/models/formbuilder/response_field_text.rb +16 -0
- data/app/models/formbuilder/response_field_time.rb +53 -0
- data/app/models/formbuilder/response_field_website.rb +31 -0
- data/app/uploaders/formbuilder/entry_attachment_uploader.rb +26 -0
- data/db/migrate/20130924185726_create_formbuilder_forms.rb +10 -0
- data/db/migrate/20130924185814_create_formbuilder_response_fields.rb +16 -0
- data/db/migrate/20130924185815_create_formbuilder_entry_attachments.rb +10 -0
- data/lib/formbuilder/engine.rb +5 -0
- data/lib/formbuilder/entry.rb +242 -0
- data/lib/formbuilder/entry_renderer.rb +47 -0
- data/lib/formbuilder/entry_table_renderer.rb +58 -0
- data/lib/formbuilder/entry_validator.rb +107 -0
- data/lib/formbuilder/form_renderer.rb +102 -0
- data/lib/formbuilder/version.rb +3 -0
- data/lib/formbuilder.rb +12 -0
- data/lib/tasks/formbuilder_tasks.rake +4 -0
- metadata +258 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 8903a78b92442b180ead19dd35b636f5b31427f9
|
4
|
+
data.tar.gz: 06b5c87025806f7354abff694997adb6405cd07d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c36e2043201c9e356973ddf02c08b52337f0d615c36ccbe70ce1adf738db14916bd74463b5a8c9f0b0cf0ce5449b42a5b7eca65957160d6aea0a4e07d3c44a16
|
7
|
+
data.tar.gz: ef2b24b1fc81547d028fb9d2c73a612e50b99d5dbeef7a77a4285ca952c6ddf99249aaaf7a395a3570c5fd6eabbe294361839ed4ac648176a14d037b6ffb016a
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright 2013 YOURNAME
|
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/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
begin
|
2
|
+
require 'bundler/setup'
|
3
|
+
rescue LoadError
|
4
|
+
puts 'You must `gem install bundler` and `bundle install` to run rake tasks'
|
5
|
+
end
|
6
|
+
|
7
|
+
require 'rdoc/task'
|
8
|
+
|
9
|
+
RDoc::Task.new(:rdoc) do |rdoc|
|
10
|
+
rdoc.rdoc_dir = 'rdoc'
|
11
|
+
rdoc.title = 'Formbuilder'
|
12
|
+
rdoc.options << '--line-numbers'
|
13
|
+
rdoc.rdoc_files.include('README.rdoc')
|
14
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
15
|
+
end
|
16
|
+
|
17
|
+
APP_RAKEFILE = File.expand_path("../spec/dummy/Rakefile", __FILE__)
|
18
|
+
load 'rails/tasks/engine.rake'
|
19
|
+
|
20
|
+
|
21
|
+
|
22
|
+
Bundler::GemHelper.install_tasks
|
23
|
+
|
24
|
+
require 'rake/testtask'
|
@@ -0,0 +1,53 @@
|
|
1
|
+
# A controller to integrate with the Formbuilder.js frontend (https://github.com/dobtco/formbuilder)
|
2
|
+
|
3
|
+
module Formbuilder
|
4
|
+
class FormsController < ApplicationController
|
5
|
+
|
6
|
+
before_filter :load_form
|
7
|
+
|
8
|
+
protect_from_forgery except: :update
|
9
|
+
|
10
|
+
def update
|
11
|
+
existing_response_field_ids = []
|
12
|
+
cids = {}
|
13
|
+
|
14
|
+
(params[:fields] || []).each_with_index do |field_params, i|
|
15
|
+
response_field = field_params[:id].present? ?
|
16
|
+
@form.response_fields.find { |rf| rf.id == field_params[:id].to_i } :
|
17
|
+
@form.response_fields.build
|
18
|
+
|
19
|
+
response_field.update_attributes(transformed_field_params(field_params, i))
|
20
|
+
cids[response_field.id] = field_params[:cid]
|
21
|
+
existing_response_field_ids.push response_field.id
|
22
|
+
end
|
23
|
+
|
24
|
+
# destroy fields that no longer exist
|
25
|
+
@form.response_fields.each do |response_field|
|
26
|
+
response_field.destroy unless response_field.id.in?(existing_response_field_ids)
|
27
|
+
end
|
28
|
+
|
29
|
+
@form.response_fields.reload
|
30
|
+
|
31
|
+
@form.response_fields.each do |rf|
|
32
|
+
rf.cid = cids[rf.id]
|
33
|
+
end
|
34
|
+
|
35
|
+
render json: @form.response_fields.to_json(methods: [:field_type, :cid])
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
def load_form
|
40
|
+
@form = Formbuilder::Form.find(params[:id])
|
41
|
+
end
|
42
|
+
|
43
|
+
def transformed_field_params(field_params, i)
|
44
|
+
filtered_params = field_params.reject { |k, v|
|
45
|
+
!k.to_sym.in?(Formbuilder::ResponseField::ALLOWED_PARAMS) || v.blank?
|
46
|
+
}.merge(
|
47
|
+
sort_order: i,
|
48
|
+
type: "Formbuilder::ResponseField#{field_params[:field_type].camelize}"
|
49
|
+
)
|
50
|
+
end
|
51
|
+
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class EntryAttachment < ActiveRecord::Base
|
3
|
+
|
4
|
+
mount_uploader :upload, Formbuilder::EntryAttachmentUploader
|
5
|
+
before_save :update_upload_attributes
|
6
|
+
|
7
|
+
private
|
8
|
+
def update_upload_attributes
|
9
|
+
if upload.present? && upload_changed?
|
10
|
+
self.content_type = upload.file.content_type
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,85 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class ResponseField < ActiveRecord::Base
|
3
|
+
|
4
|
+
default_scope -> { order('sort_order') }
|
5
|
+
|
6
|
+
# For backbone saving compatibility
|
7
|
+
attr_accessor :cid
|
8
|
+
|
9
|
+
# Does this field take an input?
|
10
|
+
# (An example of a non-input field is a section break.)
|
11
|
+
attr_accessor :input_field
|
12
|
+
|
13
|
+
# Does this field have a preset list of options?
|
14
|
+
attr_accessor :options_field
|
15
|
+
|
16
|
+
# Do we need to serialize the response for this field?
|
17
|
+
attr_accessor :serialized
|
18
|
+
|
19
|
+
# Should we sort this field's responses as numeric values?
|
20
|
+
attr_accessor :sort_as_numeric
|
21
|
+
|
22
|
+
# Underscored name of this field
|
23
|
+
attr_accessor :field_type
|
24
|
+
|
25
|
+
after_initialize -> {
|
26
|
+
@input_field = true
|
27
|
+
}
|
28
|
+
|
29
|
+
scope :not_blind, -> { where(blind: false) }
|
30
|
+
scope :not_admin_only, -> { where(admin_only: false) }
|
31
|
+
|
32
|
+
belongs_to :form
|
33
|
+
|
34
|
+
serialize :field_options, Hash
|
35
|
+
|
36
|
+
ALLOWED_PARAMS = [:key, :blind, :label, :field_options, :required, :admin_only]
|
37
|
+
|
38
|
+
def length_validations(include_units = true)
|
39
|
+
return_hash = {
|
40
|
+
minlength: field_options[:minlength],
|
41
|
+
maxlength: field_options[:maxlength]
|
42
|
+
}
|
43
|
+
|
44
|
+
return_hash[:min_max_length_units] = field_options[:min_max_length_units] if include_units
|
45
|
+
|
46
|
+
return_hash.select { |k, v| v.present? }
|
47
|
+
end
|
48
|
+
|
49
|
+
def has_length_validations?
|
50
|
+
length_validations(false).any?
|
51
|
+
end
|
52
|
+
|
53
|
+
def min_max_validations
|
54
|
+
return_hash = {
|
55
|
+
min: field_options[:min],
|
56
|
+
max: field_options[:max]
|
57
|
+
}
|
58
|
+
|
59
|
+
return_hash.select { |k, v| v.present? }
|
60
|
+
end
|
61
|
+
|
62
|
+
def render_entry_for_table(value, opts = {})
|
63
|
+
"""
|
64
|
+
<td data-column-id='#{self.id}'>
|
65
|
+
#{render_entry(value, opts)}
|
66
|
+
</td>
|
67
|
+
"""
|
68
|
+
end
|
69
|
+
|
70
|
+
def render_input(value, opts = {})
|
71
|
+
raise 'Not implemented'
|
72
|
+
end
|
73
|
+
|
74
|
+
def render_entry(value, opts = {})
|
75
|
+
value
|
76
|
+
end
|
77
|
+
|
78
|
+
def audit_response(value, all_responses)
|
79
|
+
end
|
80
|
+
|
81
|
+
def validate_response(value)
|
82
|
+
end
|
83
|
+
|
84
|
+
end
|
85
|
+
end
|
@@ -0,0 +1,349 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class ResponseFieldAddress < ResponseField
|
3
|
+
|
4
|
+
after_initialize -> {
|
5
|
+
@serialized = true
|
6
|
+
@field_type = 'address'
|
7
|
+
}
|
8
|
+
|
9
|
+
def render_input(value, opts = {})
|
10
|
+
selected_country = (value['country'] || 'US').to_sym
|
11
|
+
|
12
|
+
"""
|
13
|
+
<div class='input-line'>
|
14
|
+
<span class='street'>
|
15
|
+
<input type'text' name='response_fields[#{self[:id]}][street]' value='#{value['street']}' />
|
16
|
+
<label>Address</label>
|
17
|
+
</span>
|
18
|
+
</div>
|
19
|
+
|
20
|
+
<div class='input-line'>
|
21
|
+
<span class='city'>
|
22
|
+
<input type'text' name='response_fields[#{self[:id]}][city]' value='#{value['city']}' />
|
23
|
+
<label>City</label>
|
24
|
+
</span>
|
25
|
+
|
26
|
+
<span class='state'>
|
27
|
+
<input type'text' name='response_fields[#{self[:id]}][state]' value='#{value['state']}' />
|
28
|
+
<label>State / Province / Region</label>
|
29
|
+
</span>
|
30
|
+
</div>
|
31
|
+
|
32
|
+
<div class='input-line'>
|
33
|
+
<span class='zip'>
|
34
|
+
<input type'text' name='response_fields[#{self[:id]}][zipcode]' value='#{value['zipcode']}' />
|
35
|
+
<label>Zipcode</label>
|
36
|
+
</span>
|
37
|
+
|
38
|
+
<span class='country'>
|
39
|
+
<select name='response_fields[#{self[:id]}][country]'>
|
40
|
+
#{country_options(selected_country)}
|
41
|
+
</select>
|
42
|
+
<label>Country</label>
|
43
|
+
</span>
|
44
|
+
</div>
|
45
|
+
"""
|
46
|
+
end
|
47
|
+
|
48
|
+
def render_entry(value, opts = {})
|
49
|
+
"""
|
50
|
+
#{value['street']}<br />
|
51
|
+
#{value['city']} #{value['state']} #{value['zipcode']}<br />
|
52
|
+
#{value['country']}
|
53
|
+
"""
|
54
|
+
end
|
55
|
+
|
56
|
+
def audit_response(value, all_responses)
|
57
|
+
begin
|
58
|
+
coords = Geocoder.coordinates("#{value['street']} #{value['city']} " +
|
59
|
+
"#{value['state']} #{value['zipcode']} #{value['country']}")
|
60
|
+
|
61
|
+
all_responses["#{self.id}_x"] = coords[0]
|
62
|
+
all_responses["#{self.id}_y"] = coords[1]
|
63
|
+
rescue
|
64
|
+
all_responses["#{self.id}_x"] = nil
|
65
|
+
all_responses["#{self.id}_y"] = nil
|
66
|
+
end
|
67
|
+
end
|
68
|
+
|
69
|
+
private
|
70
|
+
def country_options(selected_country)
|
71
|
+
all_countries.map do |k, v|
|
72
|
+
"""
|
73
|
+
<option value='#{k}' #{selected_country == k ? 'selected' : ''}>#{v}</option>
|
74
|
+
"""
|
75
|
+
end.join('')
|
76
|
+
end
|
77
|
+
|
78
|
+
# http://www.iso.org/iso/country_names_and_code_elements_txt
|
79
|
+
def all_countries
|
80
|
+
{
|
81
|
+
:"AF" => "Afghanistan",
|
82
|
+
:"AL" => "Albania",
|
83
|
+
:"DZ" => "Algeria",
|
84
|
+
:"AS" => "American Samoa",
|
85
|
+
:"AD" => "Andorra",
|
86
|
+
:"AO" => "Angola",
|
87
|
+
:"AI" => "Anguilla",
|
88
|
+
:"AQ" => "Antarctica",
|
89
|
+
:"AG" => "Antigua and Barbuda",
|
90
|
+
:"AR" => "Argentina",
|
91
|
+
:"AM" => "Armenia",
|
92
|
+
:"AW" => "Aruba",
|
93
|
+
:"AU" => "Australia",
|
94
|
+
:"AT" => "Austria",
|
95
|
+
:"AZ" => "Azerbaijan",
|
96
|
+
:"BS" => "Bahamas",
|
97
|
+
:"BH" => "Bahrain",
|
98
|
+
:"BD" => "Bangladesh",
|
99
|
+
:"BB" => "Barbados",
|
100
|
+
:"BY" => "Belarus",
|
101
|
+
:"BE" => "Belgium",
|
102
|
+
:"BZ" => "Belize",
|
103
|
+
:"BJ" => "Benin",
|
104
|
+
:"BM" => "Bermuda",
|
105
|
+
:"BT" => "Bhutan",
|
106
|
+
:"BO" => "Bolivia",
|
107
|
+
:"BA" => "Bosnia and Herzegovina",
|
108
|
+
:"BW" => "Botswana",
|
109
|
+
:"BV" => "Bouvet Island",
|
110
|
+
:"BR" => "Brazil",
|
111
|
+
:"BQ" => "British Antarctic Territory",
|
112
|
+
:"IO" => "British Indian Ocean Territory",
|
113
|
+
:"VG" => "British Virgin Islands",
|
114
|
+
:"BN" => "Brunei",
|
115
|
+
:"BG" => "Bulgaria",
|
116
|
+
:"BF" => "Burkina Faso",
|
117
|
+
:"BI" => "Burundi",
|
118
|
+
:"KH" => "Cambodia",
|
119
|
+
:"CM" => "Cameroon",
|
120
|
+
:"CA" => "Canada",
|
121
|
+
:"CT" => "Canton and Enderbury Islands",
|
122
|
+
:"CV" => "Cape Verde",
|
123
|
+
:"KY" => "Cayman Islands",
|
124
|
+
:"CF" => "Central African Republic",
|
125
|
+
:"TD" => "Chad",
|
126
|
+
:"CL" => "Chile",
|
127
|
+
:"CN" => "China",
|
128
|
+
:"CX" => "Christmas Island",
|
129
|
+
:"CC" => "Cocos [Keeling] Islands",
|
130
|
+
:"CO" => "Colombia",
|
131
|
+
:"KM" => "Comoros",
|
132
|
+
:"CG" => "Congo - Brazzaville",
|
133
|
+
:"CD" => "Congo - Kinshasa",
|
134
|
+
:"CK" => "Cook Islands",
|
135
|
+
:"CR" => "Costa Rica",
|
136
|
+
:"HR" => "Croatia",
|
137
|
+
:"CU" => "Cuba",
|
138
|
+
:"CY" => "Cyprus",
|
139
|
+
:"CZ" => "Czech Republic",
|
140
|
+
:"CI" => "Côte d’Ivoire",
|
141
|
+
:"DK" => "Denmark",
|
142
|
+
:"DJ" => "Djibouti",
|
143
|
+
:"DM" => "Dominica",
|
144
|
+
:"DO" => "Dominican Republic",
|
145
|
+
:"NQ" => "Dronning Maud Land",
|
146
|
+
:"DD" => "East Germany",
|
147
|
+
:"EC" => "Ecuador",
|
148
|
+
:"EG" => "Egypt",
|
149
|
+
:"SV" => "El Salvador",
|
150
|
+
:"GQ" => "Equatorial Guinea",
|
151
|
+
:"ER" => "Eritrea",
|
152
|
+
:"EE" => "Estonia",
|
153
|
+
:"ET" => "Ethiopia",
|
154
|
+
:"FK" => "Falkland Islands",
|
155
|
+
:"FO" => "Faroe Islands",
|
156
|
+
:"FJ" => "Fiji",
|
157
|
+
:"FI" => "Finland",
|
158
|
+
:"FR" => "France",
|
159
|
+
:"GF" => "French Guiana",
|
160
|
+
:"PF" => "French Polynesia",
|
161
|
+
:"TF" => "French Southern Territories",
|
162
|
+
:"FQ" => "French Southern and Antarctic Territories",
|
163
|
+
:"GA" => "Gabon",
|
164
|
+
:"GM" => "Gambia",
|
165
|
+
:"GE" => "Georgia",
|
166
|
+
:"DE" => "Germany",
|
167
|
+
:"GH" => "Ghana",
|
168
|
+
:"GI" => "Gibraltar",
|
169
|
+
:"GR" => "Greece",
|
170
|
+
:"GL" => "Greenland",
|
171
|
+
:"GD" => "Grenada",
|
172
|
+
:"GP" => "Guadeloupe",
|
173
|
+
:"GU" => "Guam",
|
174
|
+
:"GT" => "Guatemala",
|
175
|
+
:"GG" => "Guernsey",
|
176
|
+
:"GN" => "Guinea",
|
177
|
+
:"GW" => "Guinea-Bissau",
|
178
|
+
:"GY" => "Guyana",
|
179
|
+
:"HT" => "Haiti",
|
180
|
+
:"HM" => "Heard Island and McDonald Islands",
|
181
|
+
:"HN" => "Honduras",
|
182
|
+
:"HK" => "Hong Kong SAR China",
|
183
|
+
:"HU" => "Hungary",
|
184
|
+
:"IS" => "Iceland",
|
185
|
+
:"IN" => "India",
|
186
|
+
:"ID" => "Indonesia",
|
187
|
+
:"IR" => "Iran",
|
188
|
+
:"IQ" => "Iraq",
|
189
|
+
:"IE" => "Ireland",
|
190
|
+
:"IM" => "Isle of Man",
|
191
|
+
:"IL" => "Israel",
|
192
|
+
:"IT" => "Italy",
|
193
|
+
:"JM" => "Jamaica",
|
194
|
+
:"JP" => "Japan",
|
195
|
+
:"JE" => "Jersey",
|
196
|
+
:"JT" => "Johnston Island",
|
197
|
+
:"JO" => "Jordan",
|
198
|
+
:"KZ" => "Kazakhstan",
|
199
|
+
:"KE" => "Kenya",
|
200
|
+
:"KI" => "Kiribati",
|
201
|
+
:"KW" => "Kuwait",
|
202
|
+
:"KG" => "Kyrgyzstan",
|
203
|
+
:"LA" => "Laos",
|
204
|
+
:"LV" => "Latvia",
|
205
|
+
:"LB" => "Lebanon",
|
206
|
+
:"LS" => "Lesotho",
|
207
|
+
:"LR" => "Liberia",
|
208
|
+
:"LY" => "Libya",
|
209
|
+
:"LI" => "Liechtenstein",
|
210
|
+
:"LT" => "Lithuania",
|
211
|
+
:"LU" => "Luxembourg",
|
212
|
+
:"MO" => "Macau SAR China",
|
213
|
+
:"MK" => "Macedonia",
|
214
|
+
:"MG" => "Madagascar",
|
215
|
+
:"MW" => "Malawi",
|
216
|
+
:"MY" => "Malaysia",
|
217
|
+
:"MV" => "Maldives",
|
218
|
+
:"ML" => "Mali",
|
219
|
+
:"MT" => "Malta",
|
220
|
+
:"MH" => "Marshall Islands",
|
221
|
+
:"MQ" => "Martinique",
|
222
|
+
:"MR" => "Mauritania",
|
223
|
+
:"MU" => "Mauritius",
|
224
|
+
:"YT" => "Mayotte",
|
225
|
+
:"FX" => "Metropolitan France",
|
226
|
+
:"MX" => "Mexico",
|
227
|
+
:"FM" => "Micronesia",
|
228
|
+
:"MI" => "Midway Islands",
|
229
|
+
:"MD" => "Moldova",
|
230
|
+
:"MC" => "Monaco",
|
231
|
+
:"MN" => "Mongolia",
|
232
|
+
:"ME" => "Montenegro",
|
233
|
+
:"MS" => "Montserrat",
|
234
|
+
:"MA" => "Morocco",
|
235
|
+
:"MZ" => "Mozambique",
|
236
|
+
:"MM" => "Myanmar [Burma]",
|
237
|
+
:"NA" => "Namibia",
|
238
|
+
:"NR" => "Nauru",
|
239
|
+
:"NP" => "Nepal",
|
240
|
+
:"NL" => "Netherlands",
|
241
|
+
:"AN" => "Netherlands Antilles",
|
242
|
+
:"NT" => "Neutral Zone",
|
243
|
+
:"NC" => "New Caledonia",
|
244
|
+
:"NZ" => "New Zealand",
|
245
|
+
:"NI" => "Nicaragua",
|
246
|
+
:"NE" => "Niger",
|
247
|
+
:"NG" => "Nigeria",
|
248
|
+
:"NU" => "Niue",
|
249
|
+
:"NF" => "Norfolk Island",
|
250
|
+
:"KP" => "North Korea",
|
251
|
+
:"VD" => "North Vietnam",
|
252
|
+
:"MP" => "Northern Mariana Islands",
|
253
|
+
:"NO" => "Norway",
|
254
|
+
:"OM" => "Oman",
|
255
|
+
:"PC" => "Pacific Islands Trust Territory",
|
256
|
+
:"PK" => "Pakistan",
|
257
|
+
:"PW" => "Palau",
|
258
|
+
:"PS" => "Palestinian Territories",
|
259
|
+
:"PA" => "Panama",
|
260
|
+
:"PZ" => "Panama Canal Zone",
|
261
|
+
:"PG" => "Papua New Guinea",
|
262
|
+
:"PY" => "Paraguay",
|
263
|
+
:"YD" => "People's Democratic Republic of Yemen",
|
264
|
+
:"PE" => "Peru",
|
265
|
+
:"PH" => "Philippines",
|
266
|
+
:"PN" => "Pitcairn Islands",
|
267
|
+
:"PL" => "Poland",
|
268
|
+
:"PT" => "Portugal",
|
269
|
+
:"PR" => "Puerto Rico",
|
270
|
+
:"QA" => "Qatar",
|
271
|
+
:"RO" => "Romania",
|
272
|
+
:"RU" => "Russia",
|
273
|
+
:"RW" => "Rwanda",
|
274
|
+
:"RE" => "Réunion",
|
275
|
+
:"BL" => "Saint Barthélemy",
|
276
|
+
:"SH" => "Saint Helena",
|
277
|
+
:"KN" => "Saint Kitts and Nevis",
|
278
|
+
:"LC" => "Saint Lucia",
|
279
|
+
:"MF" => "Saint Martin",
|
280
|
+
:"PM" => "Saint Pierre and Miquelon",
|
281
|
+
:"VC" => "Saint Vincent and the Grenadines",
|
282
|
+
:"WS" => "Samoa",
|
283
|
+
:"SM" => "San Marino",
|
284
|
+
:"SA" => "Saudi Arabia",
|
285
|
+
:"SN" => "Senegal",
|
286
|
+
:"RS" => "Serbia",
|
287
|
+
:"CS" => "Serbia and Montenegro",
|
288
|
+
:"SC" => "Seychelles",
|
289
|
+
:"SL" => "Sierra Leone",
|
290
|
+
:"SG" => "Singapore",
|
291
|
+
:"SK" => "Slovakia",
|
292
|
+
:"SI" => "Slovenia",
|
293
|
+
:"SB" => "Solomon Islands",
|
294
|
+
:"SO" => "Somalia",
|
295
|
+
:"ZA" => "South Africa",
|
296
|
+
:"GS" => "South Georgia and the South Sandwich Islands",
|
297
|
+
:"KR" => "South Korea",
|
298
|
+
:"ES" => "Spain",
|
299
|
+
:"LK" => "Sri Lanka",
|
300
|
+
:"SD" => "Sudan",
|
301
|
+
:"SR" => "Suriname",
|
302
|
+
:"SJ" => "Svalbard and Jan Mayen",
|
303
|
+
:"SZ" => "Swaziland",
|
304
|
+
:"SE" => "Sweden",
|
305
|
+
:"CH" => "Switzerland",
|
306
|
+
:"SY" => "Syria",
|
307
|
+
:"ST" => "São Tomé and Príncipe",
|
308
|
+
:"TW" => "Taiwan",
|
309
|
+
:"TJ" => "Tajikistan",
|
310
|
+
:"TZ" => "Tanzania",
|
311
|
+
:"TH" => "Thailand",
|
312
|
+
:"TL" => "Timor-Leste",
|
313
|
+
:"TG" => "Togo",
|
314
|
+
:"TK" => "Tokelau",
|
315
|
+
:"TO" => "Tonga",
|
316
|
+
:"TT" => "Trinidad and Tobago",
|
317
|
+
:"TN" => "Tunisia",
|
318
|
+
:"TR" => "Turkey",
|
319
|
+
:"TM" => "Turkmenistan",
|
320
|
+
:"TC" => "Turks and Caicos Islands",
|
321
|
+
:"TV" => "Tuvalu",
|
322
|
+
:"UM" => "U.S. Minor Outlying Islands",
|
323
|
+
:"PU" => "U.S. Miscellaneous Pacific Islands",
|
324
|
+
:"VI" => "U.S. Virgin Islands",
|
325
|
+
:"UG" => "Uganda",
|
326
|
+
:"UA" => "Ukraine",
|
327
|
+
:"SU" => "Union of Soviet Socialist Republics",
|
328
|
+
:"AE" => "United Arab Emirates",
|
329
|
+
:"GB" => "United Kingdom",
|
330
|
+
:"US" => "United States",
|
331
|
+
:"ZZ" => "Unknown or Invalid Region",
|
332
|
+
:"UY" => "Uruguay",
|
333
|
+
:"UZ" => "Uzbekistan",
|
334
|
+
:"VU" => "Vanuatu",
|
335
|
+
:"VA" => "Vatican City",
|
336
|
+
:"VE" => "Venezuela",
|
337
|
+
:"VN" => "Vietnam",
|
338
|
+
:"WK" => "Wake Island",
|
339
|
+
:"WF" => "Wallis and Futuna",
|
340
|
+
:"EH" => "Western Sahara",
|
341
|
+
:"YE" => "Yemen",
|
342
|
+
:"ZM" => "Zambia",
|
343
|
+
:"ZW" => "Zimbabwe",
|
344
|
+
:"AX" => "Åland Islands"
|
345
|
+
}
|
346
|
+
end
|
347
|
+
|
348
|
+
end
|
349
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class ResponseFieldCheckboxes < ResponseField
|
3
|
+
|
4
|
+
after_initialize -> {
|
5
|
+
@serialized = true
|
6
|
+
@options_field = true
|
7
|
+
@field_type = 'checkboxes'
|
8
|
+
}
|
9
|
+
|
10
|
+
def render_input(value, opts = {})
|
11
|
+
value ||= {}
|
12
|
+
|
13
|
+
str = (self[:field_options]["options"] || []).each_with_index.map do |option, i|
|
14
|
+
checked = value.present? ? value[option['label']] : (option['checked'] == 'true')
|
15
|
+
|
16
|
+
"""
|
17
|
+
<label>
|
18
|
+
<input type='checkbox' name='response_fields[#{self[:id]}][#{i}]' #{checked ? 'checked' : ''} value='on' />
|
19
|
+
#{option['label']}
|
20
|
+
</label>
|
21
|
+
"""
|
22
|
+
end.join('')
|
23
|
+
|
24
|
+
if self[:field_options]['include_other_option']
|
25
|
+
str += """
|
26
|
+
<div class='other-option'>
|
27
|
+
<label>
|
28
|
+
<input type='checkbox' name='response_fields[#{self[:id]}][other_checkbox]' #{value['Other'] ? 'checked' : ''} value='on' />
|
29
|
+
Other
|
30
|
+
</label>
|
31
|
+
|
32
|
+
<input type='text' name='response_fields[#{self[:id]}][other]' value='#{value['Other']}' />
|
33
|
+
</div>
|
34
|
+
"""
|
35
|
+
end
|
36
|
+
|
37
|
+
str
|
38
|
+
end
|
39
|
+
|
40
|
+
def render_entry(value, opts = {})
|
41
|
+
"""
|
42
|
+
<table class='response-table'>
|
43
|
+
<thead>
|
44
|
+
<tr>
|
45
|
+
<th class='key'>Key</th>
|
46
|
+
<th class='response'>Response</th>
|
47
|
+
</tr>
|
48
|
+
</thead>
|
49
|
+
<tbody>
|
50
|
+
""" +
|
51
|
+
|
52
|
+
(value || {}).map do |k, v|
|
53
|
+
"""
|
54
|
+
<tr class='#{v ? 'true' : 'false'}'>
|
55
|
+
<td>#{k}</td>
|
56
|
+
<td class='response'>#{v ? (k == 'Other' ? v : '<span class="icon-ok"></span>') : ''}</td>
|
57
|
+
</tr>
|
58
|
+
"""
|
59
|
+
end.join('') +
|
60
|
+
|
61
|
+
"""
|
62
|
+
</tbody>
|
63
|
+
</table>
|
64
|
+
"""
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,46 @@
|
|
1
|
+
module Formbuilder
|
2
|
+
class ResponseFieldDate < ResponseField
|
3
|
+
|
4
|
+
after_initialize -> {
|
5
|
+
@serialized = true
|
6
|
+
@sort_as_numeric = true
|
7
|
+
@field_type = 'date'
|
8
|
+
}
|
9
|
+
|
10
|
+
def render_input(value, opts = {})
|
11
|
+
"""
|
12
|
+
<div class='input-line'>
|
13
|
+
<span class='month'>
|
14
|
+
<input type='text' name='response_fields[#{self[:id]}][month]' value='#{value['month']}' maxlength='2' />
|
15
|
+
<label>MM</label>
|
16
|
+
</span>
|
17
|
+
|
18
|
+
<span class='above-line'>/</span>
|
19
|
+
|
20
|
+
<span class='day'>
|
21
|
+
<input type='text' name='response_fields[#{self[:id]}][day]' value='#{value['day']}' maxlength='2' />
|
22
|
+
<label>DD</label>
|
23
|
+
</span>
|
24
|
+
|
25
|
+
<span class='above-line'>/</span>
|
26
|
+
|
27
|
+
<span class='year'>
|
28
|
+
<input type='text' name='response_fields[#{self[:id]}][year]' value='#{value['year']}' maxlength='4' />
|
29
|
+
<label>YYYY</label>
|
30
|
+
</span>
|
31
|
+
</div>
|
32
|
+
"""
|
33
|
+
end
|
34
|
+
|
35
|
+
def render_entry(value, opts = {})
|
36
|
+
"#{value['month']}/#{value['day']}/#{value['year']}"
|
37
|
+
end
|
38
|
+
|
39
|
+
def validate_response(value)
|
40
|
+
if value['year'].to_i == 0 || !(DateTime.new(value['year'].to_i, value['month'].to_i, value['day'].to_i) rescue false)
|
41
|
+
"isn't a valid date."
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|