Prevent double saving on entity creation

This commit is contained in:
Ramon Wenger 2019-05-08 14:42:58 +02:00
parent 2a6d2fe693
commit bd1286abba
3 changed files with 21 additions and 7 deletions

View File

@ -55,7 +55,7 @@
</div>
<div slot="footer">
<a class="button button--primary" data-cy="modal-save-button" v-on:click="save">Speichern</a>
<a class="button button--primary" data-cy="modal-save-button" :class="{'button--disabled': disableSave}" v-on:click="save">Speichern</a>
<a class="button" v-on:click="$emit('hide')">Abbrechen</a>
</div>
</modal>
@ -85,6 +85,10 @@
'show-task-selection': {
type: Boolean,
default: false
},
'disable-save': {
type: Boolean,
default: false
}
},
@ -237,11 +241,13 @@
this.localContentBlock.contents.splice(index, 1, el);
},
save() {
if (!this.localContentBlock.title) {
this.error = true;
return false;
if (!this.disableSave) {
if (!this.localContentBlock.title) {
this.error = true;
return false;
}
this.$emit('save', this.localContentBlock);
}
this.$emit('save', this.localContentBlock);
},
setContentBlockType(checked, localContentBlock) {
this.localContentBlock.isAssignment = checked;

View File

@ -4,6 +4,7 @@
:show-task-selection="true"
@save="saveContentBlock"
@hide="hideModal"
:disable-save="saving"
></contents-form>
</template>
@ -25,6 +26,7 @@
this.$store.dispatch('hideModal');
},
saveContentBlock(contentBlock) {
this.saving = true;
this.$apollo.mutate({
mutation: NEW_CONTENT_BLOCK_MUTATION,
variables: {
@ -45,6 +47,7 @@
}
}]
}).then(() => {
this.saving = false;
this.hideModal();
});
}
@ -57,7 +60,8 @@
contents: [
{}
]
}
},
saving: false
}
}
}

View File

@ -4,6 +4,7 @@
:show-task-selection="false"
@save="saveEntry"
block-type="RoomEntry"
:disable-save="saving"
@hide="hideModal"
></contents-form>
</template>
@ -24,7 +25,8 @@
entry: {
title: '',
contents: []
}
},
saving: false
}
},
@ -36,6 +38,7 @@
methods: {
saveEntry(entry) {
this.saving = true;
this.$apollo.mutate({
mutation: NEW_ROOM_ENTRY_MUTATION,
variables: {
@ -62,6 +65,7 @@
}
}
}).then(() => {
this.saving = false;
this.hideModal();
});
},