From 2f0fcb2cbd48bb711a83b3ae4bb1823b76a7ad94 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Sat, 31 Jan 2015 11:42:20 +0100 Subject: [PATCH 01/15] Upgrade the version of dependencies: - Ruby 2.2.0 - Rails 4.2 - Simpleform 3.1 - Momentjs-rails 2.9 - Update the submodule --- .ruby-gemset | 1 + .ruby-version | 1 + Gemfile | 4 ++-- bootstrap-datetimepicker | 2 +- datetimepicker-rails.gemspec | 2 +- 5 files changed, 6 insertions(+), 4 deletions(-) create mode 100644 .ruby-gemset create mode 100644 .ruby-version diff --git a/.ruby-gemset b/.ruby-gemset new file mode 100644 index 0000000..251c00b --- /dev/null +++ b/.ruby-gemset @@ -0,0 +1 @@ +rails4.2 diff --git a/.ruby-version b/.ruby-version new file mode 100644 index 0000000..76521af --- /dev/null +++ b/.ruby-version @@ -0,0 +1 @@ +ruby-2.2.0 diff --git a/Gemfile b/Gemfile index f392bf0..435a3cf 100644 --- a/Gemfile +++ b/Gemfile @@ -2,5 +2,5 @@ source 'https://rubygems.org' # Specify your gem's dependencies in datetimepicker-rails.gemspec gemspec -gem 'simple_form', '>= 3.1.0.rc1' -gem 'momentjs-rails', '>= 2.8.1' \ No newline at end of file +gem 'simple_form', '~> 3.1' +gem 'momentjs-rails', '~> 2.9' \ No newline at end of file diff --git a/bootstrap-datetimepicker b/bootstrap-datetimepicker index 2c22d7d..1b2fe6e 160000 --- a/bootstrap-datetimepicker +++ b/bootstrap-datetimepicker @@ -1 +1 @@ -Subproject commit 2c22d7d3dd429caa8d03d092ba84b5abaadd1d02 +Subproject commit 1b2fe6ef0062e17238117852f2c6b3ec2c2b0710 diff --git a/datetimepicker-rails.gemspec b/datetimepicker-rails.gemspec index feff0fb..d4c82ad 100644 --- a/datetimepicker-rails.gemspec +++ b/datetimepicker-rails.gemspec @@ -9,7 +9,7 @@ Gem::Specification.new do |gem| gem.authors = ["zpaulovics"] gem.email = ["zpaulovics@gmail.com"] gem.description = %q{A date and time picker for Twitter Bootstrap in Rails using Simple Form} - gem.summary = %q{This gem packages the bootstrap-datetimepicker for Rails 3.1+ asset pipeline, and creates the Simple Form custom fields. The current version is compatible with Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+} + gem.summary = %q{This gem packages the bootstrap-datetimepicker for Rails 3.1+ asset pipeline, and creates the Simple Form custom fields. The current version is compatible with Bootstrap 3+, Rails 4+ and SimpleForm 3.1+} gem.homepage = "https://github.com/zpaulovics/datetimepicker-rails.git" gem.files = `git ls-files`.split($/) From 0c0bc17293c94e984f7e97d414c366ad292070b1 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Sat, 31 Jan 2015 15:14:09 +0100 Subject: [PATCH 02/15] Upgrade the gem's artifects according to bootsrap-datetimepicker version 4.0.0 --- README.md | 129 +++++++++++++++--- .../datetimepicker_rails/install_generator.rb | 42 ++++-- .../templates/inputs/date_picker_input.rb | 11 +- .../templates/inputs/datetime_picker_input.rb | 11 +- .../templates/inputs/time_picker_input.rb | 9 +- lib/generators/templates/js/pickers.js | 12 +- 6 files changed, 169 insertions(+), 45 deletions(-) diff --git a/README.md b/README.md index ba81101..e026f40 100644 --- a/README.md +++ b/README.md @@ -2,7 +2,6 @@ This gem packages the bootstrap-datetimepicker for Rails asset pipeline and creates the Simple Form custom fields for your project. - ### Features - Prepares the vendor directory (javascripts, stylesheets) @@ -15,10 +14,17 @@ This gem packages the bootstrap-datetimepicker for Rails asset pipeline and crea - You can customise the picker's iconset to use the Font-Awesome icons (dafault: Glyphicon) - Easy to install and use in your projects +### The current 4.0.0 version compatibility + - Ruby 2.2.0 + - Rails 4.2 + - Simpleform 3.1 + - Momentjs-rails 2.9 + - http://eonasdan.github.io/bootstrap-datetimepicker version 4.0.0 + -### Compatibility +### Compatibility details -Master & eonasdan branches, tags v3.0.2+: Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+ (using https://github.com/eonasdan/bootstrap-datetimepicker.git as submodule, well maintained repo). Any further development will be made on these branches. +Master & eonasdan branches, tags v4.0.0+: Bootstrap 3+, Rails 4+ and SimpleForm 3.1+ (using https://github.com/eonasdan/bootstrap-datetimepicker.git as submodule, well maintained repo). Any further development will be made on these branches. Tag v3.0.1 and tarruda branch: Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+ (using an upgraded version of https://github.com/tarruda/bootstrap-datetimepicker.git as inline code, not maintained). No further development, only bug fix for fatal issues on this branch. @@ -27,7 +33,7 @@ Tag v1.0.0: Rails 3.2, Bootstrap 2.3.2 & SimpleForm >= 2.0.4 - No further develo ### Dependency -Versions v3.1.1+ has a dependency on the moment.js version 2.8.1 javascript library (for details refer to: http://momentjs.com/) and the gem includes the dependency reference in its Gemfile (gem 'momentjs-rails', '>= 2.8.1', :github => 'derekprior/momentjs-rails'). +Versions v4.0.0+ has a dependency on the moment.js version 2.9 javascript library (for details refer to: http://momentjs.com/) and the gem includes the dependency reference in its Gemfile (gem 'momentjs-rails', '~> 2.9', :github => 'derekprior/momentjs-rails'). Versions v3.0.2 & v3.0.3 has a dependency on the moment.js version v2.7, but the gem **have not installed this library** out of the box, so **you have to look after that**. Put "gem 'momentjs-rails', '2.7', :github => 'derekprior/momentjs-rails'" to your project Gemfile to install it. @@ -42,7 +48,7 @@ The project home page: https://github.com/zpaulovics/datetimepicker-rails.git According your needs, add one of the lines below to your application's Gemfile: -**Option 1:** Master & eonasdan branches, tags v3.0.2+: Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+ (using https://github.com/eonasdan/bootstrap-datetimepicker.git as submodule, well maintained repo). Any further development will be made on these branches: +**Option 1:** Master & eonasdan branches, tags v4.0.0+: Bootstrap 3+, Rails 4+ and SimpleForm 3.1+ (using https://github.com/eonasdan/bootstrap-datetimepicker.git as submodule, well maintained repo). Any further development will be made on these branches: ``` bash gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: 'master', submodules: true @@ -76,7 +82,7 @@ or Add this line to app/assets/javascripts/application.js -From version 3.0.2+: +From version 4.0.0+: ```javascript //= require moment @@ -84,7 +90,7 @@ From version 3.0.2+: //= require pickers // You may include any languages (optional) -//= require locales/bootstrap-datetimepicker.hu +//= require moment/hu ``` Earlier version: @@ -131,8 +137,6 @@ The current version will copy the required files to your projects 'vendor/assets the SimpleForm 'input' and the 'pickers.js' files to your needs at your own area. That gives you much more flexibility to use your preferred options of the bootstrap-datetimepicker plugin. -All available language files will be copied to your vendor/assets/locales directory. - ### Using datetimepicker-rails Just call datetimepicker() with any selector. @@ -161,20 +165,85 @@ The scripts below will be included when you use the "require pickers" or "requir need different activation scripts, ignore the //= require pickers or //= require bootstrap-datetimepicker/pickers line (depending on your installation) in app/assets/javascripts/application.js. +From version 4.0.0+: + +```javascript + $(document).on('ready, page:change', function() { + $('.datepicker').datetimepicker({ + }); + }); + + $(document).on('ready, page:change', function() { + $('.datetimepicker').datetimepicker({ + }); + }); + + $(document).on('ready, page:change', function() { + $('.timepicker').datetimepicker({ + }); + }); +``` + +The default values of the options: + +``` + format: false, + dayViewHeaderFormat: 'MMMM YYYY', + extraFormats: false, + stepping: 1, + minDate: false, + maxDate: false, + useCurrent: true, + collapse: true, + locale: moment.locale(), + defaultDate: false, + disabledDates: false, + enabledDates: false, + icons: { + time: 'glyphicon glyphicon-time', + date: 'glyphicon glyphicon-calendar', + up: 'glyphicon glyphicon-chevron-up', + down: 'glyphicon glyphicon-chevron-down', + previous: 'glyphicon glyphicon-chevron-left', + next: 'glyphicon glyphicon-chevron-right', + today: 'glyphicon glyphicon-screenshot', + clear: 'glyphicon glyphicon-trash' + }, + useStrict: false, + sideBySide: false, + daysOfWeekDisabled: [], + calendarWeeks: false, + viewMode: 'days', + toolbarPlacement: 'default', + showTodayButton: false, + showClear: false, + widgetPositioning: { + horizontal: 'auto', + vertical: 'auto' + }, + widgetParent: null, + keepOpen: false +``` +For more details, please refer to Bootstrap 3 Datepicker v4 Docs site: + - [documentation](http://eonasdan.github.io/bootstrap-datetimepicker/#bootstrap-3-datepicker-v4-docs) + - [options](http://eonasdan.github.io/bootstrap-datetimepicker/Options/) + +Earlier version: + ```javascript - $(document).on('ready page:change', function() { + $(document).on('ready, page:change', function() { $('.datepicker').datetimepicker({ pickTime: false }); }); - $(document).on('ready page:change', function() { + $(document).on('ready, page:change', function() { $('.datetimepicker').datetimepicker({ pickSeconds: false }); }); - $(document).on('ready page:change', function() { + $(document).on('ready, page:change', function() { $('.timepicker').datetimepicker({ pickDate: false, pickSeconds: false @@ -188,12 +257,13 @@ Specify your intended date and time formats in your config/locales/en.yml or rel en: datepicker: - dformat: '%d/%m/%Y' # display format of the date (this is the default, can be ommited) - pformat: 'DD/MM/YYYY' # picking format of the date (this is the default, can be ommited) - weekstart: 0 # the week starts on Sunday (this is the default, can be ommited) + dformat: '%d/%m/%Y' # display format of the date (this is the default, can be ommited) + pformat: 'DD/MM/YYYY' # picking format of the date (this is the default, can be ommited) + weekstart: 0 # the week starts on Sunday (this is the default, can be ommited) timepicker: - dformat: '%R' # display format of the time (this is the default, can be ommited) - pformat: 'HH:mm' # picking format of the time (this is the default, can be ommited) + dformat: '%R' # display format of the time (this is the default, can be ommited) + pformat: 'HH:mm' # picking format of the time (this is the default, can be ommited) + dayViewHeaderFormat: 'MMMM YYYY' # picking format of the time (this is the default, can be ommited) #### Notes for formating date/time: @@ -226,6 +296,9 @@ not release any documentation. Here is the related part of the source code: ### For more details of usage +[I have a demo application using the datetimeoicker-rails gem here] (https://github.com/zpaulovics/dateTimeDemo) + + See the documentation & excellent demos provided by plugin's authors: 1. for current version: by [@Eonasdan](https://github.com/Eonasdan) the documentation is [here](http://eonasdan.github.io/bootstrap-datetimepicker/), @@ -233,6 +306,28 @@ See the documentation & excellent demos provided by plugin's authors: 2. for earlier version: by [@tarruda](https://github.com/tarruda) the documentation is [here](http://tarruda.github.com/bootstrap-datetimepicker/). +### Bugfix - dataToOptions function in the bootstrap-datetimepicker.js + +My SimpleForm custom field implementation assumes to work the data-date-* attributes correctly in your picker. +I find out that, there is a bug in your dataToOptions function that prevents the perfect working of this gem. + +The generator has a patching function to fix the issue. It finds above code in the in the bootstrap-datetimepicker.js +``` + dataToOptions = function () { + var eData = element.data(), + dataOptions = {}; +``` +Then insert the lines below: +``` + if (element.is('input')) { + eData = element.data(); + } else { + eData = element.find('input').data(); + } +``` +I have already raised a pull request of this fix. As soon as it will be accepted you can ignore this hacking. + + ### Contributing 1. Fork it. diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index ae585cb..b9f6f8f 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -11,7 +11,11 @@ class InstallGenerator < Rails::Generators::Base date: "fa fa-calendar", time: "fa fa-clock-o", up: "fa fa-chevron-up", - down: "fa fa-chevron-down" + down: "fa fa-chevron-down", + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-crosshairs', + clear: 'fa fa-trash-o' } def source_path @@ -57,25 +61,21 @@ def create_pickers_js icons = icon_family == 'Glyphicon' ? '' : get_icons vendor 'assets/javascripts/pickers.js' do <<-FILE -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.datepicker').datetimepicker({ -#{icons} direction: 'bottom', - pickTime: false +#{icons} }); }); -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.datetimepicker').datetimepicker({ -#{icons} direction: 'bottom', -pickSeconds: false +#{icons} }); }); -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.timepicker').datetimepicker({ -#{icons} direction: 'bottom', - pickDate: false, - pickSeconds: false +#{icons} }); }); FILE @@ -109,6 +109,22 @@ def copy_bootstrap_datetimepicker end + + # We need to hack the bootstrap-datetimepicker.js by the time + # the bugfix pull request will be accepted by Eonasdan + def hacking_dataToOptions_bug + gsub_file 'vendor/assets/javascripts/bootstrap-datetimepicker.js', + /dataOptions\s=\s\{\}\;\s/, + <<-FILE +dataOptions = {}; + if (element.is('input')) { + eData = element.data(); + } else { + eData = element.find('input').data(); + } + FILE + end + private def get_icons @@ -117,6 +133,10 @@ def get_icons icons += " time: \'#{options[:custom_icons][:time]}\',\n" icons += " up: \'#{options[:custom_icons][:up]}\',\n" icons += " down: \'#{options[:custom_icons][:down]}\'\n" + icons += " previous: \'#{options[:custom_icons][:previous]}\'\n" + icons += " next: \'#{options[:custom_icons][:next]}\'\n" + icons += " today: \'#{options[:custom_icons][:today]}\'\n" + icons += " clear: \'#{options[:custom_icons][:clear]}\'\n" icons += " },\n" end diff --git a/lib/generators/templates/inputs/date_picker_input.rb b/lib/generators/templates/inputs/date_picker_input.rb index 3c0a4e4..a623031 100644 --- a/lib/generators/templates/inputs/date_picker_input.rb +++ b/lib/generators/templates/inputs/date_picker_input.rb @@ -5,10 +5,15 @@ def input(wrapper_options) input_html_options[:value] ||= I18n.localize(value, :format => display_pattern) if value.present? input_html_options[:type] = 'text' - picker_pettern = I18n.t('datepicker.pformat', :default => 'DD/MM/YYYY') + picker_pattern = I18n.t('datepicker.pformat', :default => 'DD/MM/YYYY') + dayViewHeaderFormat = I18n.t('dayViewHeaderFormat', :default => 'MMMM YYYY') + date_options = { + locale: I18n.locale.to_s, + dayViewHeaderFormat: dayViewHeaderFormat, + format: picker_pattern + } input_html_options[:data] ||= {} - input_html_options[:data].merge!({ date_format: picker_pettern, date_language: I18n.locale.to_s, - date_weekstart: I18n.t('datepicker.weekstart', :default => 0) }) + input_html_options[:data].merge!({date_options: date_options }) template.content_tag :div, class: 'input-group date datepicker' do input = super(wrapper_options) # leave StringInput do the real rendering diff --git a/lib/generators/templates/inputs/datetime_picker_input.rb b/lib/generators/templates/inputs/datetime_picker_input.rb index 8178196..c3a7f34 100644 --- a/lib/generators/templates/inputs/datetime_picker_input.rb +++ b/lib/generators/templates/inputs/datetime_picker_input.rb @@ -5,10 +5,15 @@ def input(wrapper_options) input_html_options[:value] ||= I18n.localize(value, :format => display_pattern) if value.present? input_html_options[:type] = 'text' - picker_pettern = I18n.t('datepicker.pformat', :default => 'DD/MM/YYYY') + ' ' + I18n.t('timepicker.pformat', :default => 'HH:mm') + picker_pattern = I18n.t('datepicker.pformat', :default => 'DD/MM/YYYY') + ' ' + I18n.t('timepicker.pformat', :default => 'HH:mm') + dayViewHeaderFormat = I18n.t('dayViewHeaderFormat', :default => 'MMMM YYYY') + date_options = { + locale: I18n.locale.to_s, + dayViewHeaderFormat: dayViewHeaderFormat, + format: picker_pattern + } input_html_options[:data] ||= {} - input_html_options[:data].merge!({ date_format: picker_pettern, date_language: I18n.locale.to_s, - date_weekstart: I18n.t('datepicker.weekstart', :default => 0) }) + input_html_options[:data].merge!({date_options: date_options }) template.content_tag :div, class: 'input-group date datetimepicker' do input = super(wrapper_options) # leave StringInput do the real rendering diff --git a/lib/generators/templates/inputs/time_picker_input.rb b/lib/generators/templates/inputs/time_picker_input.rb index ca0a6c9..f79661f 100644 --- a/lib/generators/templates/inputs/time_picker_input.rb +++ b/lib/generators/templates/inputs/time_picker_input.rb @@ -5,10 +5,13 @@ def input(wrapper_options) input_html_options[:value] ||= I18n.localize(value, :format => display_pattern) if value.present? input_html_options[:type] = 'text' - picker_pettern = I18n.t('timepicker.pformat', :default => 'HH:mm') + picker_pattern = I18n.t('timepicker.pformat', :default => 'HH:mm') + date_options = { + locale: I18n.locale.to_s, + format: picker_pattern + } input_html_options[:data] ||= {} - input_html_options[:data].merge!({ date_format: picker_pettern, date_language: I18n.locale.to_s, - date_weekstart: I18n.t('datepicker.weekstart', :default => 0) }) + input_html_options[:data].merge!({date_options: date_options }) template.content_tag :div, class: 'input-group date timepicker' do input = super(wrapper_options) # leave StringInput do the real rendering diff --git a/lib/generators/templates/js/pickers.js b/lib/generators/templates/js/pickers.js index 4b4c46a..2b0bd81 100644 --- a/lib/generators/templates/js/pickers.js +++ b/lib/generators/templates/js/pickers.js @@ -1,18 +1,14 @@ -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.datepicker').datetimepicker({ - pickTime: false }); }); -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.datetimepicker').datetimepicker({ - pickSeconds: false }); }); -$(document).on('ready page:change', function() { +$(document).on('ready, page:change', function() { $('.timepicker').datetimepicker({ - pickDate: false, - pickSeconds: false }); -}); \ No newline at end of file +}); From ca8bb2d8149a2bea652719ad2de5ad850172ea32 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Sat, 31 Jan 2015 15:15:52 +0100 Subject: [PATCH 03/15] Bumped the version to 4.0.0.RC1 --- lib/datetimepicker-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index 8e30003..6f1f553 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "3.1.1" + VERSION = "4.0.0.RC1" end end From 8eb0fbbdc9a7e086528c0ed8b9998b606cc149fe Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Mon, 2 Feb 2015 19:47:06 +0100 Subject: [PATCH 04/15] Remove the legacy picker.js Correct the picker's locator (remove _ character) - there is a conflict with the class name generated by SimpleForm based on the input definiton name. --- lib/datetimepicker-rails/version.rb | 2 +- .../datetimepicker_rails/install_generator.rb | 4 ++++ lib/generators/templates/js/index.js | 3 --- lib/generators/templates/js/pickers.js | 14 -------------- 4 files changed, 5 insertions(+), 18 deletions(-) delete mode 100644 lib/generators/templates/js/index.js delete mode 100644 lib/generators/templates/js/pickers.js diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index 6f1f553..4e0e8e9 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "4.0.0.RC1" + VERSION = "4.0.0.RC2" end end diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index b9f6f8f..28c5984 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -63,18 +63,21 @@ def create_pickers_js vendor 'assets/javascripts/pickers.js' do <<-FILE $(document).on('ready, page:change', function() { $('.datepicker').datetimepicker({ +// Any customisation of object creation should be inserted here #{icons} }); }); $(document).on('ready, page:change', function() { $('.datetimepicker').datetimepicker({ +// Any customisation of object creation should be inserted here #{icons} }); }); $(document).on('ready, page:change', function() { $('.timepicker').datetimepicker({ +// Any customisation of object creation should be inserted here #{icons} }); }); @@ -117,6 +120,7 @@ def hacking_dataToOptions_bug /dataOptions\s=\s\{\}\;\s/, <<-FILE dataOptions = {}; + if (element.is('input')) { eData = element.data(); } else { diff --git a/lib/generators/templates/js/index.js b/lib/generators/templates/js/index.js deleted file mode 100644 index 20ad12c..0000000 --- a/lib/generators/templates/js/index.js +++ /dev/null @@ -1,3 +0,0 @@ -//= require ./bootstrap-datetimepicker -//= require ./pickers -//= require_tree ./locales/ \ No newline at end of file diff --git a/lib/generators/templates/js/pickers.js b/lib/generators/templates/js/pickers.js deleted file mode 100644 index 2b0bd81..0000000 --- a/lib/generators/templates/js/pickers.js +++ /dev/null @@ -1,14 +0,0 @@ -$(document).on('ready, page:change', function() { - $('.datepicker').datetimepicker({ - }); -}); - -$(document).on('ready, page:change', function() { - $('.datetimepicker').datetimepicker({ - }); -}); - -$(document).on('ready, page:change', function() { - $('.timepicker').datetimepicker({ - }); -}); From 49273ecbc69e5de7a3b6339793ef97492f0f8bef Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Tue, 3 Feb 2015 07:17:15 +0100 Subject: [PATCH 05/15] Updated the README. --- README.md | 67 ++++++++++++++++++++++--------------------------------- 1 file changed, 27 insertions(+), 40 deletions(-) diff --git a/README.md b/README.md index e026f40..ec0edbd 100644 --- a/README.md +++ b/README.md @@ -22,20 +22,16 @@ This gem packages the bootstrap-datetimepicker for Rails asset pipeline and crea - http://eonasdan.github.io/bootstrap-datetimepicker version 4.0.0 -### Compatibility details +### Branches Master & eonasdan branches, tags v4.0.0+: Bootstrap 3+, Rails 4+ and SimpleForm 3.1+ (using https://github.com/eonasdan/bootstrap-datetimepicker.git as submodule, well maintained repo). Any further development will be made on these branches. -Tag v3.0.1 and tarruda branch: Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+ (using an upgraded version of https://github.com/tarruda/bootstrap-datetimepicker.git as inline code, not maintained). No further development, only bug fix for fatal issues on this branch. - -Tag v1.0.0: Rails 3.2, Bootstrap 2.3.2 & SimpleForm >= 2.0.4 - No further development, only bug fix for fatal issues on this branch. +Tag v1.0.0: Rails 3.2, Bootstrap 2.3.2 & SimpleForm >= 2.0.4 - It is archived. No further development or maintenance. ### Dependency -Versions v4.0.0+ has a dependency on the moment.js version 2.9 javascript library (for details refer to: http://momentjs.com/) and the gem includes the dependency reference in its Gemfile (gem 'momentjs-rails', '~> 2.9', :github => 'derekprior/momentjs-rails'). - -Versions v3.0.2 & v3.0.3 has a dependency on the moment.js version v2.7, but the gem **have not installed this library** out of the box, so **you have to look after that**. Put "gem 'momentjs-rails', '2.7', :github => 'derekprior/momentjs-rails'" to your project Gemfile to install it. +Versions v4.0.0+ has a dependency on the moment.js version 2.9+ javascript library (for details refer to: http://momentjs.com/). Includes the dependency reference in its Gemfile (gem 'momentjs-rails', '~> 2.9', :github => 'derekprior/momentjs-rails'). ### Credits and references @@ -55,12 +51,7 @@ gem 'datetimepicker-rails', github: 'zpaulovics/datetimepicker-rails', branch: ' ``` -**Option 2:** Tag v3.0.1 and tarruda branch: Bootstrap 3+, Rails 4+ and SimpleForm 3.1.RC1+ (using an upgraded version of https://github.com/tarruda/bootstrap-datetimepicker.git as inline code, not maintained). *No further development, only bug fix for fatal issues on this branch*. - - gem 'datetimepicker-rails', '>= 3.0.0', :git => 'git://github.com/zpaulovics/datetimepicker-rails.git', :branch => 'tarruda' - - -**Option 3:** Tag v1.0.0: Rails 3.2, Bootstrap 2.3.2 & SimpleForm >= 2.0.4 - *No further development, only bug fix for fatal issues on this branch*. +**Option 2:** Tag v1.0.0: Rails 3.2, Bootstrap 2.3.2 & SimpleForm >= 2.0.4 - *No further development or maintenance*. gem 'datetimepicker-rails', git: 'git://github.com/zpaulovics/datetimepicker-rails', tag: 'v1.0.0' @@ -82,7 +73,7 @@ or Add this line to app/assets/javascripts/application.js -From version 4.0.0+: +For version 4.0.0+: ```javascript //= require moment @@ -90,10 +81,10 @@ From version 4.0.0+: //= require pickers // You may include any languages (optional) -//= require moment/hu +//= require moment/ ``` -Earlier version: +For version v1.0.0: ```javascript //= require bootstrap-datetimepicker/core @@ -126,11 +117,12 @@ To run the generator use the following command: ``` $ rails generate datetimepicker_rails:install ``` -if you want to use the default Glyphicon icons for the pickers, or execute the following command +if you want to use the default Glyphicon icons for the pickers. + +To use the Font-Awesome icons for the pickers, execute the following command (only for version v4.0.0+) ``` $ rails generate datetimepicker_rails:install Font-Awesome ``` -to use the Font-Awesome icons for the pickers. The current version will copy the required files to your projects 'vendor/assets' directory (not to the gem's vendor/assets directory as before). That makes it possible to tailor by your projects @@ -158,28 +150,29 @@ Just call datetimepicker() with any selector. <%= f.input :closing_date, :as => :date_picker %> -<%= f.input :begin-at, :as => :time_picker %> +<%= f.input :begin_at, :as => :time_picker %> ``` -The scripts below will be included when you use the "require pickers" or "require bootstrap-datetimepicker/pickers". If you -need different activation scripts, ignore the //= require pickers or //= require bootstrap-datetimepicker/pickers line -(depending on your installation) in app/assets/javascripts/application.js. +The scripts below will be included when you use the "require pickers" (for version v4.0.0+) or "require bootstrap-datetimepicker/pickers" (for version v1.0.0). If you need different activation scripts, ignore the //= require pickers (for version v4.0.0+) or //= require bootstrap-datetimepicker/pickers (for version v1.0.0) line in app/assets/javascripts/application.js. -From version 4.0.0+: +Version 4.0.0+: ```javascript $(document).on('ready, page:change', function() { $('.datepicker').datetimepicker({ + // Any customisation should be inserted here }); }); $(document).on('ready, page:change', function() { $('.datetimepicker').datetimepicker({ + // Any customisation should be inserted here }); }); $(document).on('ready, page:change', function() { $('.timepicker').datetimepicker({ + // Any customisation should be inserted here }); }); ``` @@ -225,10 +218,10 @@ The default values of the options: keepOpen: false ``` For more details, please refer to Bootstrap 3 Datepicker v4 Docs site: - - [documentation](http://eonasdan.github.io/bootstrap-datetimepicker/#bootstrap-3-datepicker-v4-docs) - - [options](http://eonasdan.github.io/bootstrap-datetimepicker/Options/) + - [for public API documentation](http://eonasdan.github.io/bootstrap-datetimepicker/#bootstrap-3-datepicker-v4-docs) + - [for description of the options](http://eonasdan.github.io/bootstrap-datetimepicker/Options/) -Earlier version: +Version v1.0.0: ```javascript $(document).on('ready, page:change', function() { @@ -259,7 +252,6 @@ Specify your intended date and time formats in your config/locales/en.yml or rel datepicker: dformat: '%d/%m/%Y' # display format of the date (this is the default, can be ommited) pformat: 'DD/MM/YYYY' # picking format of the date (this is the default, can be ommited) - weekstart: 0 # the week starts on Sunday (this is the default, can be ommited) timepicker: dformat: '%R' # display format of the time (this is the default, can be ommited) pformat: 'HH:mm' # picking format of the time (this is the default, can be ommited) @@ -274,13 +266,9 @@ This should be applied for any version. * pformat is the format, that used by the JavaScript library to format the date/time string submitted by a form. -1. pformat for current versions (3.0.2+): We have upgraded to the repository -of bootstrap-datetimepicker by Eonasdan as submodule, the new library is using the moment.js -(for more information see Moment's documentation [here](http://momentjs.com/docs/#/displaying/format/). +1. pformat for current versions: We have upgraded to the repository of bootstrap-datetimepicker by Eonasdan as submodule, the new library is using the moment.js (for more information see Moment's documentation [here](http://momentjs.com/docs/#/displaying/format/). -2. pformat for earlier versions: Earlier versions are based on the bootstrap-datetimepicker -by @tarruda, which applies a different pattern to make the date to string conversion. He does -not release any documentation. Here is the related part of the source code: +2. pformat for version v1.0.0: Version v1.0.0 are based on the bootstrap-datetimepicker by @tarruda, which applies a different pattern to make the date to string conversion. He does not release any documentation. Here is the related part of the source code: ``` dd: {property: 'UTCDate', getPattern: function() { return '(0?[1-9]|[1-2][0-9]|3[0-1])\\b';}}, MM: {property: 'UTCMonth', getPattern: function() {return '(0?[1-9]|1[0-2])\\b';}}, @@ -296,28 +284,27 @@ not release any documentation. Here is the related part of the source code: ### For more details of usage -[I have a demo application using the datetimeoicker-rails gem here] (https://github.com/zpaulovics/dateTimeDemo) +[You can find a demo application using the datetimeoicker-rails gem here] (https://github.com/zpaulovics/dateTimeDemo) See the documentation & excellent demos provided by plugin's authors: 1. for current version: by [@Eonasdan](https://github.com/Eonasdan) the documentation is [here](http://eonasdan.github.io/bootstrap-datetimepicker/), -2. for earlier version: by [@tarruda](https://github.com/tarruda) the documentation is [here](http://tarruda.github.com/bootstrap-datetimepicker/). +2. for version v1.0.0: by [@tarruda](https://github.com/tarruda) the documentation is [here](http://tarruda.github.com/bootstrap-datetimepicker/). ### Bugfix - dataToOptions function in the bootstrap-datetimepicker.js -My SimpleForm custom field implementation assumes to work the data-date-* attributes correctly in your picker. -I find out that, there is a bug in your dataToOptions function that prevents the perfect working of this gem. +This SimpleForm custom field implementation use the data-date-* attributes feature of bootstrap-datetimepicker, but there is a bug in dataToOptions function. -The generator has a patching function to fix the issue. It finds above code in the in the bootstrap-datetimepicker.js +The generator has a patch to fix this issue. It finds above code in the in the bootstrap-datetimepicker.js ``` dataToOptions = function () { var eData = element.data(), dataOptions = {}; ``` -Then insert the lines below: +Then inserts the lines below: ``` if (element.is('input')) { eData = element.data(); @@ -325,7 +312,7 @@ Then insert the lines below: eData = element.find('input').data(); } ``` -I have already raised a pull request of this fix. As soon as it will be accepted you can ignore this hacking. +A pull request has been raised to fix this issue. As soon as it will be accepted this hacking will be removed. ### Contributing From d09dc75e2f4d43692b7b76e06e01c9ba42a83560 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Tue, 3 Feb 2015 07:51:39 +0100 Subject: [PATCH 06/15] Correct the README --- README.md | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/README.md b/README.md index ec0edbd..3b21469 100644 --- a/README.md +++ b/README.md @@ -71,7 +71,7 @@ or ``` -Add this line to app/assets/javascripts/application.js +Add the following lines to app/assets/javascripts/application.js For version 4.0.0+: @@ -124,10 +124,9 @@ To use the Font-Awesome icons for the pickers, execute the following command (on $ rails generate datetimepicker_rails:install Font-Awesome ``` -The current version will copy the required files to your projects 'vendor/assets' directory -(not to the gem's vendor/assets directory as before). That makes it possible to tailor by your projects -the SimpleForm 'input' and the 'pickers.js' files to your needs at your own area. That gives you much more -flexibility to use your preferred options of the bootstrap-datetimepicker plugin. +The current version will copy the required files to your projects 'vendor/assets' directory (not to the gem's vendor/assets directory as before). That gives you much more flexibility to use your preferred options of the bootstrap-datetimepicker plugin. + +To tailor the picker to your specific needs you can modify the SimpleForm 'input' definition files and/or the 'pickers.js' file at your own project area. ### Using datetimepicker-rails From f188a3f890b6235b17aa2bece2f79cf459ec2f49 Mon Sep 17 00:00:00 2001 From: Nerian Date: Thu, 5 Feb 2015 18:52:26 +0100 Subject: [PATCH 07/15] Daterange input. --- README.md | 43 ++++++++++++++----- .../datetimepicker_rails/install_generator.rb | 41 +++++++++++++++--- .../wrappers/ranged_datetime_wrapper.rb | 13 ++++++ 3 files changed, 79 insertions(+), 18 deletions(-) create mode 100644 lib/generators/templates/wrappers/ranged_datetime_wrapper.rb diff --git a/README.md b/README.md index 3b21469..a36eb6a 100644 --- a/README.md +++ b/README.md @@ -150,6 +150,11 @@ Just call datetimepicker() with any selector. <%= f.input :closing_date, :as => :date_picker %> <%= f.input :begin_at, :as => :time_picker %> + +
+ <%= f.input :publish_date, as: :datetime_picker, wrapper: :ranged_datetime %> + <%= f.input :expiration_date, as: :datetime_picker, wrapper: :ranged_datetime %> +
``` The scripts below will be included when you use the "require pickers" (for version v4.0.0+) or "require bootstrap-datetimepicker/pickers" (for version v1.0.0). If you need different activation scripts, ignore the //= require pickers (for version v4.0.0+) or //= require bootstrap-datetimepicker/pickers (for version v1.0.0) line in app/assets/javascripts/application.js. @@ -158,21 +163,37 @@ Version 4.0.0+: ```javascript $(document).on('ready, page:change', function() { - $('.datepicker').datetimepicker({ - // Any customisation should be inserted here - }); - }); + $('.timepicker').datetimepicker(); - $(document).on('ready, page:change', function() { - $('.datetimepicker').datetimepicker({ - // Any customisation should be inserted here + $('.datetimepicker').datetimepicker(); + + $('.datepicker').datetimepicker(); + + $('.datetimerange').each(function(){ + var $this = $(this) + var range1 = $($this.find('.input-group')[0]) + var range2 = $($this.find('.input-group')[1]) + + if(range1.data("DateTimePicker").date() != null) + range2.data("DateTimePicker").minDate(range1.data("DateTimePicker").date()); + + if(range2.data("DateTimePicker").date() != null) + range1.data("DateTimePicker").maxDate(range2.data("DateTimePicker").date()); + + range1.on("dp.change",function (e) { + if(e.date) + range2.data("DateTimePicker").minDate(e.date); + else + range2.data("DateTimePicker").minDate(false); }); - }); - $(document).on('ready, page:change', function() { - $('.timepicker').datetimepicker({ - // Any customisation should be inserted here + range2.on("dp.change",function (e) { + if(e.date) + range1.data("DateTimePicker").maxDate(e.date); + else + range1.data("DateTimePicker").maxDate(false); }); + }) }); ``` diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index 28c5984..6f94c5f 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -51,6 +51,11 @@ def copy_time_picker options[:custom_icons][:time]) unless icon_family == 'Glyphicon' end + def copy_datetime_wrapper + template "wrappers/ranged_datetime_wrapper.rb", "config/initializers/ranged_datetime_wrapper.rb" unless + File.exist?('config/initializers/ranged_datetime_wrapper.rb') + end + # def copy_pickers_js # copy_file("#{source_paths.last}/js/pickers.js", # "vendor/assets/javascripts/pickers.js") @@ -62,24 +67,46 @@ def create_pickers_js vendor 'assets/javascripts/pickers.js' do <<-FILE $(document).on('ready, page:change', function() { - $('.datepicker').datetimepicker({ + $('.datetimepicker').datetimepicker({ // Any customisation of object creation should be inserted here #{icons} }); -}); -$(document).on('ready, page:change', function() { - $('.datetimepicker').datetimepicker({ + $('.timepicker').datetimepicker({ // Any customisation of object creation should be inserted here #{icons} }); -}); -$(document).on('ready, page:change', function() { - $('.timepicker').datetimepicker({ + $('.datepicker').datetimepicker({ // Any customisation of object creation should be inserted here #{icons} }); + + $('.datetimerange').each(function(){ + var $this = $(this) + var range1 = $($this.find('.input-group')[0]) + var range2 = $($this.find('.input-group')[1]) + + if(range1.data("DateTimePicker").date() != null) + range2.data("DateTimePicker").minDate(range1.data("DateTimePicker").date()); + + if(range2.data("DateTimePicker").date() != null) + range1.data("DateTimePicker").maxDate(range2.data("DateTimePicker").date()); + + range1.on("dp.change",function (e) { + if(e.date) + range2.data("DateTimePicker").minDate(e.date); + else + range2.data("DateTimePicker").minDate(false); + }); + + range2.on("dp.change",function (e) { + if(e.date) + range1.data("DateTimePicker").maxDate(e.date); + else + range1.data("DateTimePicker").maxDate(false); + }); + }) }); FILE end diff --git a/lib/generators/templates/wrappers/ranged_datetime_wrapper.rb b/lib/generators/templates/wrappers/ranged_datetime_wrapper.rb new file mode 100644 index 0000000..c70a768 --- /dev/null +++ b/lib/generators/templates/wrappers/ranged_datetime_wrapper.rb @@ -0,0 +1,13 @@ +SimpleForm.setup do |config| + config.wrappers :ranged_datetime, tag: 'div', class: 'form-group col-md-6', error_class: 'has-error' do |b| + b.use :html5 + b.use :placeholder + b.optional :readonly + + b.use :label, class: 'control-label' + b.use :input, class: 'form-control' + + b.use :error, wrap_with: { tag: 'span', class: 'help-block' } + b.use :hint, wrap_with: { tag: 'p', class: 'help-block' } + end +end From cdefcfd8776ab17f9051e6e6178eb160d2257c52 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Fri, 6 Feb 2015 14:02:05 +0100 Subject: [PATCH 08/15] Bumped the version to 4.0.0.RC3 --- lib/datetimepicker-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index 4e0e8e9..6817b9c 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "4.0.0.RC2" + VERSION = "4.0.0.RC3" end end From b94266f954b0ced10c276214d5bddd04bf4184f8 Mon Sep 17 00:00:00 2001 From: Nerian Date: Wed, 11 Feb 2015 11:17:34 +0100 Subject: [PATCH 09/15] Add missing commas --- lib/generators/datetimepicker_rails/install_generator.rb | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index 6f94c5f..6df5b76 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -163,10 +163,10 @@ def get_icons icons += " date: \'#{options[:custom_icons][:date]}\',\n" icons += " time: \'#{options[:custom_icons][:time]}\',\n" icons += " up: \'#{options[:custom_icons][:up]}\',\n" - icons += " down: \'#{options[:custom_icons][:down]}\'\n" - icons += " previous: \'#{options[:custom_icons][:previous]}\'\n" - icons += " next: \'#{options[:custom_icons][:next]}\'\n" - icons += " today: \'#{options[:custom_icons][:today]}\'\n" + icons += " down: \'#{options[:custom_icons][:down]}\',\n" + icons += " previous: \'#{options[:custom_icons][:previous]}\',\n" + icons += " next: \'#{options[:custom_icons][:next]}\',\n" + icons += " today: \'#{options[:custom_icons][:today]}\',\n" icons += " clear: \'#{options[:custom_icons][:clear]}\'\n" icons += " },\n" end From 9cf6aca800492b5a0048fe8eadef961d512cb9db Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Wed, 11 Feb 2015 17:04:54 +0100 Subject: [PATCH 10/15] Remove two unneeded commas. --- lib/generators/datetimepicker_rails/install_generator.rb | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index 6df5b76..f67527d 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -66,7 +66,7 @@ def create_pickers_js icons = icon_family == 'Glyphicon' ? '' : get_icons vendor 'assets/javascripts/pickers.js' do <<-FILE -$(document).on('ready, page:change', function() { +$(document).on('ready page:change', function() { $('.datetimepicker').datetimepicker({ // Any customisation of object creation should be inserted here #{icons} @@ -168,7 +168,7 @@ def get_icons icons += " next: \'#{options[:custom_icons][:next]}\',\n" icons += " today: \'#{options[:custom_icons][:today]}\',\n" icons += " clear: \'#{options[:custom_icons][:clear]}\'\n" - icons += " },\n" + icons += " }\n" end end From 37882fc6d45b1ead1c1f459114f0136976e7d6af Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Wed, 11 Feb 2015 17:10:36 +0100 Subject: [PATCH 11/15] Bumpded the version to 4.0.0.RC4 --- lib/datetimepicker-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index 6817b9c..a39749f 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "4.0.0.RC3" + VERSION = "4.0.0.RC4" end end From 91e33db22a77b8015fea86b7c1e9c6db5e9bf2c0 Mon Sep 17 00:00:00 2001 From: Nerian Date: Wed, 11 Feb 2015 11:20:00 +0100 Subject: [PATCH 12/15] Refactor the pickers.js template so that the options are stored in a variable, and used in each picker call. --- README.md | 82 +++++++++++-------- .../datetimepicker_rails/install_generator.rb | 44 ++++------ 2 files changed, 65 insertions(+), 61 deletions(-) diff --git a/README.md b/README.md index a36eb6a..1cdcf0f 100644 --- a/README.md +++ b/README.md @@ -162,39 +162,53 @@ The scripts below will be included when you use the "require pickers" (for versi Version 4.0.0+: ```javascript - $(document).on('ready, page:change', function() { - $('.timepicker').datetimepicker(); - - $('.datetimepicker').datetimepicker(); - - $('.datepicker').datetimepicker(); - - $('.datetimerange').each(function(){ - var $this = $(this) - var range1 = $($this.find('.input-group')[0]) - var range2 = $($this.find('.input-group')[1]) - - if(range1.data("DateTimePicker").date() != null) - range2.data("DateTimePicker").minDate(range1.data("DateTimePicker").date()); - - if(range2.data("DateTimePicker").date() != null) - range1.data("DateTimePicker").maxDate(range2.data("DateTimePicker").date()); - - range1.on("dp.change",function (e) { - if(e.date) - range2.data("DateTimePicker").minDate(e.date); - else - range2.data("DateTimePicker").minDate(false); - }); +var default_picker_options = { + icons: { + date: 'fa fa-calendar', + time: 'fa fa-clock-o', + up: 'fa fa-chevron-up', + down: 'fa fa-chevron-down', + previous: 'fa fa-chevron-left', + next: 'fa fa-chevron-right', + today: 'fa fa-crosshairs', + clear: 'fa fa-trash-o' + } +} + +$(document).on('ready page:change', function() { + $('.datetimepicker').datetimepicker(default_picker_options); + + $('.timepicker').datetimepicker(default_picker_options); + + $('.datepicker').datetimepicker(default_picker_options); + + $('.datetimerange').each(function(){ + var $this = $(this) + var range1 = $($this.find('.input-group')[0]) + var range2 = $($this.find('.input-group')[1]) + + if(range1.data("DateTimePicker").date() != null) + range2.data("DateTimePicker").minDate(range1.data("DateTimePicker").date()); + + if(range2.data("DateTimePicker").date() != null) + range1.data("DateTimePicker").maxDate(range2.data("DateTimePicker").date()); + + range1.on("dp.change",function (e) { + if(e.date) + range2.data("DateTimePicker").minDate(e.date); + else + range2.data("DateTimePicker").minDate(false); + }); - range2.on("dp.change",function (e) { - if(e.date) - range1.data("DateTimePicker").maxDate(e.date); - else - range1.data("DateTimePicker").maxDate(false); - }); - }) + range2.on("dp.change",function (e) { + if(e.date) + range1.data("DateTimePicker").maxDate(e.date); + else + range1.data("DateTimePicker").maxDate(false); }); + }) +}); + ``` The default values of the options: @@ -244,19 +258,19 @@ For more details, please refer to Bootstrap 3 Datepicker v4 Docs site: Version v1.0.0: ```javascript - $(document).on('ready, page:change', function() { + $(document).on('ready page:change', function() { $('.datepicker').datetimepicker({ pickTime: false }); }); - $(document).on('ready, page:change', function() { + $(document).on('ready page:change', function() { $('.datetimepicker').datetimepicker({ pickSeconds: false }); }); - $(document).on('ready, page:change', function() { + $(document).on('ready page:change', function() { $('.timepicker').datetimepicker({ pickDate: false, pickSeconds: false diff --git a/lib/generators/datetimepicker_rails/install_generator.rb b/lib/generators/datetimepicker_rails/install_generator.rb index f67527d..f4cd137 100644 --- a/lib/generators/datetimepicker_rails/install_generator.rb +++ b/lib/generators/datetimepicker_rails/install_generator.rb @@ -56,31 +56,21 @@ def copy_datetime_wrapper File.exist?('config/initializers/ranged_datetime_wrapper.rb') end - # def copy_pickers_js - # copy_file("#{source_paths.last}/js/pickers.js", - # "vendor/assets/javascripts/pickers.js") - # end - def create_pickers_js puts("icon_family: #{icon_family}") icons = icon_family == 'Glyphicon' ? '' : get_icons vendor 'assets/javascripts/pickers.js' do <<-FILE -$(document).on('ready page:change', function() { - $('.datetimepicker').datetimepicker({ -// Any customisation of object creation should be inserted here +var default_picker_options = { #{icons} - }); +} - $('.timepicker').datetimepicker({ -// Any customisation of object creation should be inserted here -#{icons} - }); +$(document).on('ready page:change', function() { + $('.datetimepicker').datetimepicker(default_picker_options); - $('.datepicker').datetimepicker({ -// Any customisation of object creation should be inserted here -#{icons} - }); + $('.timepicker').datetimepicker(default_picker_options); + + $('.datepicker').datetimepicker(default_picker_options); $('.datetimerange').each(function(){ var $this = $(this) @@ -159,16 +149,16 @@ def hacking_dataToOptions_bug private def get_icons - icons = " icons: {\n" - icons += " date: \'#{options[:custom_icons][:date]}\',\n" - icons += " time: \'#{options[:custom_icons][:time]}\',\n" - icons += " up: \'#{options[:custom_icons][:up]}\',\n" - icons += " down: \'#{options[:custom_icons][:down]}\',\n" - icons += " previous: \'#{options[:custom_icons][:previous]}\',\n" - icons += " next: \'#{options[:custom_icons][:next]}\',\n" - icons += " today: \'#{options[:custom_icons][:today]}\',\n" - icons += " clear: \'#{options[:custom_icons][:clear]}\'\n" - icons += " }\n" + icons = " icons: {\n" + icons += " date: \'#{options[:custom_icons][:date]}\',\n" + icons += " time: \'#{options[:custom_icons][:time]}\',\n" + icons += " up: \'#{options[:custom_icons][:up]}\',\n" + icons += " down: \'#{options[:custom_icons][:down]}\',\n" + icons += " previous: \'#{options[:custom_icons][:previous]}\',\n" + icons += " next: \'#{options[:custom_icons][:next]}\',\n" + icons += " today: \'#{options[:custom_icons][:today]}\',\n" + icons += " clear: \'#{options[:custom_icons][:clear]}\'\n" + icons += " }\n" end end From b9c6ee47ae5a8829727a57fb191357c2b99304d0 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Thu, 12 Feb 2015 14:30:29 +0100 Subject: [PATCH 13/15] Bumped the version to 4.0.0.RC5 --- lib/datetimepicker-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index a39749f..c264eab 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "4.0.0.RC4" + VERSION = "4.0.0.RC5" end end From 976ad2f9f8a606843348c0b953f39bddd366a4be Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Fri, 13 Feb 2015 16:13:38 +0100 Subject: [PATCH 14/15] Small readme corection --- README.md | 3 +++ 1 file changed, 3 insertions(+) diff --git a/README.md b/README.md index 1cdcf0f..921e004 100644 --- a/README.md +++ b/README.md @@ -163,6 +163,9 @@ Version 4.0.0+: ```javascript var default_picker_options = { + // put here your default options that should be applied for all pickers + + // icons will be inserted if you run the generator with Font-Awesome parameter icons: { date: 'fa fa-calendar', time: 'fa fa-clock-o', From 3eb367754fb3b11fa2a5d7d3222de9ec073d4f23 Mon Sep 17 00:00:00 2001 From: zpaulovics Date: Fri, 13 Feb 2015 16:14:54 +0100 Subject: [PATCH 15/15] Bump the version to version 4.0.0 --- lib/datetimepicker-rails/version.rb | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/lib/datetimepicker-rails/version.rb b/lib/datetimepicker-rails/version.rb index c264eab..5e5ff99 100644 --- a/lib/datetimepicker-rails/version.rb +++ b/lib/datetimepicker-rails/version.rb @@ -1,5 +1,5 @@ module Datetimepicker module Rails - VERSION = "4.0.0.RC5" + VERSION = "4.0.0" end end