Module: Spree::Admin::TurboHelper

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

Instance Method Summary collapse

Instance Method Details

#turbo_close_dialogObject



22
23
24
25
26
# File 'app/helpers/spree/admin/turbo_helper.rb', line 22

def turbo_close_dialog
  turbo_stream.replace 'main-dialog' do
    render 'spree/admin/shared/dialog'
  end
end

#turbo_close_drawerObject



28
29
30
31
32
# File 'app/helpers/spree/admin/turbo_helper.rb', line 28

def turbo_close_drawer
  turbo_stream.replace 'drawer-dialog' do
    render 'spree/admin/shared/drawer'
  end
end

#turbo_close_modal(modal_id = nil) ⇒ Object



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

def turbo_close_modal(modal_id = nil)
  Spree::Deprecation.warn('turbo_close_modal is deprecated and will be removed in Spree 5.5. Use turbo_close_dialog instead.')

  modal_id ||= 'modal'

  turbo_stream.replace :modal_scripts do
    turbo_frame_tag :modal_scripts do
      javascript_tag do
        raw <<~JS
          if (document.querySelector('##{modal_id}')) {
            window.$("##{modal_id}").modal('hide');
          }
        JS
      end
    end
  end
end

#turbo_render_alerts(frame_name = :alerts) ⇒ Object



34
35
36
37
38
# File 'app/helpers/spree/admin/turbo_helper.rb', line 34

def turbo_render_alerts(frame_name = :alerts)
  turbo_stream.replace frame_name do
    render 'spree/admin/shared/alerts', frame_name: frame_name
  end
end

#turbo_save_button_tag(label = Spree.t('actions.save'), opts = {}, &block) ⇒ Object



40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
# File 'app/helpers/spree/admin/turbo_helper.rb', line 40

def turbo_save_button_tag(label = Spree.t('actions.save'), opts = {}, &block)
  opts[:class] ||= 'btn btn-primary text-center'
  opts[:class] << ' flex items-center justify-center' if opts[:class].exclude?('block') && opts[:class].exclude?('flex')

  opts['data-turbo-submits-with'] ||= "#{(:span, '', class: 'inline-block w-4 h-4 border-2 border-current border-r-transparent rounded-full animate-spin', role: 'status')}"
  opts['data-enable-button-target'] = 'button'
  if opts['data-controller'].present?
    opts['data-controller'] += ' turbo-submit-button'
  else
    opts['data-controller'] = 'turbo-submit-button'
  end

  if block_given?
    button_tag opts, &block
  else
    button_tag label, opts
  end
end