mirror of https://github.com/docusealco/docuseal
parent
2e5fe4c830
commit
a4460cd98e
@ -0,0 +1,27 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SubmitterEditFormController < ApplicationController
|
||||||
|
skip_before_action :authenticate_user!
|
||||||
|
skip_authorization_check
|
||||||
|
|
||||||
|
def update
|
||||||
|
@submitter = Submitter.find_by!(slug: params[:submitter_slug])
|
||||||
|
|
||||||
|
if @submitter.submission.archived_at? || @submitter.submission.expired? || @submitter.submission.template&.archived_at?
|
||||||
|
return redirect_to submit_form_completed_path(@submitter.slug),
|
||||||
|
alert: I18n.t('form_cannot_be_edited')
|
||||||
|
end
|
||||||
|
|
||||||
|
unless @submitter.completed_at?
|
||||||
|
return redirect_to submit_form_path(@submitter.slug)
|
||||||
|
end
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@submitter.update!(completed_at: nil, opened_at: nil)
|
||||||
|
@submitter.submission_events.where(event_type: 'complete_form').destroy_all
|
||||||
|
@submitter.documents.each(&:purge)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to submit_form_path(@submitter.slug)
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,46 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SubmitterEditValuesController < ApplicationController
|
||||||
|
NON_EDITABLE_TYPES = %w[signature initials image stamp file payment verification kba heading strikethrough].freeze
|
||||||
|
|
||||||
|
before_action :load_and_authorize_submitter
|
||||||
|
|
||||||
|
def edit
|
||||||
|
all_fields = @submitter.submission.template_fields || @submitter.submission.template.fields
|
||||||
|
@fields = all_fields.select { |f| f['submitter_uuid'] == @submitter.uuid }
|
||||||
|
.reject { |f| NON_EDITABLE_TYPES.include?(f['type']) }
|
||||||
|
end
|
||||||
|
|
||||||
|
def update
|
||||||
|
all_fields = @submitter.submission.template_fields || @submitter.submission.template.fields
|
||||||
|
editable_fields = all_fields.select { |f| f['submitter_uuid'] == @submitter.uuid }
|
||||||
|
.reject { |f| NON_EDITABLE_TYPES.include?(f['type']) }
|
||||||
|
editable_uuids = editable_fields.map { |f| f['uuid'] }
|
||||||
|
|
||||||
|
submitted_values = params[:values].to_h.slice(*editable_uuids)
|
||||||
|
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@submitter.update!(values: @submitter.values.merge(submitted_values))
|
||||||
|
|
||||||
|
@submitter.documents.each(&:purge)
|
||||||
|
|
||||||
|
SubmissionEvent.create!(
|
||||||
|
submitter: @submitter,
|
||||||
|
event_type: :admin_edit_values,
|
||||||
|
data: { user_id: current_user.id, user_email: current_user.email, updated_uuids: editable_uuids }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
Submissions::GenerateResultAttachments.call(@submitter)
|
||||||
|
|
||||||
|
redirect_to submission_path(@submitter.submission),
|
||||||
|
notice: I18n.t('submission_values_have_been_updated')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_and_authorize_submitter
|
||||||
|
@submitter = Submitter.find(params[:id])
|
||||||
|
authorize! :update, @submitter.submission
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class SubmittersReopenController < ApplicationController
|
||||||
|
before_action :load_and_authorize_submitter
|
||||||
|
|
||||||
|
def update
|
||||||
|
ActiveRecord::Base.transaction do
|
||||||
|
@submitter.update!(completed_at: nil, opened_at: nil)
|
||||||
|
|
||||||
|
@submitter.submission_events.where(event_type: 'complete_form').destroy_all
|
||||||
|
|
||||||
|
@submitter.documents.each(&:purge)
|
||||||
|
|
||||||
|
SubmissionEvent.create!(
|
||||||
|
submitter: @submitter,
|
||||||
|
event_type: :admin_reopen_form,
|
||||||
|
data: { user_id: current_user.id, user_email: current_user.email }
|
||||||
|
)
|
||||||
|
end
|
||||||
|
|
||||||
|
if @submitter.email.present?
|
||||||
|
SendSubmitterInvitationEmailJob.perform_async('submitter_id' => @submitter.id)
|
||||||
|
end
|
||||||
|
|
||||||
|
redirect_to submission_path(@submitter.submission),
|
||||||
|
notice: I18n.t('submission_has_been_reopened')
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def load_and_authorize_submitter
|
||||||
|
@submitter = Submitter.find(params[:id])
|
||||||
|
authorize! :update, @submitter.submission
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,57 @@
|
|||||||
|
<%= render 'shared/turbo_modal_large', title: t('edit_values') do %>
|
||||||
|
<div class="px-5 mb-5 mt-4">
|
||||||
|
<%= form_for '', url: submitter_edit_value_path(@submitter), method: :patch,
|
||||||
|
html: { autocomplete: 'off' }, data: { turbo_frame: :_top } do |f| %>
|
||||||
|
<% if @fields.empty? %>
|
||||||
|
<p class="text-base-content/60 text-center py-6">No editable text fields found for this submitter.</p>
|
||||||
|
<% else %>
|
||||||
|
<% field_counters = Hash.new { 0 } %>
|
||||||
|
<% @fields.each do |field| %>
|
||||||
|
<% field_counters[field['type']] += 1 %>
|
||||||
|
<% current_value = @submitter.values[field['uuid']] %>
|
||||||
|
<div class="form-control mb-4">
|
||||||
|
<label class="label py-0.5">
|
||||||
|
<span class="label-text font-medium" dir="auto">
|
||||||
|
<%= field['name'].presence || "#{field['type'].capitalize} Field #{field_counters[field['type']]}" %>
|
||||||
|
</span>
|
||||||
|
<span class="label-text-alt text-base-content/40 uppercase text-xs"><%= field['type'] %></span>
|
||||||
|
</label>
|
||||||
|
<% if field['type'] == 'select' && field['options'].present? %>
|
||||||
|
<%= select_tag "values[#{field['uuid']}]",
|
||||||
|
options_for_select(field['options'], current_value),
|
||||||
|
include_blank: true,
|
||||||
|
class: 'select select-bordered w-full' %>
|
||||||
|
<% elsif field['type'] == 'checkbox' %>
|
||||||
|
<div class="flex items-center gap-2 mt-1">
|
||||||
|
<input type="hidden" name="values[<%= field['uuid'] %>]" value="">
|
||||||
|
<input type="checkbox" name="values[<%= field['uuid'] %>]" value="true"
|
||||||
|
<%= 'checked' if current_value.to_s == 'true' %>
|
||||||
|
class="checkbox checkbox-primary" />
|
||||||
|
<span class="text-sm text-base-content/60">Checked</span>
|
||||||
|
</div>
|
||||||
|
<% elsif field['type'] == 'radio' && field['options'].present? %>
|
||||||
|
<div class="flex flex-col gap-2 mt-1">
|
||||||
|
<% field['options'].each do |opt| %>
|
||||||
|
<label class="flex items-center gap-2 cursor-pointer">
|
||||||
|
<input type="radio" name="values[<%= field['uuid'] %>]" value="<%= opt %>"
|
||||||
|
<%= 'checked' if current_value.to_s == opt.to_s %>
|
||||||
|
class="radio radio-primary radio-sm" />
|
||||||
|
<span class="text-sm"><%= opt %></span>
|
||||||
|
</label>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<%= text_field_tag "values[#{field['uuid']}]", current_value.to_s,
|
||||||
|
class: 'base-input w-full', dir: 'auto',
|
||||||
|
placeholder: field['name'].presence || field['type'] %>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<% end %>
|
||||||
|
<div class="form-control mt-5">
|
||||||
|
<%= f.button button_title(title: t('save_and_regenerate'), disabled_with: t('saving')),
|
||||||
|
class: 'base-button', disabled: @fields.empty? %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
Loading…
Reference in new issue