diff options
| author | jpl | 2017-06-28 17:45:46 +0200 | 
|---|---|---|
| committer | jpl | 2017-06-28 17:45:53 +0200 | 
| commit | f2191bd26937e7433a6ddfd2eda489a6cf4ae30e (patch) | |
| tree | 009f470c37f19174aedd3525e587bb3811b7ae9e | |
| parent | b260c832c8e129dbeacfe065d01bd0732dd80701 (diff) | |
| download | chouette-core-f2191bd26937e7433a6ddfd2eda489a6cf4ae30e.tar.bz2 | |
Refs #3862: adding validation on ITL form
| -rw-r--r-- | app/assets/javascripts/routing_constraint_zones.coffee | 47 | ||||
| -rw-r--r-- | app/assets/stylesheets/components/_alerts.sass | 4 | 
2 files changed, 33 insertions, 18 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 | 
