From aeb279276de18ddd69f80571d96fb5431633307c Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 10 Nov 2017 11:59:05 +0300 Subject: [PATCH] [PE] Show tooltip and disable editing when document is signed. --- apps/presentationeditor/main/app.js | 1 + .../main/app/controller/Main.js | 6 +- .../main/app/controller/RightMenu.js | 5 ++ .../main/app/controller/Toolbar.js | 5 +- .../main/app/view/DocumentHolder.js | 30 ++++--- .../main/app/view/FileMenuPanels.js | 8 +- .../main/app/view/RightMenu.js | 8 +- .../main/app/view/SignatureSettings.js | 80 +++++++++++++++---- .../main/app/view/Statusbar.js | 1 + apps/presentationeditor/main/app_dev.js | 1 + 10 files changed, 110 insertions(+), 35 deletions(-) diff --git a/apps/presentationeditor/main/app.js b/apps/presentationeditor/main/app.js index 03d2bac45..35ad12722 100644 --- a/apps/presentationeditor/main/app.js +++ b/apps/presentationeditor/main/app.js @@ -176,6 +176,7 @@ require([ 'presentationeditor/main/app/view/SlideSettings', 'presentationeditor/main/app/view/TableSettings', 'presentationeditor/main/app/view/TextArtSettings', + 'presentationeditor/main/app/view/SignatureSettings', 'common/main/lib/util/utils', 'common/main/lib/util/LocalStorage', 'common/main/lib/controller/Fonts' diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 29588c3a3..39572709c 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -714,14 +714,12 @@ define([ toolbarController.onApiCoAuthoringDisconnect(); me.api.UpdateInterfaceState(); - if (me.appOptions.canBrandingExt) - Common.NotificationCenter.trigger('document:ready', 'main'); + Common.NotificationCenter.trigger('document:ready', 'main'); } }, 50); } else { documentHolderController.getView('DocumentHolder').createDelayedElementsViewer(); - if (me.appOptions.canBrandingExt) - Common.NotificationCenter.trigger('document:ready', 'main'); + Common.NotificationCenter.trigger('document:ready', 'main'); } if (this.appOptions.canAnalytics && false) diff --git a/apps/presentationeditor/main/app/controller/RightMenu.js b/apps/presentationeditor/main/app/controller/RightMenu.js index b9aa0bf20..46a9cd588 100644 --- a/apps/presentationeditor/main/app/controller/RightMenu.js +++ b/apps/presentationeditor/main/app/controller/RightMenu.js @@ -211,6 +211,11 @@ define([ this.setMode({isEdit: false}); }, + SetDisabled: function(disabled, allowSignature) { + this.setMode({isEdit: !disabled}); + this.rightmenu.SetDisabled('', disabled, true, allowSignature); + }, + onInsertTable: function() { this._settings[Common.Utils.documentSettingsType.Table].needShow = true; }, diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 129ad0ec1..44fffd267 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -2043,7 +2043,10 @@ define([ this._state.activated = true; }, - DisableToolbar: function(disable) { + DisableToolbar: function(disable, viewMode) { + if (viewMode!==undefined) this.editMode = !viewMode; + disable = disable || !this.editMode; + var mask = $('.toolbar-mask'); if (disable && mask.length>0 || !disable && mask.length==0) return; diff --git a/apps/presentationeditor/main/app/view/DocumentHolder.js b/apps/presentationeditor/main/app/view/DocumentHolder.js index d9f688a57..08ab41cc1 100644 --- a/apps/presentationeditor/main/app/view/DocumentHolder.js +++ b/apps/presentationeditor/main/app/view/DocumentHolder.js @@ -68,7 +68,8 @@ define([ me._currentSpellObj = undefined; me._currLang = {}; me._state = {}; - + me._isDisabled = false; + /** coauthoring begin **/ var usersStore = PE.getCollection('Common.Collections.Users'); /** coauthoring end **/ @@ -187,6 +188,9 @@ define([ var fillViewMenuProps = function(selectedElements) { if (!selectedElements || !_.isArray(selectedElements)) return; + if (!me.viewModeMenu) + me.createDelayedElementsViewer(); + var menu_props = {}, menu_to_show = null; _.each(selectedElements, function(element, index) { @@ -210,7 +214,7 @@ define([ var showObjectMenu = function(event, docElement, eOpts){ if (me.api){ - var obj = (me.mode.isEdit) ? fillMenuProps(me.api.getSelectedElements()) : fillViewMenuProps(me.api.getSelectedElements()); + var obj = (me.mode.isEdit && !me._isDisabled) ? fillMenuProps(me.api.getSelectedElements()) : fillViewMenuProps(me.api.getSelectedElements()); if (obj) showPopupMenu(obj.menu_to_show, obj.menu_props, event, docElement, eOpts); } }; @@ -218,7 +222,7 @@ define([ var onContextMenu = function(event){ _.delay(function(){ if (event.get_Type() == Asc.c_oAscContextMenuTypes.Thumbnails) { - showPopupMenu.call(me, me.slideMenu, {isSlideSelect: event.get_IsSlideSelect(), isSlideHidden: event.get_IsSlideHidden(), fromThumbs: true}, event); + !me._isDisabled && showPopupMenu.call(me, me.slideMenu, {isSlideSelect: event.get_IsSlideSelect(), isSlideHidden: event.get_IsSlideHidden(), fromThumbs: true}, event); } else { showObjectMenu.call(me, event); } @@ -228,7 +232,7 @@ define([ var onFocusObject = function(selectedElements) { if (me.currentMenu && me.currentMenu.isVisible()){ if (me.api.asc_getCurrentFocusObject() === 0 ){ // thumbnails - if (me.slideMenu===me.currentMenu) { + if (me.slideMenu===me.currentMenu && !me._isDisabled) { var isHidden = false; _.each(selectedElements, function(element, index) { if (Asc.c_oAscTypeSelectElement.Slide == element.get_ObjectType()) { @@ -240,7 +244,7 @@ define([ me.currentMenu.alignPosition(); } } else { - var obj = (me.mode.isEdit) ? fillMenuProps(selectedElements) : fillViewMenuProps(selectedElements); + var obj = (me.mode.isEdit && !me._isDisabled) ? fillMenuProps(selectedElements) : fillViewMenuProps(selectedElements); if (obj) { if (obj.menu_to_show===me.currentMenu) { me.currentMenu.options.initMenu(obj.menu_props); @@ -579,7 +583,7 @@ define([ var onDialogAddHyperlink = function() { var win, props, text; - if (me.api && me.mode.isEdit){ + if (me.api && me.mode.isEdit && !me._isDisabled){ var handlerDlg = function(dlg, result) { if (result == 'ok') { props = dlg.getSettings(); @@ -672,7 +676,7 @@ define([ }; var onDoubleClickOnChart = function(chart) { - if (me.mode.isEdit) { + if (me.mode.isEdit && !me._isDisabled) { var diagramEditor = PE.getController('Common.Controllers.ExternalDiagramEditor').getView('Common.Views.ExternalDiagramEditor'); if (diagramEditor && chart) { @@ -1806,10 +1810,10 @@ define([ this.viewModeMenu = new Common.UI.Menu({ initMenu: function (value) { - menuViewUndo.setVisible(me.mode.canCoAuthoring && me.mode.canComments); - menuViewUndo.setDisabled(!me.api.asc_getCanUndo()); - menuViewCopySeparator.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments); - menuViewAddComment.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments); + menuViewUndo.setVisible(me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); + menuViewUndo.setDisabled(!me.api.asc_getCanUndo() && !me._isDisabled); + menuViewCopySeparator.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); + menuViewAddComment.setVisible(!value.isChart && me.api.can_AddQuotedComment() !== false && me.mode.canCoAuthoring && me.mode.canComments && !me._isDisabled); menuViewAddComment.setDisabled(value.locked); }, items: [ @@ -3226,6 +3230,10 @@ define([ } }, + SetDisabled: function(state) { + this._isDisabled = state; + }, + insertRowAboveText : 'Row Above', insertRowBelowText : 'Row Below', insertColumnLeftText : 'Column Left', diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index 363033366..1ae9d2c05 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -947,10 +947,14 @@ define([ var sign = {name: item.asc_getSigner1(), date: '18/05/2017'}; (item.asc_getValid()==0) ? valid_arr.push(sign) : invalid_arr.push(sign); }); + + // valid_arr = [{name: 'Hammish Mitchell', guid: '123', date: '18/05/2017'}, {name: 'Someone Somewhere', guid: '345', date: '18/05/2017'}]; + // invalid_arr = [{name: 'Mary White', guid: '111', date: '18/05/2017'}, {name: 'John Black', guid: '456', date: '18/05/2017'}]; + this.cntValidSign.html(this.templateValid({signatures: valid_arr, header: this.strValid})); this.cntInvalidSign.html(this.templateValid({signatures: invalid_arr, header: this.strInvalid})); - // this.cntValidSign.html(this.templateValid({signatures: [{name: 'Hammish Mitchell', date: '18/05/2017'}, {name: 'Someone Somewhere', date: '18/05/2017'}], header: this.strValid})); - // this.cntInvalidSign.html(this.templateValid({signatures: [{name: 'Mary White', date: '18/05/2017'}, {name: 'John Black', date: '18/05/2017'}], header: this.strInvalid})); + + this.btnAddInvisibleSign.setDisabled(valid_arr.length>0 || invalid_arr.length>0); }, strProtect: 'Protect Document', diff --git a/apps/presentationeditor/main/app/view/RightMenu.js b/apps/presentationeditor/main/app/view/RightMenu.js index 9f12f3b79..28dfdf324 100644 --- a/apps/presentationeditor/main/app/view/RightMenu.js +++ b/apps/presentationeditor/main/app/view/RightMenu.js @@ -280,7 +280,7 @@ define([ return (this.minimizedMode) ? null : this.$el.find(".settings-panel.active")[0].id; }, - SetDisabled: function(id, disabled, all) { + SetDisabled: function(id, disabled, all, allowSignature) { if (all) { this.slideSettings.SetSlideDisabled(disabled, disabled, disabled); this.paragraphSettings.disableControls(disabled); @@ -288,6 +288,12 @@ define([ this.tableSettings.disableControls(disabled); this.imageSettings.disableControls(disabled); this.chartSettings.disableControls(disabled); + + if (!allowSignature && this.signatureSettings) { + this.signatureSettings.disableControls(disabled); + this.btnSignature.setDisabled(disabled); + } + } else { var cmp = $("#" + id); if (disabled !== cmp.hasClass('disabled')) { diff --git a/apps/presentationeditor/main/app/view/SignatureSettings.js b/apps/presentationeditor/main/app/view/SignatureSettings.js index 28b6af1a6..80bac26ee 100644 --- a/apps/presentationeditor/main/app/view/SignatureSettings.js +++ b/apps/presentationeditor/main/app/view/SignatureSettings.js @@ -65,10 +65,9 @@ define([ initialize: function () { var me = this; - this._initSettings = true; - this._state = { DisabledControls: false, + DisabledInsertControls: false, validSignatures: undefined, invalidSignatures: undefined }; @@ -118,17 +117,11 @@ define([ if (this.api) { this.api.asc_registerCallback('asc_onUpdateSignatures', _.bind(this.onUpdateSignatures, this)); } + Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this)); return this; }, - createDelayedControls: function() { - this._initSettings = false; - }, - ChangeSettings: function(props) { - if (this._initSettings) - this.createDelayedControls(); - if (!this._state.validSignatures || !this._state.invalidSignatures) { this.onUpdateSignatures(this.api.asc_getSignatures()); } @@ -141,15 +134,19 @@ define([ }, disableControls: function(disable) { - if (this._initSettings) return; - if (this._state.DisabledControls!==disable) { this._state.DisabledControls = disable; + this.$linksView && this.$linksView.toggleClass('disabled', disable); + } + this.disableInsertControls(disable); + }, + + disableInsertControls: function(disable) { + if (this._state.DisabledInsertControls!==disable) { + this._state.DisabledInsertControls = disable; _.each(this.lockedControls, function(item) { item.setDisabled(disable); }); - this.$linksSign.toggleClass('disabled', disable); - this.$linksView.toggleClass('disabled', disable); } }, @@ -166,10 +163,12 @@ define([ var sign = {name: item.asc_getSigner1(), guid: item.asc_getId(), date: '18/05/2017'}; (item.asc_getValid()==0) ? me._state.validSignatures.push(sign) : me._state.invalidSignatures.push(sign); }); + + // me._state.validSignatures = [{name: 'Hammish Mitchell', guid: '123', date: '18/05/2017'}, {name: 'Someone Somewhere', guid: '345', date: '18/05/2017'}]; + // me._state.invalidSignatures = [{name: 'Mary White', guid: '111', date: '18/05/2017'}, {name: 'John Black', guid: '456', date: '18/05/2017'}]; + this.cntValidSign.html(this.templateValid({signatures: me._state.validSignatures, header: this.strValid})); this.cntInvalidSign.html(this.templateValid({signatures: me._state.invalidSignatures, header: this.strInvalid})); - // this.cntValidSign.html(this.templateValid({signatures: [{name: 'Hammish Mitchell', guid: '123', date: '18/05/2017'}, {name: 'Someone Somewhere', guid: '345', date: '18/05/2017'}], header: this.strValid})); - // this.cntInvalidSign.html(this.templateValid({signatures: [{name: 'Mary White', guid: '111', date: '18/05/2017'}, {name: 'John Black', guid: '456', date: '18/05/2017'}], header: this.strInvalid})); this.$linksView = $('.signature-view-link', this.$el); var width = this.$linksView.width(); @@ -201,11 +200,60 @@ define([ this.api.asc_ViewCertificate(target.attr('data-value')); }, + onDocumentReady: function() { + this.ChangeSettings(); + + var me = this, + hasSigned = (me._state.validSignatures.length>0 || me._state.invalidSignatures.length>0); + + hasSigned && this.disableEditing(hasSigned); + + if (!this._state.tip && hasSigned) { + this._state.tip = new Common.UI.SynchronizeTip({ + target : PE.getController('RightMenu').getView('RightMenu').btnSignature.btnEl, + text : this.txtSignedDocument, + showLink: hasSigned, + textLink: this.txtContinueEditing, + placement: 'left' + }); + this._state.tip.on({ + 'dontshowclick': function() { + me._state.tip.hide(); + // me.api.editSingedDoc(); + me.disableEditing(false); + }, + 'closeclick': function() { + me._state.tip.hide(); + } + }); + this._state.tip.show(); + } + }, + + disableEditing: function(disable) { + disable && PE.getController('RightMenu').getView('RightMenu').clearSelection(); + PE.getController('RightMenu').SetDisabled(disable, true); + PE.getController('Toolbar').DisableToolbar(disable, disable); + PE.getController('Statusbar').getView('Statusbar').SetDisabled(disable); + PE.getController('Common.Controllers.ReviewChanges').SetDisabled(disable); + PE.getController('DocumentHolder').getView('DocumentHolder').SetDisabled(disable); + + var leftMenu = PE.getController('LeftMenu').leftMenu; + leftMenu.btnComments.setDisabled(disable); + var comments = PE.getController('Common.Controllers.Comments'); + if (comments) + comments.setPreviewMode(disable); + + this.disableInsertControls(disable); + }, + strSignature: 'Signature', strInvisibleSign: 'Add invisible digital signature', strValid: 'Valid signatures', strInvalid: 'Invalid signatures', - strView: 'View' + strView: 'View', + txtSignedDocument: 'This document has been signed. It should not be edited.', + txtContinueEditing: 'Edit anyway' }, PE.Views.SignatureSettings || {})); }); \ No newline at end of file diff --git a/apps/presentationeditor/main/app/view/Statusbar.js b/apps/presentationeditor/main/app/view/Statusbar.js index 13a9ad775..553c3f7d7 100644 --- a/apps/presentationeditor/main/app/view/Statusbar.js +++ b/apps/presentationeditor/main/app/view/Statusbar.js @@ -369,6 +369,7 @@ define([ var langs = this.langMenu.items.length>0; this.btnLanguage.setDisabled(disable || !langs || this._state.no_paragraph); this.btnDocLanguage.setDisabled(disable || !langs); + this.mode.isEdit = !disable; }, onApiFocusObject: function(selectedObjects) { diff --git a/apps/presentationeditor/main/app_dev.js b/apps/presentationeditor/main/app_dev.js index 36dbe9e3f..b0574a8f1 100644 --- a/apps/presentationeditor/main/app_dev.js +++ b/apps/presentationeditor/main/app_dev.js @@ -167,6 +167,7 @@ require([ 'presentationeditor/main/app/view/SlideSettings', 'presentationeditor/main/app/view/TableSettings', 'presentationeditor/main/app/view/TextArtSettings', + 'presentationeditor/main/app/view/SignatureSettings', 'common/main/lib/util/utils', 'common/main/lib/util/LocalStorage', 'common/main/lib/controller/Fonts'