diff options
author | Filipa Lacerda <filipa@gitlab.com> | 2017-08-13 12:02:31 +0100 |
---|---|---|
committer | Filipa Lacerda <filipa@gitlab.com> | 2017-08-13 12:02:31 +0100 |
commit | fdfab012f0b87e3e8c3689a1f7a4fa731f330a67 (patch) | |
tree | 870efd86a85f847173136a5d8ca55115c833556d | |
parent | c9ac28faaa52062055250fc09fed94a94ebd13c2 (diff) | |
download | gitlab-ce-fdfab012f0b87e3e8c3689a1f7a4fa731f330a67.tar.gz |
Fixes autosave not enabling comment button when it is restored.
Adds back missing CSS class that was breaking tests
-rw-r--r-- | app/assets/javascripts/autosave.js | 21 | ||||
-rw-r--r-- | app/assets/javascripts/notes/components/issue_comment_form.vue | 8 | ||||
-rw-r--r-- | app/assets/javascripts/notes/mixins/autosave.js | 2 | ||||
-rw-r--r-- | app/assets/javascripts/notes/stores/getters.js | 2 | ||||
-rw-r--r-- | app/assets/stylesheets/pages/note_form.scss | 4 |
5 files changed, 20 insertions, 17 deletions
diff --git a/app/assets/javascripts/autosave.js b/app/assets/javascripts/autosave.js index cfab6c40b34..7db696159bc 100644 --- a/app/assets/javascripts/autosave.js +++ b/app/assets/javascripts/autosave.js @@ -2,17 +2,17 @@ import AccessorUtilities from './lib/utils/accessor'; window.Autosave = (function() { - function Autosave(field, key) { + function Autosave(field, key, resource) { this.field = field; this.isLocalStorageAvailable = AccessorUtilities.isLocalStorageAccessSafe(); - + this.resource = resource; if (key.join != null) { - key = key.join("/"); + key = key.join('/'); } - this.key = "autosave/" + key; - this.field.data("autosave", this); + this.key = 'autosave/' + key; + this.field.data('autosave', this); this.restore(); - this.field.on("input", (function(_this) { + this.field.on('input', (function(_this) { return function() { return _this.save(); }; @@ -29,7 +29,14 @@ window.Autosave = (function() { if ((text != null ? text.length : void 0) > 0) { this.field.val(text); } - return this.field.trigger("input"); + if (!this.resource && this.resource !== 'issue') { + this.field.trigger('input'); + } else { + // v-model does not update with jQuery trigger + // https://github.com/vuejs/vue/issues/2804#issuecomment-216968137 + const event = new Event('change', { bubbles: true, cancelable: false }); + this.field.get(0).dispatchEvent(event); + } }; Autosave.prototype.save = function() { diff --git a/app/assets/javascripts/notes/components/issue_comment_form.vue b/app/assets/javascripts/notes/components/issue_comment_form.vue index d3fe70a2bac..259644b13a4 100644 --- a/app/assets/javascripts/notes/components/issue_comment_form.vue +++ b/app/assets/javascripts/notes/components/issue_comment_form.vue @@ -184,7 +184,7 @@ } }, initAutoSave() { - this.autosave = new Autosave($(this.$refs.textarea), ['Note', 'Issue', this.getIssueData.id]); + this.autosave = new Autosave($(this.$refs.textarea), ['Note', 'Issue', this.getIssueData.id], 'issue'); }, initTaskList() { return new TaskList({ @@ -211,7 +211,7 @@ <issue-note-signed-out-widget v-if="!isLoggedIn" /> <ul v-else - class="notes notes-form timeline new-note"> + class="notes notes-form timeline"> <li class="timeline-entry"> <div class="timeline-entry-inner"> <div class="timeline-icon hidden-xs hidden-sm"> @@ -223,10 +223,10 @@ :img-size="40" /> </div> - <div > + <div class="timeline-content timeline-content-form"> <form ref="commentForm" - class="js-main-target-form timeline-content timeline-content-form common-note-form"> + class="new-note js-quick-submit common-note-form gfm-form js-main-target-form"> <div class="flash-container timeline-content"></div> <confidentialIssue v-if="isConfidentialIssue" /> <markdown-field diff --git a/app/assets/javascripts/notes/mixins/autosave.js b/app/assets/javascripts/notes/mixins/autosave.js index 8723395cf56..5843b97f225 100644 --- a/app/assets/javascripts/notes/mixins/autosave.js +++ b/app/assets/javascripts/notes/mixins/autosave.js @@ -4,7 +4,7 @@ import '../../autosave'; export default { methods: { initAutoSave() { - this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), ['Note', 'Issue', this.note.id]); + this.autosave = new Autosave($(this.$refs.noteForm.$refs.textarea), ['Note', 'Issue', this.note.id], 'issue'); }, resetAutoSave() { this.autosave.reset(); diff --git a/app/assets/javascripts/notes/stores/getters.js b/app/assets/javascripts/notes/stores/getters.js index ec3f9e5b7a0..669728f0c20 100644 --- a/app/assets/javascripts/notes/stores/getters.js +++ b/app/assets/javascripts/notes/stores/getters.js @@ -19,7 +19,7 @@ export const notesById = state => state.notes.reduce((acc, note) => { const reverseNotes = array => array.slice(0).reverse(); const isLastNote = (note, state) => !note.system && - state.userData && + state.userData !== undefined && note.author.id === state.userData.id; export const getCurrentUserLastNote = state => _.flatten( diff --git a/app/assets/stylesheets/pages/note_form.scss b/app/assets/stylesheets/pages/note_form.scss index b4468d6d0a2..3123e367b2c 100644 --- a/app/assets/stylesheets/pages/note_form.scss +++ b/app/assets/stylesheets/pages/note_form.scss @@ -20,10 +20,6 @@ } } -.new-note { - display: none; -} - .new-note, .note-edit-form { .note-form-actions { |