diff --git a/app/controllers/api/templates_controller.rb b/app/controllers/api/templates_controller.rb index 0ccc5b39..88a606f4 100644 --- a/app/controllers/api/templates_controller.rb +++ b/app/controllers/api/templates_controller.rb @@ -109,7 +109,7 @@ module Api submitters: [%i[name uuid is_requester invite_by_uuid optional_invite_by_uuid linked_to_uuid email]], fields: [[:uuid, :submitter_uuid, :name, :type, :required, :readonly, :default_value, - :title, :description, + :title, :description, :prefillable, { preferences: {}, conditions: [%i[field_uuid value action operation]], options: [%i[value uuid]], diff --git a/app/controllers/submissions_controller.rb b/app/controllers/submissions_controller.rb index 9d4de051..4f31322c 100644 --- a/app/controllers/submissions_controller.rb +++ b/app/controllers/submissions_controller.rb @@ -32,10 +32,7 @@ class SubmissionsController < ApplicationController def create save_template_message(@template, params) if params[:save_message] == '1' - if params[:is_custom_message] != '1' - params.delete(:subject) - params.delete(:body) - end + [params.delete(:subject), params.delete(:body)] if params[:is_custom_message] != '1' submissions = if params[:emails].present? @@ -46,11 +43,16 @@ class SubmissionsController < ApplicationController emails: params[:emails], params: params.merge('send_completed_email' => true)) else + submissions_attrs = submissions_params[:submission].to_h.values + + submissions_attrs, = + Submissions::NormalizeParamUtils.normalize_submissions_params!(submissions_attrs, @template) + Submissions.create_from_submitters(template: @template, user: current_user, source: :invite, submitters_order: params[:preserve_order] == '1' ? 'preserved' : 'random', - submissions_attrs: submissions_params[:submission].to_h.values, + submissions_attrs:, params: params.merge('send_completed_email' => true)) end @@ -62,9 +64,8 @@ class SubmissionsController < ApplicationController redirect_to template_path(@template), notice: I18n.t('new_recipients_have_been_added') rescue Submissions::CreateFromSubmitters::BaseError => e - render turbo_stream: turbo_stream.replace(:submitters_error, - partial: 'submissions/error', - locals: { error: e.message }), + render turbo_stream: turbo_stream.replace(:submitters_error, partial: 'submissions/error', + locals: { error: e.message }), status: :unprocessable_entity end @@ -95,7 +96,7 @@ class SubmissionsController < ApplicationController end def submissions_params - params.permit(submission: { submitters: [%i[uuid email phone name]] }) + params.permit(submission: { submitters: [:uuid, :email, :phone, :name, { values: {} }] }) end def load_template diff --git a/app/controllers/templates_controller.rb b/app/controllers/templates_controller.rb index fba51b90..73e68e85 100644 --- a/app/controllers/templates_controller.rb +++ b/app/controllers/templates_controller.rb @@ -120,7 +120,7 @@ class TemplatesController < ApplicationController submitters: [%i[name uuid is_requester linked_to_uuid invite_by_uuid optional_invite_by_uuid email]], fields: [[:uuid, :submitter_uuid, :name, :type, :required, :readonly, :default_value, - :title, :description, + :title, :description, :prefillable, { preferences: {}, conditions: [%i[field_uuid value action operation]], options: [%i[value uuid]], diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb index 31ac7190..cbee0993 100644 --- a/app/controllers/templates_preferences_controller.rb +++ b/app/controllers/templates_preferences_controller.rb @@ -27,7 +27,7 @@ class TemplatesPreferencesController < ApplicationController completed_redirect_url validate_unique_submitters require_all_submitters submitters_order require_phone_2fa default_expire_at_duration shared_link_2fa - default_expire_at + default_expire_at request_email_enabled completed_notification_email_subject completed_notification_email_body completed_notification_email_enabled completed_notification_email_attach_audit] + [completed_message: %i[title body], diff --git a/app/controllers/templates_prefillable_fields_controller.rb b/app/controllers/templates_prefillable_fields_controller.rb new file mode 100644 index 00000000..6202ca5c --- /dev/null +++ b/app/controllers/templates_prefillable_fields_controller.rb @@ -0,0 +1,26 @@ +# frozen_string_literal: true + +class TemplatesPrefillableFieldsController < ApplicationController + PREFILLABLE_FIELD_TYPES = %w[text number cells date checkbox select radio phone].freeze + + load_and_authorize_resource :template + + def create + authorize!(:update, @template) + + field = @template.fields.find { |f| f['uuid'] == params[:field_uuid] } + + if params[:prefillable] == 'false' + field.delete('prefillable') + field.delete('readonly') + elsif params[:prefillable] == 'true' + field['prefillable'] = true + field['readonly'] = true + end + + @template.save! + + render turbo_stream: turbo_stream.replace(:prefillable_fields_list, partial: 'list', + locals: { template: @template }) + end +end diff --git a/app/javascript/template_builder/area.vue b/app/javascript/template_builder/area.vue index 9622b503..ad8ab7d5 100644 --- a/app/javascript/template_builder/area.vue +++ b/app/javascript/template_builder/area.vue @@ -141,6 +141,7 @@ :with-required="false" :with-areas="false" :with-signature-id="withSignatureId" + :with-prefillable="withPrefillable" @click-formula="isShowFormulaModal = true" @click-font="isShowFontModal = true" @click-description="isShowDescriptionModal = true" @@ -353,6 +354,11 @@ export default { required: false, default: null }, + withPrefillable: { + type: Boolean, + required: false, + default: false + }, defaultSubmitters: { type: Array, required: false, diff --git a/app/javascript/template_builder/builder.vue b/app/javascript/template_builder/builder.vue index ef0748f6..cd2339f4 100644 --- a/app/javascript/template_builder/builder.vue +++ b/app/javascript/template_builder/builder.vue @@ -331,6 +331,7 @@ :default-fields="[...defaultRequiredFields, ...defaultFields]" :allow-draw="!onlyDefinedFields || drawField" :with-signature-id="withSignatureId" + :with-prefillable="withPrefillable" :data-document-uuid="document.uuid" :default-submitters="defaultSubmitters" :drag-field-placeholder="fieldsDragFieldRef.value || dragField" @@ -438,6 +439,7 @@ :field-types="fieldTypes" :with-sticky-submitters="withStickySubmitters" :with-signature-id="withSignatureId" + :with-prefillable="withPrefillable" :only-defined-fields="onlyDefinedFields" :editable="editable" :show-tour-start-form="showTourStartForm" @@ -543,7 +545,6 @@ export default { withPayment: this.withPayment, isPaymentConnected: this.isPaymentConnected, withFormula: this.withFormula, - withSignatureId: this.withSignatureId, withConditions: this.withConditions, isInlineSize: this.isInlineSize, defaultDrawFieldType: this.defaultDrawFieldType, @@ -802,6 +803,13 @@ export default { language () { return this.locale.split('-')[0].toLowerCase() }, + withPrefillable () { + if (this.template.fields) { + return this.template.fields.some((f) => f.prefillable) + } else { + return false + } + }, isInlineSize () { return CSS.supports('container-type: size') }, diff --git a/app/javascript/template_builder/document.vue b/app/javascript/template_builder/document.vue index abba5052..e512fb2c 100644 --- a/app/javascript/template_builder/document.vue +++ b/app/javascript/template_builder/document.vue @@ -11,6 +11,7 @@ :areas="areasIndex[index]" :allow-draw="allowDraw" :with-signature-id="withSignatureId" + :with-prefillable="withPrefillable" :is-drag="isDrag" :with-field-placeholder="withFieldPlaceholder" :default-fields="defaultFields" @@ -72,6 +73,11 @@ export default { required: false, default: null }, + withPrefillable: { + type: Boolean, + required: false, + default: false + }, drawFieldType: { type: String, required: false, diff --git a/app/javascript/template_builder/field.vue b/app/javascript/template_builder/field.vue index f9e1c0e9..b12a33d9 100644 --- a/app/javascript/template_builder/field.vue +++ b/app/javascript/template_builder/field.vue @@ -126,6 +126,7 @@ :default-field="defaultField" :editable="editable" :with-signature-id="withSignatureId" + :with-prefillable="withPrefillable" :background-color="dropdownBgColor" @click-formula="isShowFormulaModal = true" @click-font="isShowFontModal = true" @@ -308,6 +309,11 @@ export default { required: false, default: null }, + withPrefillable: { + type: Boolean, + required: false, + default: false + }, withOptions: { type: Boolean, required: false, diff --git a/app/javascript/template_builder/field_settings.vue b/app/javascript/template_builder/field_settings.vue index b78c6b4e..22821f4c 100644 --- a/app/javascript/template_builder/field_settings.vue +++ b/app/javascript/template_builder/field_settings.vue @@ -406,6 +406,21 @@ {{ t('read_only') }} +