commit d6e3eb0546ce52b634816dd7805db3e1ad36587a
parent 4c038a3f89c536f6fd42835074b46fade560aaac
Author: dankert <openrat@jandankert.de>
Date: Fri, 17 Dec 2021 04:29:47 +0100
New: Opening a dialog creates a new entry in history api. So, using the back button will close the dialog.
Diffstat:
4 files changed, 93 insertions(+), 103 deletions(-)
diff --git a/modules/cms/ui/themes/default/script/openrat/dialog.js b/modules/cms/ui/themes/default/script/openrat/dialog.js
@@ -2,6 +2,7 @@ import $ from "../jquery-global.js";
import View from './view.js';
import Notice from "./notice.js";
import Workbench from "./workbench.js";
+import WorkbenchNavigator from "./navigator.js";
/**
* The encapsulated view.
@@ -62,7 +63,7 @@ export default class Dialog {
this.show();
view.onCloseHandler.add( function() {
- dialog.close();
+ dialog.back();
} );
view.onChangeHandler.add( function() {
@@ -97,31 +98,20 @@ export default class Dialog {
show() {
+ //WorkbenchNavigator.navigateToNew( {'action':Workbench.state.action+'','id':Workbench.state.id } );
+ WorkbenchNavigator.navigateToNew( Workbench.state );
+
$('.or-dialog').removeClass('dialog--is-closed').addClass('dialog--is-open');
if ( this.isDirty ) {
this.element.addClass('view--is-dirty');
}
-
- let dialog = this;
-
- let escapeKeyClosingHandler = (e) => {
- if (e.code === 'Escape') {
- document.removeEventListener('keyup',escapeKeyClosingHandler);
- dialog.close();
- }
- };
-
- document.addEventListener('keyup',escapeKeyClosingHandler);
-
- // close dialog on click onto the blurred area.
- $('.or-dialog-filler,.or-act-dialog-close').click( function(e)
- {
- e.preventDefault();
- dialog.close();
- });
}
+ back() {
+ console.debug("Back from dialog");
+ history.back();
+ }
hide() {
$('.or-dialog').removeClass('dialog--is-open').addClass('dialog--is-closed'); // Dialog schließen
@@ -137,16 +127,17 @@ export default class Dialog {
if ( this.isDirty ) {
// ask the user if we should close this dialog
- let exit = window.confirm( Workbench.language.UNSAVED_CHANGES_CONFIRM );
+ //let confirmed = window.confirm( Workbench.language.UNSAVED_CHANGES_CONFIRM );
- if ( ! exit )
- return; // do not close the dialog
+ //if ( ! confirmed )
+ // return; // do not close the dialog
let notice = new Notice();
notice.msg = Workbench.language.REOPEN_CLOSED_DIALOG;
notice.setStatus( 'warning' );
notice.timeout = 120;
notice.onClick.add( function() {
+ Workbench.dialog = dialog;
dialog.show();
notice.close();
});
diff --git a/modules/cms/ui/themes/default/script/openrat/workbench.js b/modules/cms/ui/themes/default/script/openrat/workbench.js
@@ -15,6 +15,8 @@ export default class Workbench {
extra: {}
};
+ static dialog;
+
static instance;
constructor() {
@@ -57,6 +59,9 @@ export default class Workbench {
// Listening to the "popstate" event
// If the user navigates back or forward, the new state is set.
window.onpopstate = ev => {
+ console.debug("Event after navigating",ev);
+ this.closeDialog();
+ this.closeMenu();
this.loadNewActionState(ev.state);
};
@@ -102,19 +107,6 @@ export default class Workbench {
});
}
- /**
- * Starts a dialog, if necessary.
- *
- * @deprecated no dialogs are opened on load.
- */
- openModalDialog() {
-
- if ( $('#dialog').data('action') ) {
- let dialog = new Dialog();
- dialog.start('',$('#dialog').data('action'),$('#dialog').data('action'),0,{} )
- }
- }
-
/**
* Sets the workbench state with action/id.
@@ -217,6 +209,7 @@ export default class Workbench {
*/
loadNewActionState(state) {
+ console.debug("New state",state);
Workbench.state = state;
this.reloadViews();
@@ -226,6 +219,22 @@ export default class Workbench {
}
+ closeDialog() {
+ if ( Workbench.dialog ) {
+ Workbench.dialog.close();
+ Workbench.dialog = null;
+ }
+ }
+
+
+ createDialog() {
+
+ this.closeDialog();
+
+ Workbench.dialog = new Dialog();
+ return Workbench.dialog;
+ }
+
/**
*
*/
@@ -586,36 +595,35 @@ export default class Workbench {
let keyPressedHandler = (event) => {
if (event.key === 'F4') {
+ // Open "properties" dialog.
- let dialog = new Dialog();
+ let dialog = this.createDialog();
dialog.start('', '', 'prop', 0, {});
}
if (event.key === 'F2') {
+ // Toggle navigation bar
if ($('.or-workbench').hasClass('workbench--navigation-is-small'))
$('.or-act-nav-wide').click();
else
$('.or-act-nav-small').click();
}
+
+ if (event.code === 'Escape') {
+ // Close an existing dialog.
+ this.closeDialog();
+ }
};
document.addEventListener('keydown',keyPressedHandler);
+ }
- /*
- $('.keystroke').each( function() {
- let keystrokeElement = $(this);
- let keystroke = keystrokeElement.text();
- if (keystroke.length == 0)
- return; // No Keybinding.
- let keyaction = function() {
- keystrokeElement.click();
- };
- // Keybinding ausfuehren.
- document.addEventListener( )).bind('keydown', keystroke, keyaction );
- } );*/
+
+ closeMenu() {
+ $('.or-menu').removeClass('menu--is-open');
}
@@ -624,61 +632,54 @@ export default class Workbench {
*/
initializeEvents() {
- let closeMenu = function() {
- // Mit der Maus irgendwo hin geklickt, das Menü muss schließen.
- $('body').click( function() {
- //$('.toolbar-icon.or-menu-category').parents('.or-menu').removeClass('menu--is-open');
- $('.or-menu').removeClass('menu--is-open');
- });
- };
- closeMenu();
+ // Mit der Maus irgendwo hin geklickt, das Menü muss schließen.
+ $('body').click( () => {
+ this.closeMenu();
+ });
+ // close dialog on click onto the blurred area.
+ $('.or-dialog-filler,.or-act-dialog-close').click( (e) =>
+ {
+ e.preventDefault();
+ this.closeDialog();
+ }
+ );
- let closeMobileNavigation = function() {
- // Mobile navigation must close on a click on the workbench
- $('.or-act-navigation-close').click( function() {
- $('.or-workbench-navigation').removeClass('workbench-navigation--is-open');
- $('.or-workbench').removeClass('workbench--navigation-is-open');
- });
- };
- closeMobileNavigation();
+ // Mobile navigation must close on a click on the workbench
+ $('.or-act-navigation-close').click( () => {
+ $('.or-workbench-navigation').removeClass('workbench-navigation--is-open');
+ $('.or-workbench').removeClass('workbench--navigation-is-open');
+ });
- let closeDesktopNavigation = function() {
+ // Handler for desktop navigation
+ $('.or-workbench-title .or-act-nav-small').click( () => {
+ $('.or-workbench').addClass('workbench--navigation-is-small');
+ $('.or-workbench-navigation').addClass('workbench-navigation--is-small');
+ });
- // Handler for desktop navigation
- $('.or-workbench-title .or-act-nav-small').click(function () {
- $('.or-workbench').addClass('workbench--navigation-is-small');
- $('.or-workbench-navigation').addClass('workbench-navigation--is-small');
- });
- };
- closeDesktopNavigation();
-
-
- let registerGlobalSearch = function() {
- $('.or-search-input .or-input').orSearch( {
- onSearchActive: function() {
- $('.or-search').addClass('search--is-active');
- },
- onSearchInactive: function() {
- $('.or-search').removeClass('search--is-active');
- },
- dropdown : '.or-act-search-result',
- resultEntryClass: 'search-result-entry',
- //openDropdown: true, // the dropdown is automatically opened by the menu.
- select : function(obj) {
- // open the search result
- Workbench.getInstance().openNewAction( obj.name, obj.action, obj.id );
- },
- afterSelect: function() {
- //$('.or-dropdown.or-act-selector-search-results').empty();
- }
- } );
- $('.or-search .or-act-search-delete').click( function() {
- $('.or-search .or-title-input').val('').input();
- } );
- };
- registerGlobalSearch();
+
+ $('.or-search-input .or-input').orSearch( {
+ onSearchActive: function() {
+ $('.or-search').addClass('search--is-active');
+ },
+ onSearchInactive: function() {
+ $('.or-search').removeClass('search--is-active');
+ },
+ dropdown : '.or-act-search-result',
+ resultEntryClass: 'search-result-entry',
+ //openDropdown: true, // the dropdown is automatically opened by the menu.
+ select : function(obj) {
+ // open the search result
+ Workbench.getInstance().openNewAction( obj.name, obj.action, obj.id );
+ },
+ afterSelect: function() {
+ //$('.or-dropdown.or-act-selector-search-results').empty();
+ }
+ } );
+ $('.or-search .or-act-search-delete').click( () => {
+ $('.or-search .or-title-input').val('').input();
+ } );
Callback.afterNewActionHandler.add( function() {
diff --git a/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orLinkify.js b/modules/cms/ui/themes/default/script/plugin/jquery-plugin-orLinkify.js
@@ -1,7 +1,5 @@
import $ from "../jquery-global.js";
import Workbench from "../openrat/workbench.js";
-import Dialog from "../openrat/dialog.js";
-import Form from "../openrat/form.js";
import Api from "../openrat/api.js";
/**
@@ -78,7 +76,7 @@ export default function( options )
case 'edit':
case 'dialog':
- let dialog = new Dialog();
+ let dialog = Workbench.getInstance().createDialog();
let name = $link.attr('data-name');
if ( !name )
name = $link.text(); // get the name from the combined text of all children.
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
@@ -1,6 +1,6 @@
import $ from "../jquery-global.js";
import WorkbenchNavigator from "../openrat/navigator.js";
-import Dialog from "../openrat/dialog.js";
+import Workbench from "../openrat/workbench.js";
/**
* Suche mit Dropdown
@@ -33,7 +33,7 @@ export default function( options )
$(this).on('keydown',async function(e) {
if ( e.keyCode == 13 ) { // Listen to ENTER
- let dialog = new Dialog();
+ let dialog = Workbench.getInstance().createDialog();
closeSearch();
dialog.start('','search','edit',0,{'text':searchInput.val()});
searchInput.val('');