From fae286743119ff5af05eacd130af487dce2fdfc5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 28 Jun 2017 14:20:49 +0300 Subject: [PATCH] Disable/enable comment button in the toolbar. --- apps/common/main/lib/controller/Comments.js | 5 ++--- .../main/app/controller/Toolbar.js | 16 ++++++++++----- .../main/app/controller/Toolbar.js | 20 +++++++++++++------ .../main/app/view/Toolbar.js | 3 ++- .../main/app/controller/Toolbar.js | 18 ++++++++++------- .../main/app/view/Toolbar.js | 3 ++- 6 files changed, 42 insertions(+), 23 deletions(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 867fb158a..bf32c4481 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -584,9 +584,8 @@ define([ } }, onAppAddComment: function () { - if ( this.api.can_AddQuotedComment() !== false ) { - this.addDummyComment(); - } + if ( this.can_AddQuotedComment && this.api.can_AddQuotedComment() === false ) return; + this.addDummyComment(); }, // SDK diff --git a/apps/documenteditor/main/app/controller/Toolbar.js b/apps/documenteditor/main/app/controller/Toolbar.js index a441ba4d2..023b12c95 100644 --- a/apps/documenteditor/main/app/controller/Toolbar.js +++ b/apps/documenteditor/main/app/controller/Toolbar.js @@ -728,6 +728,12 @@ define([ if (toolbar.listStylesAdditionalMenuItem && (frame_pr===undefined) !== toolbar.listStylesAdditionalMenuItem.isDisabled()) toolbar.listStylesAdditionalMenuItem.setDisabled(frame_pr===undefined); + need_disable = paragraph_locked || header_locked || in_chart || this.api.can_AddQuotedComment()===false; + if (this.btnsComment && this.btnsComment.length>0 && need_disable != this.btnsComment[0].isDisabled()) + _.each (this.btnsComment, function(item){ + item.setDisabled(need_disable); + }, this); + this._state.in_equation = in_equation; }, @@ -2787,7 +2793,7 @@ define([ var me = this; if ( config.canCoAuthoring && config.canComments ) { - var _btnsComment = []; + this.btnsComment = []; var slots = me.toolbar.$el.find('.slot-comment'); slots.each(function(index, el) { var _cls = 'btn-toolbar'; @@ -2799,13 +2805,13 @@ define([ caption: me.toolbar.capBtnComment }).render( slots.eq(index) ); - _btnsComment.push(button); + me.btnsComment.push(button); }); - if ( _btnsComment.length ) { + if ( this.btnsComment.length ) { var _comments = DE.getController('Common.Controllers.Comments').getView(); - Array.prototype.push.apply(me.toolbar.toolbarControls, _btnsComment); - _btnsComment.forEach(function (btn) { + Array.prototype.push.apply(me.toolbar.paragraphControls, this.btnsComment); + this.btnsComment.forEach(function (btn) { btn.updateHint( _comments.textAddComment ); btn.on('click', function (btn, e) { Common.NotificationCenter.trigger('app:comment:add', 'toolbar'); diff --git a/apps/presentationeditor/main/app/controller/Toolbar.js b/apps/presentationeditor/main/app/controller/Toolbar.js index 9ee7a08ea..1a278f294 100644 --- a/apps/presentationeditor/main/app/controller/Toolbar.js +++ b/apps/presentationeditor/main/app/controller/Toolbar.js @@ -584,6 +584,8 @@ define([ ]}); this.toolbar.lockToolbar(PE.enumLock.noSlides, this._state.no_slides, { array: this.toolbar.btnsInsertImage.concat(this.toolbar.btnsInsertText, this.toolbar.btnsInsertShape) }); + if (this.btnsComment) + this.toolbar.lockToolbar(PE.enumLock.noSlides, this._state.no_slides, { array: this.btnsComment }); } }, @@ -648,9 +650,11 @@ define([ if (shape_locked!==undefined && this._state.shapecontrolsdisable !== shape_locked) { if (this._state.activated) this._state.shapecontrolsdisable = shape_locked; - this.toolbar.lockToolbar(PE.enumLock.shapeLock, shape_locked, {array: me.toolbar.shapeControls.concat(me.toolbar.paragraphControls)}); + this.toolbar.lockToolbar(PE.enumLock.shapeLock, shape_locked, {array: me.toolbar.shapeControls.concat(me.toolbar.paragraphControls).concat(me.btnsComment)}); } + this.toolbar.lockToolbar(PE.enumLock.commentLock, this.api.can_AddQuotedComment() === false, { array: this.btnsComment }); + if (this._state.no_object !== no_object ) { if (this._state.activated) this._state.no_object = no_object; this.toolbar.lockToolbar(PE.enumLock.noObjectSelected, no_object, {array: [me.toolbar.btnShapeAlign, me.toolbar.btnShapeArrange ]}); @@ -2059,8 +2063,9 @@ define([ onAppReady: function (config) { var me = this; + this.btnsComment = []; if ( config.canCoAuthoring && config.canComments ) { - var _btnsComment = []; + var _set = PE.enumLock; var slots = me.toolbar.$el.find('.slot-comment'); slots.each(function(index, el) { var _cls = 'btn-toolbar'; @@ -2069,21 +2074,24 @@ define([ var button = new Common.UI.Button({ cls: _cls, iconCls: 'svgicon svg-btn-comments', + lock: [_set.slideDeleted, _set.lostConnect, _set.noSlides, _set.shapeLock, _set.commentLock], caption: me.toolbar.capBtnComment }).render( slots.eq(index) ); - _btnsComment.push(button); + me.btnsComment.push(button); }); - if ( _btnsComment.length ) { + if ( this.btnsComment.length ) { var _comments = PE.getController('Common.Controllers.Comments').getView(); - // Array.prototype.push.apply(me.toolbar.toolbarControls, _btnsComment); - _btnsComment.forEach(function (btn) { + Array.prototype.push.apply(me.toolbar.lockControls, this.btnsComment); + Array.prototype.push.apply(me.toolbar.slideOnlyControls, this.btnsComment); + this.btnsComment.forEach(function (btn) { btn.updateHint( _comments.textAddComment ); btn.on('click', function (btn, e) { Common.NotificationCenter.trigger('app:comment:add', 'toolbar'); }); }, this); + this.toolbar.lockToolbar(PE.enumLock.noSlides, this._state.no_slides, { array: this.btnsComment }); } } diff --git a/apps/presentationeditor/main/app/view/Toolbar.js b/apps/presentationeditor/main/app/view/Toolbar.js index 63bc160cc..88fc2642b 100644 --- a/apps/presentationeditor/main/app/view/Toolbar.js +++ b/apps/presentationeditor/main/app/view/Toolbar.js @@ -79,7 +79,8 @@ define([ disableOnStart: 'on-start', cantPrint: 'cant-print', noTextSelected: 'no-text', - inEquation: 'in-equation' + inEquation: 'in-equation', + commentLock: 'can-comment' }; var buttonsArray = function (opts) { diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 944350a84..96f260085 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -1600,7 +1600,7 @@ define([ toolbar.mnuitemClearFilter, toolbar.btnNamedRange.menu.items[0], toolbar.btnNamedRange.menu.items[1] - ], + ].concat(this.btnsComment), merge: true, clear: [SSE.enumLock.editFormula, SSE.enumLock.editText] }); @@ -2087,6 +2087,8 @@ define([ toolbar.btnAddCell.menu.items[1].setDisabled(this._state.controlsdisabled.cells_down); toolbar.btnDeleteCell.menu.items[1].setDisabled(this._state.controlsdisabled.cells_down); } + + toolbar.lockToolbar(SSE.enumLock.commentLock, info.asc_getComments().length>0, { array: this.btnsComment }); }, onApiSelectionChanged_DiagramEditor: function(info) { @@ -2674,7 +2676,7 @@ define([ toolbar.mnuitemSortZA, toolbar.mnuitemAutoFilter, toolbar.mnuitemClearFilter - ], + ].concat(this.btnsComment), merge: true, clear: [_set.selImage, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.coAuth] }); @@ -2884,8 +2886,9 @@ define([ onAppReady: function (config) { var me = this; + this.btnsComment = []; if ( config.canCoAuthoring && config.canComments ) { - var _btnsComment = []; + var _set = SSE.enumLock; var slots = me.toolbar.$el.find('.slot-comment'); slots.each(function(index, el) { var _cls = 'btn-toolbar'; @@ -2894,16 +2897,17 @@ define([ var button = new Common.UI.Button({ cls: _cls, iconCls: 'svgicon svg-btn-comments', + lock: [_set.editCell, _set.selChart, _set.selChartText, _set.selShape, _set.selShapeText, _set.selImage, _set.lostConnect, _set.coAuth, _set.commentLock], caption: me.toolbar.capBtnComment }).render( slots.eq(index) ); - _btnsComment.push(button); + me.btnsComment.push(button); }); - if ( _btnsComment.length ) { + if ( this.btnsComment.length ) { var _comments = SSE.getController('Common.Controllers.Comments').getView(); - Array.prototype.push.apply(me.toolbar.lockControls, _btnsComment); - _btnsComment.forEach(function (btn) { + Array.prototype.push.apply(me.toolbar.lockControls, this.btnsComment); + this.btnsComment.forEach(function (btn) { btn.updateHint( _comments.textAddComment ); btn.on('click', function (btn, e) { Common.NotificationCenter.trigger('app:comment:add', 'toolbar'); diff --git a/apps/spreadsheeteditor/main/app/view/Toolbar.js b/apps/spreadsheeteditor/main/app/view/Toolbar.js index 41461ee3e..145977b16 100644 --- a/apps/spreadsheeteditor/main/app/view/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/view/Toolbar.js @@ -76,7 +76,8 @@ define([ menuFileOpen: 'menu-file-open', cantPrint: 'cant-print', multiselect: 'is-multiselect', - cantHyperlink: 'cant-hyperlink' + cantHyperlink: 'cant-hyperlink', + commentLock: 'can-comment' }; SSE.Views.Toolbar = Common.UI.Mixtbar.extend(_.extend({