From fd3c447dda1a0de1341dc582ce2226390c4ecb3e Mon Sep 17 00:00:00 2001 From: Alex Kotov Date: Thu, 15 Aug 2019 12:06:11 +0500 Subject: [PATCH] Implement disabled tabs --- app/helpers/application_helper.rb | 18 +++++++++++++----- app/views/staffs/people/_nav_tabs.html.erb | 20 ++++++++++++++++---- 2 files changed, 29 insertions(+), 9 deletions(-) diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 5ef101f..0e35405 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -41,16 +41,24 @@ module ApplicationHelper def nav_tabs_list(scope_name, current_tab_name, format, options) tag.ul class: NAV_TABS_LIST_HTML_CLASS[format] do options.each do |(k, v)| - concat nav_tabs_item scope_name, current_tab_name, k, v + concat nav_tabs_item scope_name, current_tab_name, k, *v end end end - def nav_tabs_item(scope_name, current_tab_name, tab_name, url) + def nav_tabs_item(scope_name, current_tab_name, tab_name, policy, url) tag.li class: 'nav-item' do - link_to translate(tab_name, scope: [:nav_tabs, scope_name]), - url, - class: "nav-link #{:active if current_tab_name == tab_name}" + if policy + link_to translate(tab_name, scope: [:nav_tabs, scope_name]), + url, + class: "nav-link #{:active if current_tab_name == tab_name}" + else + link_to translate(tab_name, scope: [:nav_tabs, scope_name]), + url, + class: 'nav-link disabled', + tabindex: -1, + 'aria-disabled': true + end end end end diff --git a/app/views/staffs/people/_nav_tabs.html.erb b/app/views/staffs/people/_nav_tabs.html.erb index 42db5bf..33478f0 100644 --- a/app/views/staffs/people/_nav_tabs.html.erb +++ b/app/views/staffs/people/_nav_tabs.html.erb @@ -2,9 +2,21 @@ <%= nav_tabs( :person, tab, - overview: [:staff, person], - person_comments: staff_person_person_comments_path(person), - relationships: staff_person_relationships_path(person), - passports: staff_person_passports_path(person), + overview: [ + policy([:staff, person]).show?, + [:staff, person], + ], + person_comments: [ + policy([:staff, person, :person_comment]).index?, + staff_person_person_comments_path(person), + ], + relationships: [ + policy([:staff, person, :relationship]).index?, + staff_person_relationships_path(person), + ], + passports: [ + policy([:staff, person, :passport]).index?, + staff_person_passports_path(person), + ], ) %>