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
...@@ -14,7 +14,11 @@ require('./task_list'); ...@@ -14,7 +14,11 @@ require('./task_list');
if ($('a.btn-close').length) { if ($('a.btn-close').length) {
this.taskList = new gl.TaskList({ this.taskList = new gl.TaskList({
dataType: 'issue', 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(); this.initIssueBtnEventListeners();
} }
......
...@@ -29,7 +29,11 @@ require('./merge_request_tabs'); ...@@ -29,7 +29,11 @@ require('./merge_request_tabs');
if ($("a.btn-close").length) { if ($("a.btn-close").length) {
this.taskList = new gl.TaskList({ this.taskList = new gl.TaskList({
dataType: 'merge_request', 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'); ...@@ -53,8 +53,7 @@ require('./task_list');
this.setupMainTargetNoteForm(); this.setupMainTargetNoteForm();
this.taskList = new gl.TaskList({ this.taskList = new gl.TaskList({
dataType: 'note', dataType: 'note',
selector: '.notes', selector: '.notes'
update: this.updateTaskList.bind(this)
}); });
this.collapseLongCommitList(); this.collapseLongCommitList();
...@@ -889,17 +888,6 @@ require('./task_list'); ...@@ -889,17 +888,6 @@ require('./task_list');
$editForm.find('.referenced-users').hide(); $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) { Notes.prototype.updateNotesCount = function(updateCount) {
return this.notesCountBadge.text(parseInt(this.notesCountBadge.text(), 10) + updateCount); return this.notesCountBadge.text(parseInt(this.notesCountBadge.text(), 10) + updateCount);
}; };
......
...@@ -7,7 +7,7 @@ class TaskList { ...@@ -7,7 +7,7 @@ class TaskList {
constructor(options = {}) { constructor(options = {}) {
this.selector = options.selector; this.selector = options.selector;
this.dataType = options.dataType; this.dataType = options.dataType;
this.update = options.update || this.update.bind(this); this.onSuccess = options.onSuccess || () => null;
this.init(); this.init();
} }
...@@ -15,7 +15,7 @@ class TaskList { ...@@ -15,7 +15,7 @@ class TaskList {
// Prevent duplicate event bindings // Prevent duplicate event bindings
this.disable(); this.disable();
$(`${this.selector} .js-task-list-container`).taskList('enable'); $(`${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() { disable() {
...@@ -24,18 +24,16 @@ class TaskList { ...@@ -24,18 +24,16 @@ class TaskList {
} }
update(e) { update(e) {
const $target = $(e.target);
const patchData = {}; const patchData = {};
patchData[this.dataType] = { patchData[this.dataType] = {
description: $(e.target).val(), description: $target.val(),
}; };
return $.ajax({ return $.ajax({
type: 'PATCH', type: 'PATCH',
url: $('form.js-issuable-update').attr('action'), url: $target.data('update-url') || $('form.js-issuable-update').attr('action'),
data: patchData, data: patchData,
success: (result) => { success: this.onSuccess,
document.querySelector('#task_status').innerText = result.task_status;
document.querySelector('#task_status_short').innerText = result.task_status_short;
},
}); });
} }
} }
......
...@@ -69,7 +69,7 @@ ...@@ -69,7 +69,7 @@
- if note_editable - 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 } } .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} #{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 .note-awards
= render 'award_emoji/awards_block', awardable: note, inline: false = render 'award_emoji/awards_block', awardable: note, inline: false
- if note.system - 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