scinote-web/app/javascript/vue/experiments/modals/new.vue

83 lines
2.4 KiB
Vue
Raw Normal View History

2023-12-11 22:41:03 +08:00
<template>
<div ref="modal" class="modal" tabindex="-1" role="dialog">
<div class="modal-dialog" role="document">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-label="Close">
<i class="sn-icon sn-icon-close"></i>
</button>
<h4 class="modal-title truncate !block">
{{ i18n.t('experiments.new.modal_title') }}
</h4>
</div>
<div class="modal-body">
<label class="sci-label">{{ i18n.t('experiments.new.name') }}</label>
<div class="sci-input-container-v2 mb-4">
<input type="text" class="sci-input-field"
v-model="name"
autofocus
:placeholder="i18n.t('experiments.new.name_placeholder')">
</div>
<label class="sci-label">{{ i18n.t('experiments.new.description') }}</label>
<div class="sci-input-container-v2 h-40">
<textarea class="sci-input-field"
ref="description"
v-model="description">
</textarea>
</div>
</div>
<div class="modal-footer">
<button type="button" class="btn btn-secondary" data-dismiss="modal">{{ i18n.t('general.cancel') }}</button>
<button type="button" :disabled="!validName" class="btn btn-primary" @click="submit">
{{ i18n.t('experiments.new.modal_create') }}
</button>
</div>
</div>
</div>
</div>
</template>
<script>
/* global HelperModule SmartAnnotation */
import axios from '../../../packs/custom_axios.js';
import modalMixin from '../../shared/modal_mixin';
export default {
name: 'NewModal',
props: {
createUrl: String,
},
data() {
return {
name: '',
description: '',
};
},
computed: {
validName() {
return this.name.length > 0;
},
},
mounted() {
SmartAnnotation.init($(this.$refs.description), false);
},
mixins: [modalMixin],
methods: {
submit() {
axios.post(this.createUrl, {
experiment: {
name: this.name,
description: this.$refs.description.value,
},
}).then((response) => {
this.$emit('create');
window.location.replace(response.data.path);
}).catch((error) => {
HelperModule.flashAlertMsg(error.response.data.message, 'danger');
});
},
},
};
</script>