bootstrap_builders 0.0.22 → 0.0.23

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 13e135efacb89f2efc36c3084cfbd0f38a86964d
4
- data.tar.gz: f53ca607382ca70bae61a5210e7a597a62da5ea3
3
+ metadata.gz: 59efce5d0bbcfe300000500f214a4270984043a3
4
+ data.tar.gz: 5f49a938c650f1ff9a49c5640c7549067b9d80a6
5
5
  SHA512:
6
- metadata.gz: 4c4ae24d2ad8b84d4b85acfb0e5b70e029746dde3ed01263fdf449c1d970f66e64515d522f2400a503a68d33894f3248a49ae6343c3a2bbac110e0bc55e153bb
7
- data.tar.gz: 53de5dad31c9fee42881cfded2492d970c60239ba53bce5f6ccddff6a42dc21fd16e6b09dd94574200e2ee1891cb2a17b5f6effeeb5af7e2f5d8bedf62525ea5
6
+ metadata.gz: b7c968275cbb0b8ba0b36347d181ba8661e34df2eea0266e97e141081c92d7b0348b626cb3949c28eb9f0561b51c35e358321420bb9b388dfbe7aa217d112194
7
+ data.tar.gz: a4a75d649bac054f432726e1d8080f90c35e203660640364ac4fa239747c5ee7f0c2ab595a613e3f641708be5d9ba9567157d067dc14bc627847537b278ef6fa
data/README.md CHANGED
@@ -26,6 +26,13 @@ Then add to your `application.css`:
26
26
 
27
27
  ## Usage
28
28
 
29
+ ### Date picker input for SimpleForm
30
+
31
+ ```haml
32
+ = f.input :activation_at, as: :bb_date_picker
33
+ = f.input :something_at, as: :bb_date_time_picker
34
+ ```
35
+
29
36
  ### Panel
30
37
 
31
38
  1. Panel in all its glory with elements and classes
@@ -1,3 +1,4 @@
1
+ #= require bootstrap_builders/date-picker-input
1
2
  #= require bootstrap_builders/view-port-detection
2
3
  #= require bootstrap_builders/bb-btn-responsive
3
4
  #= require bootstrap_builders/tabs
@@ -0,0 +1,97 @@
1
+ (($, window, document) ->
2
+ $this = undefined
3
+ $text_ele = undefined
4
+ $form = undefined
5
+ $year_ele = undefined
6
+ $month_ele = undefined
7
+ $day_ele = undefined
8
+ $hour_ele = undefined
9
+ $min_ele = undefined
10
+
11
+ methods = {
12
+ # Constructor.
13
+ init: (options) ->
14
+ $this = $(@)
15
+ throw "Invalid element given." if $this.length <= 0
16
+
17
+ # The hidden Rails-inputs that will get the actual values like year, month, date, hour and minute.
18
+ $text_ele = $("input.bb_date_picker", $this)
19
+ $form = $(this).parents("form").first()
20
+ $year_ele = $(".bb-date-picker-input-year", $this).first()
21
+ $month_ele = $(".bb-date-picker-input-moth", $this).first()
22
+ $day_ele = $(".bb-date-picker-input-day", $this).first()
23
+ $hour_ele = $(".bb-date-picker-input-hour", $this).first()
24
+ $min_ele = $(".bb-date-picker-input-min", $this).first()
25
+
26
+ throw "Could not find the year element." if $year_ele.length <= 0
27
+
28
+ # Update values on form-submit.
29
+ if $form.length > 0 && $form.data("bb-date-picker-input") != "true"
30
+ $form.data("bb-date-picker-input", "true")
31
+
32
+ $form.submit ->
33
+ $(".bb-date-picker-input", this).each ->
34
+ $(this).bbDatePickerInput("updateValues")
35
+ return true
36
+
37
+ # Update the values when the date is changed or upon blur
38
+ $text_ele.on "changeDate blur", ->
39
+ console.log "changeDate blur"
40
+ $(this).parents(".bb-date-picker-input").first().bbDatePickerInput("updateValues")
41
+
42
+ return $this
43
+
44
+ # Parses the date in the input-field and updates all the hidden Rails-inputs from the parsed values.
45
+ updateValues: ->
46
+ # The hidden Rails-inputs that will get the actual values like year, month, date, hour and minute.
47
+ $text_ele = $("input.bb_date_picker", $this)
48
+ throw "No text element?" if $text_ele.length <= 0
49
+
50
+ $form = $(this).parents("form").first()
51
+ $year_ele = $(".bb-date-picker-input-year", $this).first()
52
+ $month_ele = $(".bb-date-picker-input-month", $this).first()
53
+ $day_ele = $(".bb-date-picker-input-day", $this).first()
54
+ $hour_ele = $(".bb-date-picker-input-hour", $this).first()
55
+ $min_ele = $(".bb-date-picker-input-min", $this).first()
56
+
57
+ if $.trim($text_ele.val()) == ""
58
+ $year_ele.val("")
59
+ $month_ele.val("")
60
+ $day_ele.val("")
61
+ $hour_ele.val("")
62
+ $min_ele.val("")
63
+ else if match = $text_ele.val().match(/^\s*(\d+)-(\d+)-(\d+)\s+(\d+):(\d+)\s*$/)
64
+ $year_ele.val(match[1])
65
+ $month_ele.val(match[2])
66
+ $day_ele.val(match[3])
67
+ $hour_ele.val(match[4])
68
+ $min_ele.val(match[5])
69
+ else if match = $text_ele.val().match(/^\s*(\d+)-(\d+)-(\d+)\s*$/)
70
+ $year_ele.val(match[1])
71
+ $month_ele.val(match[2])
72
+ $day_ele.val(match[3])
73
+ $hour_ele.val(0)
74
+ $min_ele.val(0)
75
+ else
76
+ throw "Invalid date-format: '" + $text_ele.val() + "'."
77
+
78
+ # Set the content to be a date, if this is a date-input-picker.
79
+ if match && $text_ele.hasClass("input_date_picker")
80
+ $text_ele.val(match[1] + "-" + match[2] + "-" + match[3])
81
+
82
+ return $this
83
+ }
84
+
85
+ # Initialize the plugin.
86
+ $.fn.bbDatePickerInput = (method) ->
87
+ if methods[method]
88
+ methods[method].apply(this, Array::slice.call(arguments, 1))
89
+ else if typeof method is "object" or not method
90
+ methods.init.apply(this, arguments)
91
+ else
92
+ $.error "Method " + method + " does not exist on jquery.inputDatePicker"
93
+ ) jQuery, window, document
94
+
95
+ $ ->
96
+ $(".bb-date-picker").each ->
97
+ $(this).bbDatePickerInput()
@@ -0,0 +1,51 @@
1
+ require "simple_form"
2
+
3
+ # Create an input-text-field with a date-time-picker widget attached. Also makes sure the given date-time-value is being put in the correct format.
4
+ class BbDatePickerInput < SimpleForm::Inputs::Base
5
+ # The method that should return the widgets HTML based on the sat arguments.
6
+ def input(_wrapper_options)
7
+ # Parse the value.
8
+ if input_html_options[:value]
9
+ date = input_html_options[:value]
10
+ elsif @builder.object.present?
11
+ date = @builder.object.send(attribute_name)
12
+ else
13
+ date = nil
14
+ end
15
+
16
+ if date.present?
17
+ val = date.strftime("%Y-%m-%d")
18
+
19
+ year = date.year
20
+ month = date.month
21
+ day = date.day
22
+ end
23
+
24
+ # Parse classes.
25
+ classes = ["form-control"]
26
+
27
+ class_arg = input_html_options[:class]
28
+
29
+ if class_arg
30
+ if class_arg.is_a?(Array)
31
+ classes += class_arg
32
+ else
33
+ classes << class_arg
34
+ end
35
+ end
36
+
37
+ # Generate and return HTML for the widget.
38
+ content_tag = template.content_tag(:div, class: "bb-date-picker") do
39
+ html = ""
40
+ html << @builder.hidden_field("#{attribute_name}(1i)", value: year, class: "bb-date-picker-input-year")
41
+ html << @builder.hidden_field("#{attribute_name}(2i)", value: month, class: "bb-date-picker-input-month")
42
+ html << @builder.hidden_field("#{attribute_name}(3i)", value: day, class: "bb-date-picker-input-day")
43
+
44
+ html << template.text_field_tag("", val, class: classes, data: {date_format: "yyyy-mm-dd", provide: "datepicker"})
45
+
46
+ html.html_safe
47
+ end
48
+
49
+ content_tag
50
+ end
51
+ end
@@ -0,0 +1,55 @@
1
+ require "simple_form"
2
+
3
+ # Create an input-text-field with a date-time-picker widget attached. Also makes sure the given date-time-value is being put in the correct format.
4
+ class BbDateTimePickerInput < SimpleForm::Inputs::Base
5
+ # The method that should return the widgets HTML based on the sat arguments.
6
+ def input(_wrapper_options)
7
+ # Parse the value.
8
+ if input_html_options[:value]
9
+ date = input_html_options[:value]
10
+ elsif @builder.object.present?
11
+ date = @builder.object.send(attribute_name)
12
+ else
13
+ date = nil
14
+ end
15
+
16
+ if date.present?
17
+ val = date.strftime("%Y-%m-%d")
18
+
19
+ year = date.year
20
+ month = date.month
21
+ day = date.day
22
+ hour = date.hour
23
+ min = date.min
24
+ end
25
+
26
+ # Parse classes.
27
+ classes = ["form-control"]
28
+
29
+ class_arg = input_html_options[:class]
30
+
31
+ if class_arg
32
+ if class_arg.is_a?(Array)
33
+ classes += class_arg
34
+ else
35
+ classes << class_arg
36
+ end
37
+ end
38
+
39
+ # Generate and return HTML for the widget.
40
+ content_tag = template.content_tag(:div, class: "bb-date-picker") do
41
+ html = ""
42
+ html << @builder.hidden_field("#{attribute_name}(1i)", value: year, class: "bb-date-picker-input-year")
43
+ html << @builder.hidden_field("#{attribute_name}(2i)", value: month, class: "bb-date-picker-input-month")
44
+ html << @builder.hidden_field("#{attribute_name}(3i)", value: day, class: "bb-date-picker-input-day")
45
+ html << @builder.hidden_field("#{attribute_name}(4i)", value: hour, class: "bb-date-picker-input-hour")
46
+ html << @builder.hidden_field("#{attribute_name}(5i)", value: min, class: "bb-date-picker-input-min")
47
+
48
+ html << template.text_field_tag("", val, class: classes, data: {date_format: "yyyy-mm-dd", provide: "datepicker"})
49
+
50
+ html.html_safe
51
+ end
52
+
53
+ content_tag
54
+ end
55
+ end
@@ -1,6 +1,9 @@
1
1
  require "bootstrap_builders/engine"
2
2
  require "html_gen"
3
3
 
4
+ autoload :BbDatePickerInput, "#{File.dirname(__FILE__)}/bb_date_picker_input"
5
+ autoload :BbDateTimePickerInput, "#{File.dirname(__FILE__)}/bb_date_time_picker_input"
6
+
4
7
  module BootstrapBuilders
5
8
  extend ActiveSupport::Autoload
6
9
 
@@ -1,3 +1,3 @@
1
1
  module BootstrapBuilders
2
- VERSION = "0.0.22".freeze
2
+ VERSION = "0.0.23".freeze
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bootstrap_builders
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.22
4
+ version: 0.0.23
5
5
  platform: ruby
6
6
  authors:
7
7
  - kaspernj
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-09-24 00:00:00.000000000 Z
11
+ date: 2016-10-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rails
@@ -136,6 +136,20 @@ dependencies:
136
136
  - - '='
137
137
  - !ruby/object:Gem::Version
138
138
  version: 1.6.4
139
+ - !ruby/object:Gem::Dependency
140
+ name: simple_form
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - '='
144
+ - !ruby/object:Gem::Version
145
+ version: 3.3.1
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - '='
151
+ - !ruby/object:Gem::Version
152
+ version: 3.3.1
139
153
  - !ruby/object:Gem::Dependency
140
154
  name: capybara
141
155
  requirement: !ruby/object:Gem::Requirement
@@ -232,6 +246,7 @@ files:
232
246
  - Rakefile
233
247
  - app/assets/javascripts/bootstrap_builders.coffee
234
248
  - app/assets/javascripts/bootstrap_builders/bb-btn-responsive.coffee
249
+ - app/assets/javascripts/bootstrap_builders/date-picker-input.coffee
235
250
  - app/assets/javascripts/bootstrap_builders/tabs.js.coffee
236
251
  - app/assets/javascripts/bootstrap_builders/url-builder/README.md
237
252
  - app/assets/javascripts/bootstrap_builders/url-builder/lib/url-builder.coffee
@@ -244,6 +259,8 @@ files:
244
259
  - app/views/layouts/bootstrap_builders/application.html.erb
245
260
  - config/routes.rb
246
261
  - config/spring.rb
262
+ - lib/bb_date_picker_input.rb
263
+ - lib/bb_date_time_picker_input.rb
247
264
  - lib/bootstrap_builders.rb
248
265
  - lib/bootstrap_builders/arguments_parser.rb
249
266
  - lib/bootstrap_builders/attribute_rows.rb