From 58a1ddb834c27ec38ff7fcc5fd656ea0e05074be Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 11 Oct 2018 10:32:39 +0300 Subject: [PATCH 01/18] Find emails for sending invitation (begins with + or @) when adding comment. --- apps/common/main/lib/controller/Comments.js | 2 +- apps/common/main/lib/util/utils.js | 2 ++ apps/common/main/lib/view/Comments.js | 27 +++++++++++++++++++++ 3 files changed, 30 insertions(+), 1 deletion(-) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 47d095e8b..a951be199 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -1341,7 +1341,7 @@ define([ this.api.asc_addComment(comment); this.view.showEditContainer(false); - + this.view.pickEMail(commentVal); if (!_.isUndefined(this.api.asc_SetDocumentPlaceChangedEnabled)) { this.api.asc_SetDocumentPlaceChangedEnabled(false); } diff --git a/apps/common/main/lib/util/utils.js b/apps/common/main/lib/util/utils.js index 397fc45aa..b5c70a486 100644 --- a/apps/common/main/lib/util/utils.js +++ b/apps/common/main/lib/util/utils.js @@ -90,6 +90,7 @@ Common.Utils = _.extend(new(function() { hostnameRe = /^(((https?)|(ftps?)):\/\/)?([\-\wа-яё]*:?[\-\wа-яё]*@)?(([\-\wа-яё]+\.)+[\wа-яё\-]{2,}(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`'~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/i, localRe = /^(((https?)|(ftps?)):\/\/)([\-\wа-яё]*:?[\-\wа-яё]*@)?(([\-\wа-яё]+)(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`'~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/i, emailStrongRe = /(mailto:)?([a-z0-9'\._-]+@[a-z0-9\.-]+\.[a-z0-9]{2,4})([a-яё0-9\._%+-=\?:&]*)/ig, + emailAddStrongRe = /(mailto:|\s[@]|\s[+])?([a-z0-9'\._-]+@[a-z0-9\.-]+\.[a-z0-9]{2,4})([a-яё0-9\._%+-=\?:&]*)/ig, ipStrongRe = /(((https?)|(ftps?)):\/\/([\-\wа-яё]*:?[\-\wа-яё]*@)?)(((1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9])\.){3}(1[0-9]{2}|2[0-4][0-9]|25[0-5]|[1-9][0-9]|[0-9]))(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?/ig, hostnameStrongRe = /((((https?)|(ftps?)):\/\/([\-\wа-яё]*:?[\-\wа-яё]*@)?)|(([\-\wа-яё]*:?[\-\wа-яё]*@)?www\.))((([\-\wа-яё]+\.)+[\wа-яё\-]{2,}|([\-\wа-яё]+))(:\d+)?(\/[%\-\wа-яё]*(\.[\wа-яё]{2,})?(([\wа-яё\-\.\?\\\/+@&#;:`~=%!,\(\)]*)(\.[\wа-яё]{2,})?)*)*\/?)/ig, documentSettingsType = { @@ -200,6 +201,7 @@ Common.Utils = _.extend(new(function() { hostnameRe: hostnameRe, localRe: localRe, emailStrongRe: emailStrongRe, + emailAddStrongRe: emailAddStrongRe, ipStrongRe: ipStrongRe, hostnameStrongRe: hostnameStrongRe, documentSettingsType: documentSettingsType, diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index 5d4619ee0..c0b99c708 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -674,6 +674,27 @@ define([ return ''; }); +/* message.replace(Common.Utils.emailAddStrongRe, function(subStr, addStr, mailStr) { + // var addition = subStr.match(/^(\s[@]|\s[+])(\S*)/) || ''; + // if (addition) { + // subStr = addition[2]; + // addition = addition[1]; // + or @ + // console.log(subStr); + // } + // if (addStr) + // console.log(subStr + ', ' + mailStr); // send email + var ref = (! /((^mailto:)\/\/)/i.test(mailStr) ) ? ('mailto:' + mailStr) : mailStr; + offset = arguments[arguments.length-2]; + len = subStr.length; + var elem = _.find(arr, function(item){ + return ( (offset>=item.start) && (offsetitem.start)); + }); + if (!elem) + arr.push({start: offset, end: len+offset, str: (addStr || '') + '' + mailStr + ''}); + return ''; + }); +*/ message.replace(Common.Utils.emailStrongRe, function(subStr) { var ref = (! /((^mailto:)\/\/)/i.test(subStr) ) ? ('mailto:' + subStr) : subStr; offset = arguments[arguments.length-2]; @@ -700,6 +721,12 @@ define([ return str_res; }, + pickEMail: function (message) { + var arr = Common.Utils.String.htmlEncode(message).match(/\B[@+][A-Z0-9._%+-]+@[A-Z0-9._]+\.[A-Z]+\b/gi); + console.log(arr); // send e-mails + return arr; + }, + textComments : 'Comments', textAnonym : 'Guest', textAddCommentToDoc : 'Add Comment to Document', From 145008eaae2e3e20febf73dacb12cd9091b58ae5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 30 Oct 2018 11:13:23 +0300 Subject: [PATCH 02/18] [DE] Add user email to comment --- apps/common/main/lib/component/Menu.js | 11 +- apps/common/main/lib/controller/Comments.js | 4 +- apps/common/main/lib/view/ReviewPopover.js | 128 ++++++++++++++++++ .../main/app/controller/Main.js | 1 + 4 files changed, 140 insertions(+), 4 deletions(-) diff --git a/apps/common/main/lib/component/Menu.js b/apps/common/main/lib/component/Menu.js index 0ddfc79c8..4b8826e9b 100644 --- a/apps/common/main/lib/component/Menu.js +++ b/apps/common/main/lib/component/Menu.js @@ -550,7 +550,7 @@ define([ return this.offset; }, - alignPosition: function() { + alignPosition: function(fixedAlign, fixedOffset) { var menuRoot = (this.cmpEl.attr('role') === 'menu') ? this.cmpEl : this.cmpEl.find('[role=menu]'), @@ -597,8 +597,13 @@ define([ } } } else { - if (top + menuH > docH) - top = docH - menuH; + if (top + menuH > docH) { + if (fixedAlign) { + m = fixedAlign.match(/^([a-z]+)-([a-z]+)/); + top = offset.top - posMenu[m[1]][1] + posParent[m[2]][1] + this.offset[1] + (fixedOffset || 0); + } else + top = docH - menuH; + } if (top < 0) top = 0; diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index a951be199..96f6c76ad 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -1124,9 +1124,11 @@ define([ if (_.isUndefined(this.popover)) { this.popover = Common.Views.ReviewPopover.prototype.getPopover({ commentsStore : this.popoverComments, - renderTo : this.sdkViewName + renderTo : this.sdkViewName, + userEmail: this.mode.userEmail }); this.popover.setCommentsStore(this.popoverComments); + this.popover.setUserEmail(this.mode.userEmail); } return this.popover; }, diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 7d7d0090f..19097af7f 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -100,6 +100,7 @@ define([ this.commentsStore = options.commentsStore; this.reviewStore = options.reviewStore; + this.userEmail = options.userEmail; this._state = {commentsVisible: false, reviewVisible: false}; _options.tpl = _.template(this.template)(_options); @@ -455,6 +456,22 @@ define([ } } }); + + this.emailMenu = new Common.UI.Menu({ + maxHeight: 200, + cyclic: false, + items: [] + }).on('render:after', function(mnu) { + this.scroller = new Common.UI.Scroller({ + el: $(this.el).find('.dropdown-menu '), + useKeyboard: this.enableKeyEvents && !this.handleSelect, + minScrollbarLength : 40, + alwaysVisibleY: true + }); + }).on('show:after', function () { + this.scroller.update({alwaysVisibleY: true}); + }); + me.on({ 'show': function () { me.commentsView.autoHeightTextBox(); @@ -872,6 +889,41 @@ define([ me.e = event; }); + + if (this.userEmail && this.userEmail.length>0) { + textBox && textBox.keydown(function (event) { + if ( event.keyCode == Common.UI.Keys.SPACE || + event.keyCode == Common.UI.Keys.HOME || event.keyCode == Common.UI.Keys.END || event.keyCode == Common.UI.Keys.RIGHT || + event.keyCode == Common.UI.Keys.LEFT || event.keyCode == Common.UI.Keys.UP || event.keyCode == Common.UI.Keys.DOWN) { + // hide email menu + me.onEmailListMenu(); + } + me.e = event; + }); + textBox && textBox.on('input', function (event) { + var $this = $(this), + start = this.selectionStart, + val = $this.val(), + left = 0, right = val.length-1; + for (var i=start; i>=0; i--) { + if (val.charCodeAt(i) == 32 /*space*/ || val.charCodeAt(i) == 13 || val.charCodeAt(i) == 10 || val.charCodeAt(i) == 9) { + left = i+1; break; + } + } + for (var i=start; i<=right; i++) { + if (val.charCodeAt(i) == 32 || val.charCodeAt(i) == 13 || val.charCodeAt(i) == 10 || val.charCodeAt(i) == 9) { + right = i-1; break; + } + } + var str = val.substring(left, right+1), + res = str.match(/^(?:[@]|[+](?!1))(\S*)/); + if (res && res.length>1) { + str = res[1]; // send to show email menu + console.log(str); + me.onEmailListMenu(str, left, right); + } + }); + } }, hideTips: function () { @@ -901,6 +953,10 @@ define([ this.commentsView.setStore(this.commentsStore); }, + setUserEmail: function(email) { + this.userEmail = email; + }, + getPopover: function(options) { if (!this.popover) this.popover = new Common.Views.ReviewPopover(options); @@ -925,6 +981,78 @@ define([ } }, + onEmailListMenu: function(str, left, right) { + var emails = this.userEmail; + var me = this, + menu = me.emailMenu; + if (typeof str == 'string') { + var menuContainer = me.$window.find(Common.Utils.String.format('#menu-container-{0}', menu.id)), + arr = []; + str = str.toLowerCase(); + + for (var i = 0; i < menu.items.length; i++) { + menu.removeItem(menu.items[i]); + i--; + } + if (str.length>0) { + for (var i = 0; i < emails.length; i++) { + if (0 === emails[i].toLowerCase().indexOf(str)) { + arr.push(emails[i]); + } + } + } else + arr = emails; + + _.each(arr, function(menuItem, index) { + var mnu = new Common.UI.MenuItem({ + caption : menuItem + }).on('click', function(item, e) { + me.insertEmailToTextbox(item.caption, left, right); + }); + menu.addItem(mnu); + }); + + if (arr.length>0) { + var textbox = this.commentsView.getTextBox(), + textboxDom = textbox[0], + showPoint = [textboxDom.offsetLeft, textboxDom.offsetTop + textboxDom.clientHeight + 3]; + + if (!menu.rendered) { + // Prepare menu container + if (menuContainer.length < 1) { + menuContainer = $(Common.Utils.String.format('', menu.id)); + me.$window.append(menuContainer); + } + + menu.render(menuContainer); + menu.cmpEl.css('min-width', textboxDom.clientWidth); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('hide:after', function(){ + setTimeout(function(){ + me.commentsView.getTextBox().focus(); + }, 10); + }); + } + + menuContainer.css({left: showPoint[0], top : showPoint[1]}); + menu.menuAlignEl = textbox; + menu.show(); + menu.cmpEl.css('display', ''); + menu.alignPosition('bl-tl', -5); + } else { + menu.rendered && menu.cmpEl.css('display', 'none'); + } + } else { + menu.rendered && menu.cmpEl.css('display', 'none'); + } + }, + + insertEmailToTextbox: function(str, left, right) { + var textBox = this.commentsView.getTextBox(), + val = textBox.val(); + textBox.val(val.substring(0, left) + '+' + str + val.substring(right+1, val.length)); + }, + textAddReply : 'Add Reply', textAdd : "Add", textCancel : 'Cancel', diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index ce84eadbe..174add885 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1160,6 +1160,7 @@ define([ this.appOptions.isRestrictedEdit = !this.appOptions.isEdit && (this.appOptions.canComments || this.appOptions.canFillForms); if (this.appOptions.isRestrictedEdit && this.appOptions.canComments && this.appOptions.canFillForms) // must be one restricted mode, priority for filling forms this.appOptions.canComments = false; + this.appOptions.userEmail = ["ivanov.ivan@gmail.com", "petrov.petr@gmail.com", "abggg.sdf@gmail.com", "absss.ivan@yandex.ru"]; if ( this.appOptions.isLightVersion ) { this.appOptions.canUseHistory = From 1f8bc3d6f03bbfc5924c6f53e7a0605e2205d906 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 30 Oct 2018 12:14:09 +0300 Subject: [PATCH 03/18] Fix adding email to comment --- apps/common/main/lib/view/ReviewPopover.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 19097af7f..340918ac3 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -903,9 +903,9 @@ define([ textBox && textBox.on('input', function (event) { var $this = $(this), start = this.selectionStart, - val = $this.val(), + val = $this.val().replace(/[\n]$/, ""), left = 0, right = val.length-1; - for (var i=start; i>=0; i--) { + for (var i=start-1; i>=0; i--) { if (val.charCodeAt(i) == 32 /*space*/ || val.charCodeAt(i) == 13 || val.charCodeAt(i) == 10 || val.charCodeAt(i) == 9) { left = i+1; break; } @@ -1012,9 +1012,9 @@ define([ menu.addItem(mnu); }); - if (arr.length>0) { - var textbox = this.commentsView.getTextBox(), - textboxDom = textbox[0], + var textbox = this.commentsView.getTextBox(); + if (arr.length>0 && textbox) { + var textboxDom = textbox[0], showPoint = [textboxDom.offsetLeft, textboxDom.offsetTop + textboxDom.clientHeight + 3]; if (!menu.rendered) { @@ -1029,7 +1029,8 @@ define([ menu.cmpEl.attr({tabindex: "-1"}); menu.on('hide:after', function(){ setTimeout(function(){ - me.commentsView.getTextBox().focus(); + var tb = me.commentsView.getTextBox(); + tb && tb.focus(); }, 10); }); } @@ -1051,6 +1052,9 @@ define([ var textBox = this.commentsView.getTextBox(), val = textBox.val(); textBox.val(val.substring(0, left) + '+' + str + val.substring(right+1, val.length)); + setTimeout(function(){ + textBox[0].selectionStart = textBox[0].selectionEnd = left + str.length + 1; + }, 10); }, textAddReply : 'Add Reply', From c823cb38fe55456f0c84886acfda459cba7cdf43 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 30 Oct 2018 14:05:00 +0300 Subject: [PATCH 04/18] [DE] Fix view mode, select user email using keyboard. --- apps/common/main/lib/component/Menu.js | 2 +- apps/common/main/lib/controller/Comments.js | 6 +++--- apps/common/main/lib/view/ReviewPopover.js | 9 ++++++++- apps/documenteditor/main/app/controller/Main.js | 4 +++- 4 files changed, 15 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/component/Menu.js b/apps/common/main/lib/component/Menu.js index 4b8826e9b..4feb389c3 100644 --- a/apps/common/main/lib/component/Menu.js +++ b/apps/common/main/lib/component/Menu.js @@ -598,7 +598,7 @@ define([ } } else { if (top + menuH > docH) { - if (fixedAlign) { + if (fixedAlign && typeof fixedAlign == 'string') { // how to align if menu height > window height m = fixedAlign.match(/^([a-z]+)-([a-z]+)/); top = offset.top - posMenu[m[1]][1] + posParent[m[2]][1] + this.offset[1] + (fixedOffset || 0); } else diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 96f6c76ad..497e7de99 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -1125,10 +1125,10 @@ define([ this.popover = Common.Views.ReviewPopover.prototype.getPopover({ commentsStore : this.popoverComments, renderTo : this.sdkViewName, - userEmail: this.mode.userEmail + userEmail: (this.mode) ? this.mode.userEmail : undefined }); this.popover.setCommentsStore(this.popoverComments); - this.popover.setUserEmail(this.mode.userEmail); + (this.mode) && this.popover.setUserEmail(this.mode.userEmail); } return this.popover; }, @@ -1343,7 +1343,7 @@ define([ this.api.asc_addComment(comment); this.view.showEditContainer(false); - this.view.pickEMail(commentVal); + this.mode && this.mode.userEmail && this.view.pickEMail(commentVal); if (!_.isUndefined(this.api.asc_SetDocumentPlaceChangedEnabled)) { this.api.asc_SetDocumentPlaceChangedEnabled(false); } diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 340918ac3..1b4b6d801 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -894,9 +894,16 @@ define([ textBox && textBox.keydown(function (event) { if ( event.keyCode == Common.UI.Keys.SPACE || event.keyCode == Common.UI.Keys.HOME || event.keyCode == Common.UI.Keys.END || event.keyCode == Common.UI.Keys.RIGHT || - event.keyCode == Common.UI.Keys.LEFT || event.keyCode == Common.UI.Keys.UP || event.keyCode == Common.UI.Keys.DOWN) { + event.keyCode == Common.UI.Keys.LEFT || event.keyCode == Common.UI.Keys.UP) { // hide email menu me.onEmailListMenu(); + } else if (event.keyCode == Common.UI.Keys.DOWN) { + if (me.emailMenu && me.emailMenu.rendered && me.emailMenu.isVisible()) + _.delay(function() { + var selected = me.emailMenu.cmpEl.find('li:not(.divider):first'); + selected = selected.find('a'); + selected.focus(); + }, 10); } me.e = event; }); diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 174add885..5d2859f2c 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -232,7 +232,9 @@ define([ if (/form-control/.test(e.target.className)) me.inFormControl = false; if (!e.relatedTarget || - !/area_id/.test(e.target.id) && ($(e.target).parent().find(e.relatedTarget).length<1 || e.target.localName == 'textarea') /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + !/area_id/.test(e.target.id) + && !(e.target.localName == 'input' && $(e.target).parent().find(e.relatedTarget).length>0) /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + && !(e.target.localName == 'textarea' && $(e.target).closest('.asc-window').find(e.relatedTarget).length>0) /* Check if focus in comment goes from textarea to it's email menu */ && (e.relatedTarget.localName != 'input' || !/form-control/.test(e.relatedTarget.className)) /* Check if focus goes to text input with class "form-control" */ && (e.relatedTarget.localName != 'textarea' || /area_id/.test(e.relatedTarget.id))) /* Check if focus goes to textarea, but not to "area_id" */ { if (Common.Utils.isIE && e.originalEvent && e.originalEvent.target && /area_id/.test(e.originalEvent.target.id) && (e.originalEvent.target === e.originalEvent.srcElement)) From 25e50435bb7a12ce155be75772b3455b9777fb8f Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 23 Apr 2019 14:41:35 +0300 Subject: [PATCH 05/18] Request users for mentions, send mentions --- apps/api/documents/api.js | 21 +++- apps/common/Gateway.js | 16 +++ apps/common/main/lib/controller/Comments.js | 7 +- apps/common/main/lib/view/Comments.js | 17 ++- apps/common/main/lib/view/ReviewPopover.js | 119 +++++++++++------- .../main/app/controller/Main.js | 1 + 6 files changed, 129 insertions(+), 52 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 1f5b55412..4f17b2977 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -198,6 +198,7 @@ _config.editorConfig.canRequestClose = _config.events && !!_config.events.onRequestClose; _config.editorConfig.canRename = _config.events && !!_config.events.onRequestRename; _config.editorConfig.canMakeActionLink = _config.events && !!_config.events.onMakeActionLink; + _config.editorConfig.canRequestUsers = _config.events && !!_config.events.onRequestUsers; _config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl; _config.frameEditorId = placeholderId; @@ -536,6 +537,22 @@ }); }; + var _setUsers = function(data) { + _sendCommand({ + command: 'setUsers', + data: { + data: data + } + }); + }; + + var _showSharingSettings = function(data) { + _sendCommand({ + command: 'showSharingSettings', + data: data + }); + }; + var _processMouse = function(evt) { var r = iframe.getBoundingClientRect(); var data = { @@ -575,7 +592,9 @@ serviceCommand : _serviceCommand, attachMouseEvents : _attachMouseEvents, detachMouseEvents : _detachMouseEvents, - destroyEditor : _destroyEditor + destroyEditor : _destroyEditor, + setUsers : _setUsers, + showSharingSettings : _showSharingSettings } }; diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index a906dedba..2d2a9e169 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -98,6 +98,14 @@ if (Common === undefined) { 'resetFocus': function(data) { $me.trigger('resetfocus', data); + }, + + 'setUsers': function(data) { + $me.trigger('setusers', data); + }, + + 'showSharingSettings': function(data) { + $me.trigger('showsharingsettings', data); } }; @@ -262,6 +270,14 @@ if (Common === undefined) { _postMessage({event:'onMakeActionLink', data: config}) }, + requestUsers: function () { + _postMessage({event:'onRequestUsers'}) + }, + + requestSendNotify: function (emails) { + _postMessage({event:'onRequestSendNotify', data: emails}) + }, + on: function(event, handler){ var localHandler = function(event, data){ handler.call(me, data) diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 497e7de99..67cf2f8f8 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -1125,10 +1125,9 @@ define([ this.popover = Common.Views.ReviewPopover.prototype.getPopover({ commentsStore : this.popoverComments, renderTo : this.sdkViewName, - userEmail: (this.mode) ? this.mode.userEmail : undefined + canRequestUsers: (this.mode) ? this.mode.canRequestUsers : undefined }); this.popover.setCommentsStore(this.popoverComments); - (this.mode) && this.popover.setUserEmail(this.mode.userEmail); } return this.popover; }, @@ -1341,9 +1340,9 @@ define([ if (!_.isUndefined(comment.asc_putDocumentFlag)) comment.asc_putDocumentFlag(false); - this.api.asc_addComment(comment); + var commentId = this.api.asc_addComment(comment); this.view.showEditContainer(false); - this.mode && this.mode.userEmail && this.view.pickEMail(commentVal); + this.mode && this.mode.canRequestUsers && this.view.pickEMail(commentId, commentVal); if (!_.isUndefined(this.api.asc_SetDocumentPlaceChangedEnabled)) { this.api.asc_SetDocumentPlaceChangedEnabled(false); } diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index c0b99c708..28b9a4496 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -721,10 +721,23 @@ define([ return str_res; }, - pickEMail: function (message) { + pickEMail: function (commentId, message) { var arr = Common.Utils.String.htmlEncode(message).match(/\B[@+][A-Z0-9._%+-]+@[A-Z0-9._]+\.[A-Z]+\b/gi); console.log(arr); // send e-mails - return arr; + arr = _.map(arr, function(str){ + return str.slice(1, str.length); + }); + Common.Gateway.requestSendNotify({ + emails: arr, + actionId: commentId, // comment id + actionLink: { + action: { + type: "comment", + data: commentId + } + }, + message: message //comment text + }); }, textComments : 'Comments', diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 1b4b6d801..1769969c0 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -100,7 +100,8 @@ define([ this.commentsStore = options.commentsStore; this.reviewStore = options.reviewStore; - this.userEmail = options.userEmail; + this.canRequestUsers = options.canRequestUsers; + this.externalUsers = []; this._state = {commentsVisible: false, reviewVisible: false}; _options.tpl = _.template(this.template)(_options); @@ -109,6 +110,9 @@ define([ this.sdkBounds = {width: 0, height: 0, padding: 10, paddingTop: 20}; Common.UI.Window.prototype.initialize.call(this, _options); + + this.canRequestUsers && Common.Gateway.on('setusers', _.bind(this.setUsers, this)); + return this; }, render: function (comments, review) { @@ -890,7 +894,7 @@ define([ me.e = event; }); - if (this.userEmail && this.userEmail.length>0) { + if (this.canRequestUsers) { textBox && textBox.keydown(function (event) { if ( event.keyCode == Common.UI.Keys.SPACE || event.keyCode == Common.UI.Keys.HOME || event.keyCode == Common.UI.Keys.END || event.keyCode == Common.UI.Keys.RIGHT || @@ -960,8 +964,12 @@ define([ this.commentsView.setStore(this.commentsStore); }, - setUserEmail: function(email) { - this.userEmail = email; + setUsers: function(data) { + this.externalUsers = data.data || []; + if (this.loadMask) + this.loadMask.hide(); + this.loadMask = null; + this._state.emailSearch && this.onEmailListMenu(this._state.emailSearch.str, this._state.emailSearch.left, this._state.emailSearch.right); }, getPopover: function(options) { @@ -989,64 +997,84 @@ define([ }, onEmailListMenu: function(str, left, right) { - var emails = this.userEmail; var me = this, + users = me.externalUsers, menu = me.emailMenu; + + if (users.length<1) { + this._state.emailSearch = { + str: str, + left: left, + right: right + }; + + if (this.loadMask) return; + } if (typeof str == 'string') { var menuContainer = me.$window.find(Common.Utils.String.format('#menu-container-{0}', menu.id)), - arr = []; - str = str.toLowerCase(); + textbox = this.commentsView.getTextBox(), + textboxDom = textbox ? textbox[0] : null, + showPoint = textboxDom ? [textboxDom.offsetLeft, textboxDom.offsetTop + textboxDom.clientHeight + 3] : [0, 0]; + + if (!menu.rendered) { + // Prepare menu container + if (menuContainer.length < 1) { + menuContainer = $(Common.Utils.String.format('', menu.id)); + me.$window.append(menuContainer); + } + + menu.render(menuContainer); + menu.cmpEl.css('min-width', textboxDom ? textboxDom.clientWidth : 220); + menu.cmpEl.attr({tabindex: "-1"}); + menu.on('hide:after', function(){ + setTimeout(function(){ + var tb = me.commentsView.getTextBox(); + tb && tb.focus(); + }, 10); + }); + } for (var i = 0; i < menu.items.length; i++) { menu.removeItem(menu.items[i]); i--; } - if (str.length>0) { - for (var i = 0; i < emails.length; i++) { - if (0 === emails[i].toLowerCase().indexOf(str)) { - arr.push(emails[i]); - } - } - } else - arr = emails; - _.each(arr, function(menuItem, index) { - var mnu = new Common.UI.MenuItem({ - caption : menuItem - }).on('click', function(item, e) { - me.insertEmailToTextbox(item.caption, left, right); - }); - menu.addItem(mnu); - }); - - var textbox = this.commentsView.getTextBox(); - if (arr.length>0 && textbox) { - var textboxDom = textbox[0], - showPoint = [textboxDom.offsetLeft, textboxDom.offsetTop + textboxDom.clientHeight + 3]; - - if (!menu.rendered) { - // Prepare menu container - if (menuContainer.length < 1) { - menuContainer = $(Common.Utils.String.format('', menu.id)); - me.$window.append(menuContainer); - } - - menu.render(menuContainer); - menu.cmpEl.css('min-width', textboxDom.clientWidth); - menu.cmpEl.attr({tabindex: "-1"}); - menu.on('hide:after', function(){ - setTimeout(function(){ - var tb = me.commentsView.getTextBox(); - tb && tb.focus(); - }, 10); + if (users.length<1) { + menu.addItem(new Common.UI.MenuItem({ + template: _.template([ + '
' + ].join('')) + })); + this.loadMask = new Common.UI.LoadMask({owner: menu.cmpEl.find('li > div')}); + this.loadMask.setTitle(this.textLoading); + } else { + str = str.toLowerCase(); + if (str.length>0) { + users = _.filter(users, function(item) { + return (0 === item.email.toLowerCase().indexOf(str)) }); } + _.each(users, function(menuItem, index) { + var mnu = new Common.UI.MenuItem({ + caption : menuItem.email + }).on('click', function(item, e) { + me.insertEmailToTextbox(item.caption, left, right); + }); + menu.addItem(mnu); + }); + } + if (users.length>0 || this.loadMask) { menuContainer.css({left: showPoint[0], top : showPoint[1]}); menu.menuAlignEl = textbox; menu.show(); menu.cmpEl.css('display', ''); menu.alignPosition('bl-tl', -5); + + if (this.loadMask) { + this.loadMask.show(); + Common.Gateway.requestUsers(); + } } else { menu.rendered && menu.cmpEl.css('display', 'none'); } @@ -1071,7 +1099,8 @@ define([ textReply : 'Reply', textClose : 'Close', textResolve : 'Resolve', - textOpenAgain : "Open Again" + textOpenAgain : "Open Again", + textLoading : 'Loading' }, Common.Views.ReviewPopover || {})) }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 5d2859f2c..3308ff12c 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -339,6 +339,7 @@ define([ this.appOptions.canPlugins = false; this.plugins = this.editorConfig.plugins; this.appOptions.canMakeActionLink = this.editorConfig.canMakeActionLink; + this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') From 1f977c6393a8925780121175dfd3e7eafe3cd7ad Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 23 Apr 2019 15:02:42 +0300 Subject: [PATCH 06/18] Share document when send mentions --- apps/documenteditor/main/app/view/FileMenuPanels.js | 3 ++- apps/presentationeditor/main/app/view/FileMenuPanels.js | 3 ++- apps/spreadsheeteditor/main/app/view/FileMenuPanels.js | 3 ++- 3 files changed, 6 insertions(+), 3 deletions(-) diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 539eaa81b..45dafae27 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -988,11 +988,12 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); return this; }, changeAccessRights: function(btn,event,opts) { - if (this._docAccessDlg) return; + if (this._docAccessDlg || this._readonlyRights) return; var me = this; me._docAccessDlg = new Common.Views.DocumentAccessDialog({ diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index c3d19f6ce..cc0bada8e 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -801,11 +801,12 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); return this; }, changeAccessRights: function(btn,event,opts) { - if (this._docAccessDlg) return; + if (this._docAccessDlg || this._readonlyRights) return; var me = this; me._docAccessDlg = new Common.Views.DocumentAccessDialog({ diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 919be95ad..03a50af6e 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1255,11 +1255,12 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); return this; }, changeAccessRights: function(btn,event,opts) { - if (this._docAccessDlg) return; + if (this._docAccessDlg || this._readonlyRights) return; var me = this; me._docAccessDlg = new Common.Views.DocumentAccessDialog({ From 81e318634ef33317eec1b83f892f7800f99c149a Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 23 Apr 2019 16:01:34 +0300 Subject: [PATCH 07/18] Show user name and email when adding mentions --- apps/common/main/lib/view/ReviewPopover.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 1769969c0..584c3a77d 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -462,7 +462,7 @@ define([ }); this.emailMenu = new Common.UI.Menu({ - maxHeight: 200, + maxHeight: 190, cyclic: false, items: [] }).on('render:after', function(mnu) { @@ -930,7 +930,6 @@ define([ res = str.match(/^(?:[@]|[+](?!1))(\S*)/); if (res && res.length>1) { str = res[1]; // send to show email menu - console.log(str); me.onEmailListMenu(str, left, right); } }); @@ -1042,7 +1041,7 @@ define([ if (users.length<1) { menu.addItem(new Common.UI.MenuItem({ template: _.template([ - '
' + '
' ].join('')) })); this.loadMask = new Common.UI.LoadMask({owner: menu.cmpEl.find('li > div')}); @@ -1054,11 +1053,15 @@ define([ return (0 === item.email.toLowerCase().indexOf(str)) }); } + var tpl = _.template('
<%= caption %>
<%= options.value %>
'); _.each(users, function(menuItem, index) { var mnu = new Common.UI.MenuItem({ - caption : menuItem.email - }).on('click', function(item, e) { - me.insertEmailToTextbox(item.caption, left, right); + caption : menuItem.name, + value : menuItem.email, + template : tpl + + }).on('click', function(item, e) { + me.insertEmailToTextbox(item.options.value, left, right); }); menu.addItem(mnu); }); @@ -1070,6 +1073,7 @@ define([ menu.show(); menu.cmpEl.css('display', ''); menu.alignPosition('bl-tl', -5); + menu.scroller.update({alwaysVisibleY: true}); if (this.loadMask) { this.loadMask.show(); From 9c2d78d589f05da1d793e574be10feb6e6e423fb Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 23 Apr 2019 16:59:11 +0300 Subject: [PATCH 08/18] Remove loader while loading users for mentions --- apps/common/main/lib/view/ReviewPopover.js | 27 +++++++--------------- 1 file changed, 8 insertions(+), 19 deletions(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 584c3a77d..29d530df5 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -965,9 +965,7 @@ define([ setUsers: function(data) { this.externalUsers = data.data || []; - if (this.loadMask) - this.loadMask.hide(); - this.loadMask = null; + this.isUsersLoading = false; this._state.emailSearch && this.onEmailListMenu(this._state.emailSearch.str, this._state.emailSearch.left, this._state.emailSearch.right); }, @@ -1007,7 +1005,11 @@ define([ right: right }; - if (this.loadMask) return; + if (this.isUsersLoading) return; + + this.isUsersLoading = true; + Common.Gateway.requestUsers(); + return; } if (typeof str == 'string') { var menuContainer = me.$window.find(Common.Utils.String.format('#menu-container-{0}', menu.id)), @@ -1038,15 +1040,7 @@ define([ i--; } - if (users.length<1) { - menu.addItem(new Common.UI.MenuItem({ - template: _.template([ - '
' - ].join('')) - })); - this.loadMask = new Common.UI.LoadMask({owner: menu.cmpEl.find('li > div')}); - this.loadMask.setTitle(this.textLoading); - } else { + if (users.length>0) { str = str.toLowerCase(); if (str.length>0) { users = _.filter(users, function(item) { @@ -1067,18 +1061,13 @@ define([ }); } - if (users.length>0 || this.loadMask) { + if (users.length>0) { menuContainer.css({left: showPoint[0], top : showPoint[1]}); menu.menuAlignEl = textbox; menu.show(); menu.cmpEl.css('display', ''); menu.alignPosition('bl-tl', -5); menu.scroller.update({alwaysVisibleY: true}); - - if (this.loadMask) { - this.loadMask.show(); - Common.Gateway.requestUsers(); - } } else { menu.rendered && menu.cmpEl.css('display', 'none'); } From bb8e4f5f7f386c5f5e154c48a135c577dc785146 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 24 Apr 2019 16:31:29 +0300 Subject: [PATCH 09/18] [DE] Show comment on start --- apps/documenteditor/main/app/controller/Main.js | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 3308ff12c..f1e5cedc8 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -1010,6 +1010,10 @@ define([ me.api.UpdateInterfaceState(); me.fillTextArt(me.api.asc_getTextArtPreviews()); + if (me.editorConfig.actionLink && me.editorConfig.actionLink.action && me.editorConfig.actionLink.action.type == 'comment') { + me.contComments.getView().fireEvent('comment:show', [me.editorConfig.actionLink.action.data, false]); + } + Common.NotificationCenter.trigger('document:ready', 'main'); me.applyLicense(); } From b730cd4a7f2c3fdd883388552cf542b988864d55 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Apr 2019 12:09:05 +0300 Subject: [PATCH 10/18] Mentions: search users by email or name --- apps/common/main/lib/view/ReviewPopover.js | 23 +++++++++++----------- 1 file changed, 12 insertions(+), 11 deletions(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 29d530df5..cfda1994f 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -1044,24 +1044,25 @@ define([ str = str.toLowerCase(); if (str.length>0) { users = _.filter(users, function(item) { - return (0 === item.email.toLowerCase().indexOf(str)) + return (item.email && 0 === item.email.toLowerCase().indexOf(str) || item.name && 0 === item.name.toLowerCase().indexOf(str)) }); } var tpl = _.template('
<%= caption %>
<%= options.value %>
'); _.each(users, function(menuItem, index) { - var mnu = new Common.UI.MenuItem({ - caption : menuItem.name, - value : menuItem.email, - template : tpl - - }).on('click', function(item, e) { - me.insertEmailToTextbox(item.options.value, left, right); - }); - menu.addItem(mnu); + if (menuItem.email && menuItem.name) { + var mnu = new Common.UI.MenuItem({ + caption : menuItem.name, + value : menuItem.email, + template : tpl + }).on('click', function(item, e) { + me.insertEmailToTextbox(item.options.value, left, right); + }); + menu.addItem(mnu); + } }); } - if (users.length>0) { + if (menu.items.length>0) { menuContainer.css({left: showPoint[0], top : showPoint[1]}); menu.menuAlignEl = textbox; menu.show(); From 23f9c4b21bb0fcbe1ebc2df46da41e497ce7bde5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Apr 2019 14:58:48 +0300 Subject: [PATCH 11/18] [PE][SSE] Fix view mode, select user email using keyboard. Request users for mentions --- apps/presentationeditor/main/app/controller/Main.js | 5 ++++- apps/spreadsheeteditor/main/app/controller/Main.js | 5 ++++- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 596403e8c..92f3a27a9 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -213,7 +213,9 @@ define([ if (/form-control/.test(e.target.className)) me.inFormControl = false; if (!e.relatedTarget || - !/area_id/.test(e.target.id) && ($(e.target).parent().find(e.relatedTarget).length<1 || e.target.localName == 'textarea') /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + !/area_id/.test(e.target.id) + && !(e.target.localName == 'input' && $(e.target).parent().find(e.relatedTarget).length>0) /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + && !(e.target.localName == 'textarea' && $(e.target).closest('.asc-window').find(e.relatedTarget).length>0) /* Check if focus in comment goes from textarea to it's email menu */ && (e.relatedTarget.localName != 'input' || !/form-control/.test(e.relatedTarget.className)) /* Check if focus goes to text input with class "form-control" */ && (e.relatedTarget.localName != 'textarea' || /area_id/.test(e.relatedTarget.id))) /* Check if focus goes to textarea, but not to "area_id" */ { if (Common.Utils.isIE && e.originalEvent && e.originalEvent.target && /area_id/.test(e.originalEvent.target.id) && (e.originalEvent.target === e.originalEvent.srcElement)) @@ -316,6 +318,7 @@ define([ this.appOptions.canBack = this.editorConfig.nativeApp !== true && this.appOptions.canBackToFolder === true; this.appOptions.canPlugins = false; this.plugins = this.editorConfig.plugins; + this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index eba0c807b..be712ece4 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -212,7 +212,9 @@ define([ if (/form-control/.test(e.target.className)) me.inFormControl = false; if (!e.relatedTarget || - !/area_id/.test(e.target.id) && ($(e.target).parent().find(e.relatedTarget).length<1 || e.target.localName == 'textarea') /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + !/area_id/.test(e.target.id) + && !(e.target.localName == 'input' && $(e.target).parent().find(e.relatedTarget).length>0) /* Check if focus in combobox goes from input to it's menu button or menu items, or from comment editing area to Ok/Cancel button */ + && !(e.target.localName == 'textarea' && $(e.target).closest('.asc-window').find(e.relatedTarget).length>0) /* Check if focus in comment goes from textarea to it's email menu */ && (e.relatedTarget.localName != 'input' || !/form-control/.test(e.relatedTarget.className)) /* Check if focus goes to text input with class "form-control" */ && (e.relatedTarget.localName != 'textarea' || /area_id/.test(e.relatedTarget.id))) /* Check if focus goes to textarea, but not to "area_id" */ { if (Common.Utils.isIE && e.originalEvent && e.originalEvent.target && /area_id/.test(e.originalEvent.target.id) && (e.originalEvent.target === e.originalEvent.srcElement)) @@ -322,6 +324,7 @@ define([ this.appOptions.canBack = this.editorConfig.nativeApp !== true && this.appOptions.canBackToFolder === true; this.appOptions.canPlugins = false; this.plugins = this.editorConfig.plugins; + this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') From fe434165bf485a889edfcc012bc7517d1734b135 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 25 Apr 2019 15:22:39 +0300 Subject: [PATCH 12/18] Show comment on start --- apps/documenteditor/main/app/controller/Main.js | 11 +++++++---- apps/presentationeditor/main/app/controller/Main.js | 7 +++++++ apps/spreadsheeteditor/main/app/controller/Main.js | 11 +++++++++-- 3 files changed, 23 insertions(+), 6 deletions(-) diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index f1e5cedc8..879957f51 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -194,6 +194,7 @@ define([ Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); + Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this)); this.isShowOpenDialog = false; @@ -1010,10 +1011,6 @@ define([ me.api.UpdateInterfaceState(); me.fillTextArt(me.api.asc_getTextArtPreviews()); - if (me.editorConfig.actionLink && me.editorConfig.actionLink.action && me.editorConfig.actionLink.action.type == 'comment') { - me.contComments.getView().fireEvent('comment:show', [me.editorConfig.actionLink.action.data, false]); - } - Common.NotificationCenter.trigger('document:ready', 'main'); me.applyLicense(); } @@ -1039,6 +1036,12 @@ define([ Common.Gateway.documentReady(); }, + onDocumentReady: function() { + if (this.editorConfig.actionLink && this.editorConfig.actionLink.action && this.editorConfig.actionLink.action.type == 'comment') { + this.contComments.getView().fireEvent('comment:show', [this.editorConfig.actionLink.action.data, false]); + } + }, + onLicenseChanged: function(params) { var licType = params.asc_getLicenseType(); if (licType !== undefined && this.appOptions.canEdit && this.editorConfig.mode !== 'view' && diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 92f3a27a9..00eb66d09 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -180,6 +180,7 @@ define([ this.api.asc_registerCallback('asc_onSpellCheckInit', _.bind(this.loadLanguages, this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); + Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this)); this.isShowOpenDialog = false; @@ -789,6 +790,12 @@ define([ Common.Gateway.documentReady(); }, + onDocumentReady: function() { + if (this.editorConfig.actionLink && this.editorConfig.actionLink.action && this.editorConfig.actionLink.action.type == 'comment') { + this.getApplication().getController('Common.Controllers.Comments').getView().fireEvent('comment:show', [this.editorConfig.actionLink.action.data, false]); + } + }, + onLicenseChanged: function(params) { var licType = params.asc_getLicenseType(); if (licType !== undefined && this.appOptions.canEdit && this.editorConfig.mode !== 'view' && diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index be712ece4..c85db0204 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -169,6 +169,7 @@ define([ Common.NotificationCenter.on('goback', _.bind(this.goBack, this)); Common.NotificationCenter.on('namedrange:locked', _.bind(this.onNamedRangeLocked, this)); Common.NotificationCenter.on('download:cancel', _.bind(this.onDownloadCancel, this)); + Common.NotificationCenter.on('document:ready', _.bind(this.onDocumentReady, this)); this.stackLongActions = new Common.IrregularStack({ strongCompare : this._compareActionStrong, @@ -508,7 +509,7 @@ define([ if (type === Asc.c_oAscAsyncActionType.BlockInteraction && id == Asc.c_oAscAsyncAction.Open) { Common.Gateway.internalMessage('documentReady', {}); - this.onDocumentReady(); + this.onDocumentContentReady(); } action = this.stackLongActions.get({type: Asc.c_oAscAsyncActionType.Information}); @@ -625,7 +626,7 @@ define([ } }, - onDocumentReady: function() { + onDocumentContentReady: function() { if (this._isDocReady) return; @@ -815,6 +816,12 @@ define([ Common.Gateway.documentReady(); }, + onDocumentReady: function() { + if (this.editorConfig.actionLink && this.editorConfig.actionLink.action && this.editorConfig.actionLink.action.type == 'comment') { + this.getApplication().getController('Common.Controllers.Comments').getView().fireEvent('comment:show', [this.editorConfig.actionLink.action.data, false]); + } + }, + onLicenseChanged: function(params) { if (this.appOptions.isEditDiagram || this.appOptions.isEditMailMerge) return; From dbb0e8e499597dc099b56535551c68addd05a1e9 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 25 Jun 2019 15:05:14 +0300 Subject: [PATCH 13/18] Mentions: use hasAccess user option --- apps/common/main/lib/controller/Fonts.js | 10 +++++----- apps/common/main/lib/view/ReviewPopover.js | 10 +++++++++- 2 files changed, 14 insertions(+), 6 deletions(-) diff --git a/apps/common/main/lib/controller/Fonts.js b/apps/common/main/lib/controller/Fonts.js index 570f000e2..a20c68604 100644 --- a/apps/common/main/lib/controller/Fonts.js +++ b/apps/common/main/lib/controller/Fonts.js @@ -48,10 +48,10 @@ define([ 'common/main/lib/collection/Fonts' ], function () { 'use strict'; Common.Controllers.Fonts = Backbone.Controller.extend((function() { - var FONT_TYPE_USERUSED = 4; + var FONT_TYPE_RECENT = 4; function isFontSaved(store, rec) { - var out = rec.get('type') == FONT_TYPE_USERUSED, + var out = rec.get('type') == FONT_TYPE_RECENT, i = -1, c = store.length, su, @@ -59,7 +59,7 @@ define([ while (!out && ++i < c) { su = store.at(i); - if (su.get('type') != FONT_TYPE_USERUSED) + if (su.get('type') != FONT_TYPE_RECENT) break; out = su.get('name') == n; @@ -78,7 +78,7 @@ define([ // name: data.name, // imgidx: data.imgidx, // cloneid: node.querySelector('img').id, -// type: FONT_TYPE_USERUSED +// type: FONT_TYPE_RECENT // }; // combo.getStore().insert(0,[font]); // @@ -93,7 +93,7 @@ define([ // } // // font = combo.getStore().getAt(5); -// if (font.data.type==FONT_TYPE_USERUSED) { +// if (font.data.type==FONT_TYPE_RECENT) { // combo.getStore().remove(font); // } else { // var plugin = combo.getPlugin('scrollpane'); diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index cfda1994f..57de44be8 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -1047,8 +1047,14 @@ define([ return (item.email && 0 === item.email.toLowerCase().indexOf(str) || item.name && 0 === item.name.toLowerCase().indexOf(str)) }); } - var tpl = _.template('
<%= caption %>
<%= options.value %>
'); + var tpl = _.template('
<%= caption %>
<%= options.value %>
'), + divider = false; _.each(users, function(menuItem, index) { + if (divider && !menuItem.hasAccess) { + divider = false; + menu.addItem(new Common.UI.MenuItem({caption: '--'})); + } + if (menuItem.email && menuItem.name) { var mnu = new Common.UI.MenuItem({ caption : menuItem.name, @@ -1058,6 +1064,8 @@ define([ me.insertEmailToTextbox(item.options.value, left, right); }); menu.addItem(mnu); + if (menuItem.hasAccess) + divider = true; } }); } From 632b3c554cc716387f25c31972dc704ae9fbcc59 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 25 Jun 2019 17:58:41 +0300 Subject: [PATCH 14/18] Mentions: fix loading users --- apps/common/main/lib/view/ReviewPopover.js | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 57de44be8..958928b39 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -967,6 +967,7 @@ define([ this.externalUsers = data.data || []; this.isUsersLoading = false; this._state.emailSearch && this.onEmailListMenu(this._state.emailSearch.str, this._state.emailSearch.left, this._state.emailSearch.right); + this._state.emailSearch = null; }, getPopover: function(options) { @@ -993,7 +994,7 @@ define([ } }, - onEmailListMenu: function(str, left, right) { + onEmailListMenu: function(str, left, right, show) { var me = this, users = me.externalUsers, menu = me.emailMenu; From f19597a9cb5fd6808ce587f50722eca83389bf2a Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 26 Jun 2019 14:04:02 +0300 Subject: [PATCH 15/18] Mentions refactoring: add placeholder to comment textarea, set mentions on adding reply, clear external users when change document access rights --- apps/api/documents/api.js | 1 + apps/common/main/lib/controller/Comments.js | 4 +++- .../main/lib/template/CommentsPopover.template | 2 +- apps/common/main/lib/view/Comments.js | 1 - .../main/lib/view/DocumentAccessDialog.js | 4 +++- apps/common/main/lib/view/ReviewPopover.js | 18 ++++++++++++++---- .../documenteditor/main/app/controller/Main.js | 1 + apps/documenteditor/main/locale/en.json | 1 + .../main/app/controller/Main.js | 1 + apps/presentationeditor/main/locale/en.json | 1 + .../main/app/controller/Main.js | 1 + apps/spreadsheeteditor/main/locale/en.json | 1 + 12 files changed, 28 insertions(+), 8 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 4f17b2977..00c4688e4 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -199,6 +199,7 @@ _config.editorConfig.canRename = _config.events && !!_config.events.onRequestRename; _config.editorConfig.canMakeActionLink = _config.events && !!_config.events.onMakeActionLink; _config.editorConfig.canRequestUsers = _config.events && !!_config.events.onRequestUsers; + _config.editorConfig.canRequestSendNotify = _config.events && !!_config.events.onRequestSendNotify; _config.editorConfig.mergeFolderUrl = _config.editorConfig.mergeFolderUrl || _config.editorConfig.saveAsUrl; _config.frameEditorId = placeholderId; diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 67cf2f8f8..ec150afc0 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -494,6 +494,7 @@ define([ ascComment.asc_addReply(addReply); me.api.asc_changeComment(id, ascComment); + me.mode && me.mode.canRequestUsers && me.view.pickEMail(id, replyVal); return true; } @@ -1125,7 +1126,8 @@ define([ this.popover = Common.Views.ReviewPopover.prototype.getPopover({ commentsStore : this.popoverComments, renderTo : this.sdkViewName, - canRequestUsers: (this.mode) ? this.mode.canRequestUsers : undefined + canRequestUsers: (this.mode) ? this.mode.canRequestUsers : undefined, + canRequestSendNotify: (this.mode) ? this.mode.canRequestSendNotify : undefined }); this.popover.setCommentsStore(this.popoverComments); } diff --git a/apps/common/main/lib/template/CommentsPopover.template b/apps/common/main/lib/template/CommentsPopover.template index 45b112b7d..78f0d4a5a 100644 --- a/apps/common/main/lib/template/CommentsPopover.template +++ b/apps/common/main/lib/template/CommentsPopover.template @@ -10,7 +10,7 @@
<%=scope.pickLink(comment)%>
<% } else { %>
- + <% if (hideAddReply) { %> <% } else { %> diff --git a/apps/common/main/lib/view/Comments.js b/apps/common/main/lib/view/Comments.js index 28b9a4496..ca7aaaf1d 100644 --- a/apps/common/main/lib/view/Comments.js +++ b/apps/common/main/lib/view/Comments.js @@ -723,7 +723,6 @@ define([ pickEMail: function (commentId, message) { var arr = Common.Utils.String.htmlEncode(message).match(/\B[@+][A-Z0-9._%+-]+@[A-Z0-9._]+\.[A-Z]+\b/gi); - console.log(arr); // send e-mails arr = _.map(arr, function(str){ return str.slice(1, str.length); }); diff --git a/apps/common/main/lib/view/DocumentAccessDialog.js b/apps/common/main/lib/view/DocumentAccessDialog.js index ecdfa56c1..2d6c0fcfd 100644 --- a/apps/common/main/lib/view/DocumentAccessDialog.js +++ b/apps/common/main/lib/view/DocumentAccessDialog.js @@ -120,8 +120,10 @@ define([ _onMessage: function(msg) { if (msg && msg.Referer == "onlyoffice") { - if (msg.needUpdate) + if (msg.needUpdate) { this.trigger('accessrights', this, msg.sharingSettings); + Common.NotificationCenter.trigger('mentions:clearusers', this); + } Common.NotificationCenter.trigger('window:close', this); } }, diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 958928b39..1bd511f5b 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -101,6 +101,7 @@ define([ this.commentsStore = options.commentsStore; this.reviewStore = options.reviewStore; this.canRequestUsers = options.canRequestUsers; + this.canRequestSendNotify = options.canRequestSendNotify; this.externalUsers = []; this._state = {commentsVisible: false, reviewVisible: false}; @@ -111,7 +112,10 @@ define([ Common.UI.Window.prototype.initialize.call(this, _options); - this.canRequestUsers && Common.Gateway.on('setusers', _.bind(this.setUsers, this)); + if (this.canRequestUsers) { + Common.Gateway.on('setusers', _.bind(this.setUsers, this)); + Common.NotificationCenter.on('mentions:clearusers', _.bind(this.clearUsers, this)); + } return this; }, @@ -126,7 +130,7 @@ define([ minHeight: '', overflow: 'hidden', position: 'absolute', - zIndex: '990' + zIndex: '1001' }); var body = window.find('.body'); @@ -239,7 +243,8 @@ define([ textEdit: me.textEdit, textReply: me.textReply, textClose: me.textClose, - maxCommLength: Asc.c_oAscMaxCellOrCommentLength + maxCommLength: Asc.c_oAscMaxCellOrCommentLength, + textMention: me.canRequestSendNotify ? me.textMention : '' }) ) }); @@ -970,6 +975,10 @@ define([ this._state.emailSearch = null; }, + clearUsers: function() { + this.externalUsers = []; + }, + getPopover: function(options) { if (!this.popover) this.popover = new Common.Views.ReviewPopover(options); @@ -1103,7 +1112,8 @@ define([ textClose : 'Close', textResolve : 'Resolve', textOpenAgain : "Open Again", - textLoading : 'Loading' + textLoading : 'Loading', + textMention : '+mention will provide access to the document and send an email' }, Common.Views.ReviewPopover || {})) }); \ No newline at end of file diff --git a/apps/documenteditor/main/app/controller/Main.js b/apps/documenteditor/main/app/controller/Main.js index 879957f51..a073c4846 100644 --- a/apps/documenteditor/main/app/controller/Main.js +++ b/apps/documenteditor/main/app/controller/Main.js @@ -341,6 +341,7 @@ define([ this.plugins = this.editorConfig.plugins; this.appOptions.canMakeActionLink = this.editorConfig.canMakeActionLink; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; + this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/documenteditor/main/locale/en.json b/apps/documenteditor/main/locale/en.json index 31d60f3d7..32e3c1ad8 100644 --- a/apps/documenteditor/main/locale/en.json +++ b/apps/documenteditor/main/locale/en.json @@ -276,6 +276,7 @@ "Common.Views.ReviewPopover.textCancel": "Cancel", "Common.Views.ReviewPopover.textClose": "Close", "Common.Views.ReviewPopover.textEdit": "OK", + "Common.Views.ReviewPopover.textMention": "+mention will provide access to the document and send an email", "Common.Views.ReviewPopover.textOpenAgain": "Open Again", "Common.Views.ReviewPopover.textReply": "Reply", "Common.Views.ReviewPopover.textResolve": "Resolve", diff --git a/apps/presentationeditor/main/app/controller/Main.js b/apps/presentationeditor/main/app/controller/Main.js index 00eb66d09..2a7cc6a7c 100644 --- a/apps/presentationeditor/main/app/controller/Main.js +++ b/apps/presentationeditor/main/app/controller/Main.js @@ -320,6 +320,7 @@ define([ this.appOptions.canPlugins = false; this.plugins = this.editorConfig.plugins; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; + this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; appHeader = this.getApplication().getController('Viewport').getView('Common.Views.Header'); appHeader.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/presentationeditor/main/locale/en.json b/apps/presentationeditor/main/locale/en.json index 80a815c10..2b7671e92 100644 --- a/apps/presentationeditor/main/locale/en.json +++ b/apps/presentationeditor/main/locale/en.json @@ -198,6 +198,7 @@ "Common.Views.ReviewPopover.textCancel": "Cancel", "Common.Views.ReviewPopover.textClose": "Close", "Common.Views.ReviewPopover.textEdit": "OK", + "Common.Views.ReviewPopover.textMention": "+mention will provide access to the document and send an email", "Common.Views.ReviewPopover.textOpenAgain": "Open Again", "Common.Views.ReviewPopover.textReply": "Reply", "Common.Views.ReviewPopover.textResolve": "Resolve", diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index c85db0204..8cfe7427f 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -326,6 +326,7 @@ define([ this.appOptions.canPlugins = false; this.plugins = this.editorConfig.plugins; this.appOptions.canRequestUsers = this.editorConfig.canRequestUsers; + this.appOptions.canRequestSendNotify = this.editorConfig.canRequestSendNotify; this.headerView = this.getApplication().getController('Viewport').getView('Common.Views.Header'); this.headerView.setCanBack(this.appOptions.canBackToFolder === true, (this.appOptions.canBackToFolder) ? this.editorConfig.customization.goback.text : '') diff --git a/apps/spreadsheeteditor/main/locale/en.json b/apps/spreadsheeteditor/main/locale/en.json index 7fe61ada6..5ae57d279 100644 --- a/apps/spreadsheeteditor/main/locale/en.json +++ b/apps/spreadsheeteditor/main/locale/en.json @@ -188,6 +188,7 @@ "Common.Views.ReviewPopover.textCancel": "Cancel", "Common.Views.ReviewPopover.textClose": "Close", "Common.Views.ReviewPopover.textEdit": "OK", + "Common.Views.ReviewPopover.textMention": "+mention will provide access to the document and send an email", "Common.Views.ReviewPopover.textOpenAgain": "Open Again", "Common.Views.ReviewPopover.textReply": "Reply", "Common.Views.ReviewPopover.textResolve": "Resolve", From 3f985b6622d94fa47a9f15ceced242276fb6e089 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Wed, 26 Jun 2019 15:06:26 +0300 Subject: [PATCH 16/18] Fix bug: show users menu when comment is at the top of page (& small browser height) --- apps/common/main/lib/view/ReviewPopover.js | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 1bd511f5b..4f076ae48 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -130,7 +130,7 @@ define([ minHeight: '', overflow: 'hidden', position: 'absolute', - zIndex: '1001' + zIndex: '990' }); var body = window.find('.body'); @@ -479,6 +479,9 @@ define([ }); }).on('show:after', function () { this.scroller.update({alwaysVisibleY: true}); + me.$window.css({zIndex: '1001'}); + }).on('hide:after', function () { + me.$window.css({zIndex: '990'}); }); me.on({ From 04b3651fd055c2242b3f25c54f7ba77de29aef4d Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Thu, 11 Jul 2019 18:00:11 +0300 Subject: [PATCH 17/18] Add setSharingSettings api method: update sharing settings when add mention for users --- apps/api/documents/api.js | 12 +++++++++++- apps/common/Gateway.js | 4 ++++ .../common/main/lib/view/DocumentAccessDialog.js | 1 - .../main/app/view/FileMenuPanels.js | 16 +++++++++++++--- .../main/app/view/FileMenuPanels.js | 16 +++++++++++++--- .../main/app/view/FileMenuPanels.js | 16 +++++++++++++--- 6 files changed, 54 insertions(+), 11 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 00c4688e4..8d8dfbbec 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -554,6 +554,15 @@ }); }; + var _setSharingSettings = function(data) { + _sendCommand({ + command: 'setSharingSettings', + data: { + data: data + } + }); + }; + var _processMouse = function(evt) { var r = iframe.getBoundingClientRect(); var data = { @@ -595,7 +604,8 @@ detachMouseEvents : _detachMouseEvents, destroyEditor : _destroyEditor, setUsers : _setUsers, - showSharingSettings : _showSharingSettings + showSharingSettings : _showSharingSettings, + setSharingSettings : _setSharingSettings } }; diff --git a/apps/common/Gateway.js b/apps/common/Gateway.js index 2d2a9e169..373c41e58 100644 --- a/apps/common/Gateway.js +++ b/apps/common/Gateway.js @@ -106,6 +106,10 @@ if (Common === undefined) { 'showSharingSettings': function(data) { $me.trigger('showsharingsettings', data); + }, + + 'setSharingSettings': function(data) { + $me.trigger('setsharingsettings', data); } }; diff --git a/apps/common/main/lib/view/DocumentAccessDialog.js b/apps/common/main/lib/view/DocumentAccessDialog.js index 2d6c0fcfd..f19aefc89 100644 --- a/apps/common/main/lib/view/DocumentAccessDialog.js +++ b/apps/common/main/lib/view/DocumentAccessDialog.js @@ -122,7 +122,6 @@ define([ if (msg && msg.Referer == "onlyoffice") { if (msg.needUpdate) { this.trigger('accessrights', this, msg.sharingSettings); - Common.NotificationCenter.trigger('mentions:clearusers', this); } Common.NotificationCenter.trigger('window:close', this); } diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 45dafae27..2cae0016c 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -989,6 +989,7 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this)); return this; }, @@ -1000,9 +1001,7 @@ define([ settingsurl: this.sharingSettingsUrl }); me._docAccessDlg.on('accessrights', function(obj, rights){ - me.doc.info.sharingSettings = rights; - me._ShowHideInfoItem('rights', me.doc.info.sharingSettings!==undefined && me.doc.info.sharingSettings!==null && me.doc.info.sharingSettings.length>0); - me.cntRights.html(me.templateRights({users: me.doc.info.sharingSettings})); + me.updateSharingSettings(rights); }).on('close', function(obj){ me._docAccessDlg = undefined; }); @@ -1010,6 +1009,17 @@ define([ me._docAccessDlg.show(); }, + setSharingSettings: function(data) { + data && data.data && this.updateSharingSettings(data.data); + }, + + updateSharingSettings: function(rights) { + this.doc.info.sharingSettings = rights; + this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); + this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); + Common.NotificationCenter.trigger('mentions:clearusers', this); + }, + onLostEditRights: function() { this._readonlyRights = true; if (!this.rendered) diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index cc0bada8e..cec2bd672 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -802,6 +802,7 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this)); return this; }, @@ -813,9 +814,7 @@ define([ settingsurl: this.sharingSettingsUrl }); me._docAccessDlg.on('accessrights', function(obj, rights){ - me.doc.info.sharingSettings = rights; - me._ShowHideInfoItem('rights', me.doc.info.sharingSettings!==undefined && me.doc.info.sharingSettings!==null && me.doc.info.sharingSettings.length>0); - me.cntRights.html(me.templateRights({users: me.doc.info.sharingSettings})); + me.updateSharingSettings(rights); }).on('close', function(obj){ me._docAccessDlg = undefined; }); @@ -823,6 +822,17 @@ define([ me._docAccessDlg.show(); }, + setSharingSettings: function(data) { + data && data.data && this.updateSharingSettings(data.data); + }, + + updateSharingSettings: function(rights) { + this.doc.info.sharingSettings = rights; + this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); + this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); + Common.NotificationCenter.trigger('mentions:clearusers', this); + }, + onLostEditRights: function() { this._readonlyRights = true; if (!this.rendered) diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index 03a50af6e..fe226c362 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1256,6 +1256,7 @@ define([ setMode: function(mode) { this.sharingSettingsUrl = mode.sharingSettingsUrl; !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('showsharingsettings', _.bind(this.changeAccessRights, this)); + !!this.sharingSettingsUrl && this.sharingSettingsUrl.length && Common.Gateway.on('setsharingsettings', _.bind(this.setSharingSettings, this)); return this; }, @@ -1267,9 +1268,7 @@ define([ settingsurl: this.sharingSettingsUrl }); me._docAccessDlg.on('accessrights', function(obj, rights){ - me.doc.info.sharingSettings = rights; - me._ShowHideInfoItem('rights', me.doc.info.sharingSettings!==undefined && me.doc.info.sharingSettings!==null && me.doc.info.sharingSettings.length>0); - me.cntRights.html(me.templateRights({users: me.doc.info.sharingSettings})); + me.updateSharingSettings(rights); }).on('close', function(obj){ me._docAccessDlg = undefined; }); @@ -1277,6 +1276,17 @@ define([ me._docAccessDlg.show(); }, + setSharingSettings: function(data) { + data && data.data && this.updateSharingSettings(data.data); + }, + + updateSharingSettings: function(rights) { + this.doc.info.sharingSettings = rights; + this._ShowHideInfoItem('rights', this.doc.info.sharingSettings!==undefined && this.doc.info.sharingSettings!==null && this.doc.info.sharingSettings.length>0); + this.cntRights.html(this.templateRights({users: this.doc.info.sharingSettings})); + Common.NotificationCenter.trigger('mentions:clearusers', this); + }, + onLostEditRights: function() { this._readonlyRights = true; if (!this.rendered) From 8bcd9da3982f22789db2e18ee6e8758c45d6d536 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Fri, 12 Jul 2019 10:43:02 +0300 Subject: [PATCH 18/18] Refactoring update users rights --- apps/api/documents/api.js | 8 ++------ apps/common/main/lib/view/ReviewPopover.js | 2 +- apps/documenteditor/main/app/view/FileMenuPanels.js | 2 +- apps/presentationeditor/main/app/view/FileMenuPanels.js | 2 +- apps/spreadsheeteditor/main/app/view/FileMenuPanels.js | 2 +- 5 files changed, 6 insertions(+), 10 deletions(-) diff --git a/apps/api/documents/api.js b/apps/api/documents/api.js index 8d8dfbbec..e88648d64 100644 --- a/apps/api/documents/api.js +++ b/apps/api/documents/api.js @@ -541,9 +541,7 @@ var _setUsers = function(data) { _sendCommand({ command: 'setUsers', - data: { - data: data - } + data: data }); }; @@ -557,9 +555,7 @@ var _setSharingSettings = function(data) { _sendCommand({ command: 'setSharingSettings', - data: { - data: data - } + data: data }); }; diff --git a/apps/common/main/lib/view/ReviewPopover.js b/apps/common/main/lib/view/ReviewPopover.js index 4f076ae48..99c696079 100644 --- a/apps/common/main/lib/view/ReviewPopover.js +++ b/apps/common/main/lib/view/ReviewPopover.js @@ -972,7 +972,7 @@ define([ }, setUsers: function(data) { - this.externalUsers = data.data || []; + this.externalUsers = data.users || []; this.isUsersLoading = false; this._state.emailSearch && this.onEmailListMenu(this._state.emailSearch.str, this._state.emailSearch.left, this._state.emailSearch.right); this._state.emailSearch = null; diff --git a/apps/documenteditor/main/app/view/FileMenuPanels.js b/apps/documenteditor/main/app/view/FileMenuPanels.js index 2cae0016c..a766cd941 100644 --- a/apps/documenteditor/main/app/view/FileMenuPanels.js +++ b/apps/documenteditor/main/app/view/FileMenuPanels.js @@ -1010,7 +1010,7 @@ define([ }, setSharingSettings: function(data) { - data && data.data && this.updateSharingSettings(data.data); + data && this.updateSharingSettings(data.sharingSettings); }, updateSharingSettings: function(rights) { diff --git a/apps/presentationeditor/main/app/view/FileMenuPanels.js b/apps/presentationeditor/main/app/view/FileMenuPanels.js index cec2bd672..e338e1cb2 100644 --- a/apps/presentationeditor/main/app/view/FileMenuPanels.js +++ b/apps/presentationeditor/main/app/view/FileMenuPanels.js @@ -823,7 +823,7 @@ define([ }, setSharingSettings: function(data) { - data && data.data && this.updateSharingSettings(data.data); + data && this.updateSharingSettings(data.sharingSettings); }, updateSharingSettings: function(rights) { diff --git a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js index fe226c362..4958846b2 100644 --- a/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js +++ b/apps/spreadsheeteditor/main/app/view/FileMenuPanels.js @@ -1277,7 +1277,7 @@ define([ }, setSharingSettings: function(data) { - data && data.data && this.updateSharingSettings(data.data); + data && this.updateSharingSettings(data.sharingSettings); }, updateSharingSettings: function(rights) {