Commit be87b95d authored by bbaer's avatar bbaer
Browse files

added remove function

parent ff641cee
Pipeline #1465 passed with stage
in 2 minutes and 18 seconds
......@@ -54,6 +54,7 @@ var QfqNS = QfqNS || {};
this.data = {
url: this.$parent.data("file"),
text: this.$parent.data("text")
};
this.page = page;
this.language = this.$parent.data("highlight") || "typo3conf/ext/qfq/Resources/Public/Json/javascript.json";
......@@ -72,6 +73,7 @@ var QfqNS = QfqNS || {};
}
}
if (this.data.url) {
// Get data of a file and write it to data.text
$.get(this.data.url, function(response) {
......@@ -243,6 +245,30 @@ var QfqNS = QfqNS || {};
commentController.on('comment.edited', function() {
that._updateJSON();
});
commentController.on('comment.removed', function(e) {
console.log(e);
if(that._checkUserRemoval(e.data.uid)) {
console.log("Removed User uid: " + e.data.uid);
}
that._checkLineRemoval();
that._updateJSON();
});
};
n.CodeCorrection.prototype._checkLineRemoval = function() {
var removeLines = [];
for (var i = 0; i < this.annotations.length; i++) {
var comments = this.annotations[i].commentController.exportComments();
if(comments.length == 0) {
removeLines.push(i);
}
}
for (var ii = 0; ii < removeLines.length; ii++) {
this.annotations.splice(removeLines[ii], 1);
}
};
n.CodeCorrection.prototype._handleNew = function(eventData) {
......@@ -250,6 +276,27 @@ var QfqNS = QfqNS || {};
this._updateJSON();
};
n.CodeCorrection.prototype._checkUserRemoval = function(uid) {
var removeUser = true;
for (var i = 0; i < this.annotations.length; i++) {
var comments = this.annotations[i].commentController.exportComments();
for (var ii = 0; ii < comments.length; ii++) {
if(comments[ii].uid === uid) {
removeUser = false;
return false;
}
}
}
if (removeUser) {
for (var iii = 0; iii < this.users.length; iii++) {
if (this.users[iii].uid === uid) {
this.users.splice(i, 1);
}
}
}
return true;
};
n.CodeCorrection.prototype._addCurrentUser = function() {
if (!this.checkUserExists(this.currentUser.uid)) {
this.users.push(this.currentUser);
......
......@@ -36,6 +36,7 @@ var QfqNS = QfqNS || {};
}
this.childrenController = {};
this.eventEmitter = new EventEmitter();
this.deleted = false;
};
n.Comment.prototype.on = n.EventEmitter.onMixin;
......@@ -120,7 +121,10 @@ var QfqNS = QfqNS || {};
n.Comment.prototype._deleteMe = function(e) {
console.log("Delete pressed for:");
console.log(this.comment);
this.deleted = true;
this.$comment.remove();
this.eventEmitter.emitEvent('comment.deleted',
n.EventEmitter.makePayload(this, this.comment));
};
n.Comment.prototype._editMe = function(e) {
......
......@@ -59,7 +59,7 @@ var QfqNS = QfqNS || {};
return true;
} else if (event === "remove") {
this.eventEmitter.emitEvent('comment.removed',
n.EventEmitter.makePayload(this, "remove"));
n.EventEmitter.makePayload(this, comment));
}
console.error("[CommentController] Changehandler called without valid event");
return false;
......@@ -116,6 +116,9 @@ var QfqNS = QfqNS || {};
commentObject.on('comment.reply', function(e) {
that.requestReply(e.data);
});
commentObject.on('comment.deleted', function(e) {
that.removeComment(e);
});
};
n.CommentController.prototype.displayComments = function() {
......@@ -155,7 +158,7 @@ var QfqNS = QfqNS || {};
};
n.CommentController.prototype.removeComment = function(reference) {
this._changeHandler("remove", reference);
};
n.CommentController.prototype.updateComment = function(data) {
......@@ -186,7 +189,9 @@ var QfqNS = QfqNS || {};
n.CommentController.prototype.exportComments = function() {
var comments = [];
for(var i=0; i < this.comments.length; i++) {
comments.push(this.comments[i].comment);
if (!this.comments[i].deleted) {
comments.push(this.comments[i].comment);
}
}
return comments;
};
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment