Commit 0143573d authored by Fatih Acet's avatar Fatih Acet

Separate edit form in Changes and Discussions tab.

if we are in the Merge Requests page, this change will clone existing note-edit-form and add a mr-discussion-edit-form class to cloned element so we will have two note-edit-form in place. One for Discussions tab one for Changes tab.

For MR page, we basically need two note-edit-form because you may want to edit your comment in both tabs at the same time and we shouldn't remove or discard note-edit-form in other tab.
parent 2193ccec
...@@ -106,8 +106,9 @@ ...@@ -106,8 +106,9 @@
); );
}; };
gl.utils.getPagePath = function() { gl.utils.getPagePath = function(index) {
return $('body').data('page').split(':')[0]; index = index || 0;
return $('body').data('page').split(':')[index];
}; };
gl.utils.parseUrl = function (url) { gl.utils.parseUrl = function (url) {
......
...@@ -52,6 +52,12 @@ ...@@ -52,6 +52,12 @@
this.setupMainTargetNoteForm(); this.setupMainTargetNoteForm();
this.initTaskList(); this.initTaskList();
this.collapseLongCommitList(); this.collapseLongCommitList();
// We are in the Merge Requests page so we need another edit form for Changes tab
if (gl.utils.getPagePath(1) === 'merge_requests') {
$('.note-edit-form').clone()
.addClass('mr-discussion-edit-form').insertAfter('.note-edit-form');
}
} }
Notes.prototype.addBinding = function() { Notes.prototype.addBinding = function() {
...@@ -518,9 +524,9 @@ ...@@ -518,9 +524,9 @@
e.preventDefault(); e.preventDefault();
var $target = $(e.target); var $target = $(e.target);
var $editForm = $('.note-edit-form'); var $editForm = $(this.getEditFormSelector($target));
var $note = $target.closest('.note'); var $note = $target.closest('.note');
var $currentlyEditing = $('.note.is-editting'); var $currentlyEditing = $('.note.is-editting:visible');
if ($currentlyEditing.length) { if ($currentlyEditing.length) {
var isEditAllowed = this.checkContentToAllowEditing($currentlyEditing); var isEditAllowed = this.checkContentToAllowEditing($currentlyEditing);
...@@ -545,20 +551,32 @@ ...@@ -545,20 +551,32 @@
Notes.prototype.cancelEdit = function(e) { Notes.prototype.cancelEdit = function(e) {
e.preventDefault(); e.preventDefault();
var note = $(e.target).closest('.note'); var $target = $(e.target);
var note = $target.closest('.note');
note.find('.js-edit-warning').hide(); note.find('.js-edit-warning').hide();
note.find('.js-md-write-button').trigger('click'); note.find('.js-md-write-button').trigger('click');
this.revertNoteEditForm(); this.revertNoteEditForm($target);
return this.removeNoteEditForm(note); return this.removeNoteEditForm(note);
}; };
Notes.prototype.revertNoteEditForm = function() { Notes.prototype.revertNoteEditForm = function($target) {
var $editForm = $('.note-edit-form'); $target = $target || $('.note.is-editting:visible');
var selector = this.getEditFormSelector($target);
var $editForm = $(selector);
$editForm.insertBefore('.notes-form'); $editForm.insertBefore('.notes-form');
$editForm.find('.js-comment-button').enable(); $editForm.find('.js-comment-button').enable();
};
Notes.prototype.getEditFormSelector = function($el) {
var selector = '.note-edit-form:not(.mr-discussion-edit-form)';
if ($el.parents('#diffs').length) {
selector = '.note-edit-form.mr-discussion-edit-form';
} }
return selector;
};
Notes.prototype.removeNoteEditForm = function(note) { Notes.prototype.removeNoteEditForm = function(note) {
var form = note.find(".current-note-edit-form"); var form = note.find(".current-note-edit-form");
...@@ -866,7 +884,8 @@ ...@@ -866,7 +884,8 @@
}; };
Notes.prototype.putEditFormInPlace = function($el) { Notes.prototype.putEditFormInPlace = function($el) {
var $editForm = $('.note-edit-form');
var $editForm = $(this.getEditFormSelector($el));
var $note = $el.closest('.note'); var $note = $el.closest('.note');
$editForm.insertAfter($note.find('.note-text')); $editForm.insertAfter($note.find('.note-text'));
...@@ -886,8 +905,9 @@ ...@@ -886,8 +905,9 @@
} }
Notes.prototype.updateTaskList = function(e) { Notes.prototype.updateTaskList = function(e) {
var $list = $(e.target).closest('.js-task-list-container'); var $target = $(e.target);
var $editForm = $('.note-edit-form'); var $list = $target.closest('.js-task-list-container');
var $editForm = $(this.getEditFormSelector($target));
var $note = $list.closest('.note'); var $note = $list.closest('.note');
this.putEditFormInPlace($list); this.putEditFormInPlace($list);
......
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