File modules/cms/ui/themes/default/script/openrat/view.min.js

Last commit: Tue Feb 14 00:21:26 2023 +0100	Jan Dankert	Show fatal error messages in the UI notice window.
1 import $ from '../jquery-global.min.js'; 2 import Callback from "./callback.min.js"; 3 import Form from "./form.min.js"; 4 import Notice from "./notice.min.js"; 5 import Workbench from "./workbench.min.js"; 6 export default class View { 7 constructor( action,method,id,params ) { 8 this.action = action; 9 this.method = method; 10 this.id = id; 11 this.params = params; 12 this.onCloseHandler = new Callback(); 13 this.onChangeHandler = new Callback(); 14 this.onSaveHandler = new Callback(); 15 } 16 before() { 17 }; 18 start( element ) { 19 this.before(); 20 this.element = element; 21 return this.loadView(); 22 } 23 afterLoad() { 24 } 25 close() { 26 this.onCloseHandler.fire(); 27 } 28 fireViewLoadedEvents(element) { 29 Callback.afterViewLoadedHandler.fire( element ); 30 } 31 async loadView() { 32 let url = View.createUrl(this.action, this.method, this.id, this.params); 33 let element = this.element; 34 let view = this; 35 console.debug( view ); 36 try { 37 let response = await fetch( url,{ 38 method: 'GET', 39 headers: { 40 'Accept': 'text/html', 41 } 42 } ); 43 $(element).html(""); 44 if ( ! response.ok ) { 45 $(element).html('<div class="or-view-central"><i class="or-image-icon or-image-icon--method-logout" /></div>'); 46 if ( response.status == 403 ) { 47 throw "Permission denied"; 48 } 49 else if ( response.status == 503 ) { 50 let data = await response.text(); 51 if ( ! data ) 52 data = ''; 53 const errorDoc = new DOMParser().parseFromString(data,"text/html"); 54 const error = errorDoc.getElementById("cms-error-log"); 55 throw "CMS Service unavailable\n" + error.innerText; 56 } 57 else if ( response.status == 500 ) { 58 let data = await response.text(); 59 if ( ! data ) 60 data = ''; 61 const errorDoc = new DOMParser().parseFromString(data,"text/html"); 62 const error = errorDoc.getElementById("cms-error-log"); 63 throw "CMS Server Error\n" + error.innerText; 64 } 65 else 66 throw "Failed to load the view: " + response.status + " " + response.statusText; 67 } 68 let data = await response.text(); 69 if ( ! data ) 70 data = ''; 71 $(element).html(data); 72 $(element).find('form').each( function() { 73 let form = new Form(); 74 form.onChangeHandler.add( () => { view.onChangeHandler.fire() } ); 75 form.onSaveHandler .add( () => { view.onSaveHandler .fire() } ); 76 form.onCloseHandler .add( () => { view.close() } ); 77 form.forwardHandler.add( (action, subaction, id, data) => { 78 view.action = action; 79 view.method = subaction; 80 view.id = id; 81 view.params = data; 82 view.loadView(); 83 } ); 84 form.initOnElement(this); 85 }); 86 view.fireViewLoadedEvents( element ); 87 } 88 catch( cause ) { 89 console.error( {view:view, url:url, cause: cause} ); 90 let notice = new Notice(); 91 notice.setStatus('error'); 92 notice.msg = Workbench.language.NOTHING_DONE; 93 notice.log = cause; 94 notice.show(); 95 } 96 finally { 97 } 98 } 99 static createUrl(action, subaction, id= 0, extraid = {}) { 100 let url = './?'; 101 if(action) 102 url += '&action='+action; 103 if(subaction) 104 url += '&subaction='+subaction; 105 if(id) 106 url += '&id='+id; 107 if ( extraid instanceof FormData ) { 108 for (let pair of extraid.entries()) { 109 url += '&' + pair[0] + '=' + pair[1]; 110 } 111 } 112 else if ( extraid instanceof Object ) { 113 Object.keys(extraid).forEach( (key) => { 114 url += '&' + key + '=' + extraid[key]; 115 }); 116 } 117 else 118 throw "Illegal argument"; 119 return url; 120 } 121 }
Download modules/cms/ui/themes/default/script/openrat/view.min.js
History Tue, 14 Feb 2023 00:21:26 +0100 Jan Dankert Show fatal error messages in the UI notice window. Mon, 13 Feb 2023 22:46:58 +0100 Jan Dankert Show server error messages in the UI notice window. 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 22:06:09 +0100 dankert Refactoring: Ommit unnecessary parameters. 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. Fri, 21 Aug 2020 00:22:13 +0200 Jan Dankert Refactoring: Collect all frontend compiler scripts in update.php. Compiling of CSS and JS was extracted to a new TemplateCompiler. JS and CSS is now collected in a new openrat.[min.][js|css]. Mon, 17 Aug 2020 21:31:53 +0200 Jan Dankert Performance: For now disabling the data-loading and data-binding (was not used up to now) Sun, 23 Feb 2020 04:01:30 +0100 Jan Dankert Refactoring with Namespaces for the cms modules, part 1: moving.