diff options
| author | Zog | 2018-04-06 14:46:19 +0200 |
|---|---|---|
| committer | cedricnjanga | 2018-04-10 23:28:47 -0700 |
| commit | 03b4010981f5d47fbd8dd468bbe5fc320fd7a9e4 (patch) | |
| tree | 842e1a5ae9e28274b991f49cf335e2debb959c7e | |
| parent | 9f374650488fdbfd86fbbdc66cfebda4e9f5a551 (diff) | |
| download | chouette-core-03b4010981f5d47fbd8dd468bbe5fc320fd7a9e4.tar.bz2 | |
Refs #6426; Disable "Create opposite route" action instead of hiding it
| -rw-r--r-- | app/assets/javascripts/application.js | 6 | ||||
| -rw-r--r-- | app/decorators/route_decorator.rb | 3 | ||||
| -rw-r--r-- | app/helpers/table_builder_helper.rb | 7 | ||||
| -rw-r--r-- | app/models/user.rb | 2 | ||||
| -rw-r--r-- | lib/af83/decorator/link.rb | 10 |
5 files changed, 20 insertions, 8 deletions
diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 6a79f7e8e..3eaade37f 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -25,3 +25,9 @@ //= require "i18n" //= require "i18n/extended" //= require "i18n/translations" + +$(document).ready(function() { + $('a[disabled=disabled]').click(function(event){ + event.preventDefault(); // Prevent link from following its href + }); +}); diff --git a/app/decorators/route_decorator.rb b/app/decorators/route_decorator.rb index 4a173cbb9..646bc1620 100644 --- a/app/decorators/route_decorator.rb +++ b/app/decorators/route_decorator.rb @@ -74,10 +74,11 @@ class RouteDecorator < AF83::Decorator instance_decorator.action_link( secondary: :show, policy: :create_opposite, - if: ->{h.has_feature?(:create_opposite_routes) && object.opposite_route.nil?} + if: ->{h.has_feature?(:create_opposite_routes)} ) do |l| l.content h.t('routes.create_opposite.title') l.method :post + l.disabled { object.opposite_route.present? } l.href do h.duplicate_referential_line_route_path( context[:referential], diff --git a/app/helpers/table_builder_helper.rb b/app/helpers/table_builder_helper.rb index 63125b161..e2aa2e9ea 100644 --- a/app/helpers/table_builder_helper.rb +++ b/app/helpers/table_builder_helper.rb @@ -402,9 +402,10 @@ module TableBuilderHelper content_tag( :li, link_to( - link.href, - method: link.method, - data: link.data + link.disabled ? '#' : link.href, + method: link.disabled ? nil : link.method, + data: link.data, + disabled: link.disabled ) do link.content end, diff --git a/app/models/user.rb b/app/models/user.rb index 29148d9e9..ba166b06f 100644 --- a/app/models/user.rb +++ b/app/models/user.rb @@ -9,7 +9,7 @@ class User < ApplicationModel :recoverable, :rememberable, :trackable, :async, authentication_type # FIXME https://github.com/nbudin/devise_cas_authenticatable/issues/53 - # Work around :validatable, when database_authenticatable is diabled. + # Work around :validatable, when database_authenticatable is disabled. attr_accessor :password unless authentication_type == :database_authenticatable # Setup accessible (or protected) attributes for your model diff --git a/lib/af83/decorator/link.rb b/lib/af83/decorator/link.rb index ee09f80dc..9bf6c1ed9 100644 --- a/lib/af83/decorator/link.rb +++ b/lib/af83/decorator/link.rb @@ -85,6 +85,10 @@ class AF83::Decorator::Link in_group_for_action? :secondary end + def disabled? + !!disabled + end + def enabled? enabled = false if @options[:_if].nil? @@ -131,9 +135,9 @@ class AF83::Decorator::Link out[:class] = extra_class out.delete(:link_class) out.delete(:link_method) - out[:class] += " disabled" if disabled + out[:class] += " disabled" if disabled? out[:class].strip! - out[:disabled] = !!disabled + out[:disabled] = disabled? out end @@ -150,7 +154,7 @@ class AF83::Decorator::Link html_options ).to_html else - context.h.link_to content, href, html_options + context.h.link_to content, (disabled? ? "#" : href), html_options end end end |
