ui_bibz 2.0.0.alpha29 → 2.0.0.alpha30

Sign up to get free protection for your applications and to get access to all the features.
Files changed (28) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +2 -2
  3. data/app/assets/javascripts/form.coffee +4 -3
  4. data/app/inputs/custom_inputs/auto_complete_field_input.rb +8 -7
  5. data/app/inputs/custom_inputs/collection_input.rb +14 -6
  6. data/app/inputs/custom_inputs/date_picker_field_input.rb +2 -3
  7. data/app/inputs/custom_inputs/dropdown_select_field_input.rb +1 -1
  8. data/app/inputs/custom_inputs/formula_field_input.rb +10 -3
  9. data/app/inputs/custom_inputs/markdown_editor_field_input.rb +2 -3
  10. data/app/inputs/custom_inputs/multi_column_field_input.rb +2 -56
  11. data/app/inputs/custom_inputs/select_field_input.rb +1 -1
  12. data/app/inputs/custom_inputs/string_input.rb +13 -0
  13. data/app/inputs/custom_inputs/surround_field_input.rb +2 -3
  14. data/app/inputs/custom_inputs/switch_field_input.rb +2 -3
  15. data/lib/ui_bibz/ui/core/forms/dates/date_picker_field.rb +1 -5
  16. data/lib/ui_bibz/ui/core/forms/numbers/formula_field.rb +8 -12
  17. data/lib/ui_bibz/ui/core/forms/textareas/markdown_editor_field.rb +1 -5
  18. data/lib/ui_bibz/ui/core/forms/texts/auto_complete_field.rb +1 -5
  19. data/lib/ui_bibz/ui/core/forms/texts/surround_field.rb +1 -5
  20. data/lib/ui_bibz/ui/core/navs/components/navbar_form.rb +6 -2
  21. data/lib/ui_bibz/version.rb +1 -1
  22. data/test/dummy/db/migrate/20150123191805_create_users.rb +3 -0
  23. data/test/dummy/db/schema.rb +5 -2
  24. data/test/factories/user.rb +1 -0
  25. data/test/simple_form_test.rb +49 -20
  26. data/test/ui/core/forms/numbers/formula_field_test.rb +1 -1
  27. metadata +3 -4
  28. data/test/dummy/db/migrate/20150123191721_user.rb +0 -4
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: eba8735c72e14ff037beabdc38c39cdca776757f
4
- data.tar.gz: a1fa0ddb5be8b7056ab83e32258249ccf49bed1c
3
+ metadata.gz: 4e95355ea721ae8b499aa2062ee1b516a6e28235
4
+ data.tar.gz: 0245101963fbaefb1525f0dc4cdfd6b9021dd02a
5
5
  SHA512:
6
- metadata.gz: dd839687955389dd26fe3a3e355ff4d7803ecff01982d2f83fd0eaf99bcb8517ea3facc18bdd88c716656f010dc2cdbe5508102162f7b5780cb88fcbe157e84b
7
- data.tar.gz: 4710b15b4581678be50bb53b0efb12db286676b1b15baafb5c39eff30161d0989105712ae83650529bf0e258f506ae9c6a660a513140c8fc0ad32be06a230554
6
+ metadata.gz: 0e18e4012b7059d30f707b005805971d0f0a6d26a95cf441eb23c797554cdba1d1e7f39428ed7d124cb11b36c2b7cbbcb16680087cc7d23aefb93b95c19d50ae
7
+ data.tar.gz: 4cc538fed4faeb12b190a13921d466d23969642252d4c517334f3731f75e844cb9d6ed44c5a14ced75c014e60e8511aff40284b827b0da13118e50b78d3de709
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- ui_bibz (2.0.0.alpha29)
4
+ ui_bibz (2.0.0.alpha30)
5
5
  bootstrap (= 4.0.0.alpha5)
6
6
  font-awesome-sass
7
7
  haml
@@ -143,7 +143,7 @@ GEM
143
143
  simple_form (3.4.0)
144
144
  actionpack (> 4, < 5.1)
145
145
  activemodel (> 4, < 5.1)
146
- simplecov (0.13.0)
146
+ simplecov (0.14.0)
147
147
  docile (~> 1.1.0)
148
148
  json (>= 1.8, < 3)
149
149
  simplecov-html (~> 0.10.0)
@@ -31,10 +31,11 @@
31
31
 
32
32
  formula: ->
33
33
  me = this
34
- formula_input_field = $('.formula-field')
35
- me.updateFormulaField(formula_input_field)
34
+ formula_input_fields = $('.formula-field')
35
+ formula_input_fields.each ->
36
+ me.updateFormulaField($(this))
36
37
 
37
- formula_input_field.on 'keyup', ->
38
+ formula_input_fields.on 'keyup', ->
38
39
  me.updateFormulaField($(this))
39
40
 
40
41
  updateFormulaField: (field) ->
@@ -1,15 +1,16 @@
1
1
  module CustomInputs
2
- class AutoCompleteFieldInput < SimpleForm::Inputs::CollectionInput
2
+ class AutoCompleteFieldInput < CollectionInput
3
3
  include UiBibz::Ui::Core::Forms::Texts
4
- include ActionView::Helpers::FormOptionsHelper
5
4
 
6
5
  def input(wrapper_options)
7
- label_method, value_method = detect_collection_methods
8
- options = options || {}
9
- options = options.merge({ builder: @builder })
10
- options = options.merge(option_tags: options_from_collection_for_select(collection, label_method, label_method))
6
+ UiBibz::Ui::Core::Forms::Texts::AutoCompleteField.new(input_attribute_name, new_options, input_html_options).render
7
+ end
11
8
 
12
- UiBibz::Ui::Core::Forms::Texts::AutoCompleteField.new(attribute_name, options, input_html_options).render
9
+ def input_html_options
10
+ opts = super
11
+ opts = opts.merge({ disabled: options[:disabled] }) unless options[:disabled].blank?
12
+ opts = opts.merge({ value: @builder.object.send(attribute_name) })
13
+ opts
13
14
  end
14
15
  end
15
16
  end
@@ -14,16 +14,17 @@ module CustomInputs
14
14
 
15
15
  def new_options
16
16
  label_method, value_method = detect_collection_methods
17
+
17
18
  if options[:grouped] == true
18
19
  options.merge({ option_tags: option_groups_from_collection_for_select(
19
20
  grouped_collection,
20
21
  group_method, group_label_method,
21
22
  value_method, label_method,
22
- input_options
23
+ @builder.object.send(attribute_name)
23
24
  )})
24
25
  else
25
26
  options.merge({ option_tags: options_from_collection_for_select(
26
- collection, value_method, label_method, input_options
27
+ collection, value_method, label_method, @builder.object.send(attribute_name)
27
28
  )})
28
29
  end
29
30
  end
@@ -35,11 +36,18 @@ module CustomInputs
35
36
  end
36
37
  end
37
38
 
39
+ def input_attribute_name
40
+ "#{ @builder.object.class.to_s.parameterize.underscore }[#{ attribute_name }]"
41
+ end
42
+
38
43
  def collection
39
- if options[:grouped]
40
- @collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
41
- else
42
- @collection ||= options[:collection]
44
+ @collection ||= begin
45
+ if options[:grouped]
46
+ grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
47
+ else
48
+ collection = options.delete(:collection) || self.class.boolean_collection
49
+ collection.respond_to?(:call) ? collection.call : collection.to_a
50
+ end
43
51
  end
44
52
  end
45
53
 
@@ -1,10 +1,9 @@
1
1
  module CustomInputs
2
- class DatePickerFieldInput < SimpleForm::Inputs::StringInput
2
+ class DatePickerFieldInput < StringInput
3
3
  include UiBibz::Ui::Core::Forms::Dates
4
4
 
5
5
  def input(wrapper_options)
6
- options = @options.merge({ builder: @builder })
7
- UiBibz::Ui::Core::Forms::Dates::DatePickerField.new(attribute_name, options, input_html_options).render
6
+ UiBibz::Ui::Core::Forms::Dates::DatePickerField.new(input_attribute_name, options, input_html_options).render
8
7
  end
9
8
 
10
9
  end
@@ -2,7 +2,7 @@ module CustomInputs
2
2
  class DropdownSelectFieldInput < CollectionInput
3
3
 
4
4
  def input(wrapper_options)
5
- UiBibz::Ui::Core::Forms::Selects::DropdownSelectField.new(attribute_name, new_options, input_html_options).render
5
+ UiBibz::Ui::Core::Forms::Selects::DropdownSelectField.new(input_attribute_name, new_options, input_html_options).render
6
6
  end
7
7
 
8
8
  end
@@ -1,10 +1,17 @@
1
1
  module CustomInputs
2
- class FormulaFieldInput < SimpleForm::Inputs::StringInput
2
+ class FormulaFieldInput < StringInput
3
3
  include UiBibz::Ui::Core::Forms::Numbers
4
4
 
5
5
  def input(wrapper_options)
6
- options = @options.merge({ builder: @builder })
7
- UiBibz::Ui::Core::Forms::Numbers::FormulaField.new(attribute_name, options, input_html_options).render
6
+ UiBibz::Ui::Core::Forms::Numbers::FormulaField.new(input_attribute_name, options, input_html_options).render
7
+ end
8
+
9
+ def input_html_options
10
+ super.merge({ value: @builder.object.send(attribute_name), formula_field_value: @builder.object.send(options[:formula_field_name] || attribute_formula_name)})
11
+ end
12
+
13
+ def attribute_formula_name
14
+ "#{ attribute_name }_formula"
8
15
  end
9
16
 
10
17
  end
@@ -1,10 +1,9 @@
1
1
  module CustomInputs
2
- class MarkdownEditorFieldInput < SimpleForm::Inputs::StringInput
2
+ class MarkdownEditorFieldInput < StringInput
3
3
  include UiBibz::Ui::Core::Forms::Textareas
4
4
 
5
5
  def input(wrapper_options)
6
- options = @options.merge({ builder: @builder })
7
- UiBibz::Ui::Core::Forms::Textareas::MarkdownEditorField.new(attribute_name, options, input_html_options).render
6
+ UiBibz::Ui::Core::Forms::Textareas::MarkdownEditorField.new(input_attribute_name, options, input_html_options).render
8
7
  end
9
8
 
10
9
  end
@@ -1,63 +1,9 @@
1
1
  module CustomInputs
2
- # multi_column_input manages collection and grouped_collection
3
- class MultiColumnFieldInput < SimpleForm::Inputs::CollectionInput
2
+ class MultiColumnFieldInput < CollectionInput
4
3
  include UiBibz::Ui::Core::Forms::Selects
5
4
 
6
5
  def input(wrapper_options)
7
- label_method, value_method = detect_collection_methods
8
- i = UiBibz::Ui::Core::Forms::Selects::MultiColumnField.new(attribute_name, options, input_html_options)
9
-
10
- input_options.delete(:prompt)
11
- input_options.merge!({include_blank: false})
12
-
13
- if options[:grouped] == true
14
- @builder.grouped_collection_select(
15
- attribute_name, grouped_collection,
16
- group_method, group_label_method,
17
- value_method, label_method,
18
- input_options, i.html_options
19
- )
20
- else
21
- @builder.collection_select(
22
- attribute_name, collection, value_method, label_method,
23
- input_options, i.html_options
24
- )
25
- end
26
- end
27
-
28
- def grouped_collection
29
- @grouped_collection ||= begin
30
- grouped_collection = options.delete(:collection)
31
- grouped_collection.respond_to?(:call) ? grouped_collection.call : grouped_collection.to_a
32
- end
33
- end
34
-
35
- # Sample collection
36
- #def group_collection
37
- #@group_collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
38
- #end
39
-
40
- def collection
41
- if options[:grouped]
42
- @collection ||= grouped_collection.map { |collection| collection.try(:send, group_method) }.detect(&:present?) || []
43
- else
44
- @collection ||= options[:collection]
45
- end
46
- end
47
-
48
- def group_method
49
- @group_method ||= options.delete(:group_method)
50
- end
51
-
52
- def group_label_method
53
- label = options.delete(:group_label_method)
54
-
55
- unless label
56
- common_method_for = detect_common_display_methods(detect_collection_classes(grouped_collection))
57
- label = common_method_for[:label]
58
- end
59
-
60
- label
6
+ UiBibz::Ui::Core::Forms::Selects::MultiColumnField.new(attribute_name, new_options, input_html_options).render
61
7
  end
62
8
 
63
9
  end
@@ -2,7 +2,7 @@ module CustomInputs
2
2
  class SelectFieldInput < CollectionInput
3
3
 
4
4
  def input(wrapper_options)
5
- UiBibz::Ui::Core::Forms::Selects::SelectField.new(attribute_name, new_options, input_html_options).render
5
+ UiBibz::Ui::Core::Forms::Selects::SelectField.new(input_attribute_name, new_options, input_html_options).render
6
6
  end
7
7
  end
8
8
  end
@@ -0,0 +1,13 @@
1
+ module CustomInputs
2
+ class StringInput < SimpleForm::Inputs::StringInput
3
+
4
+ def input(wrapper_options)
5
+ super
6
+ end
7
+
8
+ def input_attribute_name
9
+ "#{ @builder.object.class.to_s.parameterize.underscore }[#{ attribute_name }]"
10
+ end
11
+
12
+ end
13
+ end
@@ -1,10 +1,9 @@
1
1
  module CustomInputs
2
- class SurroundFieldInput < SimpleForm::Inputs::StringInput
2
+ class SurroundFieldInput < StringInput
3
3
  include UiBibz::Ui::Core::Forms::Texts
4
4
 
5
5
  def input(wrapper_options)
6
- options = @options.merge({ builder: @builder })
7
- UiBibz::Ui::Core::Forms::Texts::SurroundField.new(attribute_name, options, input_html_options).render
6
+ UiBibz::Ui::Core::Forms::Texts::SurroundField.new(input_attribute_name, options, input_html_options).render
8
7
  end
9
8
 
10
9
  end
@@ -1,10 +1,9 @@
1
1
  module CustomInputs
2
- class SwitchFieldInput < SimpleForm::Inputs::Base
2
+ class SwitchFieldInput < StringInput
3
3
  include UiBibz::Ui::Core::Forms::Choices
4
4
 
5
5
  def input(wrapper_options)
6
- options = @options.merge({ builder: @builder })
7
- UiBibz::Ui::Core::Forms::Choices::SwitchField.new(attribute_name, options, input_html_options).render
6
+ UiBibz::Ui::Core::Forms::Choices::SwitchField.new(input_attribute_name, options, input_html_options).render
8
7
  end
9
8
 
10
9
  end
@@ -67,11 +67,7 @@ module UiBibz::Ui::Core::Forms::Dates
67
67
  private
68
68
 
69
69
  def text_field_input_tag name
70
- if options[:builder].nil?
71
- text_field_tag name, html_options[:value], html_options
72
- else
73
- options[:builder].text_field name, html_options
74
- end
70
+ text_field_tag name, html_options[:value], html_options
75
71
  end
76
72
 
77
73
  def component_html_data
@@ -56,19 +56,11 @@ module UiBibz::Ui::Core::Forms::Numbers
56
56
  private
57
57
 
58
58
  def text_field_input_tag
59
- if options[:builder].nil?
60
- text_field_tag content, html_options[:value], readonly: true, class: 'formula-field-result form-control'
61
- else
62
- options[:builder].text_field content, readonly: true, class: 'formula-field-result form-control'
63
- end
59
+ text_field_tag content, html_options.delete(:value), readonly: true, class: 'formula-field-result form-control'
64
60
  end
65
61
 
66
62
  def text_field_formula_input_tag
67
- if options[:builder].nil?
68
- text_field_tag formula_field_name, '', html_options
69
- else
70
- options[:builder].text_field formula_field_name, html_options
71
- end
63
+ text_field_tag formula_field_name, html_options.delete(:formula_field_value), html_options.except(:value)
72
64
  end
73
65
 
74
66
  def component_html_classes
@@ -86,14 +78,18 @@ module UiBibz::Ui::Core::Forms::Numbers
86
78
  end
87
79
 
88
80
  def formula_field_name
89
- options[:formula_field_name] || "#{ content }_formula"
81
+ options[:formula_field_name] || content_formula_name
82
+ end
83
+
84
+ def content_formula_name
85
+ content.to_s.split('').select{ |i| i == "]" }.count > 0 ? content.to_s.gsub(/]$/, "_formula]") : "#{ content }_formula"
90
86
  end
91
87
 
92
88
  def formula_field_sign
93
89
  content_tag :span, '=', class: 'formula-field-sign input-group-addon'
94
90
  end
95
91
 
96
- def status
92
+ def status
97
93
  "has-#{ options[:status] }" if options[:status]
98
94
  end
99
95
 
@@ -53,11 +53,7 @@ module UiBibz::Ui::Core::Forms::Textareas
53
53
 
54
54
  # Render html tag
55
55
  def render
56
- if options[:builder].nil?
57
- text_area_tag content, html_options[:value], html_options
58
- else
59
- options[:builder].text_area content, html_options
60
- end
56
+ text_area_tag content, html_options[:value], html_options
61
57
  end
62
58
 
63
59
  private
@@ -75,11 +75,7 @@ module UiBibz::Ui::Core::Forms::Texts
75
75
  end
76
76
 
77
77
  def text_field_input_tag
78
- if options[:builder].nil?
79
- text_field_tag content, html_options[:value], html_options
80
- else
81
- options[:builder].text_field content, html_options
82
- end
78
+ text_field_tag content, html_options[:value], html_options
83
79
  end
84
80
 
85
81
  def component_html_options
@@ -63,11 +63,7 @@ module UiBibz::Ui::Core::Forms::Texts
63
63
 
64
64
  # Simple_form or not
65
65
  def text_field_input_tag
66
- if options[:builder].nil?
67
- text_field_tag content, html_options[:value], html_options
68
- else
69
- options[:builder].text_field content, html_options
70
- end
66
+ text_field_tag content, html_options[:value], html_options
71
67
  end
72
68
 
73
69
  def component_html_classes
@@ -47,10 +47,10 @@ module UiBibz::Ui::Core::Navs
47
47
  init_haml_helpers
48
48
  @options = options
49
49
  if type == :form_for
50
- @form = form_for(model_or_url, options, &block)
50
+ @form = form_for(model_or_url, new_option, &block)
51
51
  else
52
52
  #@form = form_tag(model_or_url, class: "navbar-form form-inline #{ position }", block)
53
- html_options = html_options_for_form(model_or_url, { class: "navbar-form form-inline #{ position }" })
53
+ html_options = html_options_for_form(model_or_url, new_option)
54
54
  @form = form_tag_with_body(html_options, capture(&block))
55
55
  end
56
56
  end
@@ -62,6 +62,10 @@ module UiBibz::Ui::Core::Navs
62
62
 
63
63
  private
64
64
 
65
+ def new_option
66
+ (@options || {}).merge({ class: "navbar-form form-inline #{ position }" })
67
+ end
68
+
65
69
  def protect_against_forgery?
66
70
  false
67
71
  end
@@ -1,3 +1,3 @@
1
1
  module UiBibz
2
- VERSION = "2.0.0.alpha29"
2
+ VERSION = "2.0.0.alpha30"
3
3
  end
@@ -5,6 +5,9 @@ class CreateUsers < ActiveRecord::Migration
5
5
  t.string :name_en
6
6
  t.string :body_fr
7
7
  t.string :body_en
8
+ t.boolean :active
9
+ t.float :price
10
+ t.string :price_formula
8
11
 
9
12
  t.timestamps null: false
10
13
  end
@@ -30,8 +30,11 @@ ActiveRecord::Schema.define(version: 20170309084453) do
30
30
  t.string "name_en"
31
31
  t.string "body_fr"
32
32
  t.string "body_en"
33
- t.datetime "created_at", null: false
34
- t.datetime "updated_at", null: false
33
+ t.boolean "active"
34
+ t.float "price"
35
+ t.string "price_formula"
36
+ t.datetime "created_at", null: false
37
+ t.datetime "updated_at", null: false
35
38
  end
36
39
 
37
40
  end
@@ -4,5 +4,6 @@ FactoryGirl.define do
4
4
  name_en "Name en"
5
5
  body_fr "Body fr"
6
6
  body_en "Body en"
7
+ active true
7
8
  end
8
9
  end
@@ -7,8 +7,8 @@ include SimpleForm::ActionViewExtensions::FormHelper
7
7
  class SimpleFormTest < ActionView::TestCase
8
8
 
9
9
  setup do
10
- User.where(name_fr: 'test1').first_or_create
11
- User.where(name_fr: 'test2').first_or_create
10
+ User.where(name_fr: 'test1', active: true).first_or_create
11
+ User.where(name_fr: 'test2', active: false).first_or_create
12
12
  continent = Continent.where(name: 'Europe').first_or_create
13
13
  Country.where(name: 'France', continent_id: continent.id).first_or_create
14
14
  Country.where(name: 'Deutchland', continent_id: continent.id).first_or_create
@@ -24,18 +24,18 @@ class SimpleFormTest < ActionView::TestCase
24
24
  f.input :name_fr, as: :auto_complete_field, collection: @users, label_method: :name_fr
25
25
  end
26
26
 
27
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group auto_complete_field optional user_name_fr\"><label class=\"control-label auto_complete_field optional\" for=\"user_name_fr\">Name fr</label><input class=\"auto_complete_field optional form-control\" autocomplete=\"true\" list=\"name_fr-datalist\" type=\"text\" value=\"test1\" name=\"user[name_fr]\" id=\"user_name_fr\" /><datalist id=\"name_fr-datalist\"><option value=\"test1\">test1</option>
28
- <option value=\"test2\">test2</option></datalist></div></form>"
27
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group auto_complete_field optional user_name_fr\"><label class=\"control-label auto_complete_field optional\" for=\"user_name_fr\">Name fr</label><input type=\"text\" name=\"user[name_fr]\" id=\"user_name_fr\" value=\"test1\" class=\"auto_complete_field optional form-control\" autocomplete=\"true\" list=\"user_name_fr-datalist\" /><datalist id=\"user_name_fr-datalist\"><option value=\"1\">test1</option>
28
+ <option value=\"2\">test2</option></datalist></div></form>"
29
29
 
30
30
  assert_equal expected, actual
31
31
  end
32
32
 
33
33
  test 'date picker field input in simple form' do
34
34
  actual = simple_form_for @user do |f|
35
- f.input :name_fr, as: :date_picker_field
35
+ f.input :created_at, as: :date_picker_field
36
36
  end
37
37
 
38
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group date_picker_field optional user_name_fr\"><label class=\"control-label date_picker_field optional\" for=\"user_name_fr\">Name fr</label><input class=\"date_picker_field optional date_picker form-control\" data-date-locale=\"en\" data-provide=\"datepicker\" data-date-format=\"dd/mm/yyyy\" data-date-today-btn=\"linked\" type=\"text\" value=\"test1\" name=\"user[name_fr]\" id=\"user_name_fr\" /></div></form>"
38
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group date_picker_field optional user_created_at\"><label class=\"control-label date_picker_field optional\" for=\"user_created_at\">Created at</label><input type=\"text\" name=\"user[created_at]\" id=\"user_created_at\" class=\"date_picker_field optional date_picker form-control\" data-date-locale=\"en\" data-provide=\"datepicker\" data-date-format=\"dd/mm/yyyy\" data-date-today-btn=\"linked\" /></div></form>"
39
39
 
40
40
  assert_equal expected, actual
41
41
  end
@@ -45,7 +45,7 @@ class SimpleFormTest < ActionView::TestCase
45
45
  f.input :name_fr, as: :dropdown_select_field, collection: @users, label_method: :name_fr
46
46
  end
47
47
 
48
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group dropdown_select_field optional user_name_fr\"><label class=\"control-label dropdown_select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"name_fr\" id=\"name_fr\" class=\"dropdown_select_field optional dropdown-select-field\"><option value=\"\" label=\" \"></option><option value=\"1\">test1</option>
48
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group dropdown_select_field optional user_name_fr\"><label class=\"control-label dropdown_select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"dropdown_select_field optional dropdown-select-field\"><option value=\"1\">test1</option>
49
49
  <option value=\"2\">test2</option></select></div></form>"
50
50
 
51
51
  assert_equal expected, actual
@@ -57,18 +57,21 @@ class SimpleFormTest < ActionView::TestCase
57
57
  f.input :name_fr, as: :dropdown_select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries
58
58
  end
59
59
 
60
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group dropdown_select_field optional user_name_fr\"><label class=\"control-label dropdown_select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"name_fr\" id=\"name_fr\" class=\"dropdown_select_field optional dropdown-select-field\"><option value=\"\" label=\" \"></option><optgroup label=\"Europe\"><option value=\"1\">France</option>
60
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group dropdown_select_field optional user_name_fr\"><label class=\"control-label dropdown_select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"dropdown_select_field optional dropdown-select-field\"><optgroup label=\"Europe\"><option value=\"1\">France</option>
61
61
  <option value=\"2\">Deutchland</option></optgroup></select></div></form>"
62
62
 
63
63
  assert_equal expected, actual
64
64
  end
65
65
 
66
66
  test 'formula field input in simple form' do
67
+ @user.price = 3.0
68
+ @user.price_formula = "1+2"
69
+
67
70
  actual = simple_form_for @user do |f|
68
- f.input :name_fr, as: :formula_field
71
+ f.input :price, as: :formula_field
69
72
  end
70
73
 
71
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group formula_field optional user_name_fr\"><label class=\"control-label formula_field optional\" for=\"user_name_fr\">Name fr</label><div class=\"input-group formula_field\"><input class=\"formula_field optional formula-field form-control\" type=\"text\" name=\"user[name_fr_formula]\" id=\"user_name_fr_formula\" /><span class=\"formula-field-sign input-group-addon\">=</span><input readonly=\"readonly\" class=\"formula-field-result form-control\" type=\"text\" value=\"test1\" name=\"user[name_fr]\" id=\"user_name_fr\" /><span class=\"formula-field-alert input-group-addon\" data-toggle=\"tooltip\"><i class=\"glyph-danger glyph fa fa-exclamation-triangle\"></i></span></div></div></form>"
74
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group formula_field optional user_price\"><label class=\"control-label formula_field optional\" for=\"user_price\">Price</label><div class=\"input-group formula_field\"><input type=\"text\" name=\"user[price_formula]\" id=\"user_price_formula\" value=\"1+2\" class=\"formula_field optional formula-field form-control\" /><span class=\"formula-field-sign input-group-addon\">=</span><input type=\"text\" name=\"user[price]\" id=\"user_price\" value=\"3.0\" readonly=\"readonly\" class=\"formula-field-result form-control\" /><span class=\"formula-field-alert input-group-addon\" data-toggle=\"tooltip\"><i class=\"glyph-danger glyph fa fa-exclamation-triangle\"></i></span></div></div></form>"
72
75
 
73
76
  assert_equal expected, actual
74
77
  end
@@ -78,8 +81,8 @@ class SimpleFormTest < ActionView::TestCase
78
81
  f.input :name_fr, as: :markdown_editor_field
79
82
  end
80
83
 
81
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group markdown_editor_field optional user_name_fr\"><label class=\"control-label markdown_editor_field optional\" for=\"user_name_fr\">Name fr</label><textarea class=\"markdown_editor_field optional\" data-provide=\"markdown\" data-iconlibrary=\"fa\" name=\"user[name_fr]\" id=\"user_name_fr\">
82
- test1</textarea></div></form>"
84
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group markdown_editor_field optional user_name_fr\"><label class=\"control-label markdown_editor_field optional\" for=\"user_name_fr\">Name fr</label><textarea name=\"user[name_fr]\" id=\"user_name_fr\" class=\"markdown_editor_field optional\" data-provide=\"markdown\" data-iconlibrary=\"fa\">
85
+ </textarea></div></form>"
83
86
 
84
87
  assert_equal expected, actual
85
88
  end
@@ -89,7 +92,7 @@ test1</textarea></div></form>"
89
92
  f.input :name_fr, as: :multi_column_field, collection: @users, label_method: :name_fr
90
93
  end
91
94
 
92
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group multi_column_field optional user_name_fr\"><label class=\"control-label multi_column_field optional\" for=\"user_name_fr\">Name fr</label><input name=\"user[name_fr][]\" type=\"hidden\" value=\"\" /><select class=\"multi_column_field optional multi-column-field\" multiple=\"multiple\" name=\"user[name_fr][]\" id=\"user_name_fr\"><option value=\"1\">test1</option>
95
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group multi_column_field optional user_name_fr\"><label class=\"control-label multi_column_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"name_fr[]\" id=\"name_fr\" class=\"multi_column_field optional multi-column-field\" multiple=\"multiple\"><option value=\"1\">test1</option>
93
96
  <option value=\"2\">test2</option></select></div></form>"
94
97
 
95
98
  assert_equal expected, actual
@@ -123,17 +126,17 @@ test1</textarea></div></form>"
123
126
  f.input :name_fr, as: :surround_field
124
127
  end
125
128
 
126
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group surround_field optional user_name_fr\"><label class=\"control-label surround_field optional\" for=\"user_name_fr\">Name fr</label><input class=\"surround_field optional form-control\" type=\"text\" value=\"test1\" name=\"user[name_fr]\" id=\"user_name_fr\" /></div></form>"
129
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group surround_field optional user_name_fr\"><label class=\"control-label surround_field optional\" for=\"user_name_fr\">Name fr</label><input type=\"text\" name=\"user[name_fr]\" id=\"user_name_fr\" class=\"surround_field optional form-control\" /></div></form>"
127
130
 
128
131
  assert_equal expected, actual
129
132
  end
130
133
 
131
134
  test 'switch field input in simple form' do
132
135
  actual = simple_form_for @user do |f|
133
- f.input :name_fr, as: :switch_field, collection: @users, label_method: :name_fr
136
+ f.input :active, as: :switch_field, collection: @users, label_method: :name_fr
134
137
  end
135
138
 
136
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group switch_field optional user_name_fr\"><label class=\"control-label switch_field optional\" for=\"user_name_fr\">Name fr</label><input name=\"user[name_fr]\" type=\"hidden\" value=\"0\" /><input class=\"switch_field optional switch-field\" type=\"checkbox\" value=\"1\" name=\"user[name_fr]\" id=\"user_name_fr\" /></div></form>"
139
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group switch_field optional user_active\"><label class=\"control-label switch_field optional\" for=\"user_active\">Active</label><input type=\"checkbox\" name=\"user[active]\" id=\"user_active\" class=\"switch_field optional switch-field\" /></div></form>"
137
140
 
138
141
  assert_equal expected, actual
139
142
  end
@@ -153,7 +156,7 @@ test1</textarea></div></form>"
153
156
  f.input :name_fr, as: :select_field, collection: @users, label_method: :name_fr
154
157
  end
155
158
 
156
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"name_fr\" id=\"name_fr\" class=\"select_field optional select-field form-control\"><option value=\"\" label=\" \"></option><option value=\"1\">test1</option>
159
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"select_field optional select-field form-control\"><option value=\"1\">test1</option>
157
160
  <option value=\"2\">test2</option></select></div></form>"
158
161
 
159
162
  assert_equal expected, actual
@@ -164,8 +167,8 @@ test1</textarea></div></form>"
164
167
  f.input :name_fr, as: :select_field, refresh: { target: { data: [] }}, collection: @users, label_method: :name_fr
165
168
  end
166
169
 
167
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><div class=\"input-group field-refresh\"><select name=\"name_fr\" id=\"name_fr\" class=\"select_field optional select-field form-control\"><option value=\"\" label=\" \"></option><option value=\"1\">test1</option>
168
- <option value=\"2\">test2</option></select><span class=\"input-group-btn\"><button data-connect=\"{&quot;events&quot;:&quot;click&quot;,&quot;mode&quot;:&quot;remote&quot;,&quot;target&quot;:{&quot;selector&quot;:&quot;#name_fr&quot;,&quot;url&quot;:&quot;&quot;,&quot;data&quot;:[]}}\" class=\"btn-primary ui-bibz-connect input-refresh-button btn\"><i class=\"glyph fa fa-refresh\"></i> </button></span></div></div></form>"
170
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><div class=\"input-group field-refresh\"><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"select_field optional select-field form-control\"><option value=\"1\">test1</option>
171
+ <option value=\"2\">test2</option></select><span class=\"input-group-btn\"><button data-connect=\"{&quot;events&quot;:&quot;click&quot;,&quot;mode&quot;:&quot;remote&quot;,&quot;target&quot;:{&quot;selector&quot;:&quot;#user_name_fr&quot;,&quot;url&quot;:&quot;&quot;,&quot;data&quot;:[]}}\" class=\"btn-primary ui-bibz-connect input-refresh-button btn\"><i class=\"glyph fa fa-refresh\"></i> </button></span></div></div></form>"
169
172
 
170
173
  assert_equal expected, actual
171
174
  end
@@ -176,7 +179,33 @@ test1</textarea></div></form>"
176
179
  f.input :name_fr, as: :select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries
177
180
  end
178
181
 
179
- expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"name_fr\" id=\"name_fr\" class=\"select_field optional select-field form-control\"><option value=\"\" label=\" \"></option><optgroup label=\"Europe\"><option value=\"1\">France</option>
182
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"select_field optional select-field form-control\"><optgroup label=\"Europe\"><option value=\"1\">France</option>
183
+ <option value=\"2\">Deutchland</option></optgroup></select></div></form>"
184
+
185
+ assert_equal expected, actual
186
+ end
187
+
188
+ test 'test collection with selected option in select field into simple form' do
189
+
190
+ @user.name_fr = 1
191
+ actual = simple_form_for @user do |f|
192
+ f.input :name_fr, as: :select_field, collection: @countries
193
+ end
194
+
195
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"select_field optional select-field form-control\"><option selected=\"selected\" value=\"1\">France</option>
196
+ <option value=\"2\">Deutchland</option></select></div></form>"
197
+
198
+ assert_equal expected, actual
199
+ end
200
+
201
+ test 'test collection with selected optiongroup in select field into simple form' do
202
+
203
+ @user.name_fr = 1
204
+ actual = simple_form_for @user do |f|
205
+ f.input :name_fr, as: :select_field, collection: @continents, toto: 'lala', grouped: true, group_method: :countries
206
+ end
207
+
208
+ expected = "<form class=\"simple_form edit_user\" id=\"edit_user_1\" action=\"/users/1\" accept-charset=\"UTF-8\" method=\"post\"><input name=\"utf8\" type=\"hidden\" value=\"&#x2713;\" /><input type=\"hidden\" name=\"_method\" value=\"patch\" /><div class=\"form-group select_field optional user_name_fr\"><label class=\"control-label select_field optional\" for=\"user_name_fr\">Name fr</label><select name=\"user[name_fr]\" id=\"user_name_fr\" class=\"select_field optional select-field form-control\"><optgroup label=\"Europe\"><option selected=\"selected\" value=\"1\">France</option>
180
209
  <option value=\"2\">Deutchland</option></optgroup></select></div></form>"
181
210
 
182
211
  assert_equal expected, actual
@@ -5,7 +5,7 @@ class FormulaFieldTest < ActionView::TestCase
5
5
 
6
6
  test 'formula_field' do
7
7
  actual = UiBibz::Ui::Core::Forms::Numbers::FormulaField.new('value').render
8
- expected = "<div class=\"input-group formula_field\"><input type=\"text\" name=\"value_formula\" id=\"value_formula\" value=\"\" class=\"formula-field form-control\" /><span class=\"formula-field-sign input-group-addon\">=</span><input type=\"text\" name=\"value\" id=\"value\" readonly=\"readonly\" class=\"formula-field-result form-control\" /><span class=\"formula-field-alert input-group-addon\" data-toggle=\"tooltip\"><i class=\"glyph-danger glyph fa fa-exclamation-triangle\"></i></span></div>"
8
+ expected = "<div class=\"input-group formula_field\"><input type=\"text\" name=\"value_formula\" id=\"value_formula\" class=\"formula-field form-control\" /><span class=\"formula-field-sign input-group-addon\">=</span><input type=\"text\" name=\"value\" id=\"value\" readonly=\"readonly\" class=\"formula-field-result form-control\" /><span class=\"formula-field-alert input-group-addon\" data-toggle=\"tooltip\"><i class=\"glyph-danger glyph fa fa-exclamation-triangle\"></i></span></div>"
9
9
 
10
10
  assert_equal expected, actual
11
11
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ui_bibz
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0.alpha29
4
+ version: 2.0.0.alpha30
5
5
  platform: ruby
6
6
  authors:
7
7
  - Thooams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-03-13 00:00:00.000000000 Z
11
+ date: 2017-03-15 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -243,6 +243,7 @@ files:
243
243
  - app/inputs/custom_inputs/multi_select_field_input.rb
244
244
  - app/inputs/custom_inputs/radio_field_input.rb
245
245
  - app/inputs/custom_inputs/select_field_input.rb
246
+ - app/inputs/custom_inputs/string_input.rb
246
247
  - app/inputs/custom_inputs/surround_field_input.rb
247
248
  - app/inputs/custom_inputs/switch_field_input.rb
248
249
  - config/initializers/will_paginate.rb
@@ -381,7 +382,6 @@ files:
381
382
  - test/dummy/config/locales/en.yml
382
383
  - test/dummy/config/routes.rb
383
384
  - test/dummy/config/secrets.yml
384
- - test/dummy/db/migrate/20150123191721_user.rb
385
385
  - test/dummy/db/migrate/20150123191805_create_users.rb
386
386
  - test/dummy/db/migrate/20170309084406_continents.rb
387
387
  - test/dummy/db/migrate/20170309084453_countries.rb
@@ -518,7 +518,6 @@ test_files:
518
518
  - test/dummy/config/locales/en.yml
519
519
  - test/dummy/config/routes.rb
520
520
  - test/dummy/config/secrets.yml
521
- - test/dummy/db/migrate/20150123191721_user.rb
522
521
  - test/dummy/db/migrate/20150123191805_create_users.rb
523
522
  - test/dummy/db/migrate/20170309084406_continents.rb
524
523
  - test/dummy/db/migrate/20170309084453_countries.rb
@@ -1,4 +0,0 @@
1
- class User < ActiveRecord::Migration
2
- def change
3
- end
4
- end