mirror of https://github.com/docusealco/docuseal
parent
126a36dbf3
commit
71b8cc7172
@ -0,0 +1,49 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
class TemplatesRecipientsController < ApplicationController
|
||||
load_and_authorize_resource :template
|
||||
|
||||
def create
|
||||
authorize!(:update, @template)
|
||||
|
||||
@template.submitters =
|
||||
submitters_params.map { |s| s.reject { |_, v| v.is_a?(String) && v.blank? } }
|
||||
|
||||
@template.save!
|
||||
|
||||
render json: { submitters: @template.submitters }
|
||||
end
|
||||
|
||||
private
|
||||
|
||||
def submitters_params
|
||||
params.require(:template).permit(
|
||||
submitters: [%i[name uuid is_requester linked_to_uuid email option]]
|
||||
).fetch(:submitters, {}).values.filter_map do |s|
|
||||
next if s[:uuid].blank?
|
||||
|
||||
if s[:is_requester] == '1'
|
||||
s[:is_requester] = true
|
||||
else
|
||||
s.delete(:is_requester)
|
||||
end
|
||||
|
||||
option = s.delete(:option)
|
||||
|
||||
if option.present?
|
||||
case option
|
||||
when 'is_requester'
|
||||
s[:is_requester] = true
|
||||
when 'not_set'
|
||||
s.delete(:is_requester)
|
||||
s.delete(:email)
|
||||
s.delete(:linked_to_uuid)
|
||||
when /\Alinked_to_(.*)\z/
|
||||
s[:linked_to_uuid] = ::Regexp.last_match(-1)
|
||||
end
|
||||
end
|
||||
|
||||
s
|
||||
end
|
||||
end
|
||||
end
|
||||
@ -0,0 +1,31 @@
|
||||
export default class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
if (this.target) {
|
||||
this.input.value = this.target.value
|
||||
|
||||
this.target.addEventListener('input', (e) => {
|
||||
this.input.value = e.target.value
|
||||
})
|
||||
|
||||
this.target.addEventListener('linked-input.update', (e) => {
|
||||
this.input.value = e.target.value
|
||||
})
|
||||
}
|
||||
}
|
||||
|
||||
get input () {
|
||||
return this.querySelector('input')
|
||||
}
|
||||
|
||||
get target () {
|
||||
if (this.dataset.targetId) {
|
||||
const listItem = this.closest('[data-targets="dynamic-list.items"]')
|
||||
|
||||
if (listItem) {
|
||||
return listItem.querySelector(`#${this.dataset.targetId}`)
|
||||
} else {
|
||||
return document.getElementById(this.dataset.targetId)
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@ -0,0 +1,28 @@
|
||||
export default class extends HTMLElement {
|
||||
connectedCallback () {
|
||||
this.input.addEventListener('change', (event) => {
|
||||
if (this.dataset.attribute) {
|
||||
this.target[this.dataset.attribute] = event.target.checked
|
||||
}
|
||||
|
||||
if (this.dataset.className) {
|
||||
this.target.classList.toggle(this.dataset.className, event.target.value !== this.dataset.value)
|
||||
if (this.dataset.className === 'hidden' && this.target.tagName === 'INPUT') {
|
||||
this.target.disabled = event.target.value !== this.dataset.value
|
||||
}
|
||||
}
|
||||
|
||||
if (this.dataset.attribute === 'disabled') {
|
||||
this.target.value = ''
|
||||
}
|
||||
})
|
||||
}
|
||||
|
||||
get input () {
|
||||
return this.querySelector('input[type="checkbox"]') || this.querySelector('select')
|
||||
}
|
||||
|
||||
get target () {
|
||||
return document.getElementById(this.dataset.targetId)
|
||||
}
|
||||
}
|
||||
Loading…
Reference in new issue