Module: Crm::ResourcesHelper
- Defined in:
- app/helpers/crm/resources_helper.rb
Overview
View helpers for rendering links to arbitrary CRM resources (opportunities,
quotes, orders, invoices, etc.) as warning badges, used by CRM views that
display mixed collections of related records.
Instance Method Summary collapse
-
#resource_label_link(resource) ⇒ ActiveSupport::SafeBuffer
Renders a badge-styled link to a CRM resource, choosing a label and path from the resource's class.
Instance Method Details
#resource_label_link(resource) ⇒ ActiveSupport::SafeBuffer
Renders a badge-styled link to a CRM resource, choosing a label and path
from the resource's class. Unknown classes fall back to a polymorphic
link, then to a static label when no route resolves.
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 |
# File 'app/helpers/crm/resources_helper.rb', line 18 def resource_label_link(resource) (class: 'badge bg-warning', style: 'white-space: normal;', data: { turbo_frame: '_top' }) do || case resource.class.name when 'Opportunity' .link_to resource.name.to_s, opportunity_path(resource.id) when 'Communication' if resource.draft? && can?(:update, resource) .link_to 'Communication', edit_communication_path(resource.id) else .link_to 'Communication', communication_path(resource.id) end when 'Quote' .link_to "Quote ##{resource.reference_number}", quote_path(resource.id) when 'Order' .link_to "Order ##{resource.cart_identifier}", order_path(resource.id) when 'RoomConfiguration' .link_to resource.name_with_room.to_s, room_configuration_path(resource.id) when 'Invoice' .link_to "Invoice ##{resource.reference_number}", invoice_path(resource.id) when 'SupportCase' .link_to "Support Case ##{resource.case_number}", support_case_path(resource.id) when 'CreditApplication' .link_to "Credit Application ##{resource.reference_number}", credit_application_path(resource.id) when 'SpiffEnrollment' .link_to "Spiff Enrollment ##{resource.id}", spiff_enrollment_path(resource.id) when 'PurchaseOrder' .link_to "Purchase Order ##{resource.reference_number}", purchase_order_path(resource.id) when 'CreditMemo' .link_to "Credit Memo ##{resource.reference_number}", credit_memo_path(resource.id) when 'Rma' .link_to resource.rma_number, rma_path(resource.id) when 'Delivery' .link_to "Delivery ##{resource.id}", delivery_path(resource.id) when 'LocatorRecord' .link_to "Locator Record ##{resource.id}", locator_record_path(resource.id) when 'Payment' if resource.order .link_to resource.to_s, order_path(resource.order) else .content_tag(:span, resource.to_s) end else # Try a polymorphic link if (link = begin .link_to(resource.to_s, polymorphic_path(resource)) rescue StandardError nil end) link else # render static label .content_tag(:span, resource.to_s) end end end end |