diff --git a/browser/src/control/Control.UIManager.js b/browser/src/control/Control.UIManager.js index 618e5ef2b..4eba645eb 100644 --- a/browser/src/control/Control.UIManager.js +++ b/browser/src/control/Control.UIManager.js @@ -1006,6 +1006,65 @@ L.Control.UIManager = L.Control.extend({ } }, + // Opens a yesno modal with configurable buttons. + showYesNoButton: function(id, title, message, yesButtonText, noButtonText, yesFunction, noFunction, cancellable) { + var dialogId = this.generateModalId(id); + + var json = this._modalDialogJSON(id, title, cancellable, [ + { + id: dialogId + '-title', + type: 'fixedtext', + text: title, + hidden: !window.mode.isMobile() + }, + { + id: dialogId + '-label', + type: 'fixedtext', + text: message + }, + { + id: '', + type: 'buttonbox', + text: '', + enabled: true, + children: [ + noButtonText ? { + id: dialogId + '-nobutton', + type: 'pushbutton', + text: noButtonText + } : { type: 'container' }, + { + id: dialogId + '-yesbutton', + type: 'pushbutton', + text: yesButtonText, + } + ], + vertical: false, + layoutstyle: 'end' + }, + ]); + + this.showModal(json, + [ + { + id: dialogId + '-nobutton', + func: function() { + if (typeof noFunction === 'function') + noFunction(); + this.closeModal(dialogId); + }.bind(this) + }, + { + id: dialogId + '-yesbutton', + func: function() { + if (typeof yesFunction === 'function') + yesFunction(); + this.closeModal(dialogId); + }.bind(this) + } + ]); + }, + /// shows simple confirm modal (message + (cancel + ok) button) /// id - id of a dialog /// title - title of a dialog diff --git a/browser/src/control/Permission.js b/browser/src/control/Permission.js index 21baa6b86..3e35a1623 100644 --- a/browser/src/control/Permission.js +++ b/browser/src/control/Permission.js @@ -2,7 +2,7 @@ /* * Document permission handler */ -/* global app $ _ vex */ +/* global app $ _ */ L.Map.include({ readonlyStartingFormats: { 'txt': { canEdit: true, odfFormat: 'odt' }, @@ -148,30 +148,31 @@ L.Map.include({ _switchToEditMode: function () { // This will be handled by the native mobile app instead if (this._shouldStartReadOnly() && !window.ThisIsAMobileApp) { - var that = this; var fileName = this['wopi'].BaseFileName; var extension = this._getFileExtension(fileName); var extensionInfo = this.readonlyStartingFormats[extension]; - var buttonList = []; - if (!this['wopi'].UserCanNotWriteRelative) { - buttonList.push($.extend({}, vex.dialog.buttons.YES, { text: _('Save as ODF format') })); - } - buttonList.push($.extend({}, vex.dialog.buttons.NO, { text: extensionInfo.canEdit ? _('Continue editing') : _('Continue read only')})); + var yesButtonText = !this['wopi'].UserCanNotWriteRelative ? _('Save as ODF format'): null; + var noButtonText = extensionInfo.canEdit ? _('Continue editing') : _('Continue read only'); - vex.dialog.open({ - message: _('This document may contain formatting or content that cannot be saved in the current file format.'), - overlayClosesOnClick: false, - callback: L.bind(function (value) { - if (value) { - // offer save-as instead - this._offerSaveAs(); - } else { - this._proceedEditMode(); - } - }, that), - buttons: buttonList - }); + if (!yesButtonText) { + yesButtonText = noButtonText; + noButtonText = null; + } + + var yesFunction = !noButtonText ? function() { this._proceedEditMode(); }.bind(this) : function() { this._offerSaveAs(); }.bind(this); + var noFunction = function() { this._proceedEditMode(); }.bind(this); + + this.uiManager.showYesNoButton( + 'switch-to-edit-mode-modal', // id. + '', // Title. + _('This document may contain formatting or content that cannot be saved in the current file format.'), // Message. + yesButtonText, + noButtonText, + yesFunction, + noFunction, + false // Cancellable. + ); } else { this._proceedEditMode(); } diff --git a/cypress_test/integration_tests/desktop/calc/open_different_file_types_spec.js b/cypress_test/integration_tests/desktop/calc/open_different_file_types_spec.js index 8238c4656..e94d67e35 100644 --- a/cypress_test/integration_tests/desktop/calc/open_different_file_types_spec.js +++ b/cypress_test/integration_tests/desktop/calc/open_different_file_types_spec.js @@ -83,7 +83,7 @@ describe('Open different file types', function () { .should('be.visible') .click(); - cy.get('.vex-content button').click(); + cy.get('#modal-dialog-switch-to-edit-mode-modal-yesbutton').click(); assertData(); }); @@ -94,19 +94,17 @@ describe('Open different file types', function () { cy.get('#mobile-edit-button').should('be.visible') .click(); - cy.get('.vex-overlay').should('be.visible'); + cy.get('#modal-dialog-switch-to-edit-mode-modal-overlay').should('be.visible'); - cy.get('.vex-dialog-message') + cy.get('#modal-dialog-switch-to-edit-mode-modal-label') .should('have.text', 'This document may contain formatting or content that cannot be saved in the current file format.'); - cy.get('.vex-dialog-buttons button') + cy.get('#modal-dialog-switch-to-edit-mode-modal-yesbutton') .should('have.text', 'Continue read only') .click(); cy.get('#PermissionMode').should('be.visible') .should('have.text', ' Read-only '); - - cy.get('.vex-overlay').should('be.visible'); }); it('Open xlsm file' ,function() {