mirror of https://github.com/docusealco/docuseal
parent
fefd138dfd
commit
1e57c1ace7
@ -0,0 +1,22 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class TemplatesPreferencesController < ApplicationController
|
||||||
|
load_and_authorize_resource :template
|
||||||
|
|
||||||
|
def show; end
|
||||||
|
|
||||||
|
def create
|
||||||
|
authorize!(:update, @template)
|
||||||
|
|
||||||
|
@template.preferences = @template.preferences.merge(template_params[:preferences])
|
||||||
|
@template.save!
|
||||||
|
|
||||||
|
head :ok
|
||||||
|
end
|
||||||
|
|
||||||
|
private
|
||||||
|
|
||||||
|
def template_params
|
||||||
|
params.require(:template).permit(preferences: %i[bcc_completed request_email_subject request_email_body])
|
||||||
|
end
|
||||||
|
end
|
||||||
@ -0,0 +1,35 @@
|
|||||||
|
export default class extends HTMLElement {
|
||||||
|
connectedCallback () {
|
||||||
|
document.addEventListener('turbo:submit-end', this.onSubmitEnd)
|
||||||
|
|
||||||
|
this.form.addEventListener('submit', this.onSubmit)
|
||||||
|
}
|
||||||
|
|
||||||
|
disconnectedCallback () {
|
||||||
|
document.removeEventListener('turbo:submit-end', this.onSubmitEnd)
|
||||||
|
|
||||||
|
this.form.removeEventListener('submit', this.onSubmit)
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmit = () => {
|
||||||
|
this.element.classList.add('invisible')
|
||||||
|
}
|
||||||
|
|
||||||
|
onSubmitEnd = (event) => {
|
||||||
|
if (event.target === this.form) {
|
||||||
|
const resp = event.detail?.formSubmission?.result?.fetchResponse?.response
|
||||||
|
|
||||||
|
if (resp?.status / 100 === 2) {
|
||||||
|
this.element.classList.remove('invisible')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
get element () {
|
||||||
|
return document.getElementById(this.dataset.elementId)
|
||||||
|
}
|
||||||
|
|
||||||
|
get form () {
|
||||||
|
return this.closest('form')
|
||||||
|
}
|
||||||
|
}
|
||||||
|
After Width: | Height: | Size: 602 B |
|
After Width: | Height: | Size: 872 B |
@ -0,0 +1,22 @@
|
|||||||
|
<turbo-frame id="drawer">
|
||||||
|
<turbo-modal class="modal modal-open items-start !animate-none justify-end overflow-y-auto !justify-normal md:!justify-end" data-close-after-submit="<%= local_assigns.key?(:close_after_submit) ? local_assigns[:close_after_submit] : true %>">
|
||||||
|
<div class="absolute top-0 bottom-0 right-0 left-0" data-action="click:turbo-modal#close"></div>
|
||||||
|
<div class="bg-base-100 min-h-screen max-h-screen relative w-full relative overflow-y-auto">
|
||||||
|
<% if local_assigns[:title] %>
|
||||||
|
<div class="flex justify-between bg-base-100 py-2 px-4 items-center border-b pb-2 font-medium">
|
||||||
|
<span>
|
||||||
|
<%= local_assigns[:title] %>
|
||||||
|
</span>
|
||||||
|
<a href="#" class="text-xl" data-action="click:turbo-modal#close">×</a>
|
||||||
|
</div>
|
||||||
|
<% else %>
|
||||||
|
<span data-action="click:turbo-modal#close" class="absolute btn border border-base-100 bg-base-100 hover:bg-base-300 hover:border-base-300 btn-primary !text-base btn-sm btn-circle" style="left: -40px; top: 6px">
|
||||||
|
×
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
<div class="w-full md:w-[620px] overflow-y-auto" style="max-height: calc(100vh - <%= local_assigns[:title] ? '45px' : '0px' %>)">
|
||||||
|
<%= yield %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</turbo-modal>
|
||||||
|
</turbo-frame>
|
||||||
@ -0,0 +1,100 @@
|
|||||||
|
<%= render 'shared/turbo_drawer', title: 'Preferences', close_after_submit: false do %>
|
||||||
|
<% options = [['General', 'general'], ['API and Embedding', 'api']] %>
|
||||||
|
<toggle-visible data-element-ids="<%= options.map(&:last).to_json %>" class="relative text-center mt-3 block">
|
||||||
|
<div class="join">
|
||||||
|
<% options.each_with_index do |(label, value), index| %>
|
||||||
|
<span>
|
||||||
|
<%= radio_button_tag 'option', value, value == 'general', class: 'peer hidden', data: { action: 'change:toggle-visible#trigger' } %>
|
||||||
|
<label for="option_<%= value %>" class="<%= '!rounded-s-full' if index.zero? %> btn btn-focus btn-sm join-item md:w-48 peer-checked:btn-active normal-case <%= 'px-8 md:px-0' if value == 'general' %>">
|
||||||
|
<%= label %>
|
||||||
|
</label>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
</toggle-visible>
|
||||||
|
<div id="general" class="px-4 mb-4">
|
||||||
|
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-1' } do |f| %>
|
||||||
|
<toggle-on-submit data-element-id="email_saved_alert"></toggle-on-submit>
|
||||||
|
<%= 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| %>
|
||||||
|
<div class="form-control">
|
||||||
|
<%= ff.label :request_email_subject, 'Email subject', class: 'label' %>
|
||||||
|
<%= ff.text_field :request_email_subject, required: true, class: 'base-input', dir: 'auto' %>
|
||||||
|
</div>
|
||||||
|
<div class="form-control">
|
||||||
|
<div class="flex items-center">
|
||||||
|
<%= ff.label :request_email_body, 'Email body', class: 'label' %>
|
||||||
|
<span class="tooltip tooltip-right" data-tip="Use following placeholders text: <%= AccountConfig::DEFAULT_VALUES.dig(AccountConfig::SUBMITTER_INVITATION_EMAIL_KEY, 'body').scan(/{{.*?}}/).join(', ') %>">
|
||||||
|
<%= svg_icon('info_circle', class: 'w-4 h-4') %>
|
||||||
|
</span>
|
||||||
|
</div>
|
||||||
|
<autoresize-textarea>
|
||||||
|
<%= ff.text_area :request_email_body, required: true, class: 'base-input w-full py-2', dir: 'auto' %>
|
||||||
|
</autoresize-textarea>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div class="form-control pt-2">
|
||||||
|
<%= f.button button_title(title: 'Save', disabled_with: 'Saving'), class: 'base-button' %>
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<span id="email_saved_alert" class="text-sm invisible font-normal mt-0.5">Changes have been saved</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<%= form_for @template, url: template_preferences_path(@template), method: :post, html: { autocomplete: 'off', class: 'mt-2' } do |f| %>
|
||||||
|
<toggle-on-submit data-element-id="bcc_saved_alert"></toggle-on-submit>
|
||||||
|
<%= f.fields_for :preferences, Struct.new(:bcc_completed).new(@template.preferences['bcc_completed']) do |ff| %>
|
||||||
|
<div class="form-control">
|
||||||
|
<%= ff.label :bcc_completed, class: 'label' do %>
|
||||||
|
<span class="flex items-center space-x-1 justify-between w-full">
|
||||||
|
<span>
|
||||||
|
Completed documents BCC address
|
||||||
|
</span>
|
||||||
|
</span>
|
||||||
|
<% end %>
|
||||||
|
<%= ff.email_field :bcc_completed, autocomplete: 'off', class: 'base-input' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div class="form-control pt-3">
|
||||||
|
<%= f.button button_title(title: 'Save', disabled_with: 'Updating'), class: 'base-button' %>
|
||||||
|
<div class="flex justify-center">
|
||||||
|
<span id="bcc_saved_alert" class="text-sm invisible font-normal mt-0.5">Changes have been saved</span>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<%= render 'templates_code_modal/preferences' %>
|
||||||
|
</div>
|
||||||
|
<div id="api" class="hidden mt-2 mb-4 px-4">
|
||||||
|
<div>
|
||||||
|
<label class="text-sm font-semibold" for="template_id">
|
||||||
|
Template ID
|
||||||
|
</label>
|
||||||
|
<div class="flex gap-2 mb-4 mt-2">
|
||||||
|
<input id="template_id" type="text" value="<%= @template.id %>" class="base-input w-full" autocomplete="off" readonly>
|
||||||
|
<%= render 'shared/clipboard_copy', icon: 'copy', text: @template.id, class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy', copied_title: 'Copied' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<div>
|
||||||
|
<label class="text-sm font-semibold" for="embedding_url">
|
||||||
|
Embedding URL
|
||||||
|
</label>
|
||||||
|
<div class="flex gap-2 mb-4 mt-2">
|
||||||
|
<input id="embedding_url" type="text" value="<%= start_form_url(slug: @template.slug) %>" class="base-input w-full" autocomplete="off" readonly>
|
||||||
|
<%= render 'shared/clipboard_copy', icon: 'copy', text: start_form_url(slug: @template.slug), class: 'base-button', icon_class: 'w-6 h-6 text-white', copy_title: 'Copy', copied_title: 'Copied' %>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
<%= render 'templates_code_modal/placeholder' %>
|
||||||
|
<%= render 'templates/embedding', template: @template %>
|
||||||
|
<% if can?(:manage, TemplateSharing.new(template: @template)) %>
|
||||||
|
<%= form_for '', url: template_sharings_testing_index_path, method: :post, html: { class: 'mt-1' } do |f| %>
|
||||||
|
<%= f.hidden_field :template_id, value: @template.id %>
|
||||||
|
<div class="flex items-center justify-between">
|
||||||
|
<span>
|
||||||
|
Share template with Test Environment
|
||||||
|
</span>
|
||||||
|
<%= f.check_box :value, class: 'toggle', checked: @template.template_sharings.exists?(account_id: current_account.testing_accounts), onchange: 'this.form.requestSubmit()' %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
<div class="mb-4">
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
|
</div>
|
||||||
|
<% end %>
|
||||||
@ -0,0 +1,15 @@
|
|||||||
|
# frozen_string_literal: true
|
||||||
|
|
||||||
|
class AddPreferencesToTemplates < ActiveRecord::Migration[7.1]
|
||||||
|
class MigrationTemplate < ApplicationRecord
|
||||||
|
self.table_name = 'templates'
|
||||||
|
end
|
||||||
|
|
||||||
|
def change
|
||||||
|
add_column :templates, :preferences, :text
|
||||||
|
|
||||||
|
MigrationTemplate.where(preferences: nil).update_all(preferences: '{}')
|
||||||
|
|
||||||
|
change_column_null :templates, :preferences, false
|
||||||
|
end
|
||||||
|
end
|
||||||
Loading…
Reference in new issue