Skip to content
Snippets Groups Projects
Commit a292f669 authored by bbaer's avatar bbaer
Browse files

View Only codecorrection

parent 3d6ef9e4
No related branches found
No related tags found
1 merge request!128View Only codecorrection
Pipeline #1585 passed
......@@ -42,6 +42,7 @@ var QfqNS = QfqNS || {};
this.users = [];
this.currentUser = {};
this.language = "";
this.readOnly = false;
this.syntaxHighlight = {};
};
......@@ -58,22 +59,28 @@ var QfqNS = QfqNS || {};
};
this.page = page;
this.language = this.$parent.data("highlight") || "typo3conf/ext/qfq/Resources/Public/Json/javascript.json";
this.readOnly = this.$parent.data("view-only") || false;
this.currentUser = $container.data("uid");
var that = this;
if (this.$target.val()) {
var jImport = $.parseJSON(this.$target.val());
if (jImport.annotations) {
this.annotations = jImport.annotations;
console.log("[CodeCorrection] Imported Annotations: " + this.annotations.length);
}
if (jImport.users) {
this.users = jImport.users;
console.log("[CodeCorrection] Imported Users: " + this.users.length);
if (this.readOnly) {
var jsonAnnotations = this.$parent.data("annotations");
this.annotations = jsonAnnotations.annotations;
this.users = jsonAnnotations.users;
} else {
if (this.$target.val()) {
var jImport = $.parseJSON(this.$target.val());
if (jImport.annotations) {
this.annotations = jImport.annotations;
console.log("[CodeCorrection] Imported Annotations: " + this.annotations.length);
}
if (jImport.users) {
this.users = jImport.users;
console.log("[CodeCorrection] Imported Users: " + this.users.length);
}
}
}
if (this.data.url) {
// Get data of a file and write it to data.text
$.get(this.data.url, function(response) {
......@@ -206,8 +213,11 @@ var QfqNS = QfqNS || {};
* @private
*/
n.CodeCorrection.prototype._buildCommentContainer = function($hook) {
var options = {
readOnly: this.readOnly
};
var commentController = new n.CommentController();
commentController.buildContainer($hook);
commentController.buildContainer($hook, options);
commentController.setCurrentUser(this.currentUser);
return commentController;
};
......@@ -350,13 +360,15 @@ var QfqNS = QfqNS || {};
comments.commentController.toggle();
comments.commentController.emitEvent("new");
} else {
comments.lineNumber = lineCount;
comments.commentController = new n.CommentController();
comments.commentController.buildContainer($hook);
comments.commentController.setCurrentUser(this.currentUser);
comments.commentController.displayEditor();
this._setListeners(comments.commentController);
this.annotations.push(comments);
if (!this.readOnly) {
comments.lineNumber = lineCount;
comments.commentController = new n.CommentController();
comments.commentController.buildContainer($hook, {readOnly: this.readOnly});
comments.commentController.setCurrentUser(this.currentUser);
comments.commentController.displayEditor();
this._setListeners(comments.commentController);
this.annotations.push(comments);
}
}
};
......
......@@ -30,7 +30,7 @@ var QfqNS = QfqNS || {};
this.$comment = {};
this.$text = {};
if (arguments.length === 3) {
this.options = { readonly: false };
this.options = { readOnly: false };
} else {
this.options = options;
}
......@@ -81,7 +81,9 @@ var QfqNS = QfqNS || {};
class: "qfqCommentText"
});
$comment.html(this.comment.comment);
$comment.append(this._getCommands());
if (!this.options.readOnly) {
$comment.append(this._getCommands());
}
this.$text= $comment;
$comment.appendTo($commentWrap);
return $commentWrap;
......
......@@ -28,6 +28,7 @@ var QfqNS = QfqNS || {};
this.$container = {};
this.$parent = {};
this.height = "auto";
this.options = {};
// Event Emitter is a Library qfq uses to emit custom Events.
this.eventEmitter = new EventEmitter();
};
......@@ -69,10 +70,11 @@ var QfqNS = QfqNS || {};
this._changeHandler(event);
};
n.CommentController.prototype.buildContainer = function($hook) {
n.CommentController.prototype.buildContainer = function($hook, options) {
var $container = $("<div />", {
class: "qfqCommentContainer"
});
this.options = options;
$hook.after($container);
this.$container = $container;
};
......@@ -99,7 +101,7 @@ var QfqNS = QfqNS || {};
};
n.CommentController.prototype.addComment = function(comment, user) {
var commentObject = new n.Comment(comment, user, this.$container);
var commentObject = new n.Comment(comment, user, this.$container, this.options);
commentObject.display();
this.comments.push(commentObject);
this._changeHandler("new", commentObject);
......@@ -129,14 +131,16 @@ var QfqNS = QfqNS || {};
};
n.CommentController.prototype.displayEditor = function() {
var editor = new n.Editor();
var that = this;
var $editor = editor.buildEditor();
editor.on("editor.submit", function(editor) {
that._handleEditorSubmit(editor);
});
$editor.appendTo(this.$container);
editor.$textArea.focus();
if (!this.options.readOnly) {
var editor = new n.Editor();
var that = this;
var $editor = editor.buildEditor();
editor.on("editor.submit", function (editor) {
that._handleEditorSubmit(editor);
});
$editor.appendTo(this.$container);
editor.$textArea.focus();
}
};
n.CommentController.prototype._handleEditorSubmit = function(editor) {
......
......@@ -121,6 +121,7 @@ var QfqNS = QfqNS || {};
$.post(submitUrl, this.$form.serialize())
.done(this.ajaxSuccessHandler.bind(this))
.fail(this.submitFailureHandler.bind(this));
console.log(this.$form.serialize());
};
n.Form.prototype.serialize = function () {
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment