mirror of
https://gitlab.com/Chill-Projet/chill-bundles.git
synced 2025-06-07 18:44:08 +00:00
Revert backend to original state and load commentEditor vue app anytime CommentType form field is used
This commit is contained in:
parent
7d78512823
commit
a6eb28175a
@ -84,16 +84,6 @@
|
|||||||
{{ form_row(form.comment) }}
|
{{ form_row(form.comment) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
|
||||||
<div class="comment-container">
|
|
||||||
<label class="col-form-label col-sm-4" for="comment-widget-1">{{ 'comment_public'|trans }}</label>
|
|
||||||
<div id="comment-widget-1" data-fieldname="chill_activitybundle_activity[comment]"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
<div class="comment-container">
|
|
||||||
<label class="col-form-label col-sm-4" for="comment-widget-2">{{ 'comment_private'|trans }}</label>
|
|
||||||
<div id="comment-widget-2" data-fieldname="chill_activitybundle_activity[privateComment]"></div>
|
|
||||||
</div>
|
|
||||||
|
|
||||||
{%- if form.privateComment is defined -%}
|
{%- if form.privateComment is defined -%}
|
||||||
{{ form_row(form.privateComment) }}
|
{{ form_row(form.privateComment) }}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
@ -3,12 +3,20 @@
|
|||||||
}
|
}
|
||||||
|
|
||||||
.toggle-button {
|
.toggle-button {
|
||||||
|
background-color: white;
|
||||||
|
font-size: .8rem;
|
||||||
|
text-decoration: none;
|
||||||
position: absolute;
|
position: absolute;
|
||||||
bottom: -10px;
|
bottom: -10px;
|
||||||
left: 10px;
|
left: 20px;
|
||||||
padding: 2px 6px;
|
padding: 2px 6px;
|
||||||
cursor: pointer;
|
cursor: pointer;
|
||||||
z-index: 10;
|
z-index: 10;
|
||||||
|
transition: left 0.1s ease-in-out;
|
||||||
|
}
|
||||||
|
|
||||||
|
.rich-editor-active .toggle-button {
|
||||||
|
bottom: 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-wrapper textarea {
|
.editor-wrapper textarea {
|
||||||
@ -20,7 +28,6 @@
|
|||||||
position: relative;
|
position: relative;
|
||||||
display: flex;
|
display: flex;
|
||||||
flex-direction: column;
|
flex-direction: column;
|
||||||
width: 100%;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
.editor-wrapper {
|
.editor-wrapper {
|
||||||
|
@ -1,13 +1,23 @@
|
|||||||
import config from "./editor_config";
|
import App from "../../vuejs/CommentEditor/App.vue"
|
||||||
import {ClassicEditor} from "ckeditor5";
|
import { createApp, reactive } from "vue";
|
||||||
|
|
||||||
const ckeditorFields: NodeListOf<HTMLTextAreaElement> =
|
const ckeditorFields: NodeListOf<HTMLTextAreaElement> =
|
||||||
document.querySelectorAll("textarea[ckeditor]");
|
document.querySelectorAll(".vue-comment-editor");
|
||||||
ckeditorFields.forEach((field: HTMLTextAreaElement): void => {
|
|
||||||
ClassicEditor.create(field, config)
|
const globalState = reactive({
|
||||||
.catch((error) => {
|
isSimple: localStorage.getItem('editorMode') === 'simple'
|
||||||
console.error(error.stack);
|
});
|
||||||
throw error;
|
window.addEventListener('storage', () => {
|
||||||
});
|
globalState.isSimple = localStorage.getItem('editorMode') === 'simple';
|
||||||
|
});
|
||||||
|
|
||||||
|
ckeditorFields.forEach((field: HTMLTextAreaElement): void => {
|
||||||
|
console.log('field', field)
|
||||||
|
const app = createApp({
|
||||||
|
template: `<app></app>`
|
||||||
|
});
|
||||||
|
|
||||||
|
app.provide('globalState', globalState)
|
||||||
|
.component("app", App)
|
||||||
|
.mount(field);
|
||||||
});
|
});
|
||||||
//Fields.push.apply(Fields, document.querySelectorAll('.cf-fields textarea'));
|
|
||||||
|
@ -14,18 +14,15 @@ export default defineComponent({
|
|||||||
name: "App",
|
name: "App",
|
||||||
components: { CommentEditor },
|
components: { CommentEditor },
|
||||||
setup() {
|
setup() {
|
||||||
|
console.log('im loaded')
|
||||||
const globalState = inject('globalState');
|
const globalState = inject('globalState');
|
||||||
const fieldName = inject('fieldName')
|
|
||||||
const toggleEditorMode = () => {
|
const toggleEditorMode = () => {
|
||||||
globalState.isSimple = !globalState.isSimple;
|
globalState.isSimple = !globalState.isSimple;
|
||||||
localStorage.setItem('editorMode', globalState.isSimple ? 'simple' : 'rich');
|
localStorage.setItem('editorMode', globalState.isSimple ? 'simple' : 'rich');
|
||||||
};
|
};
|
||||||
|
|
||||||
const handleChange = (newContent) => {
|
const handleChange = (newContent) => {
|
||||||
const hiddenField = document.querySelector(`input[name="${fieldName}"]`);
|
console.log(newContent)
|
||||||
if (hiddenField) {
|
|
||||||
hiddenField.value = newContent || '';
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
return {
|
return {
|
||||||
|
@ -1,5 +1,5 @@
|
|||||||
<template>
|
<template>
|
||||||
<div class="editor-container">
|
<div :class="{'editor-container': true, 'rich-editor-active': !isSimple}">
|
||||||
<div v-if="!isSimple" class="editor-wrapper">
|
<div v-if="!isSimple" class="editor-wrapper">
|
||||||
<ckeditor
|
<ckeditor
|
||||||
name="content"
|
name="content"
|
||||||
@ -18,7 +18,7 @@
|
|||||||
@input="emitChange"
|
@input="emitChange"
|
||||||
></textarea>
|
></textarea>
|
||||||
</div>
|
</div>
|
||||||
<a @click="toggleSimpleEditor" class="toggle-button btn btn-misc">{{ isSimple ? $t("mode.rich") : $t("mode.simple") }}</a>
|
<a @click="toggleSimpleEditor" class="toggle-button">{{ isSimple ? "rich" : "simple" }}</a>
|
||||||
</div>
|
</div>
|
||||||
</template>
|
</template>
|
||||||
|
|
||||||
@ -38,6 +38,7 @@ export default defineComponent({
|
|||||||
isSimple: Boolean,
|
isSimple: Boolean,
|
||||||
},
|
},
|
||||||
setup(props, { emit }) {
|
setup(props, { emit }) {
|
||||||
|
console.log("im loaded too")
|
||||||
const { isSimple } = toRefs(props);
|
const { isSimple } = toRefs(props);
|
||||||
const content = ref("");
|
const content = ref("");
|
||||||
const classicEditor = ClassicEditor;
|
const classicEditor = ClassicEditor;
|
||||||
|
@ -1,31 +0,0 @@
|
|||||||
import { createApp, reactive } from "vue";
|
|
||||||
import App from "./App.vue";
|
|
||||||
import {_createI18n} from "ChillMainAssets/vuejs/_js/i18n";
|
|
||||||
import { appMessages } from "ChillMainAssets/vuejs/CommentEditor/i18n";
|
|
||||||
|
|
||||||
const i18n = _createI18n(appMessages);
|
|
||||||
|
|
||||||
// Global reactive state to handle editorMode
|
|
||||||
const globalState = reactive({
|
|
||||||
isSimple: localStorage.getItem('editorMode') === 'simple'
|
|
||||||
});
|
|
||||||
|
|
||||||
// Watch for changes to `localStorage` and update the state
|
|
||||||
window.addEventListener('storage', () => {
|
|
||||||
globalState.isSimple = localStorage.getItem('editorMode') === 'simple';
|
|
||||||
});
|
|
||||||
|
|
||||||
const commentWidgets = document.querySelectorAll('[id^="comment-widget"]');
|
|
||||||
commentWidgets.forEach((commentContainer) => {
|
|
||||||
const app = createApp({
|
|
||||||
template: `<app></app>`
|
|
||||||
});
|
|
||||||
|
|
||||||
const fieldName = commentContainer.dataset.fieldname;
|
|
||||||
|
|
||||||
app.use(i18n)
|
|
||||||
.provide('globalState', globalState)
|
|
||||||
.provide( 'fieldName', fieldName)
|
|
||||||
.component("app", App)
|
|
||||||
.mount(commentContainer);
|
|
||||||
});
|
|
@ -214,7 +214,9 @@
|
|||||||
|
|
||||||
{% block private_comment_widget %}
|
{% block private_comment_widget %}
|
||||||
{% for entry in form %}
|
{% for entry in form %}
|
||||||
{{ form_widget(entry) }}
|
<div class="vue-comment-editor">
|
||||||
|
{{ form_widget(entry, { attr: { ckeditor: 'true' } }) }}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
@ -224,7 +226,9 @@
|
|||||||
|
|
||||||
{% block comment_widget %}
|
{% block comment_widget %}
|
||||||
{% for entry in form %}
|
{% for entry in form %}
|
||||||
{{ form_widget(entry) }}
|
<div class="vue-comment-editor">
|
||||||
|
{{ form_widget(entry, { attr: { ckeditor: 'true' } }) }}
|
||||||
|
</div>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endblock comment_widget %}
|
{% endblock comment_widget %}
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user