[Mobile] Use config permssions to view comments

This commit is contained in:
Julia Radzhabova 2021-03-17 23:57:54 +03:00
parent 8a3a74dc2d
commit 916c911ac7
5 changed files with 139 additions and 72 deletions

View file

@ -791,6 +791,16 @@ define([
return comment; return comment;
}, },
findVisibleComment: function(uid) {
var comment;
if (this.groupCollectionFilter.length !== 0) {
comment = this.findVisibleCommentInGroup(uid);
} else if (this.collectionComments.length !== 0) {
comment = _.findWhere(this.collectionComments, {uid: uid, hide: false});
}
return comment;
},
apiShowComments: function(uid) { apiShowComments: function(uid) {
var comments, var comments,
me = this; me = this;
@ -988,12 +998,15 @@ define([
onViewPrevComment: function() { onViewPrevComment: function() {
if (this.showComments && this.showComments.length > 0) { if (this.showComments && this.showComments.length > 0) {
for (var i=0; i<this.showComments.length; i++) {
if (this.indexCurrentComment - 1 < 0) { if (this.indexCurrentComment - 1 < 0) {
this.indexCurrentComment = this.showComments.length - 1; this.indexCurrentComment = this.showComments.length - 1;
} else { } else {
this.indexCurrentComment -= 1; this.indexCurrentComment -= 1;
} }
this.view.renderViewComments(this.showComments, this.indexCurrentComment); if (this.view.renderViewComments(this.showComments, this.indexCurrentComment))
break;
}
var me = this; var me = this;
_.defer(function () { _.defer(function () {
$('.comment-menu').single('click', _.buffered(me.initMenuComments, 100, me)); $('.comment-menu').single('click', _.buffered(me.initMenuComments, 100, me));
@ -1005,12 +1018,15 @@ define([
onViewNextComment: function() { onViewNextComment: function() {
if (this.showComments && this.showComments.length > 0) { if (this.showComments && this.showComments.length > 0) {
for (var i=0; i<this.showComments.length; i++) {
if (this.indexCurrentComment + 1 === this.showComments.length) { if (this.indexCurrentComment + 1 === this.showComments.length) {
this.indexCurrentComment = 0; this.indexCurrentComment = 0;
} else { } else {
this.indexCurrentComment += 1; this.indexCurrentComment += 1;
} }
this.view.renderViewComments(this.showComments, this.indexCurrentComment); if (this.view.renderViewComments(this.showComments, this.indexCurrentComment))
break;
}
var me = this; var me = this;
_.defer(function () { _.defer(function () {
$('.comment-menu').single('click', _.buffered(me.initMenuComments, 100, me)); $('.comment-menu').single('click', _.buffered(me.initMenuComments, 100, me));
@ -1543,7 +1559,8 @@ define([
time : date.getTime(), time : date.getTime(),
userInitials : this.getInitials(username), userInitials : this.getInitials(username),
editable : (this.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), editable : (this.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username),
removable : (this.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) removable : (this.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username),
hide : !Common.Utils.UserInfoParser.canViewComment(data.asc_getReply(i).asc_getUserName())
}); });
} }
} }
@ -1573,7 +1590,8 @@ define([
groupName : (groupname && groupname.length>1) ? groupname[1] : null, groupName : (groupname && groupname.length>1) ? groupname[1] : null,
userInitials : this.getInitials(username), userInitials : this.getInitials(username),
editable : (this.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), editable : (this.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username),
removable : (this.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) removable : (this.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username),
hide : !Common.Utils.UserInfoParser.canViewComment(username)
}; };
if (comment) { if (comment) {
var replies = this.readSDKReplies(data); var replies = this.readSDKReplies(data);
@ -1611,6 +1629,7 @@ define([
comment.date = me.dateToLocaleTimeString(date); comment.date = me.dateToLocaleTimeString(date);
comment.editable = (me.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getUserName()); comment.editable = (me.appConfig.canEditComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(data.asc_getUserName());
comment.removable = (me.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getUserName()); comment.removable = (me.appConfig.canDeleteComments || (data.asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(data.asc_getUserName());
comment.hide = !Common.Utils.UserInfoParser.canViewComment(data.asc_getUserName());
replies = _.clone(comment.replys); replies = _.clone(comment.replys);
@ -1636,7 +1655,8 @@ define([
time : dateReply.getTime(), time : dateReply.getTime(),
userInitials : me.getInitials(username), userInitials : me.getInitials(username),
editable : (me.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username), editable : (me.appConfig.canEditComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canEditComment(username),
removable : (me.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username) removable : (me.appConfig.canDeleteComments || (data.asc_getReply(i).asc_getUserId() == _userId)) && Common.Utils.UserInfoParser.canDeleteComment(username),
hide : !Common.Utils.UserInfoParser.canViewComment(username)
}); });
} }
comment.replys = replies; comment.replys = replies;
@ -1708,6 +1728,15 @@ define([
} }
}, },
findVisibleCommentInGroup: function (id) {
for (var name in this.groupCollectionComments) {
var store = this.groupCollectionComments[name];
var id = _.isArray(id) ? id[0] : id;
var model = _.findWhere(store, {uid: id, hide: false});
if (model) return model;
}
},
onApiRemoveComment: function (id, silentUpdate) { onApiRemoveComment: function (id, silentUpdate) {
function remove (collection, key) { function remove (collection, key) {
if(collection instanceof Array) { if(collection instanceof Array) {

View file

@ -165,12 +165,15 @@ define([
renderViewComments: function(comments, indCurComment) { renderViewComments: function(comments, indCurComment) {
var isAndroid = Framework7.prototype.device.android === true; var isAndroid = Framework7.prototype.device.android === true;
var me = this; var me = this;
var res = false;
if ($('.page-view-comments .page-content').length > 0) { if ($('.page-view-comments .page-content').length > 0) {
var template = ''; var template = '';
if (comments && comments.length > 0) { if (comments && comments.length > 0) {
var comment = comments[indCurComment];
res = !comment.hide;
if (res) {
template = '<div class="list-block">' + template = '<div class="list-block">' +
'<ul id="comments-list">'; '<ul id="comments-list">';
var comment = comments[indCurComment];
template += '<li class="comment item-content" data-uid="' + comment.uid + '">' + template += '<li class="comment item-content" data-uid="' + comment.uid + '">' +
'<div class="item-inner">' + '<div class="item-inner">' +
'<div class="header-comment"><div class="comment-left">'; '<div class="header-comment"><div class="comment-left">';
@ -196,6 +199,7 @@ define([
if (comment.replys.length > 0) { if (comment.replys.length > 0) {
template += '<ul class="list-reply">'; template += '<ul class="list-reply">';
_.each(comment.replys, function (reply) { _.each(comment.replys, function (reply) {
if (!reply.hide) {
template += '<li class="reply-item" data-ind="' + reply.ind + '">' + template += '<li class="reply-item" data-ind="' + reply.ind + '">' +
'<div class="header-reply">' + '<div class="header-reply">' +
'<div class="reply-left">'; '<div class="reply-left">';
@ -214,6 +218,7 @@ define([
template += '</div>' + template += '</div>' +
'<div class="reply-text"><pre>' + reply.reply + '</pre></div>' + '<div class="reply-text"><pre>' + reply.reply + '</pre></div>' +
'</li>'; '</li>';
}
}); });
template += '</ul>' template += '</ul>'
} }
@ -224,7 +229,9 @@ define([
$('.page-view-comments .page-content').html(template); $('.page-view-comments .page-content').html(template);
} }
} }
}
Common.Utils.addScrollIfNeed('.page-view-comments.page', '.page-view-comments .page-content'); Common.Utils.addScrollIfNeed('.page-view-comments.page', '.page-view-comments .page-content');
return res;
}, },
renderComments: function (comments) { renderComments: function (comments) {
@ -245,6 +252,7 @@ define([
items = []; items = [];
_.each(sortComments, function (comment) { _.each(sortComments, function (comment) {
var itemTemplate = [ var itemTemplate = [
'<% if (!item.hide) { %>',
'<li class="comment item-content" data-uid="<%= item.uid %>">', '<li class="comment item-content" data-uid="<%= item.uid %>">',
'<div class="item-inner">', '<div class="item-inner">',
'<div class="header-comment"><div class="comment-left">', '<div class="header-comment"><div class="comment-left">',
@ -267,6 +275,7 @@ define([
'<% if(replys > 0) {%>', '<% if(replys > 0) {%>',
'<ul class="list-reply">', '<ul class="list-reply">',
'<% _.each(item.replys, function (reply) { %>', '<% _.each(item.replys, function (reply) { %>',
'<% if (!reply.hide) { %>',
'<li class="reply-item" data-ind="<%= reply.ind %>">', '<li class="reply-item" data-ind="<%= reply.ind %>">',
'<div class="header-reply">', '<div class="header-reply">',
'<div class="reply-left">', '<div class="reply-left">',
@ -281,11 +290,13 @@ define([
'</div>', '</div>',
'<div class="reply-text"><pre><%= reply.reply %></pre></div>', '<div class="reply-text"><pre><%= reply.reply %></pre></div>',
'</li>', '</li>',
'<% } %>',
'<% }); %>', '<% }); %>',
'</ul>', '</ul>',
'<% } %>', '<% } %>',
'</div>', '</div>',
'</li>' '</li>',
'<% } %>'
].join(''); ].join('');
items.push(_.template(itemTemplate)({ items.push(_.template(itemTemplate)({
android: Framework7.prototype.device.android, android: Framework7.prototype.device.android,

View file

@ -454,7 +454,15 @@ define([
}, },
onApiShowComment: function(comments) { onApiShowComment: function(comments) {
_isComments = comments && comments.length>0; _isComments = false;
if (comments && comments.length > 0) {
for (var i = 0; i < comments.length; ++i) {
if (this.getApplication().getController('Common.Controllers.Collaboration').findVisibleComment(comments[i])) {
_isComments = true;
break;
}
}
}
}, },
onApiHideComment: function() { onApiHideComment: function() {

View file

@ -90,7 +90,15 @@ define([
}, },
onApiShowComment: function(comments) { onApiShowComment: function(comments) {
_isComments = comments && comments.length>0; _isComments = false;
if (comments && comments.length > 0) {
for (var i = 0; i < comments.length; ++i) {
if (this.getApplication().getController('Common.Controllers.Collaboration').findVisibleComment(comments[i])) {
_isComments = true;
break;
}
}
}
}, },
onApiHideComment: function() { onApiHideComment: function() {

View file

@ -54,7 +54,8 @@ define([
var _actionSheets = [], var _actionSheets = [],
_isEdit = false, _isEdit = false,
_canViewComments = true, _canViewComments = true,
_isComments = false; _isComments = false,
_isVisibleComments = false;
function openLink(url) { function openLink(url) {
var newDocumentPage = window.open(url, '_blank'); var newDocumentPage = window.open(url, '_blank');
@ -321,8 +322,18 @@ define([
var iscellmenu, isrowmenu, iscolmenu, isallmenu, ischartmenu, isimagemenu, istextshapemenu, isshapemenu, istextchartmenu; var iscellmenu, isrowmenu, iscolmenu, isallmenu, ischartmenu, isimagemenu, istextshapemenu, isshapemenu, istextchartmenu;
var iscelllocked = cellinfo.asc_getLocked(), var iscelllocked = cellinfo.asc_getLocked(),
seltype = cellinfo.asc_getSelectionType(), seltype = cellinfo.asc_getSelectionType(),
xfs = cellinfo.asc_getXfs(); xfs = cellinfo.asc_getXfs(),
_isComments = cellinfo.asc_getComments().length>0; //prohibit adding multiple comments in one cell; comments = cellinfo.asc_getComments();
_isComments = comments.length>0; //prohibit adding multiple comments in one cell;
_isVisibleComments = false;
if (comments && comments.length > 0) {
for (var i = 0; i < comments.length; ++i) {
if (me.getApplication().getController('Common.Controllers.Collaboration').findVisibleComment(comments[i].asc_getId())) {
_isVisibleComments = true;
break;
}
}
}
switch (seltype) { switch (seltype) {
case Asc.c_oAscSelectionType.RangeCells: iscellmenu = true; break; case Asc.c_oAscSelectionType.RangeCells: iscellmenu = true; break;
@ -350,7 +361,7 @@ define([
event: 'openlink' event: 'openlink'
}); });
} }
if (_canViewComments && _isComments) { if (_canViewComments && _isVisibleComments) {
arrItems.push({ arrItems.push({
caption: me.menuViewComment, caption: me.menuViewComment,
event: 'viewcomment' event: 'viewcomment'
@ -463,12 +474,12 @@ define([
} }
if (_canViewComments) { if (_canViewComments) {
if (_isComments) { if (_isVisibleComments) {
arrItems.push({ arrItems.push({
caption: me.menuViewComment, caption: me.menuViewComment,
event: 'viewcomment' event: 'viewcomment'
}); });
} else if (iscellmenu) { } else if (iscellmenu && !_isComments) {
arrItems.push({ arrItems.push({
caption: me.menuAddComment, caption: me.menuAddComment,
event: 'addcomment' event: 'addcomment'