mirror of
https://0xacab.org/sutty/sutty
synced 2024-11-22 20:46:21 +00:00
Merge branch 'submit-once' into rails
This commit is contained in:
commit
9cf59d7137
3 changed files with 27 additions and 3 deletions
15
app/javascript/controllers/submit_once_controller.js
Normal file
15
app/javascript/controllers/submit_once_controller.js
Normal file
|
@ -0,0 +1,15 @@
|
||||||
|
import { Controller } from 'stimulus'
|
||||||
|
|
||||||
|
/*
|
||||||
|
* Deshabilita el elemento que recibe el evento, para evitar que la
|
||||||
|
* acción se realice varias veces.
|
||||||
|
*
|
||||||
|
* <form data-controller="submit-once">
|
||||||
|
* <input type="submit" data-action="submit-once#disable" />
|
||||||
|
* </form>
|
||||||
|
*/
|
||||||
|
export default class extends Controller {
|
||||||
|
disable (event) {
|
||||||
|
event.target.disabled = true
|
||||||
|
}
|
||||||
|
}
|
|
@ -4,12 +4,15 @@
|
||||||
tooltip: t('help.sites.enqueued'),
|
tooltip: t('help.sites.enqueued'),
|
||||||
text: t('sites.enqueued'),
|
text: t('sites.enqueued'),
|
||||||
type: 'secondary',
|
type: 'secondary',
|
||||||
link: nil
|
link: nil,
|
||||||
|
disabled: true
|
||||||
- else
|
- else
|
||||||
= form_tag site_enqueue_path(site),
|
= form_tag site_enqueue_path(site),
|
||||||
method: :post, class: 'form-inline inline' do
|
method: :post,
|
||||||
|
data: { controller: 'submit-once' },
|
||||||
|
class: 'form-inline inline' do
|
||||||
= button_tag type: 'submit',
|
= button_tag type: 'submit',
|
||||||
class: 'btn no-border-radius',
|
class: 'btn no-border-radius',
|
||||||
title: t('help.sites.enqueue'),
|
title: t('help.sites.enqueue'),
|
||||||
data: { toggle: 'tooltip' } do
|
data: { action: 'submit-once#disable' } do
|
||||||
= t('sites.enqueue')
|
= t('sites.enqueue')
|
||||||
|
|
|
@ -109,4 +109,10 @@ class SiteTest < ActiveSupport::TestCase
|
||||||
assert_equal %w[book cart confirmation editorial menu payment post shipment], site.data['layouts'].keys
|
assert_equal %w[book cart confirmation editorial menu payment post shipment], site.data['layouts'].keys
|
||||||
assert_equal %i[book cart confirmation editorial menu payment post shipment], site.layouts.to_h.keys
|
assert_equal %i[book cart confirmation editorial menu payment post shipment], site.layouts.to_h.keys
|
||||||
end
|
end
|
||||||
|
|
||||||
|
test 'se pueden encolar una sola vez' do
|
||||||
|
assert site.enqueue!
|
||||||
|
assert site.enqueued?
|
||||||
|
assert_not site.enqueue!
|
||||||
|
end
|
||||||
end
|
end
|
||||||
|
|
Loading…
Reference in a new issue