diff --git a/apps/common/main/lib/collection/Comments.js b/apps/common/main/lib/collection/Comments.js index 1c9fdb4b1..2f34243d7 100644 --- a/apps/common/main/lib/collection/Comments.js +++ b/apps/common/main/lib/collection/Comments.js @@ -52,6 +52,7 @@ define([ Common.Collections.Comments = Backbone.Collection.extend({ model: Common.Models.Comment, + groups: null, clearEditing: function () { this.each(function(comment) { diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index ecf6b09ad..ef24cdcf9 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -150,6 +150,8 @@ define([ this.popoverComments.comparator = function (collection) { return collection.get('time'); }; } + this.groupCollection = []; + this.view = this.createView('Common.Views.Comments', { store: this.collection }); this.view.render(); @@ -229,12 +231,12 @@ define([ this.api.asc_removeComment(id); } }, - onResolveComment: function (uid, id) { + onResolveComment: function (uid) { var t = this, reply = null, addReply = null, ascComment = buildCommentData(), // new asc_CCommentData(null), - comment = t.findComment(uid, id); + comment = t.findComment(uid); if (_.isUndefined(uid)) { uid = comment.get('uid'); @@ -279,7 +281,7 @@ define([ onShowComment: function (id, selected) { if (this.previewmode) return; - var comment = this.findComment(id, undefined); + var comment = this.findComment(id); if (comment) { if (null !== comment.get('quote')) { if (this.api) { @@ -596,47 +598,40 @@ define([ if (filter) { if (!this.view.isVisible()) { this.view.needUpdateFilter = filter; - this.filter = { - property : filter.property, - value : filter.value - }; - return; + applyOnly = true; } - this.view.needUpdateFilter = false; + this.filter = filter; - this.filter = { - property : filter.property, - value : filter.value - }; + var me = this, + comments = []; + this.filter.forEach(function(item){ + if (!me.groupCollection[item]) + me.groupCollection[item] = new Backbone.Collection([], { model: Common.Models.Comment}); + comments = comments.concat(me.groupCollection[item].models); + }); + this.collection.reset(comments); + this.collection.groups = this.filter; if (!applyOnly) { if (this.getPopover()) { this.getPopover().hide(); } - } + this.view.needUpdateFilter = false; - var t = this, endComment = null; - - this.collection.each(function (model) { - var prop = model.get(t.filter.property); - if (prop) { - model.set('hide', (null === prop.match(t.filter.value)), {silent: !!applyOnly}); + var end = true; + for (var i = this.collection.length - 1; i >= 0; --i) { + if (end) { + this.collection.at(i).set('last', true, {silent: true}); + } else { + if (this.collection.at(i).get('last')) { + this.collection.at(i).set('last', false, {silent: true}); + } + } + end = false; } - - if (model.get('last')) { - model.set('last', false, {silent:!!applyOnly}); - } - - if (!model.get('hide')) { - endComment = model; - } - }); - - if (endComment) { - endComment.set('last', true, {silent: !!applyOnly}); - } - if (!applyOnly) + this.view.render(); this.view.update(); + } } }, onAppAddComment: function (sender, to_doc) { @@ -644,12 +639,23 @@ define([ this.addDummyComment(); }, + addCommentToGroupCollection: function(comment) { + var groupname = comment.get('groupName'); + if (!this.groupCollection[groupname]) + this.groupCollection[groupname] = new Backbone.Collection([], { model: Common.Models.Comment}); + this.groupCollection[groupname].push(comment); + }, + // SDK onApiAddComment: function (id, data) { var comment = this.readSDKComment(id, data); if (comment) { - this.collection.push(comment); + if (comment.get('groupName')) { + this.addCommentToGroupCollection(comment); + (_.indexOf(this.collection.groups, comment.get('groupName'))>-1) && this.collection.push(comment); + } else + this.collection.push(comment); this.updateComments(true); @@ -668,12 +674,20 @@ define([ onApiAddComments: function (data) { for (var i = 0; i < data.length; ++i) { var comment = this.readSDKComment(data[i].asc_getId(), data[i]); - this.collection.push(comment); + comment.get('groupName') ? this.addCommentToGroupCollection(comment) : this.collection.push(comment); } this.updateComments(true); }, onApiRemoveComment: function (id, silentUpdate) { + for (var name in this.groupCollection) { + var store = this.groupCollection[name], + model = store.findWhere({uid: id}); + if (model) { + store.remove(model); + break; + } + } if (this.collection.length) { var model = this.collection.findWhere({uid: id}); if (model) { @@ -717,7 +731,7 @@ define([ replies = null, repliesCount = 0, dateReply = null, - comment = this.findComment(id); + comment = this.findComment(id) || this.findCommentInGroup(id); if (comment) { t = this; @@ -776,7 +790,7 @@ define([ } }, onApiLockComment: function (id,userId) { - var cur = this.findComment(id), + var cur = this.findComment(id) || this.findCommentInGroup(id), user = null; if (cur) { @@ -792,7 +806,7 @@ define([ } }, onApiUnLockComment: function (id) { - var cur = this.findComment(id); + var cur = this.findComment(id) || this.findCommentInGroup(id); if (cur) { cur.set('lock', false); this.getPopover() && this.getPopover().loadText(); @@ -999,11 +1013,6 @@ define([ // internal updateComments: function (needRender, disableSort) { - if (needRender && !this.view.isVisible()) { - this.view.needRender = needRender; - return; - } - var me = this; me.updateCommentsTime = new Date(); if (me.timerUpdateComments===undefined) @@ -1017,6 +1026,12 @@ define([ }, updateCommentsView: function (needRender, disableSort) { + if (needRender && !this.view.isVisible()) { + this.view.needRender = needRender; + this.onUpdateFilter(this.filter, true); + return; + } + var i, end = true; if (_.isUndefined(disableSort)) { @@ -1024,6 +1039,8 @@ define([ } if (needRender) { + this.onUpdateFilter(this.filter, true); + for (i = this.collection.length - 1; i >= 0; --i) { if (end) { this.collection.at(i).set('last', true, {silent: true}); @@ -1035,24 +1052,25 @@ define([ end = false; } - this.onUpdateFilter(this.filter, true); - this.view.render(); this.view.needRender = false; } this.view.update(); }, - findComment: function (uid, id) { - if (_.isUndefined(uid)) { - return this.collection.findWhere({id: id}); - } - + findComment: function (uid) { return this.collection.findWhere({uid: uid}); }, findPopupComment: function (id) { return this.popoverComments.findWhere({id: id}); }, + findCommentInGroup: function (id) { + for (var name in this.groupCollection) { + var store = this.groupCollection[name], + model = store.findWhere({uid: id}); + if (model) return model; + } + }, closeEditing: function (id) { var t = this; @@ -1117,8 +1135,21 @@ define([ // helpers onUpdateUsers: function() { - var users = this.userCollection; - this.collection.each(function (model) { + var users = this.userCollection, + hasGroup = false; + for (var name in this.groupCollection) { + hasGroup = true; + this.groupCollection[name].each(function (model) { + var user = users.findOriginalUser(model.get('userid')); + model.set('usercolor', (user) ? user.get('color') : null, {silent: true}); + + model.get('replys').forEach(function (reply) { + user = users.findOriginalUser(reply.get('userid')); + reply.set('usercolor', (user) ? user.get('color') : null, {silent: true}); + }); + }); + } + !hasGroup && this.collection.each(function (model) { var user = users.findOriginalUser(model.get('userid')); model.set('usercolor', (user) ? user.get('color') : null, {silent: true}); @@ -1135,7 +1166,8 @@ define([ readSDKComment: function (id, data) { var date = (data.asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getOnlyOfficeTime())) : ((data.asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getTime()))); - var user = this.userCollection.findOriginalUser(data.asc_getUserId()); + var user = this.userCollection.findOriginalUser(data.asc_getUserId()), + groupname = id.match(/^(doc|sheet[0-9]+)_/); var comment = new Common.Models.Comment({ uid : id, userid : data.asc_getUserId(), @@ -1155,7 +1187,8 @@ define([ showReplyInPopover : false, hideAddReply : !_.isUndefined(this.hidereply) ? this.hidereply : (this.showPopover ? true : false), scope : this.view, - editable : this.mode.canEditComments || (data.asc_getUserId() == this.currentUserId) + editable : this.mode.canEditComments || (data.asc_getUserId() == this.currentUserId), + groupName : (groupname && groupname.length>1) ? groupname[1] : null }); if (comment) { var replies = this.readSDKReplies(data); diff --git a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js index 52092f2f8..9f190a9aa 100644 --- a/apps/spreadsheeteditor/main/app/controller/LeftMenu.js +++ b/apps/spreadsheeteditor/main/app/controller/LeftMenu.js @@ -151,11 +151,14 @@ define([ if (this.mode.canComments) { this.api.asc_registerCallback('asc_onAddComment', _.bind(this.onApiAddComment, this)); this.api.asc_registerCallback('asc_onAddComments', _.bind(this.onApiAddComments, this)); - var collection = this.getApplication().getCollection('Common.Collections.Comments'); - for (var i = 0; i < collection.length; ++i) { - if (collection.at(i).get('userid') !== this.mode.user.id) { - this.leftMenu.markCoauthOptions('comments', true); - break; + var comments = this.getApplication().getController('Common.Controllers.Comments').groupCollection; + for (var name in comments) { + var collection = comments[name]; + for (var i = 0; i < collection.length; ++i) { + if (collection.at(i).get('userid') !== this.mode.user.id) { + this.leftMenu.markCoauthOptions('comments', true); + break; + } } } } diff --git a/apps/spreadsheeteditor/main/app/controller/Main.js b/apps/spreadsheeteditor/main/app/controller/Main.js index 79756d220..230661f1d 100644 --- a/apps/spreadsheeteditor/main/app/controller/Main.js +++ b/apps/spreadsheeteditor/main/app/controller/Main.js @@ -718,9 +718,7 @@ define([ if (window.styles_loaded || me.appOptions.isEditDiagram || me.appOptions.isEditMailMerge) { clearInterval(timer_sl); - Common.NotificationCenter.trigger('comments:updatefilter', - {property: 'uid', - value: new RegExp('^(doc_|sheet' + me.api.asc_getActiveWorksheetId() + '_)')}); + Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + me.api.asc_getActiveWorksheetId()]); documentHolderView.createDelayedElements(); toolbarController.createDelayedElements(); @@ -1619,14 +1617,8 @@ define([ if (!this.appOptions.isEditMailMerge && !this.appOptions.isEditDiagram && window.editor_elements_prepared) { this.application.getController('Statusbar').selectTab(index); - if (this.appOptions.isEdit && !this.dontCloseDummyComment) { - Common.NotificationCenter.trigger('comments:updatefilter', - { - property: 'uid', - value: new RegExp('^(doc_|sheet' + this.api.asc_getWorksheetId(index) + '_)') - }, - false // hide popover - ); + if (this.appOptions.canComments && !this.dontCloseDummyComment) { + Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + this.api.asc_getWorksheetId(index)], false ); // hide popover } } }, diff --git a/apps/spreadsheeteditor/main/app/controller/Statusbar.js b/apps/spreadsheeteditor/main/app/controller/Statusbar.js index 73233d6d2..d7af7b851 100644 --- a/apps/spreadsheeteditor/main/app/controller/Statusbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Statusbar.js @@ -384,9 +384,7 @@ define([ if (!_.isUndefined(silent)) { me.api.asc_showWorksheet(items[index].inindex); - Common.NotificationCenter.trigger('comments:updatefilter', - {property: 'uid', - value: new RegExp('^(doc_|sheet' + this.api.asc_getActiveWorksheetId() + '_)')}); + Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + this.api.asc_getActiveWorksheetId()]); if (!_.isUndefined(destPos)) { me.api.asc_moveWorksheet(items.length === destPos ? wc : items[destPos].inindex); @@ -418,12 +416,7 @@ define([ this.api.asc_closeCellEditor(); this.api.asc_addWorksheet(this.createSheetName()); - Common.NotificationCenter.trigger('comments:updatefilter', - {property: 'uid', - value: new RegExp('^(doc_|sheet' + this.api.asc_getActiveWorksheetId() + '_)') - }, - false // hide popover - ); + Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + this.api.asc_getActiveWorksheetId()], false); // hide popover } Common.NotificationCenter.trigger('edit:complete', this.statusbar); }, diff --git a/apps/spreadsheeteditor/main/app/controller/Toolbar.js b/apps/spreadsheeteditor/main/app/controller/Toolbar.js index 044fdbe37..42faf095d 100644 --- a/apps/spreadsheeteditor/main/app/controller/Toolbar.js +++ b/apps/spreadsheeteditor/main/app/controller/Toolbar.js @@ -2825,17 +2825,6 @@ define([ // }); }, - onSheetChanged: function() { - if (this.api) { - var params = this.api.asc_getSheetViewSettings(); - var menu = this.getMenuHideOptions(); - if (menu) { - menu.items.getAt(3).setChecked(!params.asc_getShowRowColHeaders()); - menu.items.getAt(4).setChecked(!params.asc_getShowGridLines()); - } - } - }, - _disableEditOptions: function(seltype, coauth_disable) { if (this.api.isCellEdited) return true; if (this.api.isRangeSelection) return true; diff --git a/apps/spreadsheeteditor/main/app/view/Statusbar.js b/apps/spreadsheeteditor/main/app/view/Statusbar.js index b18681e4d..affc00153 100644 --- a/apps/spreadsheeteditor/main/app/view/Statusbar.js +++ b/apps/spreadsheeteditor/main/app/view/Statusbar.js @@ -358,7 +358,7 @@ define([ me.fireEvent('sheet:changed', [me, sindex]); me.fireEvent('sheet:updateColors', [true]); - Common.NotificationCenter.trigger('comments:updatefilter', {property: 'uid', value: new RegExp('^(doc_|sheet' + me.api.asc_getActiveWorksheetId() + '_)')}, false); + Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + me.api.asc_getActiveWorksheetId()], false); } }, @@ -409,13 +409,7 @@ define([ this.fireEvent('sheet:changed', [this, tab.sheetindex]); this.fireEvent('sheet:updateColors', [true]); - Common.NotificationCenter.trigger('comments:updatefilter', - { - property: 'uid', - value: new RegExp('^(doc_|sheet' + this.api.asc_getActiveWorksheetId() + '_)') - }, - false // hide popover - ); + // Common.NotificationCenter.trigger('comments:updatefilter', ['doc', 'sheet' + this.api.asc_getActiveWorksheetId()], false); // hide popover }, onTabMenu: function (o, index, tab) {