diff --git a/apps/common/main/lib/collection/Users.js b/apps/common/main/lib/collection/Users.js index 02dc62235f..935224dcf7 100644 --- a/apps/common/main/lib/collection/Users.js +++ b/apps/common/main/lib/collection/Users.js @@ -74,6 +74,13 @@ define([ function(model){ return model.get('id') == id; }); + }, + + findOriginalUser: function(id) { + return this.find( + function(model){ + return model.get('idOriginal') == id; + }); } }); diff --git a/apps/common/main/lib/controller/Chat.js b/apps/common/main/lib/controller/Chat.js index e673adc0f5..36a61151dc 100644 --- a/apps/common/main/lib/controller/Chat.js +++ b/apps/common/main/lib/controller/Chat.js @@ -148,6 +148,7 @@ define([ if (user) { var usermodel = new Common.Models.User({ id : user.asc_getId(), + idOriginal : user.asc_getIdOriginal(), username : user.asc_getUserName(), online : true, color : user.asc_getColor(), @@ -170,6 +171,7 @@ define([ if (!user) { usersStore.add(new Common.Models.User({ id : change.asc_getId(), + idOriginal : change.asc_getIdOriginal(), username : change.asc_getUserName(), online : change.asc_getState(), color : change.asc_getColor(), diff --git a/apps/common/main/lib/controller/Comments.js b/apps/common/main/lib/controller/Comments.js index 0b2c0ad4a6..440da2d596 100644 --- a/apps/common/main/lib/controller/Comments.js +++ b/apps/common/main/lib/controller/Comments.js @@ -134,6 +134,10 @@ define([ }); this.view.render(); + this.userCollection = this.getApplication().getCollection('Common.Collections.Users'); + this.userCollection.on('reset', _.bind(this.onUpdateUsers, this)); + this.userCollection.on('add', _.bind(this.onUpdateUsers, this)); + this.bindViewEvents(this.view, this.events); }, setConfig: function (data, api) { @@ -162,7 +166,6 @@ define([ this.api.asc_registerCallback('asc_onShowComment', _.bind(this.onApiShowComment, this)); this.api.asc_registerCallback('asc_onHideComment', _.bind(this.onApiHideComment, this)); this.api.asc_registerCallback('asc_onUpdateCommentPosition', _.bind(this.onApiUpdateCommentPosition, this)); - this.api.asc_registerCallback('asc_onDocumentPlaceChanged', _.bind(this.onDocumentPlaceChanged, this)); } }, @@ -703,9 +706,11 @@ define([ 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()); comment.set('comment', data.asc_getText()); comment.set('userid', data.asc_getUserId()); comment.set('username', data.asc_getUserName()); + comment.set('usercolor', (user) ? user.get('color') : null); comment.set('resolved', data.asc_getSolved()); comment.set('quote', data.asc_getQuoteText()); comment.set('time', date.getTime()); @@ -721,10 +726,12 @@ define([ dateReply = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); + user = this.userCollection.findOriginalUser(data.asc_getReply(i).asc_getUserId()); replies.push(new Common.Models.Reply({ id : Common.UI.getId(), userid : data.asc_getReply(i).asc_getUserId(), username : data.asc_getReply(i).asc_getUserName(), + usercolor : (user) ? user.get('color') : null, date : t.dateToLocaleTimeString(dateReply), reply : data.asc_getReply(i).asc_getText(), time : dateReply.getTime(), @@ -751,13 +758,11 @@ define([ }, onApiLockComment: function (id,userId) { var cur = this.findComment(id), - usersStore = null, user = null; if (cur) { - usersStore = this.getApplication().getCollection('Common.Collections.Users'); - if (usersStore) { - user = usersStore.findWhere({id: userId}); + if (this.userCollection) { + user = this.userCollection.findUser(userId); if (user) { this.getPopover() && this.getPopover().saveText(); this.view.saveText(); @@ -1079,13 +1084,31 @@ define([ // helpers + onUpdateUsers: function() { + var users = this.userCollection; + this.collection.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}); + }); + }); + this.updateComments(true); + if (this.getPopover().isVisible()) + this.getPopover().update(true); + }, + 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 comment = new Common.Models.Comment({ uid : id, userid : data.asc_getUserId(), username : data.asc_getUserName(), + usercolor : (user) ? user.get('color') : null, date : this.dateToLocaleTimeString(date), quote : data.asc_getQuoteText(), comment : data.asc_getText(), @@ -1121,10 +1144,12 @@ define([ date = (data.asc_getReply(i).asc_getOnlyOfficeTime()) ? new Date(this.stringOOToLocalDate(data.asc_getReply(i).asc_getOnlyOfficeTime())) : ((data.asc_getReply(i).asc_getTime() == '') ? new Date() : new Date(this.stringUtcToLocalDate(data.asc_getReply(i).asc_getTime()))); + var user = this.userCollection.findOriginalUser(data.asc_getReply(i).asc_getUserId()); replies.push(new Common.Models.Reply({ id : Common.UI.getId(), userid : data.asc_getReply(i).asc_getUserId(), username : data.asc_getReply(i).asc_getUserName(), + usercolor : (user) ? user.get('color') : null, date : this.dateToLocaleTimeString(date), reply : data.asc_getReply(i).asc_getText(), time : date.getTime(), @@ -1157,12 +1182,14 @@ define([ return; } + var user = this.userCollection.findOriginalUser(this.currentUserId); var comment = new Common.Models.Comment({ id: -1, time: date.getTime(), date: this.dateToLocaleTimeString(date), userid: this.currentUserId, username: this.currentUserName, + usercolor: (user) ? user.get('color') : null, editTextInPopover: true, showReplyInPopover: false, hideAddReply: true, diff --git a/apps/common/main/lib/controller/ReviewChanges.js b/apps/common/main/lib/controller/ReviewChanges.js index 4e64011e67..161a4013d5 100644 --- a/apps/common/main/lib/controller/ReviewChanges.js +++ b/apps/common/main/lib/controller/ReviewChanges.js @@ -96,6 +96,9 @@ define([ Common.NotificationCenter.on('spelling:turn', this.onTurnSpelling.bind(this)); Common.NotificationCenter.on('app:ready', this.onAppReady.bind(this)); Common.NotificationCenter.on('api:disconnect', _.bind(this.onCoAuthoringDisconnect, this)); + + this.userCollection.on('reset', _.bind(this.onUpdateUsers, this)); + this.userCollection.on('add', _.bind(this.onUpdateUsers, this)); }, setConfig: function (data, api) { this.setApi(api); @@ -386,12 +389,12 @@ define([ } var date = (item.get_DateTime() == '') ? new Date() : new Date(item.get_DateTime()), - color = item.get_UserColor(), + user = me.userCollection.findOriginalUser(item.get_UserId()), change = new Common.Models.ReviewChange({ uid : Common.UI.getId(), userid : item.get_UserId(), username : item.get_UserName(), - usercolor : '#'+Common.Utils.ThemeColor.getHexColor(color.get_r(), color.get_g(), color.get_b()), + usercolor : (user) ? user.get('color') : null, date : me.dateToLocaleTimeString(date), changetext : changetext, id : Common.UI.getId(), @@ -686,6 +689,14 @@ define([ this.SetDisabled(true); }, + onUpdateUsers: function() { + var users = this.userCollection; + this.popoverChanges.each(function (model) { + var user = users.findOriginalUser(model.get('userid')); + model.set('usercolor', (user) ? user.get('color') : null); + }); + }, + textInserted: 'Inserted:', textDeleted: 'Deleted:', textParaInserted: 'Paragraph Inserted ', diff --git a/apps/common/main/lib/model/Comment.js b/apps/common/main/lib/model/Comment.js index 83479b7714..6fea9f6e12 100644 --- a/apps/common/main/lib/model/Comment.js +++ b/apps/common/main/lib/model/Comment.js @@ -55,6 +55,7 @@ define([ uid : 0, // asc userid : 0, username : 'Guest', + usercolor : null, date : undefined, quote : '', comment : '', @@ -84,6 +85,7 @@ define([ time : 0, // acs userid : 0, username : 'Guest', + usercolor : null, reply : '', date : undefined, diff --git a/apps/common/main/lib/model/ReviewChange.js b/apps/common/main/lib/model/ReviewChange.js index 280cce4958..b9c55ec3fb 100644 --- a/apps/common/main/lib/model/ReviewChange.js +++ b/apps/common/main/lib/model/ReviewChange.js @@ -55,7 +55,7 @@ define([ uid : 0, // asc userid : 0, username : 'Guest', - usercolor : '#ee3525', + usercolor : null, date : undefined, changetext : '', lock : false, diff --git a/apps/common/main/lib/model/User.js b/apps/common/main/lib/model/User.js index f224399a57..cf7ba46fc0 100644 --- a/apps/common/main/lib/model/User.js +++ b/apps/common/main/lib/model/User.js @@ -57,6 +57,7 @@ define([ return { iid : Common.UI.getId(), // internal id for rendering id : undefined, + idOriginal : undefined, username : 'Guest', color : '#fff', colorval : null, diff --git a/apps/common/main/lib/template/Comments.template b/apps/common/main/lib/template/Comments.template index 17b8874f8b..3899e288c9 100644 --- a/apps/common/main/lib/template/Comments.template +++ b/apps/common/main/lib/template/Comments.template @@ -3,7 +3,9 @@ -