storefront 0.5.1 → 0.5.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.
- data/Rakefile +1 -1
- data/lib/storefront.rb +1 -0
- data/lib/storefront/components/form.rb +2 -4
- data/lib/storefront/components/form/base.rb +40 -38
- data/lib/storefront/components/form/builder.rb +98 -96
- data/lib/storefront/components/form/errors.rb +22 -20
- data/lib/storefront/components/form/field.rb +75 -73
- data/lib/storefront/components/form/fieldset.rb +32 -30
- data/lib/storefront/components/form/hint.rb +23 -21
- data/lib/storefront/components/form/input.rb +143 -141
- data/lib/storefront/components/form/inputs.rb +4 -2
- data/lib/storefront/components/form/inputs/checkbox.rb +8 -6
- data/lib/storefront/components/form/inputs/date.rb +9 -7
- data/lib/storefront/components/form/inputs/file.rb +8 -6
- data/lib/storefront/components/form/inputs/hidden.rb +7 -5
- data/lib/storefront/components/form/inputs/radio.rb +6 -4
- data/lib/storefront/components/form/inputs/range.rb +8 -6
- data/lib/storefront/components/form/inputs/select.rb +52 -50
- data/lib/storefront/components/form/inputs/string.rb +64 -62
- data/lib/storefront/components/form/inputs/submit.rb +17 -15
- data/lib/storefront/components/form/inputs/textarea.rb +13 -11
- data/lib/storefront/components/form/inputs/value.rb +11 -9
- data/lib/storefront/components/form/label.rb +24 -22
- metadata +1 -1
@@ -1,12 +1,14 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
class
|
4
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
class Checkbox < Input
|
5
|
+
resolves :checkbox, :boolean
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def checkbox_input
|
8
|
+
simple_input :checkbox
|
9
|
+
end
|
10
|
+
alias_method :boolean_input, :checkbox_input
|
8
11
|
end
|
9
|
-
alias_method :boolean_input, :checkbox_input
|
10
12
|
end
|
11
13
|
end
|
12
14
|
end
|
@@ -1,15 +1,17 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
# accepted attributes: autocomplete, autofocus, list, max, min, readonly, required, step
|
5
|
+
class Date < Input
|
6
|
+
resolves :date, :datetime, :time, :month, :week
|
6
7
|
|
7
|
-
|
8
|
+
def range_input(options = {})
|
8
9
|
|
9
|
-
|
10
|
+
end
|
10
11
|
|
11
|
-
|
12
|
+
def date_range_input(options = {})
|
12
13
|
|
14
|
+
end
|
13
15
|
end
|
14
16
|
end
|
15
17
|
end
|
@@ -1,11 +1,13 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
# :accept => "image/gif, image/jpg, image/png, image/jpeg"
|
5
|
+
class File < Input
|
6
|
+
resolves :file
|
6
7
|
|
7
|
-
|
8
|
-
|
8
|
+
def file_input(options = {})
|
9
|
+
simple_input :file, options
|
10
|
+
end
|
9
11
|
end
|
10
12
|
end
|
11
13
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
class
|
4
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
class Hidden < Input
|
5
|
+
resolves :hidden
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def hidden_input(options = {})
|
8
|
+
simple_input :hidden, options
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,10 +1,12 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
class
|
4
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
class Radio < Input
|
5
|
+
resolves :radio, :radiobutton
|
5
6
|
|
6
|
-
|
7
|
+
def radio_input(options = {})
|
7
8
|
|
9
|
+
end
|
8
10
|
end
|
9
11
|
end
|
10
12
|
end
|
@@ -1,14 +1,16 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
class
|
4
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
class Range < Input
|
5
|
+
resolves :range, :slider
|
5
6
|
|
6
|
-
|
7
|
+
def range_input(options = {})
|
7
8
|
|
8
|
-
|
9
|
+
end
|
9
10
|
|
10
|
-
|
11
|
+
def slider_input(options = {})
|
11
12
|
|
13
|
+
end
|
12
14
|
end
|
13
15
|
end
|
14
16
|
end
|
@@ -1,67 +1,69 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
# attributes: prompt, blank, multiple
|
5
|
+
class Select < Input
|
6
|
+
resolves :select
|
6
7
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
8
|
+
def select_input(options = {})
|
9
|
+
collection = self.collection
|
10
|
+
collection = [[prompt, ""]] + collection if prompt.present?
|
11
|
+
@value = attributes.delete(:value).to_s
|
11
12
|
|
12
|
-
|
13
|
-
|
13
|
+
base_input :select, attributes.merge(options) do
|
14
|
+
collection_iterator(collection, value)
|
15
|
+
end
|
14
16
|
end
|
15
|
-
end
|
16
17
|
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
18
|
+
def collection_iterator(collection, selected = nil)
|
19
|
+
collection.map do |item|
|
20
|
+
name, options = item, {}
|
21
|
+
optgroup = false
|
22
|
+
case item
|
23
|
+
when Array
|
24
|
+
name = item[0].to_s
|
25
|
+
options[:value] = item[1].to_s
|
26
|
+
when Hash
|
27
|
+
name = item[:name].to_s
|
28
|
+
options[:value] = item[:value].to_s
|
29
|
+
optgroup = item[:children].present?
|
30
|
+
when ::String, ::Float, ::Integer, ::BigDecimal
|
31
|
+
options[:value] = item.to_s
|
32
|
+
else
|
33
|
+
name = item.name.strip.humanize
|
34
|
+
options[:value] = item.id.to_s
|
35
|
+
end
|
36
|
+
if optgroup
|
37
|
+
template.capture_haml do
|
38
|
+
template.haml_tag :optgroup, :label => options[:name], :"data-value" => options[:value] do
|
39
|
+
collection_iterator(item[:children], selected)
|
40
|
+
end
|
39
41
|
end
|
42
|
+
else
|
43
|
+
options[:selected] = "true" if selected.present? && options[:value] == selected
|
44
|
+
template.haml_tag :option, name, options
|
40
45
|
end
|
41
|
-
else
|
42
|
-
options[:selected] = "true" if selected.present? && options[:value] == selected
|
43
|
-
template.haml_tag :option, name, options
|
44
46
|
end
|
45
47
|
end
|
46
|
-
end
|
47
|
-
|
48
|
-
def boolean_collection(options = {})
|
49
|
-
[["Yes", true], ["No", false]]
|
50
|
-
end
|
51
48
|
|
52
|
-
|
53
|
-
|
54
|
-
@collection = Array(attributes.delete(:collection) || [])
|
49
|
+
def boolean_collection(options = {})
|
50
|
+
[["Yes", true], ["No", false]]
|
55
51
|
end
|
52
|
+
|
53
|
+
def collection
|
54
|
+
if @collection.nil?
|
55
|
+
@collection = Array(attributes.delete(:collection) || [])
|
56
|
+
end
|
56
57
|
|
57
|
-
|
58
|
-
|
58
|
+
@collection
|
59
|
+
end
|
59
60
|
|
60
|
-
|
61
|
-
|
62
|
-
|
61
|
+
def prompt
|
62
|
+
if @prompt.nil? && include_blank
|
63
|
+
@prompt = localize(:prompts, attribute.name, attributes.delete(:prompt), :allow_blank => true)
|
64
|
+
end
|
65
|
+
@prompt
|
63
66
|
end
|
64
|
-
@prompt
|
65
67
|
end
|
66
68
|
end
|
67
69
|
end
|
@@ -1,88 +1,90 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
# email attributes: autocomplete, autofocus, list, maxlength, multiple, pattern, placeholder, readonly, required, size
|
5
|
+
# password attributes: autocomplete, autofocus, maxlength, pattern, placeholder, readonly, required, size
|
6
|
+
# text, search, url, tel attributes: autocomplete, autofocus, list, maxlength, pattern, placeholder, readonly, required, size
|
7
|
+
class String < Input
|
8
|
+
resolves :string, :phone, :url, :email, :search, :date, :datetime, :time, :numeric, :number, :money, :percent, :password
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
10
|
+
# autofocus, pattern, placeholder, title, size, data-validate, data-validate-match, data-validate-unique
|
11
|
+
def string_input
|
12
|
+
simple_input :string
|
13
|
+
end
|
13
14
|
|
14
|
-
|
15
|
-
|
16
|
-
|
15
|
+
def password_input
|
16
|
+
simple_input :password
|
17
|
+
end
|
17
18
|
|
18
|
-
|
19
|
-
|
20
|
-
|
19
|
+
def email_input
|
20
|
+
simple_input :email
|
21
|
+
end
|
21
22
|
|
22
|
-
|
23
|
-
|
24
|
-
|
23
|
+
def url_input
|
24
|
+
simple_input :url
|
25
|
+
end
|
25
26
|
|
26
|
-
|
27
|
-
|
28
|
-
|
27
|
+
def number_input
|
28
|
+
simple_input :string, :class => "numeric", "data-type" => "numeric"
|
29
|
+
end
|
29
30
|
|
30
|
-
|
31
|
-
|
32
|
-
|
31
|
+
def numeric_input
|
32
|
+
simple_input :string, :class => "numeric", "data-type" => "numeric"
|
33
|
+
end
|
33
34
|
|
34
|
-
|
35
|
-
|
36
|
-
|
35
|
+
def search_input
|
36
|
+
simple_input :search, :class => "search", "data-type" => "search"
|
37
|
+
end
|
37
38
|
|
38
|
-
|
39
|
-
|
40
|
-
|
39
|
+
def phone_input
|
40
|
+
simple_input :tel, :class => "phone"
|
41
|
+
end
|
41
42
|
|
42
|
-
|
43
|
-
|
44
|
-
|
43
|
+
def fax_input
|
44
|
+
simple_input :tel, :class => "phone fax"
|
45
|
+
end
|
45
46
|
|
46
|
-
|
47
|
-
|
48
|
-
|
47
|
+
def date_input
|
48
|
+
simple_input :string, :class => "date", "data-type" => "date"
|
49
|
+
end
|
49
50
|
|
50
|
-
|
51
|
-
|
52
|
-
|
51
|
+
def money_input
|
52
|
+
simple_input :string, :class => "money", "data-type" => "money"
|
53
|
+
end
|
53
54
|
|
54
|
-
|
55
|
-
|
56
|
-
|
55
|
+
def percent_input
|
56
|
+
simple_input :string, :class => "percent", "data-type" => "percent"
|
57
|
+
end
|
57
58
|
|
58
|
-
|
59
|
+
def color_input
|
59
60
|
|
60
|
-
|
61
|
+
end
|
61
62
|
|
62
|
-
|
63
|
+
def autocomplete_input
|
63
64
|
=begin
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
65
|
+
default = options[:default]
|
66
|
+
#attribute = "#{attribute}".gsub(/_id$/, "")
|
67
|
+
if default.present?
|
68
|
+
name = default.name rescue ""
|
69
|
+
else
|
70
|
+
name = (object.send("#{attribute}".gsub(/_id$/, "")).name || "") rescue ""
|
71
|
+
end
|
71
72
|
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
73
|
+
options[:value] ||= default_id_for(default || object.send("#{attribute}".gsub(/_id$/, "")))
|
74
|
+
value = User.find_by_id(options[:value])
|
75
|
+
name = value.name if value
|
76
|
+
value = value.id if value
|
76
77
|
|
77
|
-
|
78
|
+
result = input(attribute, :as => :hidden, :input_html => {:class => "hidden-autocomplete", :value => value})
|
78
79
|
|
79
|
-
|
80
|
-
|
80
|
+
options[:input_html] ||= {}
|
81
|
+
options[:input_html].merge!(:class => "autocomplete-two", :value => name)
|
81
82
|
|
82
|
-
|
83
|
+
result += input("#{attribute}".gsub(/_id$/, ""), options)
|
83
84
|
|
84
|
-
|
85
|
+
result
|
85
86
|
=end
|
87
|
+
end
|
86
88
|
end
|
87
89
|
end
|
88
90
|
end
|
@@ -1,24 +1,26 @@
|
|
1
1
|
module Storefront
|
2
|
-
|
3
|
-
class
|
4
|
-
|
2
|
+
module Components
|
3
|
+
class Form
|
4
|
+
class Submit < Input
|
5
|
+
resolves :submit, :confirm, :button
|
5
6
|
|
6
|
-
|
7
|
-
|
7
|
+
def initialize(options = {})
|
8
|
+
super
|
8
9
|
|
9
|
-
|
10
|
-
|
11
|
-
|
10
|
+
attributes.delete(:name)
|
11
|
+
attributes.delete(:accesskey)
|
12
|
+
end
|
12
13
|
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
14
|
+
def submit_input
|
15
|
+
if @rich_input
|
16
|
+
rich_input :submit
|
17
|
+
else
|
18
|
+
simple_input :submit
|
19
|
+
end
|
18
20
|
end
|
21
|
+
alias_method :confirm_input, :submit_input
|
22
|
+
alias_method :button_input, :submit_input
|
19
23
|
end
|
20
|
-
alias_method :confirm_input, :submit_input
|
21
|
-
alias_method :button_input, :submit_input
|
22
24
|
end
|
23
25
|
end
|
24
26
|
end
|