File modules/cms/ui/themes/default/script/openrat/api.min.js
Last commit: Fri Feb 11 01:28:51 2022 +0100 dankert Fixed some UI problems: The dialogs are now closed after submitting the data; Workbench is reloaded after login/logout.
1 import Notice from "./notice.min.js"; 2 export default class Api { 3 sendData = function( formData ) { 4 console.debug( "API form data", formData ); 5 let api = this; 6 return new Promise( (resolve, reject) => { 7 let load = fetch( './', { 8 'method':'POST', 9 headers: { 10 'Accept': 'application/json', 11 }, 12 body:formData 13 } ); 14 load.then( response => { 15 if ( ! response.ok ) 16 reject( "Failed to post" ); 17 return response.json(); 18 }).then( data => { 19 for( let value of data['notices'] ) { 20 let notice = new Notice(); 21 notice.setContext( value.type, value.id, value.name ); 22 notice.log = value.log; 23 notice.setStatus( value.status ); 24 notice.msg = value.text; 25 notice.show(); 26 if ( api.notifyBrowser ) 27 notice.notifyBrowser() 28 }; 29 if ( data.success ) { 30 resolve(); 31 } 32 else { 33 for( name of data['errors'] ) 34 this.validationErrorForField( name ); 35 reject('API request failed'); 36 } 37 } ).catch( cause => { 38 console.warn( { 39 message: 'API request failed', 40 cause : cause, 41 data : formData, 42 } ); 43 let msg = ''; 44 try { 45 msg = JSON.parse( cause ).message; 46 } 47 catch( e ) { 48 msg = cause; 49 } 50 let notice = new Notice(); 51 notice.setStatus('error'); 52 notice.msg = msg; 53 notice.log = cause; 54 notice.show(); 55 reject( msg ); 56 } ); 57 } ); 58 } 59 validationErrorForField = function( nameOfField ) { 60 } 61 }
Downloadmodules/cms/ui/themes/default/script/openrat/api.min.js
History Fri, 11 Feb 2022 01:28:51 +0100 dankert Fixed some UI problems: The dialogs are now closed after submitting the data; Workbench is reloaded after login/logout. Sun, 6 Feb 2022 21:34:42 +0100 dankert New: Use Accept-Header instead of "output" request parameter, this is the cleaner way. Sat, 18 Dec 2021 03:47:23 +0100 dankert New: Every ES6-Module should have a minified version for performance reasons. Bad: The Minifier "Jsqueeze" is unable to minify ES6-modules, so we had to implement a simple JS-Minifier which strips out all comments.