2020-03-10 17:43:19 +03:00
|
|
|
<template>
|
2022-06-01 10:15:55 +03:00
|
|
|
<div>
|
|
|
|
<vue-editor :id="editorId" v-model="content" :editorToolbar="customToolbar" :disabled="disabled"></vue-editor>
|
2020-03-10 17:43:19 +03:00
|
|
|
</div>
|
|
|
|
</template>
|
2021-01-18 16:20:57 +03:00
|
|
|
|
2020-03-10 17:43:19 +03:00
|
|
|
<script>
|
2022-06-01 10:15:55 +03:00
|
|
|
import { VueEditor } from "vue2-editor";
|
2021-01-27 13:23:22 +03:00
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
export default {
|
2020-03-10 17:43:19 +03:00
|
|
|
name: 'akaunting-html-editor',
|
2021-01-18 16:20:57 +03:00
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
components: {
|
|
|
|
VueEditor
|
|
|
|
},
|
|
|
|
|
2020-03-10 17:43:19 +03:00
|
|
|
props: {
|
2022-06-01 10:15:55 +03:00
|
|
|
name: {
|
|
|
|
type: String,
|
|
|
|
default: '',
|
|
|
|
description: 'The name of the field',
|
|
|
|
},
|
2021-01-18 16:20:57 +03:00
|
|
|
value: {
|
|
|
|
type: String,
|
|
|
|
default: ''
|
|
|
|
},
|
2022-06-01 10:15:55 +03:00
|
|
|
model: {
|
|
|
|
type: [String, Number, Array, Object],
|
|
|
|
default: '',
|
|
|
|
description: "Selectbox selected model"
|
2021-01-18 16:20:57 +03:00
|
|
|
},
|
2022-06-01 10:15:55 +03:00
|
|
|
disabled: {
|
2021-04-07 17:53:54 +03:00
|
|
|
type: Boolean,
|
2022-06-01 10:15:55 +03:00
|
|
|
default: false,
|
|
|
|
description: "Selectbox disabled status"
|
2021-04-07 17:53:54 +03:00
|
|
|
},
|
2020-03-10 17:43:19 +03:00
|
|
|
},
|
2021-01-18 16:20:57 +03:00
|
|
|
|
2020-03-10 17:43:19 +03:00
|
|
|
data () {
|
2021-01-18 16:20:57 +03:00
|
|
|
return {
|
|
|
|
content: null,
|
|
|
|
editorId: null,
|
2022-06-01 10:15:55 +03:00
|
|
|
customToolbar: [
|
|
|
|
["bold", "italic", "underline"],
|
|
|
|
[{ list: "ordered" }, { list: "bullet" }],
|
|
|
|
],
|
2021-01-18 16:20:57 +03:00
|
|
|
}
|
2020-03-10 17:43:19 +03:00
|
|
|
},
|
2021-01-18 16:20:57 +03:00
|
|
|
|
2020-03-10 17:43:19 +03:00
|
|
|
methods: {
|
2021-01-18 16:20:57 +03:00
|
|
|
randomString() {
|
|
|
|
let text = "";
|
|
|
|
let possible = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz";
|
2020-07-28 16:34:45 +03:00
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
for (let i = 0; i < 5; i++) {
|
|
|
|
text += possible.charAt(Math.floor(Math.random() * possible.length));
|
|
|
|
}
|
2020-07-28 16:34:45 +03:00
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
return text;
|
|
|
|
},
|
|
|
|
},
|
2020-07-28 16:34:45 +03:00
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
async mounted () {
|
|
|
|
this.editorId = this.randomString();
|
2020-07-28 16:34:45 +03:00
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
this.content = this.value;
|
2020-03-10 17:43:19 +03:00
|
|
|
},
|
2020-07-28 16:34:45 +03:00
|
|
|
|
2020-03-10 17:43:19 +03:00
|
|
|
watch: {
|
2021-01-18 16:20:57 +03:00
|
|
|
value (newVal) {
|
|
|
|
if (newVal !== this.content) {
|
2022-06-01 10:15:55 +03:00
|
|
|
this.content = newVal;
|
2021-01-18 16:20:57 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2022-06-01 10:15:55 +03:00
|
|
|
model (newVal) {
|
2021-02-02 10:39:28 +03:00
|
|
|
if (newVal !== this.content) {
|
2022-06-01 10:15:55 +03:00
|
|
|
this.content = newVal;
|
2021-02-02 10:39:28 +03:00
|
|
|
}
|
|
|
|
},
|
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
content (newVal) {
|
2022-07-07 12:54:47 +03:00
|
|
|
// #337y1z3 This issue reason <p> tag broken email template
|
|
|
|
newVal = newVal.replace(/(<p[^>]+?>|<p>|<\/p>)/img, "");
|
|
|
|
|
2021-01-18 16:20:57 +03:00
|
|
|
this.$emit('input', newVal);
|
|
|
|
},
|
|
|
|
},
|
|
|
|
}
|
2020-03-10 17:43:19 +03:00
|
|
|
</script>
|