Commit 766d011b authored by Simon Knox's avatar Simon Knox

notes use new task_list, and PATCH instead of POST

use data attribute for submit url
optional onSuccess
parent d3e34cd1
Pipeline #6355993 failed with stages
in 79 minutes and 31 seconds
......@@ -14,7 +14,11 @@ require('./task_list');
if ($('a.btn-close').length) {
this.taskList = new gl.TaskList({
dataType: 'issue',
selector: '.detail-page-description'
selector: '.detail-page-description',
onSuccess: (result) => {
document.querySelector('#task_status').innerText = result.task_status;
document.querySelector('#task_status_short').innerText = result.task_status_short;
}
});
this.initIssueBtnEventListeners();
}
......
......@@ -29,7 +29,11 @@ require('./merge_request_tabs');
if ($("a.btn-close").length) {
this.taskList = new gl.TaskList({
dataType: 'merge_request',
selector: '.detail-page-description'
selector: '.detail-page-description',
onSuccess: (result) => {
document.querySelector('#task_status').innerText = result.task_status;
document.querySelector('#task_status_short').innerText = result.task_status_short;
}
});
}
}
......
......@@ -53,8 +53,7 @@ require('./task_list');
this.setupMainTargetNoteForm();
this.taskList = new gl.TaskList({
dataType: 'note',
selector: '.notes',
update: this.updateTaskList.bind(this)
selector: '.notes'
});
this.collapseLongCommitList();
......@@ -889,17 +888,6 @@ require('./task_list');
$editForm.find('.referenced-users').hide();
};
Notes.prototype.updateTaskList = function(e) {
var $target = $(e.target);
var $list = $target.closest('.js-task-list-container');
var $editForm = $(this.getEditFormSelector($target));
var $note = $list.closest('.note');
this.putEditFormInPlace($list);
$editForm.find('#note_note').val($note.find('.original-task-list').val());
$('form', $list).submit();
};
Notes.prototype.updateNotesCount = function(updateCount) {
return this.notesCountBadge.text(parseInt(this.notesCountBadge.text(), 10) + updateCount);
};
......
......@@ -7,7 +7,7 @@ class TaskList {
constructor(options = {}) {
this.selector = options.selector;
this.dataType = options.dataType;
this.update = options.update || this.update.bind(this);
this.onSuccess = options.onSuccess || () => null;
this.init();
}
......@@ -15,7 +15,7 @@ class TaskList {
// Prevent duplicate event bindings
this.disable();
$(`${this.selector} .js-task-list-container`).taskList('enable');
$(document).on('tasklist:changed', `${this.selector} .js-task-list-container`, this.update);
$(document).on('tasklist:changed', `${this.selector} .js-task-list-container`, this.update.bind(this));
}
disable() {
......@@ -24,18 +24,16 @@ class TaskList {
}
update(e) {
const $target = $(e.target);
const patchData = {};
patchData[this.dataType] = {
description: $(e.target).val(),
description: $target.val(),
};
return $.ajax({
type: 'PATCH',
url: $('form.js-issuable-update').attr('action'),
url: $target.data('update-url') || $('form.js-issuable-update').attr('action'),
data: patchData,
success: (result) => {
document.querySelector('#task_status').innerText = result.task_status;
document.querySelector('#task_status_short').innerText = result.task_status_short;
},
success: this.onSuccess,
});
}
}
......
......@@ -69,7 +69,7 @@
- if note_editable
.original-note-content.hidden{ data: { post_url: namespace_project_note_path(@project.namespace, @project, note), target_id: note.noteable.id, target_type: note.noteable.class.name.underscore } }
#{note.note}
%textarea.hidden.js-task-list-field.original-task-list= note.note
%textarea.hidden.js-task-list-field.original-task-list{ data: {update_url: namespace_project_note_path(@project.namespace, @project, note) } }= note.note
.note-awards
= render 'award_emoji/awards_block', awardable: note, inline: false
- if note.system
......
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