fix: text editor for description field
This commit is contained in:
@@ -542,7 +542,6 @@ const build_attachment_table = (file_doc) => {
|
|||||||
|
|
||||||
|
|
||||||
const make_editor = () => {
|
const make_editor = () => {
|
||||||
|
|
||||||
this.code_field_group = new frappe.ui.FieldGroup({
|
this.code_field_group = new frappe.ui.FieldGroup({
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
|
|||||||
@@ -205,9 +205,13 @@
|
|||||||
|
|
||||||
<!-- Description -->
|
<!-- Description -->
|
||||||
{% macro Description(course) %}
|
{% macro Description(course) %}
|
||||||
<div class="course-description-section" {% if course.edit_mode %} style="min-height: 100px" {% endif %}
|
{% if course.edit_mode %}
|
||||||
{% if course.edit_mode %} contenteditable="true" {% endif %} id="description"
|
<div id="description" {% if course.description %} data-description="{{ course.description }}" {% endif %}></div>
|
||||||
data-placeholder="Description">{% if course.description %}{{ frappe.utils.md_to_html(course.description) }}{% endif %}</div>
|
{% else %}
|
||||||
|
<div class="course-description-section">
|
||||||
|
{{ frappe.utils.md_to_html(course.description) }}
|
||||||
|
</div>
|
||||||
|
{% endif %}
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
@@ -419,3 +423,9 @@
|
|||||||
</div>
|
</div>
|
||||||
</div>
|
</div>
|
||||||
{% endmacro %}
|
{% endmacro %}
|
||||||
|
|
||||||
|
|
||||||
|
{% block base_scripts %}
|
||||||
|
{{ include_script("frappe-web.bundle.js") }}
|
||||||
|
{{ include_script('controls.bundle.js') }}
|
||||||
|
{% endblock %}
|
||||||
|
|||||||
@@ -70,6 +70,10 @@ frappe.ready(() => {
|
|||||||
remove_tag(e);
|
remove_tag(e);
|
||||||
});
|
});
|
||||||
|
|
||||||
|
if ($("#description").length) {
|
||||||
|
make_editor();
|
||||||
|
}
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|
||||||
@@ -338,7 +342,7 @@ const save_course = (e) => {
|
|||||||
"short_introduction": $("#intro").text(),
|
"short_introduction": $("#intro").text(),
|
||||||
"video_link": $("#video-link").text(),
|
"video_link": $("#video-link").text(),
|
||||||
"image": $("#image").attr("href"),
|
"image": $("#image").attr("href"),
|
||||||
"description": $("#description").text(),
|
"description": this.code_field_group.fields_dict["code_md"].value,
|
||||||
"course": $("#title").data("course") ? $("#title").data("course") : "",
|
"course": $("#title").data("course") ? $("#title").data("course") : "",
|
||||||
"published": $("#published").prop("checked") ? 1 : 0,
|
"published": $("#published").prop("checked") ? 1 : 0,
|
||||||
"upcoming": $("#upcoming").prop("checked") ? 1 : 0
|
"upcoming": $("#upcoming").prop("checked") ? 1 : 0
|
||||||
@@ -359,3 +363,26 @@ const save_course = (e) => {
|
|||||||
const remove_tag = (e) => {
|
const remove_tag = (e) => {
|
||||||
$(e.currentTarget).closest(".course-card-pills").remove();
|
$(e.currentTarget).closest(".course-card-pills").remove();
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
const make_editor = () => {
|
||||||
|
this.code_field_group = new frappe.ui.FieldGroup({
|
||||||
|
fields: [
|
||||||
|
{
|
||||||
|
fieldname: "code_md",
|
||||||
|
fieldtype: "Code",
|
||||||
|
options: "Markdown",
|
||||||
|
wrap: true,
|
||||||
|
max_lines: Infinity,
|
||||||
|
min_lines: 20,
|
||||||
|
default: $("#description").data("description"),
|
||||||
|
depends_on: 'eval:doc.type=="Markdown"',
|
||||||
|
}
|
||||||
|
],
|
||||||
|
body: $("#description").get(0),
|
||||||
|
});
|
||||||
|
this.code_field_group.make();
|
||||||
|
$("#description .form-section:last").removeClass("empty-section");
|
||||||
|
$("#description .frappe-control").removeClass("hide-control");
|
||||||
|
$("#description .form-column").addClass("p-0");
|
||||||
|
};
|
||||||
|
|||||||
Reference in New Issue
Block a user