Module: Plutonium::Resource::Controllers::InteractiveActions

Extended by:
ActiveSupport::Concern
Included in:
Plutonium::Resource::Controller
Defined in:
lib/plutonium/resource/controllers/interactive_actions.rb

Instance Method Summary collapse

Instance Method Details

#commit_interactive_bulk_actionObject



145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 145

def commit_interactive_bulk_action
  build_interactive_bulk_action_interaction

  if params[:pre_submit]
    respond_to do |format|
      format.turbo_stream { render turbo_stream: turbo_stream.replace("interaction-form", view_context.render(@interaction.build_form)) }
      format.html { render :interactive_bulk_action, formats: [:html], status: :unprocessable_content }
    end
    return
  end

  outcome = @interaction.call

  outcome.to_response.process(self) do |value|
    respond_to do |format|
      if outcome.success?
        return_url = redirect_url_after_action_on(resource_class)

        format.turbo_stream do
          render turbo_stream: helpers.turbo_stream_redirect(return_url)
        end
        format.html do
          redirect_to return_url, status: :see_other
        end
      else
        format.any(:html, :turbo_stream) do
          render :interactive_bulk_action, formats: [:html], status: :unprocessable_content
        end
        format.any do
          @errors = @interaction.errors
          render "errors", status: :unprocessable_content
        end
      end
    end
  end
end

#commit_interactive_record_actionObject

POST /resources/1/record_actions/:interactive_action



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
72
73
74
75
76
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 41

def commit_interactive_record_action
  build_interactive_record_action_interaction

  if params[:pre_submit]
    respond_to do |format|
      format.turbo_stream { render turbo_stream: turbo_stream.replace("interaction-form", view_context.render(@interaction.build_form)) }
      format.html { render :interactive_record_action, formats: [:html], status: :unprocessable_content }
    end
    return
  end

  outcome = @interaction.call

  outcome.to_response.process(self) do |value|
    respond_to do |format|
      if outcome.success?
        return_url = redirect_url_after_action_on(resource_record!)

        format.turbo_stream do
          render turbo_stream: helpers.turbo_stream_redirect(return_url)
        end
        format.html do
          redirect_to return_url, status: :see_other
        end
      else
        format.any(:html, :turbo_stream) do
          render :interactive_record_action, formats: [:html], status: :unprocessable_content
        end
        format.any do
          @errors = @interaction.errors
          render "errors", status: :unprocessable_content
        end
      end
    end
  end
end

#commit_interactive_resource_actionObject

POST /resources/resource_actions/:interactive_action



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 95

def commit_interactive_resource_action
  skip_verify_current_authorized_scope!
  build_interactive_resource_action_interaction

  if params[:pre_submit]
    respond_to do |format|
      format.turbo_stream { render turbo_stream: turbo_stream.replace("interaction-form", view_context.render(@interaction.build_form)) }
      format.html { render :interactive_resource_action, status: :unprocessable_content }
    end
    return
  end

  outcome = @interaction.call

  outcome.to_response.process(self) do |value|
    respond_to do |format|
      if outcome.success?
        return_url = redirect_url_after_action_on(resource_class)

        format.turbo_stream do
          render turbo_stream: helpers.turbo_stream_redirect(return_url)
        end
        format.html do
          redirect_to return_url, status: :see_other
        end
      else
        format.any(:html, :turbo_stream) do
          render :interactive_resource_action, formats: [:html], status: :unprocessable_content
        end
        format.any do
          @errors = @interaction.errors
          render "errors", status: :unprocessable_content
        end
      end
    end
  end
end

#interactive_bulk_actionObject



134
135
136
137
138
139
140
141
142
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 134

def interactive_bulk_action
  build_interactive_bulk_action_interaction

  if helpers.current_turbo_frame == "remote_modal"
    render layout: false, formats: [:html]
  else
    render :interactive_bulk_action, formats: [:html]
  end
end

#interactive_record_actionObject

GET /resources/1/record_actions/:interactive_action



30
31
32
33
34
35
36
37
38
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 30

def interactive_record_action
  build_interactive_record_action_interaction

  if helpers.current_turbo_frame == "remote_modal"
    render layout: false, formats: [:html]
  else
    render :interactive_record_action, formats: [:html]
  end
end

#interactive_resource_actionObject

GET /resources/resource_actions/:interactive_action



79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/plutonium/resource/controllers/interactive_actions.rb', line 79

def interactive_resource_action
  skip_verify_current_authorized_scope!
  build_interactive_resource_action_interaction

  respond_to do |format|
    format.any(:html, :turbo_stream) do
      if helpers.current_turbo_frame == "remote_modal"
        render layout: false, formats: [:html]
      else
        render :interactive_resource_action, formats: [:html]
      end
    end
  end
end