Commit 507b15e7 authored by Filipa Lacerda's avatar Filipa Lacerda

[ci skip] Enable submit button on paste

Reset form after response is submitted
parent 9e4164d4
...@@ -2,6 +2,7 @@ ...@@ -2,6 +2,7 @@
/* global Flash, Autosave */ /* global Flash, Autosave */
import { mapActions, mapGetters } from 'vuex'; import { mapActions, mapGetters } from 'vuex';
import _ from 'underscore';
import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue'; import userAvatarLink from '../../vue_shared/components/user_avatar/user_avatar_link.vue';
import markdownField from '../../vue_shared/components/markdown/field.vue'; import markdownField from '../../vue_shared/components/markdown/field.vue';
import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue'; import issueNoteSignedOutWidget from './issue_note_signed_out_widget.vue';
...@@ -11,19 +12,14 @@ ...@@ -11,19 +12,14 @@
export default { export default {
data() { data() {
const { getUserData, getIssueData, getNotesData } = this.$store.getters;
return { return {
note: '', note: '',
markdownDocsUrl: getNotesData.markdownDocs,
quickActionsDocsUrl: getNotesData.quickActionsDocs,
markdownPreviewUrl: getIssueData.preview_note_path,
noteType: constants.COMMENT, noteType: constants.COMMENT,
issueState: getIssueData.state, // Can't use mapGetters,
endpoint: getIssueData.create_note_path, // this needs to be in the data object because it belongs to the state
author: getUserData, issueState: this.$store.getters.getIssueData.state,
canUpdateIssue: getIssueData.current_user.can_update,
isSubmitting: false, isSubmitting: false,
isSubmitButtonDisabled: true,
}; };
}, },
components: { components: {
...@@ -31,11 +27,28 @@ ...@@ -31,11 +27,28 @@
markdownField, markdownField,
issueNoteSignedOutWidget, issueNoteSignedOutWidget,
}, },
watch: {
note(newNote) {
if (!_.isEmpty(newNote) && !this.isSubmitting) {
this.isSubmitButtonDisabled = false;
} else {
this.isSubmitButtonDisabled = true;
}
},
isSubmitting(newValue) {
if (!_.isEmpty(this.note) && !newValue) {
this.isSubmitButtonDisabled = false;
} else {
this.isSubmitButtonDisabled = true;
}
},
},
computed: { computed: {
...mapGetters([ ...mapGetters([
'getCurrentUserLastNote', 'getCurrentUserLastNote',
'getUserData', 'getUserData',
'getIssueData', 'getIssueData',
'getNotesData',
]), ]),
isLoggedIn() { isLoggedIn() {
return this.getUserData !== null; return this.getUserData !== null;
...@@ -63,8 +76,23 @@ ...@@ -63,8 +76,23 @@
'js-note-target-reopen': !this.isIssueOpen, 'js-note-target-reopen': !this.isIssueOpen,
}; };
}, },
canSubmit() { markdownDocsUrl() {
return !this.note.length || this.isSubmitting; return this.getNotesData.markdownDocs;
},
quickActionsDocsUrl() {
return this.getNotesData.quickActionsDocs;
},
markdownPreviewUrl() {
return this.getIssueData.preview_note_path;
},
author() {
return this.getUserData;
},
canUpdateIssue() {
return this.getIssueData.current_user.can_update;
},
endpoint() {
return this.getIssueData.create_note_path;
}, },
}, },
methods: { methods: {
...@@ -139,6 +167,9 @@ ...@@ -139,6 +167,9 @@
if (shouldClear) { if (shouldClear) {
this.note = ''; this.note = '';
} }
// reset autostave
this.autosave.reset();
}, },
setNoteType(type) { setNoteType(type) {
this.noteType = type; this.noteType = type;
...@@ -155,7 +186,7 @@ ...@@ -155,7 +186,7 @@
} }
}, },
initAutoSave() { initAutoSave() {
return new Autosave($(this.$refs.textarea), ['Note', 'Issue', this.getIssueData.id]); this.autosave = new Autosave($(this.$refs.textarea), ['Note', 'Issue', this.getIssueData.id]);
}, },
}, },
mounted() { mounted() {
...@@ -212,13 +243,13 @@ ...@@ -212,13 +243,13 @@
<div class="pull-left btn-group append-right-10 comment-type-dropdown js-comment-type-dropdown droplab-dropdown"> <div class="pull-left btn-group append-right-10 comment-type-dropdown js-comment-type-dropdown droplab-dropdown">
<button <button
@click="handleSave()" @click="handleSave()"
:disabled="canSubmit" :disabled="isSubmitButtonDisabled"
class="btn btn-nr btn-create comment-btn js-comment-button js-comment-submit-button" class="btn btn-nr btn-create comment-btn js-comment-button js-comment-submit-button"
type="button"> type="button">
{{commentButtonTitle}} {{commentButtonTitle}}
</button> </button>
<button <button
:disabled="canSubmit" :disabled="isSubmitButtonDisabled"
name="button" name="button"
type="button" type="button"
class="btn btn-nr comment-btn note-type-toggle js-note-new-discussion dropdown-toggle" class="btn btn-nr comment-btn note-type-toggle js-note-new-discussion dropdown-toggle"
......
...@@ -79,10 +79,8 @@ ...@@ -79,10 +79,8 @@
}, },
cancelReplyForm(shouldConfirm) { cancelReplyForm(shouldConfirm) {
if (shouldConfirm && this.$refs.noteForm.isDirty) { if (shouldConfirm && this.$refs.noteForm.isDirty) {
const msg = 'Are you sure you want to cancel creating this comment?';
// eslint-disable-next-line no-alert // eslint-disable-next-line no-alert
const isConfirmed = confirm(msg); if (!confirm('Are you sure you want to cancel creating this comment?')) {
if (!isConfirmed) {
return; return;
} }
} }
......
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