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
BaseSubmit.js
34 lines
| 1 | /** |
| 2 | * @param form {FormSubmit} |
| 3 | * @constructor |
| 4 | */ |
| 5 | function BaseSubmit( form ) { |
| 6 | this.form = form; |
| 7 | this.lastResponse = {}; |
| 8 | this.promises = []; |
| 9 | } |
| 10 | |
| 11 | BaseSubmit.prototype.submit = function () { |
| 12 | throw new Error( 'You need to replace this callback' ); |
| 13 | }; |
| 14 | BaseSubmit.prototype.getPromises = function () { |
| 15 | return this.promises.map( ( { callable } ) => new Promise( callable ) ); |
| 16 | }; |
| 17 | /** |
| 18 | * @param callable {Function} |
| 19 | * @param inputContext {InputData|Boolean} |
| 20 | */ |
| 21 | BaseSubmit.prototype.promise = function ( callable, inputContext = false ) { |
| 22 | const pathStr = inputContext ? inputContext.path.join( '.' ) : ''; |
| 23 | |
| 24 | this.promises = this.promises.filter( |
| 25 | ( { idPath } ) => !idPath || idPath !== pathStr, |
| 26 | ); |
| 27 | |
| 28 | this.promises.push( { |
| 29 | callable, |
| 30 | idPath: inputContext ? inputContext.path.join( '.' ) : '', |
| 31 | } ); |
| 32 | }; |
| 33 | |
| 34 | export default BaseSubmit; |