matestack-ui-core 0.7.2
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/README.md +228 -0
- data/Rakefile +34 -0
- data/app/concepts/matestack/ui/core/abbr/abbr.haml +5 -0
- data/app/concepts/matestack/ui/core/abbr/abbr.rb +12 -0
- data/app/concepts/matestack/ui/core/absolute/absolute.haml +3 -0
- data/app/concepts/matestack/ui/core/absolute/absolute.rb +17 -0
- data/app/concepts/matestack/ui/core/action/action.haml +3 -0
- data/app/concepts/matestack/ui/core/action/action.js +49 -0
- data/app/concepts/matestack/ui/core/action/action.rb +52 -0
- data/app/concepts/matestack/ui/core/address/address.haml +5 -0
- data/app/concepts/matestack/ui/core/address/address.rb +5 -0
- data/app/concepts/matestack/ui/core/app/app.haml +4 -0
- data/app/concepts/matestack/ui/core/app/app.js +27 -0
- data/app/concepts/matestack/ui/core/app/app.rb +98 -0
- data/app/concepts/matestack/ui/core/app/store.js +70 -0
- data/app/concepts/matestack/ui/core/article/article.haml +5 -0
- data/app/concepts/matestack/ui/core/article/article.rb +5 -0
- data/app/concepts/matestack/ui/core/async/async.haml +2 -0
- data/app/concepts/matestack/ui/core/async/async.js +76 -0
- data/app/concepts/matestack/ui/core/async/async.rb +12 -0
- data/app/concepts/matestack/ui/core/blockquote/blockquote.haml +5 -0
- data/app/concepts/matestack/ui/core/blockquote/blockquote.rb +11 -0
- data/app/concepts/matestack/ui/core/br/br.haml +5 -0
- data/app/concepts/matestack/ui/core/br/br.rb +5 -0
- data/app/concepts/matestack/ui/core/button/button.haml +5 -0
- data/app/concepts/matestack/ui/core/button/button.rb +11 -0
- data/app/concepts/matestack/ui/core/caption/caption.haml +5 -0
- data/app/concepts/matestack/ui/core/caption/caption.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/content/content.js +98 -0
- data/app/concepts/matestack/ui/core/collection/content/content.rb +18 -0
- data/app/concepts/matestack/ui/core/collection/content/next/next.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/content/next/next.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/content/page/link/link.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/content/page/link/link.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/content/previous/previous.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/content/previous/previous.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/filter/filter.js +48 -0
- data/app/concepts/matestack/ui/core/collection/filter/filter.rb +17 -0
- data/app/concepts/matestack/ui/core/collection/filter/input/input.haml +2 -0
- data/app/concepts/matestack/ui/core/collection/filter/input/input.rb +25 -0
- data/app/concepts/matestack/ui/core/collection/filter/reset/reset.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/filter/reset/reset.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/filter/submit/submit.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/filter/submit/submit.rb +5 -0
- data/app/concepts/matestack/ui/core/collection/helper.rb +113 -0
- data/app/concepts/matestack/ui/core/collection/order/order.js +56 -0
- data/app/concepts/matestack/ui/core/collection/order/order.rb +17 -0
- data/app/concepts/matestack/ui/core/collection/order/toggle/indicator/indicator.rb +13 -0
- data/app/concepts/matestack/ui/core/collection/order/toggle/toggle.haml +3 -0
- data/app/concepts/matestack/ui/core/collection/order/toggle/toggle.rb +5 -0
- data/app/concepts/matestack/ui/core/component/anonym-dynamic-component.js +10 -0
- data/app/concepts/matestack/ui/core/component/children.haml +2 -0
- data/app/concepts/matestack/ui/core/component/component.js +59 -0
- data/app/concepts/matestack/ui/core/component/dynamic.haml +6 -0
- data/app/concepts/matestack/ui/core/component/dynamic.rb +261 -0
- data/app/concepts/matestack/ui/core/component/dynamic_without_rerender.haml +2 -0
- data/app/concepts/matestack/ui/core/component/response.haml +2 -0
- data/app/concepts/matestack/ui/core/component/response_dynamic.haml +7 -0
- data/app/concepts/matestack/ui/core/component/response_dynamic_without_rerender.haml +3 -0
- data/app/concepts/matestack/ui/core/component/static.haml +1 -0
- data/app/concepts/matestack/ui/core/component/static.rb +16 -0
- data/app/concepts/matestack/ui/core/details/details.haml +3 -0
- data/app/concepts/matestack/ui/core/details/details.rb +5 -0
- data/app/concepts/matestack/ui/core/div/div.haml +3 -0
- data/app/concepts/matestack/ui/core/div/div.rb +5 -0
- data/app/concepts/matestack/ui/core/footer/footer.haml +3 -0
- data/app/concepts/matestack/ui/core/footer/footer.rb +5 -0
- data/app/concepts/matestack/ui/core/form/form.haml +2 -0
- data/app/concepts/matestack/ui/core/form/form.js +136 -0
- data/app/concepts/matestack/ui/core/form/form.rb +71 -0
- data/app/concepts/matestack/ui/core/form/inline/inline.haml +6 -0
- data/app/concepts/matestack/ui/core/form/inline/inline.rb +9 -0
- data/app/concepts/matestack/ui/core/form/input/input.haml +27 -0
- data/app/concepts/matestack/ui/core/form/input/input.rb +74 -0
- data/app/concepts/matestack/ui/core/form/select/select.haml +76 -0
- data/app/concepts/matestack/ui/core/form/select/select.rb +73 -0
- data/app/concepts/matestack/ui/core/form/submit/submit.haml +3 -0
- data/app/concepts/matestack/ui/core/form/submit/submit.rb +9 -0
- data/app/concepts/matestack/ui/core/header/header.haml +3 -0
- data/app/concepts/matestack/ui/core/header/header.rb +5 -0
- data/app/concepts/matestack/ui/core/heading/heading.haml +50 -0
- data/app/concepts/matestack/ui/core/heading/heading.rb +5 -0
- data/app/concepts/matestack/ui/core/hr/hr.haml +1 -0
- data/app/concepts/matestack/ui/core/hr/hr.rb +5 -0
- data/app/concepts/matestack/ui/core/html/html.haml +3 -0
- data/app/concepts/matestack/ui/core/html/html.js +10 -0
- data/app/concepts/matestack/ui/core/html/html.rb +17 -0
- data/app/concepts/matestack/ui/core/icon/icon.haml +5 -0
- data/app/concepts/matestack/ui/core/icon/icon.rb +5 -0
- data/app/concepts/matestack/ui/core/img/img.haml +1 -0
- data/app/concepts/matestack/ui/core/img/img.rb +5 -0
- data/app/concepts/matestack/ui/core/input/input.haml +3 -0
- data/app/concepts/matestack/ui/core/input/input.rb +5 -0
- data/app/concepts/matestack/ui/core/isolate/isolate.haml +2 -0
- data/app/concepts/matestack/ui/core/isolate/isolate.rb +11 -0
- data/app/concepts/matestack/ui/core/js/core.js +30 -0
- data/app/concepts/matestack/ui/core/js/event-hub.js +5 -0
- data/app/concepts/matestack/ui/core/js/helpers/query-params-helper.js +56 -0
- data/app/concepts/matestack/ui/core/label/label.haml +5 -0
- data/app/concepts/matestack/ui/core/label/label.rb +5 -0
- data/app/concepts/matestack/ui/core/li/li.haml +5 -0
- data/app/concepts/matestack/ui/core/li/li.rb +5 -0
- data/app/concepts/matestack/ui/core/link/link.haml +5 -0
- data/app/concepts/matestack/ui/core/link/link.rb +26 -0
- data/app/concepts/matestack/ui/core/main/main.haml +3 -0
- data/app/concepts/matestack/ui/core/main/main.rb +5 -0
- data/app/concepts/matestack/ui/core/nav/nav.haml +3 -0
- data/app/concepts/matestack/ui/core/nav/nav.rb +5 -0
- data/app/concepts/matestack/ui/core/ol/ol.haml +3 -0
- data/app/concepts/matestack/ui/core/ol/ol.rb +5 -0
- data/app/concepts/matestack/ui/core/onclick/onclick.haml +2 -0
- data/app/concepts/matestack/ui/core/onclick/onclick.js +21 -0
- data/app/concepts/matestack/ui/core/onclick/onclick.rb +5 -0
- data/app/concepts/matestack/ui/core/page/content.haml +7 -0
- data/app/concepts/matestack/ui/core/page/content.js +17 -0
- data/app/concepts/matestack/ui/core/page/content.rb +5 -0
- data/app/concepts/matestack/ui/core/page/page.haml +9 -0
- data/app/concepts/matestack/ui/core/page/page.rb +175 -0
- data/app/concepts/matestack/ui/core/paragraph/paragraph.haml +5 -0
- data/app/concepts/matestack/ui/core/paragraph/paragraph.rb +5 -0
- data/app/concepts/matestack/ui/core/partial/partial.haml +2 -0
- data/app/concepts/matestack/ui/core/partial/partial.rb +5 -0
- data/app/concepts/matestack/ui/core/pg/pg.haml +5 -0
- data/app/concepts/matestack/ui/core/pg/pg.rb +5 -0
- data/app/concepts/matestack/ui/core/plain/plain.rb +9 -0
- data/app/concepts/matestack/ui/core/progress/progress.haml +3 -0
- data/app/concepts/matestack/ui/core/progress/progress.rb +14 -0
- data/app/concepts/matestack/ui/core/section/section.haml +3 -0
- data/app/concepts/matestack/ui/core/section/section.rb +5 -0
- data/app/concepts/matestack/ui/core/slot/slot.haml +2 -0
- data/app/concepts/matestack/ui/core/slot/slot.rb +5 -0
- data/app/concepts/matestack/ui/core/small/small.haml +5 -0
- data/app/concepts/matestack/ui/core/small/small.rb +5 -0
- data/app/concepts/matestack/ui/core/span/span.haml +5 -0
- data/app/concepts/matestack/ui/core/span/span.rb +5 -0
- data/app/concepts/matestack/ui/core/strong/strong.haml +5 -0
- data/app/concepts/matestack/ui/core/strong/strong.rb +5 -0
- data/app/concepts/matestack/ui/core/sub/sub.haml +5 -0
- data/app/concepts/matestack/ui/core/sub/sub.rb +5 -0
- data/app/concepts/matestack/ui/core/summary/summary.haml +5 -0
- data/app/concepts/matestack/ui/core/summary/summary.rb +5 -0
- data/app/concepts/matestack/ui/core/table/table.haml +3 -0
- data/app/concepts/matestack/ui/core/table/table.rb +5 -0
- data/app/concepts/matestack/ui/core/tbody/tbody.haml +3 -0
- data/app/concepts/matestack/ui/core/tbody/tbody.rb +5 -0
- data/app/concepts/matestack/ui/core/td/td.haml +5 -0
- data/app/concepts/matestack/ui/core/td/td.rb +5 -0
- data/app/concepts/matestack/ui/core/tfoot/tfoot.haml +3 -0
- data/app/concepts/matestack/ui/core/tfoot/tfoot.rb +5 -0
- data/app/concepts/matestack/ui/core/th/th.haml +5 -0
- data/app/concepts/matestack/ui/core/th/th.rb +5 -0
- data/app/concepts/matestack/ui/core/thead/thead.haml +3 -0
- data/app/concepts/matestack/ui/core/thead/thead.rb +5 -0
- data/app/concepts/matestack/ui/core/time/time.haml +3 -0
- data/app/concepts/matestack/ui/core/time/time.rb +11 -0
- data/app/concepts/matestack/ui/core/tr/tr.haml +3 -0
- data/app/concepts/matestack/ui/core/tr/tr.rb +5 -0
- data/app/concepts/matestack/ui/core/transition/transition.haml +5 -0
- data/app/concepts/matestack/ui/core/transition/transition.js +26 -0
- data/app/concepts/matestack/ui/core/transition/transition.rb +31 -0
- data/app/concepts/matestack/ui/core/ul/ul.haml +3 -0
- data/app/concepts/matestack/ui/core/ul/ul.rb +5 -0
- data/app/concepts/matestack/ui/core/video/video.haml +1 -0
- data/app/concepts/matestack/ui/core/video/video.rb +7 -0
- data/app/concepts/matestack/ui/core/view/view.haml +2 -0
- data/app/concepts/matestack/ui/core/view/view.js +42 -0
- data/app/concepts/matestack/ui/core/view/view.rb +5 -0
- data/app/concepts/matestack/ui/core/youtube/youtube.haml +1 -0
- data/app/concepts/matestack/ui/core/youtube/youtube.rb +26 -0
- data/app/helpers/matestack/ui/core/application_helper.rb +35 -0
- data/app/lib/matestack/ui/app.rb +1 -0
- data/app/lib/matestack/ui/core/app_node.rb +53 -0
- data/app/lib/matestack/ui/core/component_node.rb +73 -0
- data/app/lib/matestack/ui/core/page_node.rb +96 -0
- data/app/lib/matestack/ui/core/to_cell.rb +129 -0
- data/app/lib/matestack/ui/dynamic_component.rb +1 -0
- data/app/lib/matestack/ui/page.rb +1 -0
- data/app/lib/matestack/ui/static_component.rb +1 -0
- data/config/routes.rb +3 -0
- data/lib/generators/matestack_app/USAGE +21 -0
- data/lib/generators/matestack_app/matestack_app_generator.rb +26 -0
- data/lib/generators/matestack_app/templates/matestack_app.erb +26 -0
- data/lib/generators/matestack_app/templates/matestack_app_controller.erb +7 -0
- data/lib/generators/matestack_component/USAGE +20 -0
- data/lib/generators/matestack_component/matestack_component_generator.rb +30 -0
- data/lib/generators/matestack_component/templates/matestack_component.haml.erb +5 -0
- data/lib/generators/matestack_component/templates/matestack_component.js.erb +17 -0
- data/lib/generators/matestack_component/templates/matestack_component.rb.erb +13 -0
- data/lib/generators/matestack_component/templates/matestack_component.scss.erb +1 -0
- data/lib/generators/matestack_page/USAGE +28 -0
- data/lib/generators/matestack_page/matestack_page_generator.rb +41 -0
- data/lib/generators/matestack_page/templates/matestack_page.erb +15 -0
- data/lib/matestack/ui/core.rb +15 -0
- data/lib/matestack/ui/core/engine.rb +19 -0
- data/lib/matestack/ui/core/version.rb +7 -0
- data/lib/tasks/matestack/ui/core_tasks.rake +4 -0
- data/vendor/assets/javascripts/manifest.json +4 -0
- data/vendor/assets/javascripts/matestack-ui-core.js +15309 -0
- data/vendor/assets/javascripts/matestack-ui-core.js.map +1 -0
- metadata +350 -0
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
module Matestack::Ui::Core::Form
|
|
2
|
+
class Form < Matestack::Ui::Core::Component::Dynamic
|
|
3
|
+
|
|
4
|
+
REQUIRED_KEYS = [:for, :path, :method]
|
|
5
|
+
|
|
6
|
+
def setup
|
|
7
|
+
begin
|
|
8
|
+
@component_config[:for] = form_wrapper
|
|
9
|
+
@component_config[:submit_path] = submit_path
|
|
10
|
+
@component_config[:method] = options[:method]
|
|
11
|
+
@component_config[:success] = options[:success]
|
|
12
|
+
unless options[:success].nil?
|
|
13
|
+
unless options[:success][:transition].nil?
|
|
14
|
+
@component_config[:success][:transition][:path] = transition_path options[:success]
|
|
15
|
+
end
|
|
16
|
+
end
|
|
17
|
+
@component_config[:failure] = options[:failure]
|
|
18
|
+
unless options[:failure].nil?
|
|
19
|
+
unless options[:failure][:transition].nil?
|
|
20
|
+
@component_config[:failure][:transition][:path] = transition_path options[:failure]
|
|
21
|
+
end
|
|
22
|
+
end
|
|
23
|
+
@tag_attributes.merge!({"@submit.prevent": true})
|
|
24
|
+
rescue => e
|
|
25
|
+
raise "Form component could not be setted up. Reason: #{e}"
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def submit_path
|
|
30
|
+
begin
|
|
31
|
+
if options[:path].is_a?(Symbol)
|
|
32
|
+
return ::Rails.application.routes.url_helpers.send(options[:path], options[:params])
|
|
33
|
+
else
|
|
34
|
+
return options[:path]
|
|
35
|
+
end
|
|
36
|
+
rescue
|
|
37
|
+
raise "Submit path not found"
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
|
|
41
|
+
def transition_path callback_options
|
|
42
|
+
begin
|
|
43
|
+
if callback_options[:transition][:path].is_a?(Symbol)
|
|
44
|
+
return ::Rails.application.routes.url_helpers.send(
|
|
45
|
+
callback_options[:transition][:path],
|
|
46
|
+
callback_options[:transition][:params]
|
|
47
|
+
)
|
|
48
|
+
else
|
|
49
|
+
return callback_options[:transition][:path]
|
|
50
|
+
end
|
|
51
|
+
rescue
|
|
52
|
+
raise "Transition path not found"
|
|
53
|
+
end
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def form_wrapper
|
|
57
|
+
case options[:for]
|
|
58
|
+
when Symbol
|
|
59
|
+
return options[:for]
|
|
60
|
+
when String
|
|
61
|
+
return options[:for]
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
if options[:for].respond_to?(:model_name)
|
|
65
|
+
return options[:for].model_name.singular
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
|
|
70
|
+
end
|
|
71
|
+
end
|
|
@@ -0,0 +1,6 @@
|
|
|
1
|
+
%div{"v-if": "!showInlineForm", "@click": "launchInlineForm(\"#{options[:key]}\", \"#{options[:value]}\")"}
|
|
2
|
+
= options[:value]
|
|
3
|
+
%div{"v-if": "showInlineForm"}
|
|
4
|
+
%input{"ref": "inlineinput", "v-model": input_key, "@blur": "perform", "@keyup.esc": "closeInlineForm", class: options[:class], id: component_id}
|
|
5
|
+
- if block_given?
|
|
6
|
+
= yield
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
- if options[:label]
|
|
2
|
+
%label=options[:label]
|
|
3
|
+
|
|
4
|
+
- if [:text, :number, :email, :date, :password].include?(options[:type])
|
|
5
|
+
%input{@tag_attributes,
|
|
6
|
+
"v-model#{'.number' if options[:type] == :number}": input_key,
|
|
7
|
+
type: options[:type],
|
|
8
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
9
|
+
ref: "input.#{attr_key}",
|
|
10
|
+
placeholder: options[:placeholder],
|
|
11
|
+
"init-value": init_value}
|
|
12
|
+
%span{class: "errors", "v-if": error_key }
|
|
13
|
+
%span{class: "error", "v-for": "error in #{error_key}"}
|
|
14
|
+
{{ error }}
|
|
15
|
+
|
|
16
|
+
- if options[:type] == :textarea
|
|
17
|
+
%textarea{@tag_attributes,
|
|
18
|
+
"v-model": input_key,
|
|
19
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
20
|
+
ref: "input.#{attr_key}",
|
|
21
|
+
placeholder: options[:placeholder],
|
|
22
|
+
"init-value": init_value,
|
|
23
|
+
rows: options[:rows],
|
|
24
|
+
cols: options[:cols]}
|
|
25
|
+
%span{class: "errors", "v-if": error_key }
|
|
26
|
+
%span{class: "error", "v-for": "error in #{error_key}"}
|
|
27
|
+
{{ error }}
|
|
@@ -0,0 +1,74 @@
|
|
|
1
|
+
module Matestack::Ui::Core::Form::Input
|
|
2
|
+
class Input < Matestack::Ui::Core::Component::Static
|
|
3
|
+
|
|
4
|
+
REQUIRED_KEYS = [:key, :type]
|
|
5
|
+
|
|
6
|
+
def custom_options_validation
|
|
7
|
+
raise "included form config is missing, please add ':include' to parent form component" if @included_config.nil?
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def input_key
|
|
11
|
+
'data["' + options[:key].to_s + '"]'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def error_key
|
|
15
|
+
'errors["' + options[:key].to_s + '"]'
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def input_wrapper
|
|
19
|
+
case options[:for]
|
|
20
|
+
when nil
|
|
21
|
+
return nil
|
|
22
|
+
when Symbol
|
|
23
|
+
return options[:for]
|
|
24
|
+
when String
|
|
25
|
+
return options[:for]
|
|
26
|
+
end
|
|
27
|
+
if options[:for].respond_to?(:model_name)
|
|
28
|
+
return options[:for].model_name.singular
|
|
29
|
+
end
|
|
30
|
+
end
|
|
31
|
+
|
|
32
|
+
def attr_key
|
|
33
|
+
if input_wrapper.nil?
|
|
34
|
+
return options[:key].to_s
|
|
35
|
+
else
|
|
36
|
+
return "#{input_wrapper}.#{options[:key].to_s}"
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
def init_value
|
|
41
|
+
unless options[:init].nil?
|
|
42
|
+
return options[:init]
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
unless options[:for].nil?
|
|
46
|
+
value = options[:for].send(options[:key])
|
|
47
|
+
if [true, false].include? value
|
|
48
|
+
value ? 1 : 0
|
|
49
|
+
else
|
|
50
|
+
return value
|
|
51
|
+
end
|
|
52
|
+
else
|
|
53
|
+
unless @included_config.nil? && @included_config[:for].nil?
|
|
54
|
+
if @included_config[:for].respond_to?(options[:key])
|
|
55
|
+
value = @included_config[:for].send(options[:key])
|
|
56
|
+
if [true, false].include? value
|
|
57
|
+
value ? 1 : 0
|
|
58
|
+
else
|
|
59
|
+
return value
|
|
60
|
+
end
|
|
61
|
+
else
|
|
62
|
+
if @included_config[:for].is_a?(Symbol) || @included_config[:for].is_a?(String)
|
|
63
|
+
return nil
|
|
64
|
+
end
|
|
65
|
+
if @included_config[:for].is_a?(Hash)
|
|
66
|
+
return @included_config[:for][options[:key]]
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
end
|
|
74
|
+
end
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
- if options[:label]
|
|
2
|
+
|
|
3
|
+
%label=options[:label]
|
|
4
|
+
|
|
5
|
+
- if options[:type] == :dropdown
|
|
6
|
+
|
|
7
|
+
%select{@tag_attributes,
|
|
8
|
+
"#{model_binding}" => input_key,
|
|
9
|
+
ref: "select.#{attr_key}",
|
|
10
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
11
|
+
"init-value": init_value,
|
|
12
|
+
"value-type": options_type}
|
|
13
|
+
%option{disabled: true}= options[:placeholder]
|
|
14
|
+
- if options[:options].is_a?(Hash)
|
|
15
|
+
- options[:options].each do |key, value|
|
|
16
|
+
%option{value: key}=value
|
|
17
|
+
- if options[:options].is_a?(Array)
|
|
18
|
+
- options[:options].each do |option|
|
|
19
|
+
%option{value: option}=option
|
|
20
|
+
%span{class: "errors", "v-if": error_key }
|
|
21
|
+
%span{class: "error", "v-for": "error in #{error_key}"}
|
|
22
|
+
{{ error }}
|
|
23
|
+
|
|
24
|
+
- if options[:type] == :checkbox
|
|
25
|
+
|
|
26
|
+
%div{id: component_id, ref: "select.multiple.#{attr_key}", "init-value": init_value}
|
|
27
|
+
- if options[:options].is_a?(Hash)
|
|
28
|
+
- options[:options].each do |key, value|
|
|
29
|
+
%input{@tag_attributes,
|
|
30
|
+
type: :checkbox,
|
|
31
|
+
"#{model_binding}": input_key,
|
|
32
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
33
|
+
"value-type": options_type,
|
|
34
|
+
name: value,
|
|
35
|
+
value: key}/
|
|
36
|
+
%label=value
|
|
37
|
+
- if options[:options].is_a?(Array)
|
|
38
|
+
- options[:options].each do |value|
|
|
39
|
+
%input{@tag_attributes,
|
|
40
|
+
type: :checkbox,
|
|
41
|
+
"#{model_binding}": input_key,
|
|
42
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
43
|
+
"value-type": options_type,
|
|
44
|
+
name: value,
|
|
45
|
+
value: value}/
|
|
46
|
+
%label=value
|
|
47
|
+
%span{class: "errors", "v-if": error_key }
|
|
48
|
+
%span{class: "error", "v-for": "error in #{error_key}"}
|
|
49
|
+
{{ error }}
|
|
50
|
+
|
|
51
|
+
- if options[:type] == :radio
|
|
52
|
+
|
|
53
|
+
%div{id: component_id, ref: "select.#{attr_key}", "init-value": init_value}
|
|
54
|
+
- if options[:options].is_a?(Hash)
|
|
55
|
+
- options[:options].each do |key, value|
|
|
56
|
+
%input{@tag_attributes,
|
|
57
|
+
type: :radio,
|
|
58
|
+
"#{model_binding}": input_key,
|
|
59
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
60
|
+
"value-type": options_type,
|
|
61
|
+
name: value,
|
|
62
|
+
value: key}/
|
|
63
|
+
%label=value
|
|
64
|
+
- if options[:options].is_a?(Array)
|
|
65
|
+
- options[:options].each do |value|
|
|
66
|
+
%input{@tag_attributes,
|
|
67
|
+
type: :radio,
|
|
68
|
+
"#{model_binding}": input_key,
|
|
69
|
+
"@change": "inputChanged(\"#{attr_key}\")",
|
|
70
|
+
"value-type": options_type,
|
|
71
|
+
name: value,
|
|
72
|
+
value: value}/
|
|
73
|
+
%label=value
|
|
74
|
+
%span{class: "errors", "v-if": error_key }
|
|
75
|
+
%span{class: "error", "v-for": "error in #{error_key}"}
|
|
76
|
+
{{ error }}
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
module Matestack::Ui::Core::Form::Select
|
|
2
|
+
class Select < Matestack::Ui::Core::Component::Static
|
|
3
|
+
|
|
4
|
+
REQUIRED_KEYS = [:options]
|
|
5
|
+
|
|
6
|
+
def input_key
|
|
7
|
+
'data["' + options[:key].to_s + '"]'
|
|
8
|
+
end
|
|
9
|
+
|
|
10
|
+
def error_key
|
|
11
|
+
'errors["' + options[:key].to_s + '"]'
|
|
12
|
+
end
|
|
13
|
+
|
|
14
|
+
def attr_key
|
|
15
|
+
options[:key].to_s
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def option_values
|
|
19
|
+
values = options[:options] if options[:options].is_a?(Array)
|
|
20
|
+
values = options[:options].keys if options[:options].is_a?(Hash)
|
|
21
|
+
return values
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
def options_type
|
|
25
|
+
return Integer if option_values.first.is_a?(Integer)
|
|
26
|
+
return String if option_values.first.is_a?(String)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def model_binding
|
|
30
|
+
|
|
31
|
+
if option_values.first.is_a?(Integer)
|
|
32
|
+
return "v-model.number"
|
|
33
|
+
else
|
|
34
|
+
return "v-model"
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
def init_value
|
|
39
|
+
unless options[:init].nil?
|
|
40
|
+
return options[:init]
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
unless options[:for].nil?
|
|
44
|
+
value = options[:for].send(options[:key])
|
|
45
|
+
if [true, false].include? value
|
|
46
|
+
value ? 1 : 0
|
|
47
|
+
else
|
|
48
|
+
return value
|
|
49
|
+
end
|
|
50
|
+
else
|
|
51
|
+
unless @included_config.nil? && @included_config[:for].nil?
|
|
52
|
+
if @included_config[:for].respond_to?(options[:key])
|
|
53
|
+
value = @included_config[:for].send(options[:key])
|
|
54
|
+
if [true, false].include? value
|
|
55
|
+
value ? 1 : 0
|
|
56
|
+
else
|
|
57
|
+
return value
|
|
58
|
+
end
|
|
59
|
+
else
|
|
60
|
+
if @included_config[:for].is_a?(Symbol) || @included_config[:for].is_a?(String)
|
|
61
|
+
return nil
|
|
62
|
+
end
|
|
63
|
+
if @included_config[:for].is_a?(Hash)
|
|
64
|
+
return @included_config[:for][options[:key]]
|
|
65
|
+
end
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
70
|
+
|
|
71
|
+
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
- case options[:size]
|
|
2
|
+
- when 1
|
|
3
|
+
%h1{@tag_attributes}
|
|
4
|
+
- if options[:text].blank?
|
|
5
|
+
- if block_given?
|
|
6
|
+
= yield
|
|
7
|
+
- else
|
|
8
|
+
= options[:text]
|
|
9
|
+
- when 2
|
|
10
|
+
%h2{@tag_attributes}
|
|
11
|
+
- if options[:text].blank?
|
|
12
|
+
- if block_given?
|
|
13
|
+
= yield
|
|
14
|
+
- else
|
|
15
|
+
= options[:text]
|
|
16
|
+
- when 3
|
|
17
|
+
%h3{@tag_attributes}
|
|
18
|
+
- if options[:text].blank?
|
|
19
|
+
- if block_given?
|
|
20
|
+
= yield
|
|
21
|
+
- else
|
|
22
|
+
= options[:text]
|
|
23
|
+
- when 4
|
|
24
|
+
%h4{@tag_attributes}
|
|
25
|
+
- if options[:text].blank?
|
|
26
|
+
- if block_given?
|
|
27
|
+
= yield
|
|
28
|
+
- else
|
|
29
|
+
= options[:text]
|
|
30
|
+
- when 5
|
|
31
|
+
%h5{@tag_attributes}
|
|
32
|
+
- if options[:text].blank?
|
|
33
|
+
- if block_given?
|
|
34
|
+
= yield
|
|
35
|
+
- else
|
|
36
|
+
= options[:text]
|
|
37
|
+
- when 6
|
|
38
|
+
%h6{@tag_attributes}
|
|
39
|
+
- if options[:text].blank?
|
|
40
|
+
- if block_given?
|
|
41
|
+
= yield
|
|
42
|
+
- else
|
|
43
|
+
= options[:text]
|
|
44
|
+
- else
|
|
45
|
+
%h1{@tag_attributes}
|
|
46
|
+
- if options[:text].blank?
|
|
47
|
+
- if block_given?
|
|
48
|
+
= yield
|
|
49
|
+
- else
|
|
50
|
+
= options[:text]
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
%hr{@tag_attributes}
|