From 97ecae00a6a64dadadf60ec6706944f6c9e98de7 Mon Sep 17 00:00:00 2001 From: Simon Knox Date: Wed, 8 Feb 2017 17:04:00 +1100 Subject: [PATCH] switch notes to use task_list, but keep its update function for now --- app/assets/javascripts/notes.js | 21 +++++++-------------- app/assets/javascripts/task_list.js.es6 | 12 +++++++----- 2 files changed, 14 insertions(+), 19 deletions(-) diff --git a/app/assets/javascripts/notes.js b/app/assets/javascripts/notes.js index d108da29af7..d137e327f0e 100644 --- a/app/assets/javascripts/notes.js +++ b/app/assets/javascripts/notes.js @@ -11,7 +11,7 @@ require('./dropzone_input'); require('./gfm_auto_complete'); require('vendor/jquery.caret'); // required by jquery.atwho require('vendor/jquery.atwho'); -require('vendor/task_list'); +require('./task_list'); (function() { var bind = function(fn, me) { return function() { return fn.apply(me, arguments); }; }; @@ -51,7 +51,11 @@ require('vendor/task_list'); this.addBinding(); this.setPollingInterval(); this.setupMainTargetNoteForm(); - this.initTaskList(); + this.taskList = new gl.TaskList({ + dataType: 'note', + selector: '.notes', + update: this.updateTaskList.bind(this) + }); this.collapseLongCommitList(); // We are in the Merge Requests page so we need another edit form for Changes tab @@ -125,8 +129,6 @@ require('vendor/task_list'); $(document).off("keydown", ".js-note-text"); $(document).off('click', '.js-comment-resolve-button'); $(document).off("click", '.system-note-commit-list-toggler'); - $('.note .js-task-list-container').taskList('disable'); - return $(document).off('tasklist:changed', '.note .js-task-list-container'); }; Notes.prototype.keydownNoteText = function(e) { @@ -286,7 +288,7 @@ require('vendor/task_list'); // Update datetime format on the recent note gl.utils.localTimeAgo($notesList.find("#note_" + note.id + " .js-timeago"), false); this.collapseLongCommitList(); - this.initTaskList(); + this.taskList.init(); this.refresh(); return this.updateNotesCount(1); } @@ -863,15 +865,6 @@ require('vendor/task_list'); } }; - Notes.prototype.initTaskList = function() { - this.enableTaskList(); - return $(document).on('tasklist:changed', '.note .js-task-list-container', this.updateTaskList.bind(this)); - }; - - Notes.prototype.enableTaskList = function() { - return $('.note .js-task-list-container').taskList('enable'); - }; - Notes.prototype.putEditFormInPlace = function($el) { var $editForm = $(this.getEditFormSelector($el)); var $note = $el.closest('.note'); diff --git a/app/assets/javascripts/task_list.js.es6 b/app/assets/javascripts/task_list.js.es6 index e207bb1d97e..daed051c4a5 100644 --- a/app/assets/javascripts/task_list.js.es6 +++ b/app/assets/javascripts/task_list.js.es6 @@ -1,17 +1,21 @@ +/* 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; - // Prevent duplicate event bindings - this.disable(); + this.update = options.update || this.update.bind(this); this.init(); } init() { + // 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.bind(this)); + $(document).on('tasklist:changed', this.selector + ' .js-task-list-container', this.update); } disable() { @@ -34,8 +38,6 @@ class TaskList { document.querySelector('#task_status_short').innerText = result.task_status_short; } }); - // TODO (rspeicher): Make the issue description inline-editable like a note so - // that we can re-use its form here } }