AjaxSubmit.js
2 years ago
BaseSubmit.js
2 years ago
FormSubmit.js
2 years ago
ReloadSubmit.js
2 years ago
functions.js
2 years ago
ReloadSubmit.js
37 lines
| 1 | import BaseSubmit from './BaseSubmit'; |
| 2 | |
| 3 | function ReloadSubmit( form ) { |
| 4 | BaseSubmit.call( this, form ); |
| 5 | |
| 6 | this.failPromises = []; |
| 7 | |
| 8 | this.submit = function () { |
| 9 | const { rootNode } = this.form.observable; |
| 10 | const { applyFilters } = JetPlugins.hooks; |
| 11 | |
| 12 | Promise.all( |
| 13 | applyFilters( |
| 14 | 'jet.fb.submit.reload.promises', |
| 15 | this.getPromises(), |
| 16 | { target: rootNode }, |
| 17 | ), |
| 18 | ).then( |
| 19 | () => rootNode.submit(), |
| 20 | ).catch( () => { |
| 21 | this.failPromises.forEach( current => current() ); |
| 22 | |
| 23 | this.form.toggle(); |
| 24 | } ); |
| 25 | }; |
| 26 | |
| 27 | this.onFailSubmit = function ( callable ) { |
| 28 | if ( 'function' !== typeof callable ) { |
| 29 | return; |
| 30 | } |
| 31 | this.failPromises.push( callable ); |
| 32 | }; |
| 33 | } |
| 34 | |
| 35 | ReloadSubmit.prototype = Object.create( BaseSubmit.prototype ); |
| 36 | |
| 37 | export default ReloadSubmit; |