diff --git a/app/controllers/templates_preferences_controller.rb b/app/controllers/templates_preferences_controller.rb
index cbee0993..47e1a562 100644
--- a/app/controllers/templates_preferences_controller.rb
+++ b/app/controllers/templates_preferences_controller.rb
@@ -3,6 +3,13 @@
class TemplatesPreferencesController < ApplicationController
load_and_authorize_resource :template
+ RESETTABLE_PREFERENCE_KEYS = {
+ AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY => %w[request_email_subject request_email_body submitters],
+ AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY => %w[documents_copy_email_subject documents_copy_email_body],
+ AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY => %w[completed_notification_email_subject
+ completed_notification_email_body]
+ }.freeze
+
def show; end
def create
@@ -15,6 +22,25 @@ class TemplatesPreferencesController < ApplicationController
head :ok
end
+ def destroy
+ authorize!(:update, @template)
+
+ config_key = params[:config_key]
+ preferences_to_delete = RESETTABLE_PREFERENCE_KEYS[config_key] || []
+
+ return head :ok if preferences_to_delete.blank?
+
+ preferences_to_delete.each do |key|
+ @template.preferences.delete(key)
+ end
+
+ @template.save!
+
+ render turbo_stream: turbo_stream.replace("#{config_key}_form",
+ partial: "templates_preferences/#{config_key}_form"),
+ status: :ok
+ end
+
private
def template_params
diff --git a/app/views/templates_preferences/_submitter_completed_email_form.html.erb b/app/views/templates_preferences/_submitter_completed_email_form.html.erb
new file mode 100644
index 00000000..74626f79
--- /dev/null
+++ b/app/views/templates_preferences/_submitter_completed_email_form.html.erb
@@ -0,0 +1,66 @@
+
+ <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %>
+ <% template_email_preferences_values = @template.preferences.values_at('completed_notification_email_subject', 'completed_notification_email_body').compact_blank.presence %>
+ <% is_custom_template_email = template_email_preferences_values.present? %>
+ <% if is_custom_template_email %>
+ <%= button_to nil, template_preferences_path(@template), id: 'submitter_completed_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %>
+ <% end %>
+ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
+
+ <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY %>
+ <%= f.fields_for :preferences, Struct.new(:completed_notification_email_subject, :completed_notification_email_body, :completed_notification_email_enabled, :completed_notification_email_attach_audit, :completed_notification_email_attach_documents).new(@template.preferences['completed_notification_email_subject'].presence || configs['subject'], @template.preferences['completed_notification_email_body'].presence || configs['body'], @template.preferences['completed_notification_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['completed_notification_email_attach_audit'] != false, configs['attach_documents'] != false && @template.preferences['completed_notification_email_attach_documents'] != false) do |ff| %>
+
+
+
+
+ <%= t('attach_documents_to_the_email') %>
+
+
+ <%= ff.check_box :completed_notification_email_attach_documents, { checked: ff.object.completed_notification_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %>
+
+
+
+
+ <%= t('attach_audit_log_pdf_to_the_email') %>
+
+
+ <%= ff.check_box :completed_notification_email_attach_audit, { checked: ff.object.completed_notification_email_attach_audit != false, class: 'toggle', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %>
+
+
+
+
+ <%= t('send_emails_automatically_on_completion') %>
+
+
+ <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %>
+
+
+ <% end %>
+
+ <% end %>
+
diff --git a/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb b/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb
new file mode 100644
index 00000000..0ce23e59
--- /dev/null
+++ b/app/views/templates_preferences/_submitter_documents_copy_email_form.html.erb
@@ -0,0 +1,72 @@
+
+ <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value %>
+ <% template_email_preferences_values = @template.preferences.values_at('documents_copy_email_subject', 'documents_copy_email_body').compact_blank.presence %>
+ <% is_custom_template_email = template_email_preferences_values.present? %>
+ <% if is_custom_template_email %>
+ <%= button_to nil, template_preferences_path(@template), id: 'submitter_documents_copy_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %>
+ <% end %>
+ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
+
+ <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY %>
+ <%= f.fields_for :preferences, Struct.new(:documents_copy_email_reply_to, :documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled, :documents_copy_email_attach_audit, :documents_copy_email_attach_documents).new(@template.preferences['documents_copy_email_reply_to'].presence || configs['reply_to'], @template.preferences['documents_copy_email_subject'].presence || configs['subject'], @template.preferences['documents_copy_email_body'].presence || configs['body'], @template.preferences['documents_copy_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['documents_copy_email_attach_audit'] != false, configs['attach_documents'] != false && @template.preferences['documents_copy_email_attach_documents'] != false) do |ff| %>
+
+
+ <% if can?(:manage, :reply_to) %>
+
+ <%= ff.label :documents_copy_email_reply_to, t('reply_to'), class: 'label' %>
+ <%= ff.email_field :documents_copy_email_reply_to, class: 'base-input', dir: 'auto', placeholder: t(:email) %>
+
+ <% end %>
+
+
+ <%= t('attach_documents_to_the_email') %>
+
+
+ <%= ff.check_box :documents_copy_email_attach_documents, { checked: ff.object.documents_copy_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %>
+
+
+
+
+ <%= t('attach_audit_log_pdf_to_the_email') %>
+
+
+ <%= ff.check_box :documents_copy_email_attach_audit, { checked: ff.object.documents_copy_email_attach_audit != false, class: 'toggle', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %>
+
+
+
+
+ <%= t('send_emails_automatically_on_completion') %>
+
+
+ <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false && configs['enabled'] != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %>
+
+
+ <% end %>
+
+ <% end %>
+
diff --git a/app/views/templates_preferences/_submitter_invitation_email_form.html.erb b/app/views/templates_preferences/_submitter_invitation_email_form.html.erb
new file mode 100644
index 00000000..6f6118d6
--- /dev/null
+++ b/app/views/templates_preferences/_submitter_invitation_email_form.html.erb
@@ -0,0 +1,108 @@
+
+ <% template_email_preferences_values = @template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank %>
+ <% default_template_email_preferences_values = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body') %>
+ <% is_custom_template_email = template_email_preferences_values.present? %>
+ <% multiple_submitters = @template.submitters.size > 1 && @template.submitters.size < 5 %>
+ <% if is_custom_template_email || @template.preferences['submitters'].to_a.any? %>
+ <%= button_to nil, template_preferences_path(@template), id: 'submitter_invitation_email_reset_link', method: :delete, class: 'hidden', params: { config_key: AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY }, data: { turbo_confirm: t('are_you_sure_') }, form: { data: { close_on_submit: false } } %>
+ <% end %>
+ <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
+
+ <%= f.hidden_field :config_key, value: AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY %>
+ <%= tag.input id: 'request_email_per_submitter', value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: @template.preferences['submitters'].to_a.size > 1 %>
+
+ <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(template_email_preferences_values.presence || default_template_email_preferences_values)) do |ff| %>
+
+
+ <% end %>
+
+ <% if multiple_submitters %>
+
+ <% options = @template.submitters.map { |e| [e['name'], "request_email_#{e['uuid']}"] } %>
+
+
+ <% options.each_with_index do |(label, val), index| %>
+
+ <%= f.radio_button :selected, val, checked: index.zero?, id: "#{val}_radio", data: { action: 'click:toggle-visible#trigger' }, class: 'hidden peer' %>
+ <%= f.label :selected, label, value: val, for: "#{val}_radio", class: 'tab w-full tab-lifted peer-checked:tab-active' %>
+
+ <% end %>
+
+
+ <%= f.fields_for :preferences do |ff| %>
+ <% @template.submitters.each_with_index do |submitter, index| %>
+
+ <% submitter_preferences = f.object.preferences['submitters'].to_a.find { |e| e['uuid'] == submitter['uuid'] } || {} %>
+ <% submitter_email_preferences_values = submitter_preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence %>
+ <%= ff.fields_for :submitters, Struct.new(:request_email_subject, :request_email_body).new(*(submitter_preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || template_email_preferences_values.presence || default_template_email_preferences_values)), index: nil do |fff| %>
+ <%= fff.hidden_field :uuid, value: submitter['uuid'] %>
+
+
+ <% end %>
+
+ <% end %>
+ <% end %>
+
+ <% end %>
+ <%= f.fields_for :preferences, Struct.new(:request_email_enabled).new(@template.preferences['request_email_enabled']) do |ff| %>
+
+
+ <%= t('send_signature_request_email') %>
+
+
+ <%= ff.check_box :request_email_enabled, { checked: ff.object.request_email_enabled != false, class: 'toggle' }, 'true', 'false' %>
+
+
+ <% end %>
+
+ <% end %>
+
diff --git a/app/views/templates_preferences/show.html.erb b/app/views/templates_preferences/show.html.erb
index 54f8d83f..71c0f7e4 100644
--- a/app/views/templates_preferences/show.html.erb
+++ b/app/views/templates_preferences/show.html.erb
@@ -98,92 +98,7 @@
<%= t('signature_request_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
-
- <%= tag.input id: 'request_email_per_submitter', value: '1', name: 'request_email_per_submitter', class: 'peer', type: 'checkbox', hidden: true, checked: @template.preferences['submitters'].to_a.size > 1 %>
-
- <%= f.fields_for :preferences, Struct.new(:request_email_subject, :request_email_body).new(*(@template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))) do |ff| %>
-
-
- <% end %>
-
- <% if @template.submitters.size > 1 && @template.submitters.size < 5 %>
-
- <% options = @template.submitters.map { |e| [e['name'], "request_email_#{e['uuid']}"] } %>
-
-
- <% options.each_with_index do |(label, val), index| %>
-
- <%= f.radio_button :selected, val, checked: index.zero?, id: "#{val}_radio", data: { action: 'click:toggle-visible#trigger' }, class: 'hidden peer' %>
- <%= f.label :selected, label, value: val, for: "#{val}_radio", class: 'tab w-full tab-lifted peer-checked:tab-active' %>
-
- <% end %>
-
-
- <%= f.fields_for :preferences do |ff| %>
- <% @template.submitters.each_with_index do |submitter, index| %>
-
- <% submitter_preferences = f.object.preferences['submitters'].to_a.find { |e| e['uuid'] == submitter['uuid'] } || {} %>
- <%= ff.fields_for :submitters, Struct.new(:request_email_subject, :request_email_body).new(*(submitter_preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || @template.preferences.values_at('request_email_subject', 'request_email_body').compact_blank.presence || AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY).value.values_at('subject', 'body'))), index: nil do |fff| %>
- <%= fff.hidden_field :uuid, value: submitter['uuid'] %>
-
- <%= fff.label :request_email_subject, t('email_subject'), class: 'label' %>
- <%= fff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %>
-
-
- <% end %>
-
- <% end %>
- <% end %>
-
- <% end %>
- <%= f.fields_for :preferences, Struct.new(:request_email_enabled).new(@template.preferences['request_email_enabled']) do |ff| %>
-
-
- <%= 'Send signature request email' %>
-
-
- <%= ff.check_box :request_email_enabled, { checked: ff.object.request_email_enabled != false, class: 'toggle' }, 'true', 'false' %>
-
-
- <% end %>
-
- <% end %>
+ <%= render 'templates_preferences/submitter_invitation_email_form' %>
@@ -192,63 +107,7 @@
<%= t('documents_copy_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
-
- <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_DOCUMENTS_COPY_EMAIL_KEY).value %>
- <%= f.fields_for :preferences, Struct.new(:documents_copy_email_reply_to, :documents_copy_email_subject, :documents_copy_email_body, :documents_copy_email_enabled, :documents_copy_email_attach_audit, :documents_copy_email_attach_documents).new(@template.preferences['documents_copy_email_reply_to'].presence || configs['reply_to'], @template.preferences['documents_copy_email_subject'].presence || configs['subject'], @template.preferences['documents_copy_email_body'].presence || configs['body'], @template.preferences['documents_copy_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['documents_copy_email_attach_audit'] != false, configs['attach_documents'] != false && @template.preferences['documents_copy_email_attach_documents'] != false) do |ff| %>
-
- <%= ff.label :documents_copy_email_subject, t('email_subject'), class: 'label' %>
- <%= ff.text_field :documents_copy_email_subject, required: true, class: 'base-input', dir: 'auto' %>
-
-
- <% if can?(:manage, :reply_to) %>
-
- <%= ff.label :documents_copy_email_reply_to, t('reply_to'), class: 'label' %>
- <%= ff.email_field :documents_copy_email_reply_to, class: 'base-input', dir: 'auto', placeholder: t(:email) %>
-
- <% end %>
-
-
- <%= t('attach_documents_to_the_email') %>
-
-
- <%= ff.check_box :documents_copy_email_attach_documents, { checked: ff.object.documents_copy_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %>
-
-
-
-
- <%= t('attach_audit_log_pdf_to_the_email') %>
-
-
- <%= ff.check_box :documents_copy_email_attach_audit, { checked: ff.object.documents_copy_email_attach_audit != false, class: 'toggle', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %>
-
-
-
-
- <%= t('send_emails_automatically_on_completion') %>
-
-
- <%= ff.check_box :documents_copy_email_enabled, { checked: ff.object.documents_copy_email_enabled != false && configs['enabled'] != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %>
-
-
- <% end %>
-
- <% end %>
+ <%= render 'templates_preferences/submitter_documents_copy_email_form' %>
@@ -257,57 +116,7 @@
<%= t('completed_notification_email') %>
- <%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' }, data: { close_on_submit: false } do |f| %>
-
- <% configs = AccountConfigs.find_or_initialize_for_key(current_account, AccountConfig::SUBMITTER_COMPLETED_EMAIL_KEY).value %>
- <%= f.fields_for :preferences, Struct.new(:completed_notification_email_subject, :completed_notification_email_body, :completed_notification_email_enabled, :completed_notification_email_attach_audit, :completed_notification_email_attach_documents).new(@template.preferences['completed_notification_email_subject'].presence || configs['subject'], @template.preferences['completed_notification_email_body'].presence || configs['body'], @template.preferences['completed_notification_email_enabled'], configs['attach_audit_log'] != false && @template.preferences['completed_notification_email_attach_audit'] != false, configs['attach_documents'] != false && @template.preferences['completed_notification_email_attach_documents'] != false) do |ff| %>
-
- <%= ff.label :completed_notification_email_subject, t('email_subject'), class: 'label' %>
- <%= ff.text_field :completed_notification_email_subject, required: true, class: 'base-input', dir: 'auto' %>
-
-
-
-
- <%= t('attach_documents_to_the_email') %>
-
-
- <%= ff.check_box :completed_notification_email_attach_documents, { checked: ff.object.completed_notification_email_attach_documents != false, class: 'toggle', disabled: configs['attach_documents'] == false }, 'true', 'false' %>
-
-
-
-
- <%= t('attach_audit_log_pdf_to_the_email') %>
-
-
- <%= ff.check_box :completed_notification_email_attach_audit, { checked: ff.object.completed_notification_email_attach_audit != false, class: 'toggle', disabled: configs['attach_audit_log'] == false }, 'true', 'false' %>
-
-
-
-
- <%= t('send_emails_automatically_on_completion') %>
-
-
- <%= ff.check_box :completed_notification_email_enabled, { checked: ff.object.completed_notification_email_enabled != false, class: 'toggle', disabled: configs['enabled'] == false }, 'true', 'false' %>
-
-
- <% end %>
-
- <% end %>
+ <%= render 'templates_preferences/submitter_completed_email_form' %>
@@ -359,9 +168,9 @@
<%= t('share_template_with_test_mode') %>
-
- <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts) %>
-
+
+ <%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts) %>
+
<% end %>
diff --git a/config/locales/i18n.yml b/config/locales/i18n.yml
index 30a30231..92d43e72 100644
--- a/config/locales/i18n.yml
+++ b/config/locales/i18n.yml
@@ -840,6 +840,8 @@ en: &en
desktop: Desktop
mobile: Mobile
tablet: Tablet
+ reset_default: Reset default
+ send_signature_request_email: Send signature request email
submission_sources:
api: API
bulk: Bulk Send
@@ -1764,6 +1766,8 @@ es: &es
desktop: Escritorio
mobile: Móvil
tablet: Tableta
+ reset_default: Restablecer por defecto
+ send_signature_request_email: Enviar correo de solicitud de firma
submission_sources:
api: API
bulk: Envío masivo
@@ -2689,6 +2693,8 @@ it: &it
desktop: Desktop
mobile: Mobile
tablet: Tablet
+ reset_default: Reimposta predefinito
+ send_signature_request_email: Invia email di richiesta firma
submission_sources:
api: API
bulk: Invio massivo
@@ -3611,6 +3617,8 @@ fr: &fr
desktop: Bureau
mobile: Mobile
tablet: Tablette
+ reset_default: Réinitialiser par défaut
+ send_signature_request_email: Envoyer un e-mail de demande de signature
submission_sources:
api: API
bulk: Envoi en masse
@@ -4537,6 +4545,8 @@ pt: &pt
desktop: Computador
mobile: Celular
tablet: Tablet
+ reset_default: Redefinir para padrão
+ send_signature_request_email: Enviar e-mail de solicitação de assinatura
submission_sources:
api: API
bulk: Envio em massa
@@ -5463,6 +5473,8 @@ de: &de
desktop: Desktop
mobile: Mobil
tablet: Tablet
+ reset_default: Standard zurücksetzen
+ send_signature_request_email: Signaturanfrage-E-Mail senden
submission_sources:
api: API
bulk: Massenversand
@@ -6750,6 +6762,8 @@ nl: &nl
desktop: Desktop
mobile: Mobiel
tablet: Tablet
+ reset_default: Standaard herstellen
+ send_signature_request_email: E-mail met handtekeningaanvraag verzenden
submission_sources:
api: API
bulk: Bulkverzending
diff --git a/config/routes.rb b/config/routes.rb
index 20a3035d..05abbfc4 100644
--- a/config/routes.rb
+++ b/config/routes.rb
@@ -108,7 +108,7 @@ Rails.application.routes.draw do
resource :preview, only: %i[show], controller: 'templates_preview'
resource :form, only: %i[show], controller: 'templates_form_preview'
resource :code_modal, only: %i[show], controller: 'templates_code_modal'
- resource :preferences, only: %i[show create], controller: 'templates_preferences'
+ resource :preferences, only: %i[show create destroy], controller: 'templates_preferences'
resource :share_link, only: %i[show create], controller: 'templates_share_link'
resources :recipients, only: %i[create], controller: 'templates_recipients'
resources :prefillable_fields, only: %i[create], controller: 'templates_prefillable_fields'