From 145008eaae2e3e20febf73dacb12cd9091b58ae5 Mon Sep 17 00:00:00 2001 From: Julia Radzhabova Date: Tue, 30 Oct 2018 11:13:23 +0300 Subject: [PATCH] [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 =