From 470fdcc1ba45ddcf68aa42c188d7d7ccf8a391cf Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 26 Jul 2023 23:02:41 +0300 Subject: [PATCH] [PDFE] Change edit/view modes --- apps/common/main/lib/view/Draw.js | 2 +- apps/common/main/lib/view/Header.js | 37 ++++++++++++++++--- apps/pdfeditor/main/app/controller/Main.js | 1 + apps/pdfeditor/main/app/controller/Toolbar.js | 9 +++-- 4 files changed, 39 insertions(+), 10 deletions(-) diff --git a/apps/common/main/lib/view/Draw.js b/apps/common/main/lib/view/Draw.js index a3c42942ab..f69a4ba309 100644 --- a/apps/common/main/lib/view/Draw.js +++ b/apps/common/main/lib/view/Draw.js @@ -249,7 +249,7 @@ define([ }); me.btnEraser.updateHint(me.hintEraser); me.btnSelect.updateHint(me.hintSelect); - Common.NotificationCenter.trigger('tab:visible', 'draw', Common.UI.LayoutManager.isElementVisible('toolbar-draw')); + Common.NotificationCenter.trigger('tab:visible', 'draw', (!me.isPDFEditor || me.appConfig && me.appConfig.isPDFEdit) && Common.UI.LayoutManager.isElementVisible('toolbar-draw')); setEvents.call(me); }); diff --git a/apps/common/main/lib/view/Header.js b/apps/common/main/lib/view/Header.js index 0c0db6b4f4..0dc4b7c34e 100644 --- a/apps/common/main/lib/view/Header.js +++ b/apps/common/main/lib/view/Header.js @@ -246,6 +246,14 @@ define([ } } + function changePDFMode(config) { + var me = this; + if (!me.btnPDFMode || !config) return; + me.btnPDFMode.setIconCls('toolbar__icon icon--inverse ' + (config.isPDFEdit ? 'btn-edit' : (config.isPDFAnnotate ? 'btn-menu-comments' : 'btn-sheet-view'))); + me.btnPDFMode.setCaption(config.isPDFEdit ? me.textEdit : (config.isPDFAnnotate ? me.textComment : me.textView)); + me.btnPDFMode.updateHint(config.isPDFEdit ? me.tipEdit : (config.isPDFAnnotate ? me.tipComment : me.tipView)); + } + function onResize() { if (appConfig && appConfig.isEdit && !(appConfig.customization && appConfig.customization.compactHeader)) { updateDocNamePosition(appConfig); @@ -388,17 +396,17 @@ define([ me.btnSearch.updateHint(me.tipSearch + Common.Utils.String.platformKey('Ctrl+F')); if (me.btnPDFMode) { - // me.btnPDFMode.updateHint(me.tipPDFMode); var menuTemplate = _.template('
' + '<% if (!_.isEmpty(iconCls)) { %>' + '' + '<% } %>' + '<%= caption %>
' + - '<% if (options.description !== null) { %>' + + '<% if (options.description !== null) { %>' + '<% } %>
'); me.btnPDFMode.setMenu(new Common.UI.Menu({ cls: 'ppm-toolbar', - style: 'max-width: 220px;', + style: 'width: 220px;', + menuAlign: 'tr-br', items: [ { caption: me.textEdit, @@ -423,6 +431,19 @@ define([ } ] })); + me.btnPDFMode.menu.on('item:click', function (menu, item) { + if (item.value==='edit' && appConfig.canPDFEdit) { + appConfig.isPDFEdit = true; + appConfig.isPDFAnnotate = false; + } else if (item.value==='comment' && appConfig.canPDFAnnotate) { + appConfig.isPDFEdit = false; + appConfig.isPDFAnnotate = true; + } else if (item.value==='view') { + appConfig.isPDFEdit = appConfig.isPDFAnnotate = false; + } + changePDFMode.call(me, appConfig); + Common.NotificationCenter.trigger('pdf:mode'); + }); } if (appConfig.isEdit && !(appConfig.customization && appConfig.customization.compactHeader)) Common.NotificationCenter.on('window:resize', onResize); @@ -668,14 +689,15 @@ define([ if (isPDFEditor) { me.btnPDFMode = new Common.UI.Button({ cls: 'btn-header btn-header-pdf-mode no-caret', - iconCls: 'toolbar__icon icon--inverse ' + (config.isPDFEdit ? 'btn-edit' : (config.isPDFAnnotate ? 'btn-menu-comments' : 'btn-sheet-view')), - caption: config.isPDFEdit ? me.textEdit : (config.isPDFAnnotate ? me.textComment : me.textView), + iconCls: 'toolbar__icon icon--inverse btn-sheet-view', + caption: me.textView, menu: true, dataHint: '0', dataHintDirection: 'bottom', dataHintOffset: 'big' }); me.btnPDFMode.render($html.find('#slot-btn-pdf-mode')); + changePDFMode.call(me, config); } else $html.find('#slot-btn-pdf-mode').hide(); @@ -999,7 +1021,10 @@ define([ textEdit: 'Editing', textViewDesc: 'All changes will be saved locally', textCommentDesc: 'All changes will be saved to the file. Real time collaboration', - textEditDesc: 'All changes will be saved to the file. Real time collaboration' + textEditDesc: 'All changes will be saved to the file. Real time collaboration', + tipView: 'Viewing', + tipComment: 'Commenting', + tipEdit: 'Editing' } }(), Common.Views.Header || {})) }); diff --git a/apps/pdfeditor/main/app/controller/Main.js b/apps/pdfeditor/main/app/controller/Main.js index ae446a4257..5b33c37aea 100644 --- a/apps/pdfeditor/main/app/controller/Main.js +++ b/apps/pdfeditor/main/app/controller/Main.js @@ -1164,6 +1164,7 @@ define([ this.appOptions.canRequestEditRights = this.editorConfig.canRequestEditRights; this.appOptions.canEdit = true; this.appOptions.isEdit = true; + this.permissions.edit = this.permissions.comment = true; // !! Only for test !! this.appOptions.canPDFEdit = (this.permissions.edit !== false) && // can edit (this.editorConfig.canRequestEditRights || this.editorConfig.mode !== 'view') && // if mode=="view" -> canRequestEditRights must be defined (this.appOptions.canLicense); diff --git a/apps/pdfeditor/main/app/controller/Toolbar.js b/apps/pdfeditor/main/app/controller/Toolbar.js index 568f617775..12af9d8d2b 100644 --- a/apps/pdfeditor/main/app/controller/Toolbar.js +++ b/apps/pdfeditor/main/app/controller/Toolbar.js @@ -190,6 +190,9 @@ define([ Common.NotificationCenter.on('api:disconnect', _.bind(this.onApiCoAuthoringDisconnect, this)); this.api.asc_registerCallback('asc_onCanCopyCut', _.bind(this.onApiCanCopyCut, this)); this.api.asc_registerCallback('asc_onContextMenu', _.bind(this.onContextMenu, this)); + Common.NotificationCenter.on('pdf:mode', _.bind(function () { + this.toolbar.setVisible('draw', this.mode.isPDFEdit && Common.UI.LayoutManager.isElementVisible('toolbar-draw')); + }, this)); } }, @@ -472,19 +475,19 @@ define([ me.toolbar.btnCopy.$el.removeClass('split'); me.toolbar.processPanelVisible(null, true, true); } - + } + if ( config.canPDFEdit ) { var drawtab = me.getApplication().getController('Common.Controllers.Draw'); drawtab.setApi(me.api).setMode(config); $panel = drawtab.createToolbarPanel(); if ($panel) { tab = {action: 'draw', caption: me.toolbar.textTabDraw, extcls: 'canedit', layoutname: 'toolbar-draw', dataHintTitle: 'C'}; me.toolbar.addTab(tab, $panel, 2); - me.toolbar.setVisible('draw', Common.UI.LayoutManager.isElementVisible('toolbar-draw')); Array.prototype.push.apply(me.toolbar.lockControls, drawtab.getView().getButtons()); Array.prototype.push.apply(me.toolbar.paragraphControls, drawtab.getView().getButtons()); } - } + var tab = {caption: me.toolbar.textTabView, action: 'view', extcls: config.isEdit ? 'canedit' : '', layoutname: 'toolbar-view', dataHintTitle: 'W'}; var viewtab = me.getApplication().getController('ViewTab'); viewtab.setApi(me.api).setConfig({toolbar: me, mode: config});