binda 0.0.3 → 0.0.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +14 -29
- data/Rakefile +16 -10
- data/app/assets/javascripts/binda/components/form_item.js +12 -1
- data/app/assets/javascripts/binda/components/form_item_asset.js +1 -0
- data/app/assets/javascripts/binda/components/form_item_choice.js +58 -0
- data/app/assets/javascripts/binda/components/form_item_editor.js +39 -0
- data/app/assets/javascripts/binda/components/form_item_repeater.js +7 -0
- data/app/assets/javascripts/binda/components/sortable.js +0 -1
- data/app/assets/javascripts/binda/dist/binda.bundle.js +175 -8
- data/app/assets/javascripts/binda/index.js +4 -0
- data/app/assets/stylesheets/binda/components/form_item.scss +64 -2
- data/app/controllers/binda/application_controller.rb +2 -10
- data/app/controllers/binda/choices_controller.rb +19 -0
- data/app/controllers/binda/components_controller.rb +38 -134
- data/app/controllers/binda/field_groups_controller.rb +18 -30
- data/app/controllers/binda/structures_controller.rb +6 -6
- data/app/controllers/concerns/binda/component_controller_helper.rb +16 -0
- data/app/models/binda/checkbox.rb +7 -0
- data/app/models/binda/choice.rb +11 -0
- data/app/models/binda/component.rb +12 -136
- data/app/models/binda/field_group.rb +1 -1
- data/app/models/binda/field_setting.rb +40 -8
- data/app/models/binda/radio.rb +5 -0
- data/app/models/binda/repeater.rb +11 -79
- data/app/models/binda/select.rb +7 -0
- data/app/models/binda/structure.rb +13 -13
- data/app/models/concerns/binda/component_model_helper.rb +170 -0
- data/app/views/binda/components/_form_item_new_repeater.html.erb +3 -5
- data/app/views/binda/components/_form_item_selectable.html.erb +72 -0
- data/app/views/binda/components/_form_section.html.erb +7 -2
- data/app/views/binda/components/_form_section_repeater.html.erb +10 -0
- data/app/views/binda/field_groups/_form_item.html.erb +54 -26
- data/app/views/binda/field_groups/_form_item_choice.erb +96 -0
- data/app/views/binda/field_groups/_form_section.html.erb +2 -2
- data/app/views/binda/field_groups/_form_section_repeater.html.erb +2 -2
- data/config/locales/en.yml +7 -0
- data/config/routes.rb +2 -1
- data/db/migrate/1_create_binda_tables.rb +17 -0
- data/lib/binda/engine.rb +6 -0
- data/lib/binda/version.rb +1 -1
- data/lib/generators/binda/install/install_generator.rb +6 -8
- data/lib/generators/binda/setup/setup_generator.rb +8 -4
- metadata +66 -42
- data/app/controllers/binda/dates_controller.rb +0 -62
- data/app/controllers/binda/texts_controller.rb +0 -62
- data/app/views/binda/dates/_form.html.erb +0 -22
- data/app/views/binda/dates/edit.html.erb +0 -6
- data/app/views/binda/dates/index.html.erb +0 -27
- data/app/views/binda/dates/new.html.erb +0 -5
- data/app/views/binda/dates/show.html.erb +0 -9
- data/app/views/binda/repeaters/_form.html.erb +0 -27
- data/app/views/binda/repeaters/edit.html.erb +0 -6
- data/app/views/binda/repeaters/index.html.erb +0 -29
- data/app/views/binda/repeaters/new.html.erb +0 -5
- data/app/views/binda/repeaters/show.html.erb +0 -14
- data/app/views/binda/structures/add_child.html.erb +0 -0
- data/app/views/binda/texts/_form.html.erb +0 -22
- data/app/views/binda/texts/edit.html.erb +0 -6
- data/app/views/binda/texts/index.html.erb +0 -27
- data/app/views/binda/texts/new.html.erb +0 -5
- data/app/views/binda/texts/show.html.erb +0 -9
@@ -1,31 +1,31 @@
|
|
1
1
|
module Binda
|
2
|
-
|
2
|
+
class Structure < ApplicationRecord
|
3
3
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
4
|
+
# Associations
|
5
|
+
has_many :components
|
6
|
+
has_many :categories
|
7
|
+
has_many :field_groups
|
8
8
|
|
9
9
|
# Validations
|
10
10
|
validates :name, presence: true
|
11
11
|
validates :slug, uniqueness: true
|
12
12
|
accepts_nested_attributes_for :field_groups, allow_destroy: true, reject_if: :is_rejected
|
13
13
|
|
14
|
-
|
14
|
+
# Slug
|
15
15
|
extend FriendlyId
|
16
16
|
friendly_id :name, use: [:slugged, :finders]
|
17
17
|
|
18
18
|
|
19
19
|
# CUSTOM METHODS
|
20
20
|
# --------------
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
21
|
+
# https://github.com/norman/friendly_id/issues/436
|
22
|
+
def should_generate_new_friendly_id?
|
23
|
+
slug.blank?
|
24
|
+
end
|
25
25
|
|
26
26
|
def is_rejected( attributes )
|
27
|
-
|
28
|
-
|
27
|
+
attributes['name'].blank?
|
28
|
+
end
|
29
29
|
|
30
|
-
|
30
|
+
end
|
31
31
|
end
|
@@ -0,0 +1,170 @@
|
|
1
|
+
module Binda
|
2
|
+
module ComponentModelHelper
|
3
|
+
#
|
4
|
+
# Component helpers are supposed to simplify common operation like
|
5
|
+
# retrieving data belonging to the component instance (texts, assets, dates and so on)
|
6
|
+
|
7
|
+
extend ActiveSupport::Concern
|
8
|
+
|
9
|
+
# Get the object related to that field setting
|
10
|
+
# If the object doesn't exists yet it will return nil
|
11
|
+
#
|
12
|
+
# @param field_slug [string] The slug of the field setting
|
13
|
+
# @return [string] Returns the content of the string/text
|
14
|
+
# @return [nil] Returns null if it's empty or it doesn't exists
|
15
|
+
def get_text field_slug
|
16
|
+
obj = self.texts.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
17
|
+
obj.content unless obj.nil?
|
18
|
+
end
|
19
|
+
|
20
|
+
# Get the object related to that field setting
|
21
|
+
#
|
22
|
+
# @param field_slug [string] The slug of the field setting
|
23
|
+
# @return [boolean]
|
24
|
+
def has_text field_slug
|
25
|
+
obj = self.texts.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
26
|
+
if obj.present?
|
27
|
+
return !obj.content.blank?
|
28
|
+
else
|
29
|
+
return false
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Check if the field has an attached image
|
34
|
+
#
|
35
|
+
# @param field_slug [string] The slug of the field setting
|
36
|
+
# @return [boolean]
|
37
|
+
def has_image field_slug
|
38
|
+
obj = self.assets.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }.image
|
39
|
+
return obj.present?
|
40
|
+
end
|
41
|
+
|
42
|
+
# Get the image url based on the size provided,
|
43
|
+
# default is Carrierwave default (usually the real size)
|
44
|
+
#
|
45
|
+
# @param field_slug [string] The slug of the field setting
|
46
|
+
# @param size [string] The size. It can be 'thumb' 200x200 cropped,
|
47
|
+
# 'medium' 700x700 max size, 'large' 1400x1400 max size, or blank
|
48
|
+
# @return [string] The url of the image
|
49
|
+
def get_image_url field_slug, size = ''
|
50
|
+
get_image_info( field_slug, size, 'url' )
|
51
|
+
end
|
52
|
+
|
53
|
+
# Get the image path based on the size provided,
|
54
|
+
# default is Carrierwave default (usually the real size)
|
55
|
+
#
|
56
|
+
# @param field_slug [string] The slug of the field setting
|
57
|
+
# @param size [string] The size. It can be 'thumb' 200x200 cropped,
|
58
|
+
# 'medium' 700x700 max size, 'large' 1400x1400 max size, or blank
|
59
|
+
# @return [string] The url of the image
|
60
|
+
def get_image_path field_slug, size = ''
|
61
|
+
get_image_info( field_slug, size, 'path' )
|
62
|
+
end
|
63
|
+
|
64
|
+
# Get the object related to that field setting
|
65
|
+
#
|
66
|
+
# @param field_slug [string] The slug of the field setting
|
67
|
+
# @param size [string] The size. It can be 'thumb' 200x200 cropped,
|
68
|
+
# 'medium' 700x700 max size, 'large' 1400x1400 max size, or blank
|
69
|
+
# @param info [string] String of the info to be retrieved
|
70
|
+
# @return [string] The info requested if present
|
71
|
+
# @return [boolean] Returns false if no info is found or if image isn't found
|
72
|
+
def get_image_info field_slug, size, info
|
73
|
+
obj = self.assets.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
74
|
+
if obj.image.present?
|
75
|
+
if obj.image.respond_to?(size) && %w[thumb medium large].include?(size)
|
76
|
+
obj.image.send(size).send(info)
|
77
|
+
else
|
78
|
+
obj.image.send(info)
|
79
|
+
end
|
80
|
+
end
|
81
|
+
end
|
82
|
+
|
83
|
+
# Check if the field has an attached date
|
84
|
+
#
|
85
|
+
# @param field_slug [string] The slug of the field setting
|
86
|
+
# @return [datetime] The date
|
87
|
+
# @return [boolean] Reutrn false if nothing is found
|
88
|
+
def has_date field_slug
|
89
|
+
obj = self.dates.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
90
|
+
if obj.present?
|
91
|
+
return !obj.date.nil?
|
92
|
+
else
|
93
|
+
return false
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
# Get the object related to that field setting
|
98
|
+
#
|
99
|
+
# @param field_slug [string] The slug of the field setting
|
100
|
+
# @return [boolean]
|
101
|
+
def get_date field_slug
|
102
|
+
obj = self.dates.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
103
|
+
obj.date unless obj.nil?
|
104
|
+
end
|
105
|
+
|
106
|
+
# Check if exists any repeater with that slug
|
107
|
+
#
|
108
|
+
# @param field_slug [string] The slug of the field setting
|
109
|
+
# @return [boolean]
|
110
|
+
def has_repeater field_slug
|
111
|
+
obj = self.repeaters.find_all{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
112
|
+
return obj.present?
|
113
|
+
end
|
114
|
+
|
115
|
+
# Get the all repeater instances
|
116
|
+
#
|
117
|
+
# @param field_slug [string] The slug of the field setting
|
118
|
+
# @return [hash]
|
119
|
+
def get_repeater field_slug
|
120
|
+
obj = self.repeaters.find_all{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
121
|
+
obj.sort_by(&:position) unless obj.nil?
|
122
|
+
end
|
123
|
+
|
124
|
+
# Find or create a field by field setting and field type
|
125
|
+
# This is used in Binda's form
|
126
|
+
#
|
127
|
+
# @param field_setting_id [string] The field setting id
|
128
|
+
# @param field_type [string] THe field type
|
129
|
+
def find_or_create_a_field_by field_setting_id, field_type
|
130
|
+
if FieldSetting.get_fieldables.include?( field_type.capitalize ) && field_setting_id.is_a?( Integer )
|
131
|
+
self.send( field_type.pluralize ).find_or_create_by( field_setting_id: field_setting_id )
|
132
|
+
else
|
133
|
+
raise ArgumentError, "One parameter of find_or_create_a_field_by() is not correct.", caller
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
# Get the radio choice
|
138
|
+
#
|
139
|
+
# If by mistake the Radio instance has many choices associated,
|
140
|
+
# only the first one will be retrieved.
|
141
|
+
#
|
142
|
+
# @param field_slug [string] The slug of the field setting
|
143
|
+
# @return [object] The active record object of the selected choice
|
144
|
+
def get_radio_choice field_slug
|
145
|
+
obj = self.radios.find{ |t| t.field_setting_id == FieldSetting.get_id( field_slug ) }
|
146
|
+
obj.choices.first
|
147
|
+
end
|
148
|
+
|
149
|
+
# Get the select choices
|
150
|
+
#
|
151
|
+
# @param field_slug [string] The slug of the field setting
|
152
|
+
# @return [array] An array containing the selected choices objects
|
153
|
+
def get_select_choices field_slug
|
154
|
+
# select cannot be chosen has variable name, therefore is prefixed with 's'
|
155
|
+
obj = self.selects.find{ |t| t.field_setting_id = FieldSetting.get_id( field_slug ) }
|
156
|
+
obj.choices
|
157
|
+
end
|
158
|
+
|
159
|
+
# Get the checkbox choice
|
160
|
+
#
|
161
|
+
# @param field_slug [string] The slug of the field setting
|
162
|
+
# @return [array] The active record object of the selected choice
|
163
|
+
def get_checkbox_choices field_slug
|
164
|
+
# select cannot be chosen has variable name, therefore is prefixed with '_'
|
165
|
+
obj = self.checkboxes.find{ |t| t.field_setting_id = FieldSetting.get_id( field_slug ) }
|
166
|
+
obj.choices
|
167
|
+
end
|
168
|
+
|
169
|
+
end
|
170
|
+
end
|
@@ -3,14 +3,12 @@
|
|
3
3
|
<%# - - - - - - - - - - - - - - %>
|
4
4
|
<%= simple_form_for @component, url: structure_component_path( structure_id: @component.structure.id, id: @component.id ), defaults: { label: false } do |f| %>
|
5
5
|
<!-- SPLIT -->
|
6
|
-
|
7
|
-
|
8
|
-
<li id="repeater_<%= repeater.id %>">
|
6
|
+
<li id="repeater_<%= @repeater.id %>">
|
9
7
|
|
10
8
|
<%# - - - - - - - - - - - - %>
|
11
9
|
<%# REMOVE BUTTON %>
|
12
10
|
<%# - - - - - - - - - - - - %>
|
13
|
-
<a class="form-item--delete-repeater-item" href="<%= repeater_path( id: repeater.id ) %>" data-id="<%= repeater.id %>""><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
11
|
+
<a class="form-item--delete-repeater-item" href="<%= repeater_path( id: @repeater.id ) %>" data-id="<%= @repeater.id %>""><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></a>
|
14
12
|
|
15
13
|
<%# - - - - - - - - - - - - - - %>
|
16
14
|
<%# FIRST REPEATER %>
|
@@ -22,7 +20,7 @@
|
|
22
20
|
<%= ff.input :field_setting_id, as: :hidden, input_html: { value: @repeater_setting.id } %>
|
23
21
|
<%= ff.input :id, as: :hidden, input_html: { value: ff.object.id } %>
|
24
22
|
<% @repeater_setting.children.order( :position ).each do |repeater_setting_child| %>
|
25
|
-
<%= render "form_section_repeater", f: ff, repeater_setting_child: repeater_setting_child, repeater: repeater %>
|
23
|
+
<%= render "form_section_repeater", f: ff, repeater_setting_child: repeater_setting_child, repeater: @repeater %>
|
26
24
|
<% end %>
|
27
25
|
<% end %>
|
28
26
|
</div>
|
@@ -0,0 +1,72 @@
|
|
1
|
+
<%# HEADING %>
|
2
|
+
<h5 class="form-item--<%= field_setting.field_type.underscore %>-caption"><%= field_setting.name.capitalize %></h5>
|
3
|
+
|
4
|
+
<% unless field_setting.description.blank? %>
|
5
|
+
<small class="text-muted"><%= field_setting.description %></small>
|
6
|
+
<% end %>
|
7
|
+
|
8
|
+
<% if field_setting.choices.any? %>
|
9
|
+
|
10
|
+
<%# - - - - - - - - - - - - %>
|
11
|
+
<%# RADIO %>
|
12
|
+
<%# - - - - - - - - - - - - %>
|
13
|
+
<% if field_setting.field_type === 'radio' %>
|
14
|
+
<% current = @component.find_or_create_a_field_by( field_setting.id, 'radio' ) %>
|
15
|
+
<%= f.simple_fields_for "radios_attributes[]", current do |ff| %>
|
16
|
+
<% if ff.object.choices.any? %>
|
17
|
+
<%= ff.input :choice_ids, as: :radio_buttons, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, checked: ff.object.choices.first.id, include_blank: false %>
|
18
|
+
<% else %>
|
19
|
+
<%= ff.input :choice_ids, as: :radio_buttons, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, checked: field_setting.default_choice.id, include_blank: false %>
|
20
|
+
<% end %>
|
21
|
+
<%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
|
22
|
+
<%= ff.input :id, as: :hidden, input_html: { value: ff.object.id } %>
|
23
|
+
<%= ff.input :fieldable_id, as: :hidden %>
|
24
|
+
<%= ff.input :fieldable_type, as: :hidden %>
|
25
|
+
<% end %>
|
26
|
+
|
27
|
+
|
28
|
+
<%# - - - - - - - - - - - - %>
|
29
|
+
<%# SELECT %>
|
30
|
+
<%# - - - - - - - - - - - - %>
|
31
|
+
<% elsif field_setting.field_type === 'select' %>
|
32
|
+
<% current = @component.find_or_create_a_field_by( field_setting.id, 'select' ) %>
|
33
|
+
<%= f.simple_fields_for "selects_attributes[]", current do |ff| %>
|
34
|
+
<% if ff.object.choices.any? %>
|
35
|
+
<%= ff.input :choice_ids, as: :select, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, selected: ff.object.choice_ids, include_blank: false %>
|
36
|
+
<% else %>
|
37
|
+
<%= ff.input :choice_ids, as: :select, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, selected: field_setting.default_choice.id, include_blank: false %>
|
38
|
+
<% end %>
|
39
|
+
<%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
|
40
|
+
<%= ff.input :id, as: :hidden, input_html: { value: ff.object.id } %>
|
41
|
+
<%= ff.input :fieldable_id, as: :hidden %>
|
42
|
+
<%= ff.input :fieldable_type, as: :hidden %>
|
43
|
+
<% end %>
|
44
|
+
|
45
|
+
|
46
|
+
<%# - - - - - - - - - - - - %>
|
47
|
+
<%# CHECKBOX %>
|
48
|
+
<%# - - - - - - - - - - - - %>
|
49
|
+
<% elsif field_setting.field_type === 'checkbox' %>
|
50
|
+
<% current = @component.find_or_create_a_field_by( field_setting.id, 'checkbox' ) %>
|
51
|
+
<%= f.simple_fields_for "checkboxes_attributes[]", current do |ff| %>
|
52
|
+
<% if ff.object.choices.any? %>
|
53
|
+
<%= ff.input :choice_ids, as: :check_boxes, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, checked: ff.object.choice_ids, include_blank: false %>
|
54
|
+
<% else %>
|
55
|
+
<%= ff.input :choice_ids, as: :check_boxes, collection: field_setting.choices.order(:label), label_method: :label, value_method: :id, checked: field_setting.default_choice.id, include_blank: false %>
|
56
|
+
<% end %>
|
57
|
+
<%= ff.input :field_setting_id, as: :hidden, input_html: { value: field_setting.id } %>
|
58
|
+
<%= ff.input :id, as: :hidden, input_html: { value: ff.object.id } %>
|
59
|
+
<%= ff.input :fieldable_id, as: :hidden %>
|
60
|
+
<%= ff.input :fieldable_type, as: :hidden %>
|
61
|
+
<% end %>
|
62
|
+
<% end %>
|
63
|
+
|
64
|
+
<% else %>
|
65
|
+
<p>Sorry, no choice is available.
|
66
|
+
<% if current_user.is_superadmin %>
|
67
|
+
Please ensure you setup at least two possible choices in the <a href="<%= edit_structure_field_group_path( structure_id: @structure.id, id: field_setting.field_group.id )%>">field group setup</a>.
|
68
|
+
<% else %>
|
69
|
+
Please contact the administrator.
|
70
|
+
<% end %>
|
71
|
+
</p>
|
72
|
+
<% end %>
|
@@ -32,6 +32,11 @@
|
|
32
32
|
<%# REPEATER %>
|
33
33
|
<%# - - - - - - - - - - - - %>
|
34
34
|
<% elsif field_setting.field_type == 'repeater' %>
|
35
|
-
<% repeaters = @component.repeaters.where( field_setting: field_setting ) %>
|
35
|
+
<% repeaters = @component.repeaters.where( field_setting: field_setting ).order('position') %>
|
36
36
|
<%= render 'form_item_repeater', f: f, repeater_setting: field_setting, repeaters: repeaters %>
|
37
|
-
|
37
|
+
|
38
|
+
|
39
|
+
<% elsif ['radio', 'select', 'checkbox'].include? field_setting.field_type %>
|
40
|
+
<%= render 'form_item_selectable', f: f, field_setting: field_setting %>
|
41
|
+
|
42
|
+
<% end %>
|
@@ -28,4 +28,14 @@
|
|
28
28
|
<% end %>
|
29
29
|
|
30
30
|
|
31
|
+
<%# - - - - - - - - - - - - %>
|
32
|
+
<%# RADIO %>
|
33
|
+
<%# - - - - - - - - - - - - %>
|
34
|
+
<% elsif repeater_setting_child.field_type == 'radio' %>
|
35
|
+
<% current = repeater.find_or_create_a_field_by( repeater_setting_child.id, 'radio' ) %>
|
36
|
+
<%= f.simple_fields_for "radios_attributes[]", current do |ff| %>
|
37
|
+
<%= render 'form_item_radio', ff: ff, field_setting: repeater_setting_child %>
|
38
|
+
<% end %>
|
39
|
+
|
40
|
+
|
31
41
|
<% end %>
|
@@ -21,42 +21,70 @@
|
|
21
21
|
<%# - - - - - - - - - - - - %>
|
22
22
|
<%# NAME %>
|
23
23
|
<%# - - - - - - - - - - - - %>
|
24
|
-
<
|
25
|
-
|
24
|
+
<div class="form-item--half-size">
|
25
|
+
<h5><%= t(:name).capitalize %></h5>
|
26
|
+
<%= ff.input :name, as: :string, input_html: { class: "form-item--input" } %>
|
27
|
+
</div>
|
26
28
|
|
27
29
|
|
28
30
|
<%# - - - - - - - - - - - - %>
|
29
|
-
<%#
|
31
|
+
<%# FIELD TYPE %>
|
30
32
|
<%# - - - - - - - - - - - - %>
|
31
|
-
<
|
32
|
-
|
33
|
+
<div class="form-item--half-size">
|
34
|
+
<h5><%= t(:field_type).capitalize %></h5>
|
35
|
+
<% if ff.object.field_type.nil? %>
|
36
|
+
<%= ff.input :field_type, as: :select, collection: get_field_types, include_blank: false, prompt: t(:select_field_type), input_html: { class: 'form-item--select-input' } %>
|
37
|
+
<% else %>
|
38
|
+
<%= ff.input :field_type, as: :string, disabled: true, input_html: { class: "form-item--input" } %>
|
39
|
+
<% end %>
|
40
|
+
</div>
|
33
41
|
|
42
|
+
<% if ff.object.new_record? %>
|
34
43
|
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
44
|
+
<%# - - - - - - - - - - - - %>
|
45
|
+
<%# SLUG %>
|
46
|
+
<%# - - - - - - - - - - - - %>
|
47
|
+
<div class="form-item--half-size">
|
48
|
+
<%= ff.input :slug, as: :hidden, input_html: { class: "form-item--input" } %>
|
49
|
+
</div>
|
41
50
|
|
51
|
+
<% else %>
|
42
52
|
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
53
|
+
<%# - - - - - - - - - - - - %>
|
54
|
+
<%# SLUG %>
|
55
|
+
<%# - - - - - - - - - - - - %>
|
56
|
+
<div class="form-item--half-size">
|
57
|
+
<h5><%= t(:slug).capitalize %></h5>
|
58
|
+
<%= ff.input :slug, as: :string, input_html: { class: "form-item--input" } %>
|
59
|
+
</div>
|
48
60
|
|
61
|
+
<%# - - - - - - - - - - - - %>
|
62
|
+
<%# DESCRIPTION %>
|
63
|
+
<%# - - - - - - - - - - - - %>
|
64
|
+
<div class="form-item--full-size">
|
65
|
+
<h5><%= t(:description).capitalize %></h5>
|
66
|
+
<%= ff.input :description, input_html: { class: "form-item--input" } %>
|
67
|
+
</div>
|
68
|
+
|
69
|
+
<%# - - - - - - - - - - - - %>
|
70
|
+
<%# POSITION %>
|
71
|
+
<%# - - - - - - - - - - - - %>
|
72
|
+
<div class="form-item--full-size">
|
73
|
+
<h5><%= t(:position).capitalize %></h5>
|
74
|
+
<%= ff.input :position, as: :integer, input_html: { class: "form-item--input" } %>
|
75
|
+
</div>
|
76
|
+
|
77
|
+
<% choiceables = ['radio', 'select', 'checkbox'] %>
|
78
|
+
<% if choiceables.include? ff.object.field_type %>
|
79
|
+
|
80
|
+
<%# - - - - - - - - - - - - %>
|
81
|
+
<%# CHOICES %>
|
82
|
+
<%# - - - - - - - - - - - - %>
|
83
|
+
<%= render 'form_item_choice', f: f, ff: ff, section: section %>
|
84
|
+
|
85
|
+
<% end %>
|
49
86
|
|
50
|
-
<%# - - - - - - - - - - - - %>
|
51
|
-
<%# FIELD TYPE %>
|
52
|
-
<%# - - - - - - - - - - - - %>
|
53
|
-
<h5><%= "#{ t :field_type }".capitalize %></h5>
|
54
|
-
<% if ff.object.field_type.nil? %>
|
55
|
-
<%= ff.input :field_type, as: :select, collection: get_field_types, include_blank: false, prompt: "#{ t :select_field_type}", input_html: { class: 'form-item--select-input' } %>
|
56
|
-
<% else %>
|
57
|
-
<%= ff.input :field_type, as: :string, disabled: true, input_html: { class: "form-item--input" } %>
|
58
87
|
<% end %>
|
88
|
+
<div class="clearfix"></div>
|
59
89
|
|
60
90
|
</div>
|
61
|
-
|
62
|
-
<div class="clearfix"></div>
|
@@ -0,0 +1,96 @@
|
|
1
|
+
<%# - - - - - - - - - - - - %>
|
2
|
+
<%# CHOICES %>
|
3
|
+
<%# - - - - - - - - - - - - %>
|
4
|
+
<h5><%= t(:choices).capitalize %></h5>
|
5
|
+
<div class="form-item--choices">
|
6
|
+
|
7
|
+
<%= ff.simple_fields_for :choices, ff.object.choices.order( :label ) do |fff| %>
|
8
|
+
<div class="form-item--choice">
|
9
|
+
<%= fff.input :id, as: :hidden %>
|
10
|
+
<%= fff.association :field_setting, as: :hidden %>
|
11
|
+
<div class="form-item--choice-label">
|
12
|
+
<small class="text-muted"><%= t(:choice_label).capitalize %></small>
|
13
|
+
<%= fff.input :label %>
|
14
|
+
</div>
|
15
|
+
<div class="form-item--choice-content">
|
16
|
+
<small class="text-muted"><%= t(:choice_value).capitalize %></small>
|
17
|
+
<%= fff.input :value %>
|
18
|
+
</div>
|
19
|
+
<a href="<%= choice_path( fff.object ) %>" class="form-item--delete-choice">
|
20
|
+
<span><span class="glyphicon glyphicon-trash" aria-hidden="true"></span></span>
|
21
|
+
</a>
|
22
|
+
<div class="clearfix"></div>
|
23
|
+
</div>
|
24
|
+
<% end %>
|
25
|
+
|
26
|
+
<%# - - - - - - - - - - - - %>
|
27
|
+
<%# DEFAULT INITIAL CHOICE %>
|
28
|
+
<%# - - - - - - - - - - - - %>
|
29
|
+
<% unless ff.object.choices.find_all{|c| c.persisted? }.any? %>
|
30
|
+
<%= f.simple_fields_for "new_choices[]", ff.object.choices.build() do |fff| %>
|
31
|
+
<div class="form-item--choice">
|
32
|
+
<%= fff.association :field_setting, as: :hidden %>
|
33
|
+
<div class="form-item--choice-label">
|
34
|
+
<small class="text-muted"><%= t(:choice_label).capitalize %></small>
|
35
|
+
<%= fff.input :label %>
|
36
|
+
</div>
|
37
|
+
<div class="form-item--choice-content">
|
38
|
+
<small class="text-muted"><%= t(:choice_value).capitalize %></small>
|
39
|
+
<%= fff.input :value %>
|
40
|
+
</div>
|
41
|
+
<a href="#" class="form-item--toggle-choice form-item--js-delete-choice">
|
42
|
+
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
43
|
+
</a>
|
44
|
+
<div class="clearfix"></div>
|
45
|
+
</div>
|
46
|
+
<% end %>
|
47
|
+
<% end %>
|
48
|
+
|
49
|
+
<%# - - - - - - - - - - - - %>
|
50
|
+
<%# NEW CHOICE %>
|
51
|
+
<%# - - - - - - - - - - - - %>
|
52
|
+
<%= f.simple_fields_for "new_choices[]", ff.object.choices.build() do |fff| %>
|
53
|
+
<div class="form-item--choice form-item--new-choice">
|
54
|
+
<%= fff.association :field_setting, as: :hidden %>
|
55
|
+
<div class="form-item--choice-label">
|
56
|
+
<small class="text-muted"><%= t(:choice_label).capitalize %></small>
|
57
|
+
<%= fff.input :label %>
|
58
|
+
</div>
|
59
|
+
<div class="form-item--choice-content">
|
60
|
+
<small class="text-muted"><%= t(:choice_value).capitalize %></small>
|
61
|
+
<%= fff.input :value %>
|
62
|
+
</div>
|
63
|
+
<a href="#" class="form-item--toggle-choice form-item--js-delete-choice">
|
64
|
+
<span class="glyphicon glyphicon-trash" aria-hidden="true"></span>
|
65
|
+
</a>
|
66
|
+
<div class="clearfix"></div>
|
67
|
+
</div>
|
68
|
+
<% end %>
|
69
|
+
|
70
|
+
<a href="#" class="form-item--toggle-choice form-item--add-choice">
|
71
|
+
<%= t(:add_choice).capitalize %> <span class="glyphicon glyphicon-plus" aria-hidden="true"></span>
|
72
|
+
</a>
|
73
|
+
|
74
|
+
</div>
|
75
|
+
|
76
|
+
<div class="clearfix"></div>
|
77
|
+
|
78
|
+
|
79
|
+
<%# - - - - - - - - - - - - %>
|
80
|
+
<%# DEFAULT CHOICE %>
|
81
|
+
<%# - - - - - - - - - - - - %>
|
82
|
+
<% if ff.object.choices.find_all{|c| c.persisted? }.any? %>
|
83
|
+
<div class="form-item--half-size">
|
84
|
+
<h5><%= t(:default_choice).capitalize %></h5>
|
85
|
+
<%= ff.input :default_choice_id, as: :select, collection: ff.object.choices.find_all{|c| c.persisted? }, label_method: :label, include_blank: false, selected: ff.object.default_choice.id, hint: t(:default_choice_description).capitalize %>
|
86
|
+
</div>
|
87
|
+
<% end %>
|
88
|
+
|
89
|
+
|
90
|
+
<%# - - - - - - - - - - - - %>
|
91
|
+
<%# ALLOW NULL %>
|
92
|
+
<%# - - - - - - - - - - - - %>
|
93
|
+
<div class="form-item--half-size">
|
94
|
+
<h5><%= t(:allow_null).capitalize %></h5>
|
95
|
+
<%= ff.input :allow_null, as: :boolean, boolean_style: :inline, input_html: { class: "form-item--input" }, checked_value: true, unchecked_value: false, selected: ff.object.allow_null, default: false %>
|
96
|
+
</div>
|