Sha256: 229d8c67f4478bc89a805a76c4ee9bf7170746a4ef7498fec941ecaeaa780431
Contents?: true
Size: 1.77 KB
Versions: 14
Compression:
Stored size: 1.77 KB
Contents
document.addEventListener('dynamic_scaffold:load', function (){ const csrfParam = document.querySelector('.authenticity_param_name') if(!csrfParam) return const csrfParamName = csrfParam.value function submit(button){ const form = DynamicScaffold.createElement('form', { method: 'post', action: button.getAttribute('data-action'), style: 'display: none;' }) form.appendChild(DynamicScaffold.createElement('input', { type: 'hidden', name: csrfParamName, value: document.querySelector('input[name=' + csrfParamName + ']').value })) form.appendChild(DynamicScaffold.createElement('input', { type: 'hidden', name: '_method', value: 'delete' })) document.body.appendChild(form) form.submit() } const buttons = document.querySelectorAll('.dynamicScaffoldJs-destory') if(buttons.length === 0) return const wrapper = buttons[0].closest('.dynamicScaffoldJs-item-wrapper') Array.prototype.forEach.call(buttons, function(button){ const row = button.closest('.dynamicScaffoldJs-item-row') button.addEventListener('click', function(e){ e.preventDefault() row.classList.add('dynamicScaffold-destorying') DynamicScaffold.confirm({ message: button.getAttribute('data-confirm-message'), ok: { text: wrapper.getAttribute('data-confirm-ok'), class: wrapper.getAttribute('data-confirm-ok-class'), action: function(){ submit(button) } }, cancel: { text: wrapper.getAttribute('data-confirm-cancel'), class: wrapper.getAttribute('data-confirm-cancel-class'), action: function(){ row.classList.remove("dynamicScaffold-destorying") } } }) }) }) })
Version data entries
14 entries across 14 versions & 1 rubygems