effective_bootstrap 0.0.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/MIT-LICENSE +20 -0
- data/README.md +93 -0
- data/app/assets/icons/activity.svg +13 -0
- data/app/assets/icons/airplay.svg +14 -0
- data/app/assets/icons/alert-circle.svg +15 -0
- data/app/assets/icons/alert-octagon.svg +15 -0
- data/app/assets/icons/alert-triangle.svg +15 -0
- data/app/assets/icons/align-center.svg +16 -0
- data/app/assets/icons/align-justify.svg +16 -0
- data/app/assets/icons/align-left.svg +16 -0
- data/app/assets/icons/align-right.svg +16 -0
- data/app/assets/icons/anchor.svg +15 -0
- data/app/assets/icons/aperture.svg +19 -0
- data/app/assets/icons/arrow-down-circle.svg +15 -0
- data/app/assets/icons/arrow-down-left.svg +14 -0
- data/app/assets/icons/arrow-down-right.svg +14 -0
- data/app/assets/icons/arrow-down.svg +14 -0
- data/app/assets/icons/arrow-left-circle.svg +15 -0
- data/app/assets/icons/arrow-left.svg +14 -0
- data/app/assets/icons/arrow-right-circle.svg +15 -0
- data/app/assets/icons/arrow-right.svg +14 -0
- data/app/assets/icons/arrow-up-circle.svg +15 -0
- data/app/assets/icons/arrow-up-left.svg +14 -0
- data/app/assets/icons/arrow-up-right.svg +14 -0
- data/app/assets/icons/arrow-up.svg +14 -0
- data/app/assets/icons/at-sign.svg +14 -0
- data/app/assets/icons/award.svg +14 -0
- data/app/assets/icons/bar-chart-2.svg +15 -0
- data/app/assets/icons/bar-chart.svg +15 -0
- data/app/assets/icons/battery-charging.svg +15 -0
- data/app/assets/icons/battery.svg +14 -0
- data/app/assets/icons/bell-off.svg +14 -0
- data/app/assets/icons/bell.svg +13 -0
- data/app/assets/icons/bluetooth.svg +13 -0
- data/app/assets/icons/bold.svg +14 -0
- data/app/assets/icons/book-open.svg +14 -0
- data/app/assets/icons/book.svg +14 -0
- data/app/assets/icons/bookmark.svg +13 -0
- data/app/assets/icons/box.svg +15 -0
- data/app/assets/icons/briefcase.svg +14 -0
- data/app/assets/icons/calendar.svg +16 -0
- data/app/assets/icons/camera-off.svg +14 -0
- data/app/assets/icons/camera.svg +14 -0
- data/app/assets/icons/cast.svg +14 -0
- data/app/assets/icons/check-circle.svg +14 -0
- data/app/assets/icons/check-square.svg +14 -0
- data/app/assets/icons/check.svg +13 -0
- data/app/assets/icons/chevron-down.svg +13 -0
- data/app/assets/icons/chevron-left.svg +13 -0
- data/app/assets/icons/chevron-right.svg +13 -0
- data/app/assets/icons/chevron-up.svg +13 -0
- data/app/assets/icons/chevrons-down.svg +14 -0
- data/app/assets/icons/chevrons-left.svg +14 -0
- data/app/assets/icons/chevrons-right.svg +14 -0
- data/app/assets/icons/chevrons-up.svg +14 -0
- data/app/assets/icons/chrome.svg +17 -0
- data/app/assets/icons/circle.svg +13 -0
- data/app/assets/icons/clipboard.svg +14 -0
- data/app/assets/icons/clock.svg +14 -0
- data/app/assets/icons/cloud-drizzle.svg +19 -0
- data/app/assets/icons/cloud-lightning.svg +14 -0
- data/app/assets/icons/cloud-off.svg +14 -0
- data/app/assets/icons/cloud-rain.svg +16 -0
- data/app/assets/icons/cloud-snow.svg +19 -0
- data/app/assets/icons/cloud.svg +13 -0
- data/app/assets/icons/code.svg +14 -0
- data/app/assets/icons/codepen.svg +17 -0
- data/app/assets/icons/command.svg +13 -0
- data/app/assets/icons/compass.svg +14 -0
- data/app/assets/icons/copy.svg +14 -0
- data/app/assets/icons/corner-down-left.svg +14 -0
- data/app/assets/icons/corner-down-right.svg +14 -0
- data/app/assets/icons/corner-left-down.svg +14 -0
- data/app/assets/icons/corner-left-up.svg +14 -0
- data/app/assets/icons/corner-right-down.svg +14 -0
- data/app/assets/icons/corner-right-up.svg +14 -0
- data/app/assets/icons/corner-up-left.svg +14 -0
- data/app/assets/icons/corner-up-right.svg +14 -0
- data/app/assets/icons/cpu.svg +22 -0
- data/app/assets/icons/credit-card.svg +14 -0
- data/app/assets/icons/crop.svg +14 -0
- data/app/assets/icons/crosshair.svg +17 -0
- data/app/assets/icons/database.svg +15 -0
- data/app/assets/icons/delete.svg +15 -0
- data/app/assets/icons/disc.svg +14 -0
- data/app/assets/icons/dollar-sign.svg +14 -0
- data/app/assets/icons/download-cloud.svg +15 -0
- data/app/assets/icons/download.svg +15 -0
- data/app/assets/icons/droplet.svg +13 -0
- data/app/assets/icons/edit-2.svg +13 -0
- data/app/assets/icons/edit-3.svg +14 -0
- data/app/assets/icons/edit.svg +14 -0
- data/app/assets/icons/external-link.svg +15 -0
- data/app/assets/icons/eye-off.svg +14 -0
- data/app/assets/icons/eye.svg +14 -0
- data/app/assets/icons/facebook.svg +13 -0
- data/app/assets/icons/fast-forward.svg +14 -0
- data/app/assets/icons/feather.svg +15 -0
- data/app/assets/icons/file-minus.svg +15 -0
- data/app/assets/icons/file-plus.svg +16 -0
- data/app/assets/icons/file-text.svg +17 -0
- data/app/assets/icons/file.svg +14 -0
- data/app/assets/icons/film.svg +20 -0
- data/app/assets/icons/filter.svg +13 -0
- data/app/assets/icons/flag.svg +14 -0
- data/app/assets/icons/folder-minus.svg +14 -0
- data/app/assets/icons/folder-plus.svg +15 -0
- data/app/assets/icons/folder.svg +13 -0
- data/app/assets/icons/git-branch.svg +16 -0
- data/app/assets/icons/git-commit.svg +15 -0
- data/app/assets/icons/git-merge.svg +15 -0
- data/app/assets/icons/git-pull-request.svg +16 -0
- data/app/assets/icons/github.svg +13 -0
- data/app/assets/icons/gitlab.svg +13 -0
- data/app/assets/icons/globe.svg +15 -0
- data/app/assets/icons/grid.svg +16 -0
- data/app/assets/icons/hard-drive.svg +16 -0
- data/app/assets/icons/hash.svg +16 -0
- data/app/assets/icons/headphones.svg +14 -0
- data/app/assets/icons/heart.svg +13 -0
- data/app/assets/icons/help-circle.svg +15 -0
- data/app/assets/icons/home.svg +14 -0
- data/app/assets/icons/image.svg +15 -0
- data/app/assets/icons/inbox.svg +14 -0
- data/app/assets/icons/info.svg +15 -0
- data/app/assets/icons/instagram.svg +15 -0
- data/app/assets/icons/italic.svg +15 -0
- data/app/assets/icons/layers.svg +15 -0
- data/app/assets/icons/layout.svg +15 -0
- data/app/assets/icons/life-buoy.svg +19 -0
- data/app/assets/icons/link-2.svg +14 -0
- data/app/assets/icons/link.svg +14 -0
- data/app/assets/icons/linkedin.svg +15 -0
- data/app/assets/icons/list.svg +18 -0
- data/app/assets/icons/loader.svg +20 -0
- data/app/assets/icons/lock.svg +14 -0
- data/app/assets/icons/log-in.svg +15 -0
- data/app/assets/icons/log-out.svg +15 -0
- data/app/assets/icons/mail.svg +14 -0
- data/app/assets/icons/map-pin.svg +14 -0
- data/app/assets/icons/map.svg +15 -0
- data/app/assets/icons/maximize-2.svg +16 -0
- data/app/assets/icons/maximize.svg +13 -0
- data/app/assets/icons/menu.svg +15 -0
- data/app/assets/icons/message-circle.svg +13 -0
- data/app/assets/icons/message-square.svg +13 -0
- data/app/assets/icons/mic-off.svg +17 -0
- data/app/assets/icons/mic.svg +16 -0
- data/app/assets/icons/minimize-2.svg +16 -0
- data/app/assets/icons/minimize.svg +13 -0
- data/app/assets/icons/minus-circle.svg +14 -0
- data/app/assets/icons/minus-square.svg +14 -0
- data/app/assets/icons/minus.svg +13 -0
- data/app/assets/icons/monitor.svg +15 -0
- data/app/assets/icons/moon.svg +13 -0
- data/app/assets/icons/more-horizontal.svg +15 -0
- data/app/assets/icons/more-vertical.svg +15 -0
- data/app/assets/icons/move.svg +18 -0
- data/app/assets/icons/music.svg +14 -0
- data/app/assets/icons/navigation-2.svg +13 -0
- data/app/assets/icons/navigation.svg +13 -0
- data/app/assets/icons/octagon.svg +13 -0
- data/app/assets/icons/package.svg +16 -0
- data/app/assets/icons/paperclip.svg +13 -0
- data/app/assets/icons/pause-circle.svg +15 -0
- data/app/assets/icons/pause.svg +14 -0
- data/app/assets/icons/percent.svg +15 -0
- data/app/assets/icons/phone-call.svg +13 -0
- data/app/assets/icons/phone-forwarded.svg +15 -0
- data/app/assets/icons/phone-incoming.svg +15 -0
- data/app/assets/icons/phone-missed.svg +15 -0
- data/app/assets/icons/phone-off.svg +14 -0
- data/app/assets/icons/phone-outgoing.svg +15 -0
- data/app/assets/icons/phone.svg +13 -0
- data/app/assets/icons/pie-chart.svg +14 -0
- data/app/assets/icons/play-circle.svg +14 -0
- data/app/assets/icons/play.svg +13 -0
- data/app/assets/icons/plus-circle.svg +15 -0
- data/app/assets/icons/plus-square.svg +15 -0
- data/app/assets/icons/plus.svg +14 -0
- data/app/assets/icons/pocket.svg +14 -0
- data/app/assets/icons/power.svg +14 -0
- data/app/assets/icons/printer.svg +15 -0
- data/app/assets/icons/radio.svg +14 -0
- data/app/assets/icons/refresh-ccw.svg +15 -0
- data/app/assets/icons/refresh-cw.svg +15 -0
- data/app/assets/icons/repeat.svg +16 -0
- data/app/assets/icons/rewind.svg +14 -0
- data/app/assets/icons/rotate-ccw.svg +14 -0
- data/app/assets/icons/rotate-cw.svg +14 -0
- data/app/assets/icons/rss.svg +15 -0
- data/app/assets/icons/save.svg +15 -0
- data/app/assets/icons/scissors.svg +17 -0
- data/app/assets/icons/search.svg +14 -0
- data/app/assets/icons/send.svg +14 -0
- data/app/assets/icons/server.svg +16 -0
- data/app/assets/icons/settings.svg +14 -0
- data/app/assets/icons/share-2.svg +17 -0
- data/app/assets/icons/share.svg +15 -0
- data/app/assets/icons/shield-off.svg +15 -0
- data/app/assets/icons/shield.svg +13 -0
- data/app/assets/icons/shopping-bag.svg +15 -0
- data/app/assets/icons/shopping-cart.svg +15 -0
- data/app/assets/icons/shuffle.svg +17 -0
- data/app/assets/icons/sidebar.svg +14 -0
- data/app/assets/icons/skip-back.svg +14 -0
- data/app/assets/icons/skip-forward.svg +14 -0
- data/app/assets/icons/slack.svg +17 -0
- data/app/assets/icons/slash.svg +14 -0
- data/app/assets/icons/sliders.svg +21 -0
- data/app/assets/icons/smartphone.svg +14 -0
- data/app/assets/icons/speaker.svg +15 -0
- data/app/assets/icons/spinner.svg +1 -0
- data/app/assets/icons/square.svg +13 -0
- data/app/assets/icons/star.svg +13 -0
- data/app/assets/icons/stop-circle.svg +14 -0
- data/app/assets/icons/sun.svg +21 -0
- data/app/assets/icons/sunrise.svg +20 -0
- data/app/assets/icons/sunset.svg +20 -0
- data/app/assets/icons/tablet.svg +22 -0
- data/app/assets/icons/tag.svg +14 -0
- data/app/assets/icons/target.svg +15 -0
- data/app/assets/icons/terminal.svg +14 -0
- data/app/assets/icons/thermometer.svg +13 -0
- data/app/assets/icons/thumbs-down.svg +13 -0
- data/app/assets/icons/thumbs-up.svg +13 -0
- data/app/assets/icons/toggle-left.svg +14 -0
- data/app/assets/icons/toggle-right.svg +14 -0
- data/app/assets/icons/trash-2.svg +16 -0
- data/app/assets/icons/trash.svg +14 -0
- data/app/assets/icons/trending-down.svg +14 -0
- data/app/assets/icons/trending-up.svg +14 -0
- data/app/assets/icons/triangle.svg +13 -0
- data/app/assets/icons/truck.svg +16 -0
- data/app/assets/icons/tv.svg +14 -0
- data/app/assets/icons/twitter.svg +13 -0
- data/app/assets/icons/type.svg +15 -0
- data/app/assets/icons/umbrella.svg +13 -0
- data/app/assets/icons/underline.svg +14 -0
- data/app/assets/icons/unlock.svg +14 -0
- data/app/assets/icons/upload-cloud.svg +16 -0
- data/app/assets/icons/upload.svg +15 -0
- data/app/assets/icons/user-check.svg +15 -0
- data/app/assets/icons/user-minus.svg +15 -0
- data/app/assets/icons/user-plus.svg +16 -0
- data/app/assets/icons/user-x.svg +16 -0
- data/app/assets/icons/user.svg +14 -0
- data/app/assets/icons/users.svg +16 -0
- data/app/assets/icons/video-off.svg +14 -0
- data/app/assets/icons/video.svg +14 -0
- data/app/assets/icons/voicemail.svg +15 -0
- data/app/assets/icons/volume-1.svg +14 -0
- data/app/assets/icons/volume-2.svg +14 -0
- data/app/assets/icons/volume-x.svg +15 -0
- data/app/assets/icons/volume.svg +13 -0
- data/app/assets/icons/watch.svg +15 -0
- data/app/assets/icons/wifi-off.svg +19 -0
- data/app/assets/icons/wifi.svg +16 -0
- data/app/assets/icons/wind.svg +13 -0
- data/app/assets/icons/x-circle.svg +15 -0
- data/app/assets/icons/x-square.svg +15 -0
- data/app/assets/icons/x.svg +14 -0
- data/app/assets/icons/zap-off.svg +16 -0
- data/app/assets/icons/zap.svg +13 -0
- data/app/assets/icons/zoom-in.svg +16 -0
- data/app/assets/icons/zoom-out.svg +15 -0
- data/app/assets/javascripts/effective_bootstrap.js +9 -0
- data/app/assets/javascripts/effective_bootstrap/base.js.coffee +37 -0
- data/app/assets/javascripts/effective_date/initialize.js.coffee +4 -0
- data/app/assets/javascripts/effective_date/input.js +5 -0
- data/app/assets/javascripts/effective_datetime/bootstrap-datetimepicker.js +2637 -0
- data/app/assets/javascripts/effective_datetime/initialize.js.coffee +4 -0
- data/app/assets/javascripts/effective_datetime/input.js +5 -0
- data/app/assets/javascripts/effective_datetime/moment.js +4535 -0
- data/app/assets/javascripts/effective_datetime/overrides.js.coffee +38 -0
- data/app/assets/javascripts/effective_datetime/turbolinks.js.coffee +5 -0
- data/app/assets/javascripts/effective_phone/initialize.js.coffee +4 -0
- data/app/assets/javascripts/effective_phone/input.js +2 -0
- data/app/assets/javascripts/effective_phone/jquery.maskedInput.js +182 -0
- data/app/assets/javascripts/effective_price/input.js.coffee +34 -0
- data/app/assets/javascripts/effective_select/initialize.js.coffee +45 -0
- data/app/assets/javascripts/effective_select/input.js +3 -0
- data/app/assets/javascripts/effective_select/overrides.js.coffee +45 -0
- data/app/assets/javascripts/effective_select/select2.js +5746 -0
- data/app/assets/javascripts/effective_time/initialize.js.coffee +4 -0
- data/app/assets/javascripts/effective_time/input.js +5 -0
- data/app/assets/stylesheets/effective_bootstrap.scss +8 -0
- data/app/assets/stylesheets/effective_bootstrap/base.scss +11 -0
- data/app/assets/stylesheets/effective_bootstrap/icons.scss +27 -0
- data/app/assets/stylesheets/effective_date/input.scss +1 -0
- data/app/assets/stylesheets/effective_datetime/bootstrap-datetimepicker.scss +374 -0
- data/app/assets/stylesheets/effective_datetime/input.scss +2 -0
- data/app/assets/stylesheets/effective_datetime/overrides.scss +28 -0
- data/app/assets/stylesheets/effective_select/bootstrap-theme.css +564 -0
- data/app/assets/stylesheets/effective_select/input.scss +3 -0
- data/app/assets/stylesheets/effective_select/overrides.scss +92 -0
- data/app/assets/stylesheets/effective_select/select2.css +484 -0
- data/app/assets/stylesheets/effective_time/input.scss +1 -0
- data/app/helpers/effective_bootstrap_helper.rb +52 -0
- data/app/helpers/effective_form_builder_helper.rb +23 -0
- data/app/helpers/effective_icons_helper.rb +46 -0
- data/app/models/effective/access_denied.rb +17 -0
- data/app/models/effective/form_builder.rb +100 -0
- data/app/models/effective/form_input.rb +319 -0
- data/app/models/effective/form_inputs/check_box.rb +62 -0
- data/app/models/effective/form_inputs/checks.rb +73 -0
- data/app/models/effective/form_inputs/collection_input.rb +144 -0
- data/app/models/effective/form_inputs/date_field.rb +22 -0
- data/app/models/effective/form_inputs/datetime_field.rb +53 -0
- data/app/models/effective/form_inputs/email_field.rb +15 -0
- data/app/models/effective/form_inputs/error_field.rb +47 -0
- data/app/models/effective/form_inputs/form_group.rb +26 -0
- data/app/models/effective/form_inputs/number_field.rb +6 -0
- data/app/models/effective/form_inputs/password_field.rb +24 -0
- data/app/models/effective/form_inputs/phone_field.rb +34 -0
- data/app/models/effective/form_inputs/price_field.rb +37 -0
- data/app/models/effective/form_inputs/radios.rb +74 -0
- data/app/models/effective/form_inputs/select.rb +87 -0
- data/app/models/effective/form_inputs/static_field.rb +20 -0
- data/app/models/effective/form_inputs/submit.rb +42 -0
- data/app/models/effective/form_inputs/text_area.rb +11 -0
- data/app/models/effective/form_inputs/text_field.rb +6 -0
- data/app/models/effective/form_inputs/time_field.rb +22 -0
- data/app/models/effective/form_inputs/url_field.rb +15 -0
- data/app/views/effective/style_guide/__fields.html.haml +42 -0
- data/app/views/effective/style_guide/__inline_fields.html.haml +4 -0
- data/app/views/effective/style_guide/_effective_form_with.html.haml +23 -0
- data/app/views/effective/style_guide/_feather_icons.html.haml +9 -0
- data/config/effective_bootstrap.rb +24 -0
- data/lib/effective_bootstrap.rb +31 -0
- data/lib/effective_bootstrap/engine.rb +11 -0
- data/lib/effective_bootstrap/version.rb +3 -0
- data/lib/generators/effective_bootstrap/install_generator.rb +14 -0
- metadata +419 -0
@@ -0,0 +1,62 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class CheckBox < Effective::FormInput
|
4
|
+
|
5
|
+
def to_html(&block)
|
6
|
+
case layout
|
7
|
+
when :horizontal
|
8
|
+
build_wrapper do
|
9
|
+
content_tag(:div, '', class: 'col-sm-2') + content_tag(:div, class: 'col-sm-10') do
|
10
|
+
build_content(&block)
|
11
|
+
end
|
12
|
+
end
|
13
|
+
else
|
14
|
+
build_content(&block)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def build_content(&block)
|
19
|
+
build_check_box_wrap {
|
20
|
+
build_input(&block) + build_label + build_feedback + build_hint
|
21
|
+
}
|
22
|
+
end
|
23
|
+
|
24
|
+
def build_check_box_wrap(&block)
|
25
|
+
if custom?
|
26
|
+
content_tag(:div, yield, class: 'form-group custom-control custom-checkbox' + (inline? ? ' custom-control-inline' : ''))
|
27
|
+
else
|
28
|
+
content_tag(:div, yield, class: 'form-check' + (inline? ? ' form-check-inline' : ''))
|
29
|
+
end
|
30
|
+
end
|
31
|
+
|
32
|
+
def label_options
|
33
|
+
if custom?
|
34
|
+
{ class: 'custom-control-label' }
|
35
|
+
else
|
36
|
+
{ class: 'form-check-label' }
|
37
|
+
end
|
38
|
+
end
|
39
|
+
|
40
|
+
def input_html_options
|
41
|
+
if custom?
|
42
|
+
{ class: 'custom-control-input' }
|
43
|
+
else
|
44
|
+
{ class: 'form-check-input' }
|
45
|
+
end
|
46
|
+
end
|
47
|
+
|
48
|
+
private
|
49
|
+
|
50
|
+
def inline? # default false
|
51
|
+
return @inline unless @inline.nil?
|
52
|
+
@inline = (options[:input].delete(:inline) == true)
|
53
|
+
end
|
54
|
+
|
55
|
+
def custom? # default true
|
56
|
+
return @custom unless @custom.nil?
|
57
|
+
@custom = (options.delete(:custom) != false)
|
58
|
+
end
|
59
|
+
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
@@ -0,0 +1,73 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class Checks < CollectionInput
|
4
|
+
|
5
|
+
def build_input(&block)
|
6
|
+
@builder.collection_check_boxes(name, options_collection, value_method, label_method, collection_options, item_input_options) { |builder| build_item(builder) }
|
7
|
+
end
|
8
|
+
|
9
|
+
def build_wrapper(&block)
|
10
|
+
if layout == :horizontal
|
11
|
+
content_tag(:fieldset, content_tag(:div, yield, class: 'row'), options[:wrapper])
|
12
|
+
else
|
13
|
+
content_tag(:fieldset, yield, options[:wrapper])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
|
17
|
+
def wrapper_options
|
18
|
+
{ class: "form-group #{tag_id}" }
|
19
|
+
end
|
20
|
+
|
21
|
+
def feedback_options
|
22
|
+
return false if layout == :inline
|
23
|
+
|
24
|
+
{
|
25
|
+
valid: { class: 'valid-feedback', style: ('display: block;' if has_error? && !has_error?(name)) }.compact,
|
26
|
+
invalid: { class: 'invalid-feedback', style: ('display: block;' if has_error?(name)) }.compact
|
27
|
+
}
|
28
|
+
end
|
29
|
+
|
30
|
+
def input_html_options
|
31
|
+
if custom?
|
32
|
+
{ class: 'custom-control-input' }
|
33
|
+
else
|
34
|
+
{ class: 'form-check-input' }
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
def build_label
|
39
|
+
return BLANK if options[:label] == false
|
40
|
+
return BLANK if name.kind_of?(NilClass)
|
41
|
+
|
42
|
+
text = (options[:label].delete(:text) || (object.class.human_attribute_name(name) if object) || BLANK).html_safe
|
43
|
+
|
44
|
+
content_tag((inline? ? :label : :legend), text, options[:label])
|
45
|
+
end
|
46
|
+
|
47
|
+
def build_item(builder)
|
48
|
+
build_item_wrap { builder.check_box + builder.label(item_label_options) }
|
49
|
+
end
|
50
|
+
|
51
|
+
def build_item_wrap(&block)
|
52
|
+
if custom?
|
53
|
+
content_tag(:div, yield, class: 'custom-control custom-checkbox ' + (inline? ? 'custom-control-inline' : 'form-group'))
|
54
|
+
else
|
55
|
+
content_tag(:div, yield, class: 'form-check' + (inline? ? ' form-check-inline' : ''))
|
56
|
+
end
|
57
|
+
end
|
58
|
+
|
59
|
+
def item_input_options
|
60
|
+
options[:input].except(:inline, :custom)
|
61
|
+
end
|
62
|
+
|
63
|
+
def item_label_options
|
64
|
+
if custom?
|
65
|
+
{ class: 'custom-control-label' }
|
66
|
+
else
|
67
|
+
{ class: 'form-check-label' }
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
73
|
+
end
|
@@ -0,0 +1,144 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class CollectionInput < Effective::FormInput
|
4
|
+
def initialize(name, options, builder:, html_options: nil)
|
5
|
+
super
|
6
|
+
assign_options_collection!
|
7
|
+
assign_options_collection_methods!
|
8
|
+
end
|
9
|
+
|
10
|
+
def polymorphic?
|
11
|
+
return @polymorphic unless @polymorphic.nil?
|
12
|
+
@polymorphic = (options.delete(:polymorphic) || false)
|
13
|
+
end
|
14
|
+
|
15
|
+
def grouped?
|
16
|
+
return @grouped unless @grouped.nil?
|
17
|
+
@grouped = (options.delete(:grouped) || false)
|
18
|
+
end
|
19
|
+
|
20
|
+
def inline? # default false
|
21
|
+
return @inline unless @inline.nil?
|
22
|
+
@inline = (options[:input].delete(:inline) == true)
|
23
|
+
end
|
24
|
+
|
25
|
+
def custom? # default true
|
26
|
+
return @custom unless @custom.nil?
|
27
|
+
@custom = (options.delete(:custom) != false)
|
28
|
+
end
|
29
|
+
|
30
|
+
def collection_options
|
31
|
+
return @collection_options unless @collection_options.nil?
|
32
|
+
|
33
|
+
checked = options[:input].delete(:checked)
|
34
|
+
selected = options[:input].delete(:selected)
|
35
|
+
passed_value = options[:input].delete(:value)
|
36
|
+
include_blank = options[:input].delete(:include_blank)
|
37
|
+
|
38
|
+
@collection_options = {
|
39
|
+
checked: (checked || selected || passed_value || value),
|
40
|
+
selected: (selected || checked || passed_value || value),
|
41
|
+
include_blank: include_blank
|
42
|
+
}.compact
|
43
|
+
end
|
44
|
+
|
45
|
+
def html_options
|
46
|
+
# Not sure why I need this. But they're merged in if I don't.
|
47
|
+
options[:input].merge(skip_default_ids: nil, allow_method_names_outside_object: nil)
|
48
|
+
end
|
49
|
+
|
50
|
+
def value_method
|
51
|
+
@value_method ||= options[:input].delete(:value_method)
|
52
|
+
end
|
53
|
+
|
54
|
+
def label_method
|
55
|
+
@label_method ||= options[:input].delete(:label_method)
|
56
|
+
end
|
57
|
+
|
58
|
+
def group_method
|
59
|
+
@group_method ||= options[:input].delete(:group_method)
|
60
|
+
end
|
61
|
+
|
62
|
+
def group_label_method
|
63
|
+
@group_label_method ||= options[:input].delete(:group_label_method)
|
64
|
+
end
|
65
|
+
|
66
|
+
def option_key_method
|
67
|
+
@option_key_method ||= options[:input].delete(:option_key_method)
|
68
|
+
end
|
69
|
+
|
70
|
+
def option_value_method
|
71
|
+
@option_value_method ||= options[:input].delete(:option_value_method)
|
72
|
+
end
|
73
|
+
|
74
|
+
def options_collection
|
75
|
+
@options_collection || []
|
76
|
+
end
|
77
|
+
|
78
|
+
# This is a grouped polymorphic collection
|
79
|
+
# [["Clinics", [["Clinc 50", "Clinic_50"], ["Clinic 43", "Clinic_43"]]], ["Contacts", [["Contact 544", "Contact_544"]]]]
|
80
|
+
def assign_options_collection!
|
81
|
+
collection = options[:input].delete(:collection)
|
82
|
+
|
83
|
+
grouped = collection.kind_of?(Hash) && collection.values.all? { |v| v.respond_to?(:to_a) }
|
84
|
+
|
85
|
+
if grouped? && !grouped && collection.present?
|
86
|
+
raise "Grouped collection expecting a Hash {'Posts' => Post.all, 'Events' => Event.all} or a Hash {'Posts' => [['Post A', 1], ['Post B', 2]], 'Events' => [['Event A', 1], ['Event B', 2]]}"
|
87
|
+
end
|
88
|
+
|
89
|
+
if grouped
|
90
|
+
collection.transform_values! { |group| group.to_a }
|
91
|
+
end
|
92
|
+
|
93
|
+
if polymorphic?
|
94
|
+
if grouped
|
95
|
+
collection.values.each do |group|
|
96
|
+
group.transform_values! { |obj| [obj.to_s, "#{obj.class.model_name}_#{obj.id}"] }
|
97
|
+
end
|
98
|
+
else
|
99
|
+
collection.transform_values! { |obj| [obj.to_s, "#{obj.class.model_name}_#{obj.id}"] }
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
@options_collection = collection.to_a
|
104
|
+
end
|
105
|
+
|
106
|
+
def assign_options_collection_methods!
|
107
|
+
options[:input].reverse_merge!(
|
108
|
+
if grouped? && polymorphic?
|
109
|
+
{ group_method: :last, group_label_method: :first, option_key_method: :second, option_value_method: :first }
|
110
|
+
elsif grouped?
|
111
|
+
{ group_method: :last, group_label_method: :first, option_key_method: :second, option_value_method: :first }
|
112
|
+
elsif options_collection[0].kind_of?(Array)
|
113
|
+
{ label_method: :first, value_method: :second }
|
114
|
+
elsif options_collection[0].kind_of?(ActiveRecord::Base)
|
115
|
+
{ label_method: :to_s, value_method: :id }
|
116
|
+
else
|
117
|
+
{ label_method: :to_s, value_method: :to_s }
|
118
|
+
end
|
119
|
+
)
|
120
|
+
end
|
121
|
+
|
122
|
+
def polymorphic_type_method
|
123
|
+
name.to_s.sub('_id', '') + '_type'
|
124
|
+
end
|
125
|
+
|
126
|
+
def polymorphic_id_method
|
127
|
+
name.to_s.sub('_id', '') + '_id'
|
128
|
+
end
|
129
|
+
|
130
|
+
def polymorphic_value(obj)
|
131
|
+
"#{object.class.model_name}_#{object.id}" if object
|
132
|
+
end
|
133
|
+
|
134
|
+
def polymorphic_type_value
|
135
|
+
value.try(:class).try(:model_name)
|
136
|
+
end
|
137
|
+
|
138
|
+
def polymorphic_id_value
|
139
|
+
value.try(:id)
|
140
|
+
end
|
141
|
+
|
142
|
+
end
|
143
|
+
end
|
144
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class DateField < DatetimeField
|
4
|
+
|
5
|
+
def input_html_options
|
6
|
+
{
|
7
|
+
class: ['form-control', 'effective_date_time_picker', 'effective_date', ('not-date-linked' if not_date_linked?)].compact.join(' '),
|
8
|
+
pattern: '\d{4}(-\d{2})?(-\d{2})?'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def input_js_options
|
13
|
+
{ format: 'YYYY-MM-DD', showTodayButton: true, showClear: true, useCurrent: 'hour', disabledDates: disabled_dates.presence }.compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def input_group_options
|
17
|
+
{ input_group: { class: 'input-group' }, prepend: content_tag(:span, icon('calendar'), class: 'input-group-text') }
|
18
|
+
end
|
19
|
+
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
@@ -0,0 +1,53 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class DatetimeField < Effective::FormInput
|
4
|
+
|
5
|
+
def input_html_options
|
6
|
+
{
|
7
|
+
class: ['form-control', 'effective_date_time_picker', 'effective_datetime', ('not-date-linked' if not_date_linked?)].compact.join(' '),
|
8
|
+
pattern: '\d{4}(-\d{2})?-(\d{2})?( \d+)?(:\d{2})?'
|
9
|
+
}
|
10
|
+
end
|
11
|
+
|
12
|
+
def input_js_options
|
13
|
+
{ format: 'YYYY-MM-DD HH:mm', sideBySide: true, showTodayButton: true, showClear: true, useCurrent: 'hour', disabledDates: disabled_dates.presence }.compact
|
14
|
+
end
|
15
|
+
|
16
|
+
def input_group_options
|
17
|
+
{ input_group: { class: 'input-group' }, prepend: content_tag(:span, icon('calendar'), class: 'input-group-text') }
|
18
|
+
end
|
19
|
+
|
20
|
+
def build_input(&block)
|
21
|
+
@builder.super_text_field(name, options[:input])
|
22
|
+
end
|
23
|
+
|
24
|
+
private
|
25
|
+
|
26
|
+
def disabled_dates
|
27
|
+
return @disabled_dates unless @disabled_dates.nil?
|
28
|
+
|
29
|
+
@disabled_dates ||= (
|
30
|
+
Array(options.delete(:disabledDates)).map do |obj|
|
31
|
+
if obj.respond_to?(:strftime)
|
32
|
+
obj.strftime('%F')
|
33
|
+
elsif obj.kind_of?(Range) && obj.first.respond_to?(:strftime)
|
34
|
+
[obj.first].tap do |dates|
|
35
|
+
dates << (dates.last + 1.day) until (dates.last + 1.day) > obj.last
|
36
|
+
end
|
37
|
+
elsif obj.kind_of?(String)
|
38
|
+
obj
|
39
|
+
else
|
40
|
+
raise 'unexpected disabledDates data. Expected a DateTime, Range of DateTimes or String'
|
41
|
+
end
|
42
|
+
end.flatten.compact
|
43
|
+
)
|
44
|
+
end
|
45
|
+
|
46
|
+
def not_date_linked?
|
47
|
+
return @not_date_linked unless @not_date_linked.nil?
|
48
|
+
@not_date_linked = (options.delete(:date_linked) == false)
|
49
|
+
end
|
50
|
+
|
51
|
+
end
|
52
|
+
end
|
53
|
+
end
|
@@ -0,0 +1,15 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class EmailField < Effective::FormInput
|
4
|
+
|
5
|
+
def input_html_options
|
6
|
+
{ class: 'form-control', placeholder: 'someone@example.com' }
|
7
|
+
end
|
8
|
+
|
9
|
+
def input_group_options
|
10
|
+
{ input_group: { class: 'input-group' }, prepend: content_tag(:span, icon('at-sign'), class: 'input-group-text') }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
14
|
+
end
|
15
|
+
end
|
@@ -0,0 +1,47 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class ErrorField < Effective::FormInput
|
4
|
+
|
5
|
+
def input_html_options
|
6
|
+
{ class: 'alert alert-danger' }
|
7
|
+
end
|
8
|
+
|
9
|
+
def to_html(&block)
|
10
|
+
return nil unless has_error?(name)
|
11
|
+
|
12
|
+
case layout
|
13
|
+
when :horizontal
|
14
|
+
build_wrapper do
|
15
|
+
content_tag(:div, '', class: 'col-sm-2') + content_tag(:div, build_error_content, class: 'col-sm-10')
|
16
|
+
end
|
17
|
+
else
|
18
|
+
content_tag(:div, build_error_content, class: 'form-group')
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
def build_error_content
|
23
|
+
include_name = include_name?
|
24
|
+
|
25
|
+
content = (
|
26
|
+
if name.blank?
|
27
|
+
object.errors.full_messages.to_sentence
|
28
|
+
elsif include_name?
|
29
|
+
object.errors.full_messages_for(name).to_sentence
|
30
|
+
else
|
31
|
+
object.errors.messages[name].to_sentence
|
32
|
+
end
|
33
|
+
)
|
34
|
+
|
35
|
+
content_tag(:div, content, options[:input])
|
36
|
+
end
|
37
|
+
|
38
|
+
private
|
39
|
+
|
40
|
+
def include_name?
|
41
|
+
return @include_name unless @include_name.nil?
|
42
|
+
@include_name = options[:input].key?(:include_name) ? options[:input].delete(:include_name) : true
|
43
|
+
end
|
44
|
+
|
45
|
+
end
|
46
|
+
end
|
47
|
+
end
|
@@ -0,0 +1,26 @@
|
|
1
|
+
module Effective
|
2
|
+
module FormInputs
|
3
|
+
class FormGroup < Effective::FormInput
|
4
|
+
|
5
|
+
def input_html_options
|
6
|
+
if layout == :horizontal
|
7
|
+
{ class: 'form-group col-sm-10' }
|
8
|
+
else
|
9
|
+
{ class: 'form-group' }
|
10
|
+
end
|
11
|
+
end
|
12
|
+
|
13
|
+
def to_html(&block)
|
14
|
+
case layout
|
15
|
+
when :horizontal
|
16
|
+
build_wrapper do
|
17
|
+
content_tag(:div, '', class: 'col-sm-2') + content_tag(:div, capture(&block), options[:input])
|
18
|
+
end
|
19
|
+
else
|
20
|
+
content_tag(:div, capture(&block), options[:input])
|
21
|
+
end
|
22
|
+
end
|
23
|
+
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|