aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRobert2017-06-27 19:58:48 +0200
committerRobert2017-06-27 20:11:18 +0200
commit083d23585935139b5e87b99bf5cc2a79f4a53cca (patch)
treed733458dca16e08cece47d915146f8e95126cf6a
parentdcf8868773491c66c4527fe768ceacef38cf0e16 (diff)
downloadchouette-core-083d23585935139b5e87b99bf5cc2a79f4a53cca.tar.bz2
Refs: #3595@0.5h live event subscription & smart_date class added to all date input elements
-rw-r--r--app/assets/javascripts/smart_date.coffee8
-rw-r--r--app/views/calendars/_filters.html.slim2
-rw-r--r--app/views/referentials/_period_fields.html.slim4
-rw-r--r--app/views/referentials/show.html.slim4
-rw-r--r--app/views/time_tables/_date_fields.html.slim2
-rw-r--r--app/views/time_tables/_excluded_date_fields.html.slim2
-rw-r--r--app/views/time_tables/_filter.html.slim4
-rw-r--r--app/views/time_tables/_period_fields.html.slim4
-rw-r--r--app/views/workbenches/_filters.html.slim4
-rw-r--r--spec/models/calendar/calendar_date_spec.rb38
10 files changed, 17 insertions, 55 deletions
diff --git a/app/assets/javascripts/smart_date.coffee b/app/assets/javascripts/smart_date.coffee
index d9228670d..7ea634a19 100644
--- a/app/assets/javascripts/smart_date.coffee
+++ b/app/assets/javascripts/smart_date.coffee
@@ -1,8 +1,8 @@
-
-smartDateSelector = '.smart_date'
-smartDateSelectSelector = "#{smartDateSelector} select"
legalDaysPerMonth = [31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31]
+isLeapYear = (year) ->
+ (year % 4 == 0) && ((year % 400 == 0) || (year % 100 != 0))
+
correctDay = (dateValues) ->
[day, month, year] = dateValues
return day if legalDaysPerMonth[month-1] >= day
@@ -18,4 +18,4 @@ smartCorrectDate = ->
$(daySelector).val(correctedDay)
$ ->
- $(smartDateSelectSelector).on 'change', smartCorrectDate
+ $(document).on 'change', '.smart_date select', smartCorrectDate
diff --git a/app/views/calendars/_filters.html.slim b/app/views/calendars/_filters.html.slim
index 6bcf25f99..4c30f69dc 100644
--- a/app/views/calendars/_filters.html.slim
+++ b/app/views/calendars/_filters.html.slim
@@ -15,7 +15,7 @@
.form-group
= f.label Calendar.human_attribute_name(:date), class: 'control-label'
- = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date' }, class: 'form-control', include_blank: true
+ = f.input :contains_date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }, class: 'form-control', include_blank: true
.actions
= link_to 'Effacer', calendars_path, class: 'btn btn-link'
diff --git a/app/views/referentials/_period_fields.html.slim b/app/views/referentials/_period_fields.html.slim
index 1e201a39f..95e204554 100644
--- a/app/views/referentials/_period_fields.html.slim
+++ b/app/views/referentials/_period_fields.html.slim
@@ -8,8 +8,8 @@
.wrapper
div
- = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :begin, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
div
- = f.input :end, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :end, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
div
= link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')
diff --git a/app/views/referentials/show.html.slim b/app/views/referentials/show.html.slim
index dfa264c0b..8308cf770 100644
--- a/app/views/referentials/show.html.slim
+++ b/app/views/referentials/show.html.slim
@@ -68,9 +68,9 @@
.row
.col-lg-8.col-ld-offset-2.col-md-8.col-md-offset-2.col-sm-8.col-sm-offset-2.col-xs-12
= f.input :date_type, as: :radio_buttons, label: false
- = f.input :begin_date, as: :date, label: t('titles.clean_up.begin_date'),:wrapper_html => { class: 'date', title: t('titles.clean_up.begin_date') }
+ = f.input :begin_date, as: :date, label: t('titles.clean_up.begin_date'),:wrapper_html => { class: 'date smart_date', title: t('titles.clean_up.begin_date') }
- = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper hidden', title: t('titles.clean_up.end_date') }
+ = f.input :end_date, as: :date, label: t('titles.clean_up.end_date'), :wrapper_html => { class: 'date cleanup_end_date_wrapper hidden smert_date', title: t('titles.clean_up.end_date') }
.modal-footer
button.btn.btn-link type='button' data-dismiss='modal' Annuler
diff --git a/app/views/time_tables/_date_fields.html.slim b/app/views/time_tables/_date_fields.html.slim
index 1599dd7ff..811c241bb 100644
--- a/app/views/time_tables/_date_fields.html.slim
+++ b/app/views/time_tables/_date_fields.html.slim
@@ -8,7 +8,7 @@
.wrapper
div
- = f.input :date, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
= f.input :in_out, as: :hidden, :input_html => {:value => true}
div
= link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')
diff --git a/app/views/time_tables/_excluded_date_fields.html.slim b/app/views/time_tables/_excluded_date_fields.html.slim
index dba5bf952..8e4003920 100644
--- a/app/views/time_tables/_excluded_date_fields.html.slim
+++ b/app/views/time_tables/_excluded_date_fields.html.slim
@@ -9,7 +9,7 @@
.wrapper
div
/ = f.label @time_table.human_attribute_name("date"), class: 'col-md-1'
- = f.input :date, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :date, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
= f.input :in_out, as: :hidden, input_html: {value: false}
div
= link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')
diff --git a/app/views/time_tables/_filter.html.slim b/app/views/time_tables/_filter.html.slim
index cee915911..10e46d884 100644
--- a/app/views/time_tables/_filter.html.slim
+++ b/app/views/time_tables/_filter.html.slim
@@ -18,8 +18,8 @@
.form-group.togglable
= f.label @time_tables.human_attribute_name(:bounding_dates), required: false, class: 'control-label'
.filter_menu
- = f.input :start_date_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true
- = f.input :end_date_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true
+ = f.input :start_date_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true
+ = f.input :end_date_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true
.actions
diff --git a/app/views/time_tables/_period_fields.html.slim b/app/views/time_tables/_period_fields.html.slim
index f879ded00..6b3fde311 100644
--- a/app/views/time_tables/_period_fields.html.slim
+++ b/app/views/time_tables/_period_fields.html.slim
@@ -8,8 +8,8 @@
.wrapper
div
- = f.input :period_start, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :period_start, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
div
- = f.input :period_end, as: :date, label: false, wrapper_html: { class: 'date' }
+ = f.input :period_end, as: :date, label: false, wrapper_html: { class: 'date smart_date' }
div
= link_to_remove_association '', f, class: 'fa fa-trash', data: { confirm: 'Etes-vous sûr(e) ?' }, title: t('actions.delete')
diff --git a/app/views/workbenches/_filters.html.slim b/app/views/workbenches/_filters.html.slim
index 0aedbdd62..4eaf910c0 100644
--- a/app/views/workbenches/_filters.html.slim
+++ b/app/views/workbenches/_filters.html.slim
@@ -25,8 +25,8 @@
= f.label Referential.human_attribute_name(:validity_period), required: false, class: 'control-label'
.filter_menu
= f.simple_fields_for :validity_period do |p|
- = p.input :begin_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true
- = p.input :end_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true
+ = p.input :begin_gteq, as: :date, label: t('simple_form.from'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @begin_range, include_blank: @begin_range ? false : true
+ = p.input :end_lteq, as: :date, label: t('simple_form.to'), wrapper_html: { class: 'date smart_date filter_menu-item' }, default: @end_range, include_blank: @end_range ? false : true
.actions
= link_to 'Effacer', @workbench, class: 'btn btn-link'
diff --git a/spec/models/calendar/calendar_date_spec.rb b/spec/models/calendar/calendar_date_spec.rb
deleted file mode 100644
index 25fe8ba8d..000000000
--- a/spec/models/calendar/calendar_date_spec.rb
+++ /dev/null
@@ -1,38 +0,0 @@
-RSpec.describe Calendar::CalendarDate do
-
- subject { described_class.new(year, month, day) }
- let( :year ){ 2000 }
- let( :month ){ 2 }
-
- let( :str_repr ){ %r{#{year}-0?#{month}-0?#{day}} }
-
-
-
- shared_examples_for "date accessors" do
- it "accesses year" do
- expect( subject.year ).to eq(year)
- end
- it "accesses month" do
- expect( subject.month ).to eq(month)
- end
- it "accesses day" do
- expect( subject.day ).to eq(day)
- end
- it "converts to a string" do
- expect( subject.to_s ).to match(str_repr)
- end
- end
-
- context 'legal' do
- let( :day ){ 29 }
- it { expect_it.to be_legal }
- it_should_behave_like "date accessors"
- end
-
- context 'illegal' do
- let( :day ){ 30 }
- it { expect_it.not_to be_legal }
- it_should_behave_like "date accessors"
- end
-
-end