From 39f29c5ef8f20b3dbd51497874bf9a46f911fdbb Mon Sep 17 00:00:00 2001 From: Maxim Kadushkin Date: Fri, 23 Feb 2018 00:19:40 +0300 Subject: [PATCH] [common] lock/unlock header buttons on file menu events --- apps/common/main/lib/view/Header.js | 29 +++++++++++++++++++ apps/common/main/resources/less/header.less | 11 +++++++ .../main/app/controller/Viewport.js | 23 +++++++++++++-- .../main/app/controller/Viewport.js | 26 ++++++++++++++--- .../main/app/controller/Viewport.js | 26 ++++++++++++++--- 5 files changed, 104 insertions(+), 11 deletions(-) diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index 21263f6da..38e2729e0 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -630,6 +630,35 @@ define([ return this.btnSave; }, + lockHeaderBtns: function (alias, lock) { + var me = this; + if ( alias == 'users' ) { + if ( lock ) + $btnUsers.addClass('disabled').attr('disabled', 'disabled'); else + $btnUsers.removeClass('disabled').attr('disabled', ''); + } else { + function _lockButton(btn) { + if ( btn ) { + if ( lock ) { + btn.keepState = { + disabled: btn.isDisabled() + }; + } else { + btn.setDisabled( btn.keepState.disabled ); + delete me.btnUndo.keepState; + } + } + } + + if ( alias == 'undo' ) { + _lockButton(me.btnUndo); + } else + if ( alias == 'redo' ) { + _lockButton(me.btnRedo); + } + } + }, + textBack: 'Go to Documents', txtRename: 'Rename', textSaveBegin: 'Saving...', diff --git a/apps/common/main/resources/less/header.less b/apps/common/main/resources/less/header.less index 73243b7f6..e53a67037 100644 --- a/apps/common/main/resources/less/header.less +++ b/apps/common/main/resources/less/header.less @@ -168,6 +168,11 @@ cursor: pointer; font-size: 14px; } + + &.disabled { + opacity: 0.65; + pointer-events: none; + } } .cousers-menu { @@ -180,6 +185,12 @@ width: 285px; font-size: 12px; + z-index: 1042; + + .top-title & { + top: @height-title + @height-tabs - 8px; + } + > label { white-space: normal; } diff --git a/apps/documenteditor/main/app/controller/Viewport.js b/apps/documenteditor/main/app/controller/Viewport.js index 83097ded2..c1cc0ea62 100644 --- a/apps/documenteditor/main/app/controller/Viewport.js +++ b/apps/documenteditor/main/app/controller/Viewport.js @@ -68,6 +68,10 @@ define([ var me = this; this.addListeners({ + 'FileMenu': { + 'menu:hide': me.onFileMenu.bind(me, 'hide'), + 'menu:show': me.onFileMenu.bind(me, 'show') + }, 'Toolbar': { 'render:before' : function (toolbar) { var config = DE.getController('Main').appOptions; @@ -79,12 +83,17 @@ define([ Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal'); }, 'undo:disabled' : function (state) { - if ( me.header.btnUndo ) - me.header.btnUndo.setDisabled(state); + if ( me.header.btnUndo ) { + if ( me.header.btnUndo.keepState ) + me.header.btnUndo.keepState.disabled = state; + else me.header.btnUndo.setDisabled(state); + } }, 'redo:disabled' : function (state) { if ( me.header.btnRedo ) - me.header.btnRedo.setDisabled(state); + if ( me.header.btnRedo.keepState ) + me.header.btnRedo.keepState.disabled = state; + else me.header.btnRedo.setDisabled(state); }, 'save:disabled' : function (state) { if ( me.header.btnSave ) @@ -197,6 +206,14 @@ define([ onWindowResize: function(e) { this.onLayoutChanged('window'); Common.NotificationCenter.trigger('window:resize'); + }, + + onFileMenu: function (opts) { + var me = this; + var _need_disable = opts == 'show'; + + me.header.lockHeaderBtns( 'undo', _need_disable ); + me.header.lockHeaderBtns( 'redo', _need_disable ); } }); }); diff --git a/apps/presentationeditor/main/app/controller/Viewport.js b/apps/presentationeditor/main/app/controller/Viewport.js index 298096677..6d80c3200 100644 --- a/apps/presentationeditor/main/app/controller/Viewport.js +++ b/apps/presentationeditor/main/app/controller/Viewport.js @@ -69,6 +69,10 @@ define([ // This most important part when we will tell our controller what events should be handled this.addListeners({ + 'FileMenu': { + 'menu:hide': me.onFileMenu.bind(me, 'hide'), + 'menu:show': me.onFileMenu.bind(me, 'show') + }, 'Toolbar': { 'render:before' : function (toolbar) { var config = PE.getController('Main').appOptions; @@ -80,12 +84,18 @@ define([ Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal'); }, 'undo:disabled' : function (state) { - if ( me.header.btnUndo ) - me.header.btnUndo.setDisabled(state); + if ( me.header.btnUndo ) { + if ( me.header.btnUndo.keepState ) + me.header.btnUndo.keepState.disabled = state; + else me.header.btnUndo.setDisabled(state); + } }, 'redo:disabled' : function (state) { - if ( me.header.btnRedo ) - me.header.btnRedo.setDisabled(state); + if ( me.header.btnRedo ) { + if ( me.header.btnRedo.keepState ) + me.header.btnRedo.keepState.disabled = state; + else me.header.btnRedo.setDisabled(state); + } }, 'save:disabled' : function (state) { if ( me.header.btnSave ) @@ -236,6 +246,14 @@ define([ element.msRequestFullscreen(); } } + }, + + onFileMenu: function (opts) { + var me = this; + var _need_disable = opts == 'show'; + + me.header.lockHeaderBtns( 'undo', _need_disable ); + me.header.lockHeaderBtns( 'redo', _need_disable ); } }); }); diff --git a/apps/spreadsheeteditor/main/app/controller/Viewport.js b/apps/spreadsheeteditor/main/app/controller/Viewport.js index dadd49ec1..9998b0722 100644 --- a/apps/spreadsheeteditor/main/app/controller/Viewport.js +++ b/apps/spreadsheeteditor/main/app/controller/Viewport.js @@ -67,6 +67,10 @@ define([ // This most important part when we will tell our controller what events should be handled this.addListeners({ + 'FileMenu': { + 'menu:hide': me.onFileMenu.bind(me, 'hide'), + 'menu:show': me.onFileMenu.bind(me, 'show') + }, 'Toolbar': { 'render:before' : function (toolbar) { var config = SSE.getController('Main').appOptions; @@ -78,12 +82,18 @@ define([ Common.Utils.InternalSettings.get('toolbar-height-compact') : Common.Utils.InternalSettings.get('toolbar-height-normal'); }, 'undo:disabled' : function (state) { - if ( me.header.btnUndo ) - me.header.btnUndo.setDisabled(state); + if ( me.header.btnUndo ) { + if ( me.header.btnUndo.keepState ) + me.header.btnUndo.keepState.disabled = state; + else me.header.btnUndo.setDisabled(state); + } }, 'redo:disabled' : function (state) { - if ( me.header.btnRedo ) - me.header.btnRedo.setDisabled(state); + if ( me.header.btnRedo ) { + if ( me.header.btnRedo.keepState ) + me.header.btnRedo.keepState.disabled = state; + else me.header.btnRedo.setDisabled(state); + } }, 'save:disabled' : function (state) { if ( me.header.btnSave ) @@ -205,6 +215,14 @@ define([ onWindowResize: function(e) { this.onLayoutChanged('window'); Common.NotificationCenter.trigger('window:resize'); + }, + + onFileMenu: function (opts) { + var me = this; + var _need_disable = opts == 'show'; + + me.header.lockHeaderBtns( 'undo', _need_disable ); + me.header.lockHeaderBtns( 'redo', _need_disable ); } }); });