openrat-cms

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs | README

commit bb407109c6e5b0fd8b3074a0910468542f7ba9f0
parent b9d16a7751f404a4fe143e117fe69316a2e597ec
Author: dankert <openrat@jandankert.de>
Date:   Sun,  6 Feb 2022 21:34:42 +0100

New: Use Accept-Header instead of "output" request parameter, this is the cleaner way.

Diffstat:
Mmodules/cms/ui/themes/default/script/openrat/api.js | 8+++++++-
Mmodules/cms/ui/themes/default/script/openrat/api.min.js | 11+++++++----
Mmodules/cms/ui/themes/default/script/openrat/view.js | 11++++++++---
Mmodules/cms/ui/themes/default/script/openrat/view.min.js | 33+++++++++++++++++++++------------
Mmodules/cms/ui/themes/default/script/openrat/workbench.js | 57+++++++++++++++++++++++++++++++++++++++++++++++++--------
Mmodules/cms/ui/themes/default/script/openrat/workbench.min.js | 67+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++--------
Mmodules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js | 4++--
Mmodules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js | 4++--
Mmodules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.js | 7++++++-
Mmodules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.min.js | 7++++++-
10 files changed, 167 insertions(+), 42 deletions(-)

diff --git a/modules/cms/ui/themes/default/script/openrat/api.js b/modules/cms/ui/themes/default/script/openrat/api.js @@ -30,7 +30,13 @@ export default class Api { let api = this; return new Promise( (resolve, reject) => { - let load = fetch( './', { 'method':'POST', body:formData } ); + let load = fetch( './', { + 'method':'POST', + headers: { + 'Accept': 'application/json', + }, + body:formData + } ); load.then( response => { if ( ! response.ok ) diff --git a/modules/cms/ui/themes/default/script/openrat/api.min.js b/modules/cms/ui/themes/default/script/openrat/api.min.js @@ -1,7 +1,4 @@ -import $ from '../jquery-global.min.js'; -import Workbench from "./workbench.min.js"; import Notice from "./notice.min.js"; -import Callback from "./callback.min.js"; export default class Api { static modes = { get : 1, @@ -15,7 +12,13 @@ sendData = function( formData ) { console.debug( "API form data", formData ); let api = this; return new Promise( (resolve, reject) => { -let load = fetch( './api/', { 'method':'POST', body:formData } ); +let load = fetch( './', { +'method':'POST', +headers: { +'Accept': 'application/json', +}, +body:formData +} ); load.then( response => { if ( ! response.ok ) reject( "Failed to post" ); diff --git a/modules/cms/ui/themes/default/script/openrat/view.js b/modules/cms/ui/themes/default/script/openrat/view.js @@ -74,7 +74,12 @@ export default class View { console.debug( view ); try { - let response = await fetch( url,{} ); + let response = await fetch( url,{ + method: 'GET', + headers: { + 'Accept': 'text/html', + } + } ); $(element).html(""); if ( ! response.ok ) { @@ -175,8 +180,8 @@ export default class View { else throw "Illegal argument"; - if ( api ) - url += '&output=json'; + //if ( api ) + // url += '&output=json'; return url; } diff --git a/modules/cms/ui/themes/default/script/openrat/view.min.js b/modules/cms/ui/themes/default/script/openrat/view.min.js @@ -2,6 +2,7 @@ import $ from '../jquery-global.min.js'; import Callback from "./callback.min.js"; import Form from "./form.min.js"; import Notice from "./notice.min.js"; +import Workbench from "./workbench.min.js"; export default class View { constructor( action,method,id,params ) { this.action = action; @@ -28,14 +29,28 @@ fireViewLoadedEvents(element) { Callback.afterViewLoadedHandler.fire( element ); } async loadView() { -let url = View.createUrl( this.action,this.method,this.id,this.params,false); +let url = View.createUrl( this.action,this.method,this.id,this.params,false); let element = this.element; -let view = this; +let view = this; console.debug( view ); try { -let response = await fetch( url,{} ); -if ( ! response.ok ) +let response = await fetch( url,{ +method: 'GET', +headers: { +'Accept': 'text/html', +} +} ); +$(element).html(""); +if ( ! response.ok ) { +$(element).html('<div class="or-view-central"><i class="or-image-icon or-image-icon--method-logout" /></div>'); +if ( response.status == 403 ) { +throw "Permission denied"; +} +else if ( response.status == 503 ) +throw "server error"; +else throw "failed to load the view"; +} let data = await response.text(); if ( ! data ) data = ''; @@ -57,11 +72,10 @@ form.initOnElement(this); view.fireViewLoadedEvents( element ); } catch( cause ) { -$(element).html(""); console.error( {view:view, url:url, cause: cause} ); let notice = new Notice(); notice.setStatus('error'); -notice.msg = "View error"; +notice.msg = Workbench.language.NOTHING_DONE; notice.log = cause; notice.show(); } @@ -70,10 +84,7 @@ finally { } static createUrl(action,subaction,id,extraid={},api=false ) { -let url = './'; -if ( api ) -url += 'api/'; -url += '?'; +let url = './?'; if(action) url += '&action='+action; if(subaction) @@ -92,8 +103,6 @@ url += '&' + key + '=' + extraid[key]; } else throw "Illegal argument"; -if ( api ) -url += '&output=json'; return url; } } \ No newline at end of file diff --git a/modules/cms/ui/themes/default/script/openrat/workbench.js b/modules/cms/ui/themes/default/script/openrat/workbench.js @@ -195,7 +195,12 @@ export default class Workbench { console.debug('ping'); try { - let response = await fetch( url ); + let response = await fetch( url,{ + method: 'GET', + headers: { + 'Accept': 'application/json', + } + } ); if ( !response.ok ) throw "ping failed"; @@ -309,7 +314,12 @@ export default class Workbench { let url = View.createUrl('profile', 'userinfo', 0, {}, true); - let response = await fetch(url); + let response = await fetch(url,{ + method: 'GET', + headers: { + 'Accept': 'application/json', + } + }); let json = await response.json(); let style = json.output['style']; @@ -328,7 +338,13 @@ export default class Workbench { let url = View.createUrl('profile', 'language', 0, {}, true); - let response = await fetch(url); + let response = await fetch(url,{ + method: 'GET', + headers: { + 'Accept': 'application/json', + } + } + ); let data = await response.json(); Workbench.language = data.output.language; @@ -341,7 +357,12 @@ export default class Workbench { let url = View.createUrl('profile', 'uisettings', 0, {}, true); - let response = await fetch(url); + let response = await fetch(url,{ + method: 'GET', + headers: { + 'Accept': 'application/json', + } + }); let data = await response.json(); Workbench.settings = data.output.settings.settings; @@ -588,7 +609,12 @@ export default class Workbench { let url = View.createUrl('profile', 'available', id, {'queryaction': action}, true); // Die Inhalte des Zweiges laden. - let response = await fetch(url); + let response = await fetch(url, { + method: 'GET', + headers: { + 'Accept': 'application/json', + } + }); let data = await response.json(); for (let method of Object.values(data.output.views)) @@ -721,7 +747,12 @@ export default class Workbench { let url = View.createUrl('tree','path',Workbench.state.id, {'type':Workbench.state.action} ); // Die Inhalte des Zweiges laden. - let loadPromise = fetch( url ); + let loadPromise = fetch( url,{ + method: 'GET', + headers: { + 'Accept': 'text/html', + } + } ); /** * open a object in the navigation tree. @@ -808,7 +839,12 @@ export default class Workbench { let loadBranchUrl = View.createUrl('tree','branch',0,{type:type}); let $targetElement = $(this); - let response = await fetch( loadBranchUrl ); + let response = await fetch( loadBranchUrl,{ + method: 'GET', + headers: { + 'Accept': 'text/html', + } + } ); let html = await response.text(); // Den neuen Unter-Zweig erzeugen. @@ -889,7 +925,12 @@ export default class Workbench { let type = id?'folder':'projects'; let loadBranchUrl = './?action=tree&subaction=branch&id='+id+'&type='+type; - let load = fetch( loadBranchUrl ); + let load = fetch( loadBranchUrl,{ + method: 'GET', + headers: { + 'Accept': 'text/html', + } + } ); load .then( response => response.text() ) .then( html => { diff --git a/modules/cms/ui/themes/default/script/openrat/workbench.min.js b/modules/cms/ui/themes/default/script/openrat/workbench.min.js @@ -38,6 +38,7 @@ this.closeMenu(); this.loadNewActionState(ev.state); }; this.registerWorkbench(); +this.initializeTheme(); this.initializeStartupNotices(); this.initializeEvents(); this.initializeKeystrokes(); @@ -49,6 +50,13 @@ this.initializePingTimer(); this.initializeDirtyWarning(); console.info('Application started'); } +initializeTheme() { +if (window.localStorage) { +let style = window.localStorage.getItem('style'); +if (style) +this.setUserStyle(style); +} +} initializeDirtyWarning() { window.addEventListener('beforeunload', function (e) { if ( $('.or-view--is-dirty').length > 0 ) { @@ -95,7 +103,12 @@ let ping = async () => { let url = View.createUrl('profile','ping',0, {}, true); console.debug('ping'); try { -let response = await fetch( url ); +let response = await fetch( url,{ +method: 'GET', +headers: { +'Accept': 'application/json', +} +} ); if ( !response.ok ) throw "ping failed"; } catch( cause ) { @@ -157,7 +170,12 @@ return all; } async loadUserStyle() { let url = View.createUrl('profile', 'userinfo', 0, {}, true); -let response = await fetch(url); +let response = await fetch(url,{ +method: 'GET', +headers: { +'Accept': 'application/json', +} +}); let json = await response.json(); let style = json.output['style']; this.setUserStyle(style); @@ -168,13 +186,24 @@ static settings = {}; static language = {}; async loadLanguage() { let url = View.createUrl('profile', 'language', 0, {}, true); -let response = await fetch(url); +let response = await fetch(url,{ +method: 'GET', +headers: { +'Accept': 'application/json', +} +} +); let data = await response.json(); Workbench.language = data.output.language; } async loadUISettings() { let url = View.createUrl('profile', 'uisettings', 0, {}, true); -let response = await fetch(url); +let response = await fetch(url,{ +method: 'GET', +headers: { +'Accept': 'application/json', +} +}); let data = await response.json(); Workbench.settings = data.output.settings.settings; } @@ -204,6 +233,8 @@ return view.start( $viewElement ); } setUserStyle( styleName ) { +if ( window.localStorage ) +window.localStorage.setItem('style',styleName); let styleUrl = View.createUrl('index','themestyle',0,{'style':styleName} ); document.getElementById('user-style').setAttribute('href',styleUrl); } @@ -298,7 +329,12 @@ $('.or-workbench-title .or-dropdown-entry.or-act-clickable').addClass('dropdown- $('.or-workbench-title .or-filtered').removeClass('dropdown-entry--active').addClass('dropdown-entry--inactive'); $('.or-workbench-title .or-filtered .or-link').attr('data-id', id); let url = View.createUrl('profile', 'available', id, {'queryaction': action}, true); -let response = await fetch(url); +let response = await fetch(url, { +method: 'GET', +headers: { +'Accept': 'application/json', +} +}); let data = await response.json(); for (let method of Object.values(data.output.views)) $('.or-workbench-title .or-filtered > .or-link[data-method=\'' + method + '\']') @@ -379,7 +415,12 @@ $('.or-sidebar').find('.or-sidebar-button').orLinkify(); ); Callback.afterNewActionHandler.add( function() { let url = View.createUrl('tree','path',Workbench.state.id, {'type':Workbench.state.action} ); -let loadPromise = fetch( url ); +let loadPromise = fetch( url,{ +method: 'GET', +headers: { +'Accept': 'text/html', +} +} ); function openNavTree(action, id) { let $navControl = $('.or-link[data-action="'+action+'"][data-id="'+id+'"]').closest('.or-navtree-node'); if ( $navControl.is( '.or-navtree-node--is-closed' ) ) @@ -431,7 +472,12 @@ $element.find('.or-act-load-nav-tree').each( async function() { let type = $(this).data('type') || 'root'; let loadBranchUrl = View.createUrl('tree','branch',0,{type:type}); let $targetElement = $(this); -let response = await fetch( loadBranchUrl ); +let response = await fetch( loadBranchUrl,{ +method: 'GET', +headers: { +'Accept': 'text/html', +} +} ); let html = await response.text(); let $ul = $.create('ul' ).addClass('navtree-list'); $ul.appendTo( $targetElement.empty() ).html( html ); @@ -470,7 +516,12 @@ var selectorEl = this; let id = $(this).data('init-folder-id'); let type = id?'folder':'projects'; let loadBranchUrl = './?action=tree&subaction=branch&id='+id+'&type='+type; -let load = fetch( loadBranchUrl ); +let load = fetch( loadBranchUrl,{ +method: 'GET', +headers: { +'Accept': 'text/html', +} +} ); load .then( response => response.text() ) .then( html => { diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.js @@ -50,11 +50,11 @@ export default function( options ) $('.or-search').addClass('search--is-active'); dropdownEl.addClass('search-result--is-active'); - let url = './?action='+settings.action+'&subaction='+settings.method+'&output=json&search='+searchArgument; + let url = './?action='+settings.action+'&subaction='+settings.method+'&search='+searchArgument; let response = await fetch( url, { method: 'GET', headers: { - 'Content-Type': 'application/json', + 'Accept': 'application/json' } } ); if ( ! response.ok ) throw "Search request getting an error"; diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orSearch.min.js @@ -37,11 +37,11 @@ if ( searchArgument.length ) settings.onSearchActive(); $('.or-search').addClass('search--is-active'); dropdownEl.addClass('search-result--is-active'); -let url = './api/?action='+settings.action+'&subaction='+settings.method+'&output=json&search='+searchArgument; +let url = './?action='+settings.action+'&subaction='+settings.method+'&search='+searchArgument; let response = await fetch( url, { method: 'GET', headers: { -'Content-Type': 'application/json', +'Accept': 'application/json' } } ); if ( ! response.ok ) throw "Search request getting an error"; diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.js @@ -62,7 +62,12 @@ export default function(options) console.debug( { url:loadBranchUrl } ); // Die Inhalte des Zweiges laden. - fetch( loadBranchUrl ) + fetch( loadBranchUrl,{ + method: 'GET', + headers: { + 'Accept': 'text/html', + } + } ) .then( response => { if (!response.ok) throw "Failed to load tree"; return response } ) .then( response => response.text() ) .then( html => { diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.min.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orTree.min.js @@ -37,7 +37,12 @@ else { ; } console.debug( { url:loadBranchUrl } ); -fetch( loadBranchUrl ) +fetch( loadBranchUrl,{ +method: 'GET', +headers: { +'Accept': 'text/html', +} +} ) .then( response => { if (!response.ok) throw "Failed to load tree"; return response } ) .then( response => response.text() ) .then( html => {