Module: Spree::Admin::BulkOperationsHelper

Defined in:
app/helpers/spree/admin/bulk_operations_helper.rb

Instance Method Summary collapse

Instance Method Details

render a link to perform a bulk action

Parameters:

  • text (String)

    the text of the link

  • path (String)

    the path of the link

  • options (Hash) (defaults to: {})

    the options of the link

Options Hash (options):

  • :icon (String)

    the icon of the link

  • :url (String)

    the url to perform the bulk action to be set for the form in bulk modal

  • :class (String)

    the class of the link

  • :data (String)

    the data of the link

Returns:

  • (String)


46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'app/helpers/spree/admin/bulk_operations_helper.rb', line 46

def bulk_action_link(text, path, options = {})
  options[:data] ||= {}
  options[:data][:action] ||= 'click->bulk-operation#setBulkAction click->bulk-dialog#open'
  options[:data][:turbo_frame] ||= :bulk_dialog
  options[:data][:url] ||= options[:url]
  options[:class] ||= 'btn'

  tooltip_text = nil
  if options[:icon]
    if options[:only_icon]
      tooltip_text = options[:title] || text
      text = icon(options[:icon], class: 'mr-0')
      options[:data][:controller] = 'tooltip'
      options.delete(:title)
    else
      text = icon(options[:icon]) + ' ' + text
    end
  end

  link_content = text
  link_content += tooltip(tooltip_text) if tooltip_text

  link_to link_content, path, options
end

#bulk_operations_checkbox(object) ⇒ String

render a checkbox to select an item for bulk operations

Parameters:

  • object (Spree::Product, Spree::User, Spree::Order)

Returns:

  • (String)


23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'app/helpers/spree/admin/bulk_operations_helper.rb', line 23

def bulk_operations_checkbox(object)
   :div, class: "custom-control form-checkbox ml-1" do
    check_box_tag(
      "ids[]",
      object.id,
      false,
      class: "custom-control-input",
      id: "ids_#{object.id}",
      data: { bulk_operation_target: "checkbox" }
    ) +
    (:label, (:span, ""), class: "custom-control-label", for: "ids_#{object.id}")
  end
end

#bulk_operations_close_buttonObject

render a close button for the bulk modal



72
73
74
75
76
77
78
79
80
81
82
# File 'app/helpers/spree/admin/bulk_operations_helper.rb', line 72

def bulk_operations_close_button
  button_tag(
    '',
    type: 'button',
    class: 'btn-close mr-1',
    data: {
      action: 'bulk-operation#cancel',
      aria_label: Spree.t(:close)
    }
  )
end

#bulk_operations_counterString

render a counter for the bulk operations

Returns:

  • (String)


86
87
88
89
90
91
92
93
# File 'app/helpers/spree/admin/bulk_operations_helper.rb', line 86

def bulk_operations_counter
  (:div, class: 'bulk-operations-counter') do
    (:span, class: 'bulk-operations-counter-label') do
      (:strong, '', data: { bulk_operation_target: 'counter' }) +
      Spree.t("admin.selected")
    end
  end
end

#bulk_operations_select_all_checkboxString

render a checkbox to select all items for bulk operations

Returns:

  • (String)


6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/helpers/spree/admin/bulk_operations_helper.rb', line 6

def bulk_operations_select_all_checkbox
   :div, class: "custom-control form-checkbox ml-1" do
    check_box_tag(
      nil,
      nil,
      false,
      id: "checkAllMasterCheckbox",
      class: "custom-control-input",
      data: { bulk_operation_target: "checkboxAll" }
    ) +
    (:label, (:span, ""), class: "custom-control-label", for: "checkAllMasterCheckbox")
  end
end