mirror of https://github.com/docusealco/docuseal
				
				
				
			
							parent
							
								
									73423a6f44
								
							
						
					
					
						commit
						377244f948
					
				| @ -0,0 +1,38 @@ | |||||||
|  | # frozen_string_literal: true | ||||||
|  | 
 | ||||||
|  | class TemplatesFormPreviewController < ApplicationController | ||||||
|  |   PRELOAD_ALL_PAGES_AMOUNT = 200 | ||||||
|  | 
 | ||||||
|  |   layout 'form' | ||||||
|  | 
 | ||||||
|  |   load_and_authorize_resource :template | ||||||
|  | 
 | ||||||
|  |   def show | ||||||
|  |     @submitter = Submitter.new(uuid: params[:uuid] || @template.submitters.first['uuid'], | ||||||
|  |                                account: current_account, | ||||||
|  |                                submission: @template.submissions.new(template_submitters: @template.submitters, | ||||||
|  |                                                                      account: current_account)) | ||||||
|  | 
 | ||||||
|  |     @submitter.submission.submitters = @template.submitters.map { |item| Submitter.new(uuid: item['uuid']) } | ||||||
|  | 
 | ||||||
|  |     ActiveRecord::Associations::Preloader.new( | ||||||
|  |       records: [@submitter], | ||||||
|  |       associations: [submission: [:template, { template_schema_documents: :blob }]] | ||||||
|  |     ).call | ||||||
|  | 
 | ||||||
|  |     total_pages = | ||||||
|  |       @submitter.submission.template_schema_documents.sum { |e| e.metadata.dig('pdf', 'number_of_pages').to_i } | ||||||
|  | 
 | ||||||
|  |     if total_pages < PRELOAD_ALL_PAGES_AMOUNT | ||||||
|  |       ActiveRecord::Associations::Preloader.new( | ||||||
|  |         records: @submitter.submission.template_schema_documents, | ||||||
|  |         associations: [:blob, { preview_images_attachments: :blob }] | ||||||
|  |       ).call | ||||||
|  |     end | ||||||
|  | 
 | ||||||
|  |     @attachments_index = ActiveStorage::Attachment.where(record: @submitter.submission.submitters, name: :attachments) | ||||||
|  |                                                   .preload(:blob).index_by(&:uuid) | ||||||
|  | 
 | ||||||
|  |     @form_configs = Submitters::FormConfigs.call(@submitter) | ||||||
|  |   end | ||||||
|  | end | ||||||
| @ -1,3 +1,3 @@ | |||||||
| <div class="flex mt-4"> | <div class="flex mt-4"> | ||||||
|   <%= render 'docuseal_logo' %> |   <%= render 'submit_form/docuseal_logo' %> | ||||||
| </div> | </div> | ||||||
|  | |||||||
| @ -1,3 +1,3 @@ | |||||||
| <% data_attachments = attachments_index.values.select { |e| e.record_id == submitter.id }.to_json(only: %i[uuid], methods: %i[url filename content_type]) %> | <% data_attachments = attachments_index.values.select { |e| e.record_id == submitter.id }.to_json(only: %i[uuid], methods: %i[url filename content_type]) %> | ||||||
| <% data_fields = (submitter.submission.template_fields || submitter.submission.template.fields).select { |f| f['submitter_uuid'] == submitter.uuid }.to_json %> | <% data_fields = (submitter.submission.template_fields || submitter.submission.template.fields).select { |f| f['submitter_uuid'] == submitter.uuid }.to_json %> | ||||||
| <submission-form data-is-demo="<%= Docuseal.demo? %>" data-with-confetti="<%= configs[:with_confetti] %>" data-completed-redirect-url="<%= submitter.preferences['completed_redirect_url'] %>" data-completed-message="<%= configs[:completed_message].to_json %>" data-completed-button="<%= configs[:completed_button].to_json %>" data-go-to-last="<%= submitter.preferences.key?('go_to_last') ? submitter.preferences['go_to_last'] : submitter.opened_at? %>" data-submitter="<%= submitter.to_json(only: %i[uuid slug name phone email]) %>" data-can-send-email="<%= Accounts.can_send_emails?(submitter.submission.account) %>" data-attachments="<%= data_attachments %>" data-fields="<%= data_fields %>" data-values="<%= submitter.values.to_json %>" data-with-typed-signature="<%= configs[:with_typed_signature] %>" data-previous-signature-value="<%= local_assigns[:signature_attachment]&.uuid %>" data-remember-signature="<%= configs[:prefill_signature] %>"></submission-form> | <submission-form data-is-demo="<%= Docuseal.demo? %>" data-with-confetti="<%= configs[:with_confetti] %>" data-completed-redirect-url="<%= submitter.preferences['completed_redirect_url'] %>" data-completed-message="<%= configs[:completed_message].to_json %>" data-completed-button="<%= configs[:completed_button].to_json %>" data-go-to-last="<%= submitter.preferences.key?('go_to_last') ? submitter.preferences['go_to_last'] : submitter.opened_at? %>" data-submitter="<%= submitter.to_json(only: %i[uuid slug name phone email]) %>" data-can-send-email="<%= Accounts.can_send_emails?(submitter.submission.account) %>" data-attachments="<%= data_attachments %>" data-fields="<%= data_fields %>" data-values="<%= submitter.values.to_json %>" data-with-typed-signature="<%= configs[:with_typed_signature] %>" data-previous-signature-value="<%= local_assigns[:signature_attachment]&.uuid %>" data-remember-signature="<%= configs[:prefill_signature] %>" data-dry-run="<%= local_assigns[:dry_run] %>" data-expand="<%= local_assigns[:expand] %>" data-scroll-padding="<%= local_assigns[:scroll_padding] %>"></submission-form> | ||||||
|  | |||||||
| @ -0,0 +1,24 @@ | |||||||
|  | <% banner_html = capture do %> | ||||||
|  |   <div class="sticky top-0 z-50 bg-base-100 py-2 px-2 flex items-center" style="margin: 0px -8px -16px -8px"> | ||||||
|  |     <div class="text-xl md:text-3xl font-semibold focus:text-clip" style="width: 100%; overflow: hidden; text-overflow: ellipsis; white-space: nowrap;"> | ||||||
|  |       <%= @template.name %> | ||||||
|  |     </div> | ||||||
|  |     <div class="flex items-center" style="margin-left: 20px; flex-shrink: 0"> | ||||||
|  |       <% if @template.submitters.size > 1 %> | ||||||
|  |         <form action="<%= template_form_path(@template) %>" method="get" class="mr-3"> | ||||||
|  |           <select onchange="this.form.submit()" name="uuid" class="select base-input text-center font-normal" style="width: 180px; flex-shrink: 0;"> | ||||||
|  |             <% @template.submitters.each do |submitter| %> | ||||||
|  |               <%= tag.option(value: submitter['uuid'], selected: submitter['uuid'] == @submitter.uuid) do %> | ||||||
|  |                 <%= submitter['name'] %> | ||||||
|  |               <% end %> | ||||||
|  |             <% end %> | ||||||
|  |           </select> | ||||||
|  |         </form> | ||||||
|  |       <% end %> | ||||||
|  |       <a href="<%= edit_template_path(@template) %>" class="base-button" data-turbo="false" style="flex-shrink: 0; padding: 0px 24px;"> | ||||||
|  |         Exit Preview | ||||||
|  |       </a> | ||||||
|  |     </div> | ||||||
|  |   </div> | ||||||
|  | <% end %> | ||||||
|  | <%= render template: 'submit_form/show', locals: { dry_run: true, expand: false, banner_html:, scroll_padding: '-120px' } %> | ||||||
					Loading…
					
					
				
		Reference in new issue