gitlab-org--gitlab-foss/app/assets/javascripts/task_list.js.es6

45 lines
1.4 KiB
JavaScript
Raw Normal View History

/* eslint-disable class-methods-use-this, no-new, func-names, prefer-template, no-unneeded-ternary, object-shorthand, space-before-function-paren, comma-dangle, quote-props, consistent-return, no-else-return, no-param-reassign, max-len */
/* global UsersSelect */
require('vendor/task_list');
class TaskList {
constructor(options = {}) {
this.selector = options.selector;
this.dataType = options.dataType;
this.update = options.update || this.update.bind(this);
this.init();
}
init() {
// Prevent duplicate event bindings
this.disable();
2017-02-08 08:10:04 +00:00
$(`${this.selector} .js-task-list-container`).taskList('enable');
$(document).on('tasklist:changed', `${this.selector} .js-task-list-container`, this.update);
}
disable() {
2017-02-08 08:10:04 +00:00
$(`${this.selector} .js-task-list-container`).taskList('disable');
return $(document).off('tasklist:changed', `${this.selector} .js-task-list-container`);
}
update(e) {
2017-02-08 08:10:04 +00:00
const patchData = {};
patchData[this.dataType] = {
2017-02-08 08:10:04 +00:00
description: $(e.target).val(),
};
return $.ajax({
type: 'PATCH',
url: $('form.js-issuable-update').attr('action'),
data: patchData,
2017-02-08 08:10:04 +00:00
success: (result) => {
document.querySelector('#task_status').innerText = result.task_status;
document.querySelector('#task_status_short').innerText = result.task_status_short;
2017-02-08 08:10:04 +00:00
},
});
}
}
window.gl = window.gl || {};
window.gl.TaskList = TaskList;