diff options
| -rw-r--r-- | app/assets/javascripts/routing_constraint_zones.coffee | 47 | ||||
| -rw-r--r-- | app/assets/stylesheets/components/_alerts.sass | 4 | ||||
| -rw-r--r-- | app/models/referential_metadata.rb | 4 | ||||
| -rw-r--r-- | app/views/access_link_pairs/_access_link_pair.html.slim | 1 | ||||
| -rw-r--r-- | config/locales/referentials.fr.yml | 1 | ||||
| -rw-r--r-- | spec/models/referential_metadata_spec.rb | 2 |
6 files changed, 37 insertions, 22 deletions
diff --git a/app/assets/javascripts/routing_constraint_zones.coffee b/app/assets/javascripts/routing_constraint_zones.coffee index ceb9fb218..8721dfb38 100644 --- a/app/assets/javascripts/routing_constraint_zones.coffee +++ b/app/assets/javascripts/routing_constraint_zones.coffee @@ -30,29 +30,40 @@ $('#ITL_stoppoints').find('.nested-fields').remove() $('#ITL_stoppoints').find('.nested-head').after(html) - # VALIDATION - selection = [] - $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) -> - v = $(e.target).val() + # VALIDATION + selection = [] - if ( $.inArray(v, selection) != -1 ) - selection.splice(selection.indexOf(v), 1) - else - selection.push(v) + totalItems = collection.length - alertMsg = "<div class='alert alert-danger' style='margin-bottom:15px;'> - <p class='small'>Un ITL doit comporter au moins deux arrêts</p> - </div>" + $('#ITL_stoppoints').on 'click', "input[type='checkbox']", (e) -> + v = $(e.target).val() - $(document).on 'click', "input[type='submit']", (e)-> - inputName = $('#routing_constraint_zone_name').val() + if ( $.inArray(v, selection) != -1 ) + selection.splice(selection.indexOf(v), 1) + else + selection.push(v) - $('.alert-danger').remove() + alertMsg1 = "<div class='alert alert-danger' style='margin-bottom:15px;'> + <p class='small'>Un ITL doit comporter au moins deux arrêts</p> + </div>" + alertMsg2 = "<div class='alert alert-danger' style='margin-bottom:15px;'> + <p class='small'>Un ITL ne peut recouvrir tous les arrêts d'un itinéraire</p> + </div>" - if ( selection.length < 2 && inputName != "") - e.preventDefault() - $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() - $('#ITL_stoppoints').prepend(alertMsg) + $(document).on 'click', "input[type='submit']", (e)-> + inputName = $('#routing_constraint_zone_name').val() + + $('.alert-danger').remove() + + if ( selection.length < 2 && inputName != "" ) + e.preventDefault() + $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() + $('#ITL_stoppoints').prepend(alertMsg1) + + if ( selection.length == totalItems && inputName != "" ) + e.preventDefault() + $('#routing_constraint_zone_name').closest('.form-group').removeClass('has-error').find('.help-block').remove() + $('#ITL_stoppoints').prepend(alertMsg2) $ -> ITL_stoppoints() diff --git a/app/assets/stylesheets/components/_alerts.sass b/app/assets/stylesheets/components/_alerts.sass index 923b67cbc..50799ff65 100644 --- a/app/assets/stylesheets/components/_alerts.sass +++ b/app/assets/stylesheets/components/_alerts.sass @@ -21,6 +21,10 @@ color: inherit border-color: inherit + form, .simple_form + & + margin-bottom: 15px + &.alert-dismissible padding-right: 70px diff --git a/app/models/referential_metadata.rb b/app/models/referential_metadata.rb index 357465c63..b774072c7 100644 --- a/app/models/referential_metadata.rb +++ b/app/models/referential_metadata.rb @@ -44,8 +44,8 @@ class ReferentialMetadata < ActiveRecord::Base validate :check_end_greather_than_begin def check_end_greather_than_begin - if self.begin and self.end and self.begin > self.end - errors.add(:end, :invalid) + if self.begin and self.end and self.begin >= self.end + errors.add(:base, I18n.t('referentials.errors.short_period')) end end diff --git a/app/views/access_link_pairs/_access_link_pair.html.slim b/app/views/access_link_pairs/_access_link_pair.html.slim index 3eebfd7f6..c313f9044 100644 --- a/app/views/access_link_pairs/_access_link_pair.html.slim +++ b/app/views/access_link_pairs/_access_link_pair.html.slim @@ -1,5 +1,4 @@ tr - - require 'pry'; binding.pry td .link .access_point diff --git a/config/locales/referentials.fr.yml b/config/locales/referentials.fr.yml index b9e337503..f69c26276 100644 --- a/config/locales/referentials.fr.yml +++ b/config/locales/referentials.fr.yml @@ -41,6 +41,7 @@ fr: user_excluded: "%{user} est une valeur réservée" overlapped_referential: "%{referential} couvre le même périmètre d'offre" overlapped_period: "Une autre période chevauche cette période" + short_period: La durée minimum d'une période est de deux jours activerecord: models: referential: diff --git a/spec/models/referential_metadata_spec.rb b/spec/models/referential_metadata_spec.rb index 0f628c8d1..91a2a7fc2 100644 --- a/spec/models/referential_metadata_spec.rb +++ b/spec/models/referential_metadata_spec.rb @@ -87,7 +87,7 @@ RSpec.describe ReferentialMetadata, :type => :model do it "should validate that end is greather than or equlals to begin" do expect(period(begin: "2016-11-21", end: "2016-11-22")).to be_valid - expect(period(begin: "2016-11-21", end: "2016-11-21")).to be_valid + expect(period(begin: "2016-11-21", end: "2016-11-21")).to_not be_valid expect(period(begin: "2016-11-22", end: "2016-11-21")).to_not be_valid end |
