File modules/cms/ui/themes/default/script/openrat/dialog.js
Last commit: Fri Feb 11 01:41:54 2022 +0100 dankert Fix: Reading dirty marker.
1 import $ from "../jquery-global.js"; 2 import View from './view.js'; 3 import Notice from "./notice.js"; 4 import Workbench from "./workbench.js"; 5 import WorkbenchNavigator from "./navigator.js"; 6 7 /** 8 * The encapsulated view. 9 */ 10 export default class Dialog { 11 12 /** 13 * A dialog is a special area in the workbench for displaying and inputting data. 14 * A dialog contains a view. 15 */ 16 constructor() { 17 18 this.view; 19 20 /** 21 * the DOM element which contains the dialog. 22 * @type {*|jQuery|HTMLElement} 23 */ 24 this.element = $('.or-dialog-content .or-view'); 25 } 26 27 /** 28 * Set Dirty-marker. 29 * @param dirty true, if unsaved changes exist 30 */ 31 set isDirty( dirty ) { 32 if ( dirty ) 33 this.element.addClass('view--is-dirty'); 34 else 35 this.element.removeClass('view--is-dirty'); 36 } 37 38 /** 39 * Get Dirty-marker. 40 * @return true, if unsaved changes exist 41 */ 42 get isDirty() { 43 return this.element.hasClass('view--is-dirty'); 44 } 45 46 /** 47 * Creating a new dialog. 48 * 49 * @param name 50 * @param action Action 51 * @param method 52 * @param id Id 53 * @param params 54 * 55 * @return Promise of underlying view 56 */ 57 start( name,action,method,id,params ) 58 { 59 // Attribute aus dem aktuellen Editor holen, falls die Daten beim Aufrufer nicht angegeben sind. 60 if (!action) 61 action = Workbench.state.action; 62 63 if (!id) 64 id = Workbench.state.id; 65 66 let dialog = this; 67 68 let view = new View( action,method,id,params ); 69 70 Notice.removeAllNotices(); 71 72 $('.or-dialog-content .or-view').html(''); // Clear old content 73 74 $('.or-dialog-content .or-act-dialog-name').html( name ); 75 this.show(); 76 77 view.onCloseHandler.add( function() { 78 dialog.back(); 79 } ); 80 81 view.onChangeHandler.add( function() { 82 // data has changed 83 console.debug("Changes detected"); 84 dialog.isDirty = true; 85 }); 86 87 view.onSaveHandler.add( function() { 88 // data was saved 89 dialog.isDirty = false; 90 }); 91 92 this.view = view; 93 94 Workbench.getInstance().startSpinner(); 95 96 let viewPromise = this.view.start( this.element ); 97 98 viewPromise.then( 99 () => Workbench.getInstance().stopSpinner() 100 ); 101 102 return viewPromise; 103 } 104 105 106 107 show() { 108 109 //WorkbenchNavigator.navigateToNew( {'action':Workbench.state.action+'','id':Workbench.state.id } ); 110 WorkbenchNavigator.navigateToNew( Workbench.state ); 111 112 $('.or-dialog').removeClass('dialog--is-closed').addClass('dialog--is-open'); 113 114 if ( this.isDirty ) { 115 this.element.addClass('view--is-dirty'); 116 } 117 } 118 119 back() { 120 console.debug("Back from dialog"); 121 history.back(); 122 } 123 124 hide() { 125 $('.or-dialog').removeClass('dialog--is-open').addClass('dialog--is-closed'); // Dialog schließen 126 } 127 128 129 /** 130 * Closing the dialog. 131 */ 132 close() { 133 134 let dialog = this; 135 136 if ( this.isDirty ) { 137 // ask the user if we should close this dialog 138 //let confirmed = window.confirm( Workbench.language.UNSAVED_CHANGES_CONFIRM ); 139 140 //if ( ! confirmed ) 141 // return; // do not close the dialog 142 143 let notice = new Notice(); 144 notice.msg = Workbench.language.REOPEN_CLOSED_DIALOG; 145 notice.setStatus( 'warning' ); 146 notice.timeout = 120; 147 notice.onClick.add( function() { 148 Workbench.dialog = dialog; 149 dialog.show(); 150 notice.close(); 151 }); 152 notice.show(); 153 } 154 155 // Remove dirty-flag from view 156 $('.or-dialog-content .or-view.or-view--is-dirty').removeClass('view--is-dirty'); 157 this.hide(); 158 //$(document).unbind('keyup',this.escapeKeyClosingHandler); // Cleanup ESC-Key-Listener 159 } 160 }
Downloadmodules/cms/ui/themes/default/script/openrat/dialog.js
History Fri, 11 Feb 2022 01:41:54 +0100 dankert Fix: Reading dirty marker. 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. Fri, 17 Dec 2021 04:29:47 +0100 dankert New: Opening a dialog creates a new entry in history api. So, using the back button will close the dialog. Tue, 30 Nov 2021 00:25:32 +0100 Jan Dankert Cleanup the notices. Wed, 14 Apr 2021 00:26:41 +0200 Jan Dankert Fix: 'unbind()' is unsupported in OQuery (and deprecated in JQuery). Thu, 1 Apr 2021 23:16:03 +0200 Jan Dankert Fix: Close dialog on escape key. Thu, 1 Apr 2021 01:01:54 +0200 Jan Dankert New: Some fixes for OQuery, our new selfmade light JQuery replacement. Now the UI is back again. Wed, 31 Mar 2021 01:52:57 +0200 Jan Dankert New: Replace JQuery with OQuery, a selfmade light JQuery replacement. Sat, 27 Mar 2021 05:14:11 +0100 Jan Dankert Refactoring: Converting all script files to ES6 modules (work in progress); removed jquery-ui (drag and drop will be replaced by HTML5, sortable by a small lib) Wed, 17 Mar 2021 22:27:33 +0100 Jan Dankert Refactoring: Using ES6-Modules (experimental) Tue, 16 Mar 2021 23:52:22 +0100 Jan Dankert Refactoring: Use ES6 classes. Mon, 15 Mar 2021 23:29:48 +0100 Jan Dankert Refactoring: Use ES6 classes. Tue, 23 Feb 2021 01:00:33 +0100 Jan Dankert New: Undo for closed dialogs with unsaved changes. Wed, 17 Feb 2021 02:34:51 +0100 Jan Dankert Refactoring: Extract Dialog into a separate js class