feat: edit class

This commit is contained in:
Jannat Patel
2023-04-11 16:45:34 +05:30
parent 9b70b4212f
commit 5fb7e88318
4 changed files with 25 additions and 14 deletions

View File

@@ -160,10 +160,14 @@ def authenticate():
@frappe.whitelist()
def create_class(title, start_date, end_date, description):
class_details = frappe.get_doc(
def create_class(title, start_date, end_date, description=None, name=None):
if name:
class_details = frappe.get_doc("LMS Class", name)
else:
class_details = frappe.get_doc({"doctype": "LMS Class"})
class_details.update(
{
"doctype": "LMS Class",
"title": title,
"start_date": start_date,
"end_date": end_date,

View File

@@ -391,11 +391,7 @@ const reorder_chapter = (e) => {
};
const open_class_dialog = (e) => {
let class_details = $(e.currentTarget).data("class");
console.log(class_details);
console.log(decodeURIComponent(class_details));
console.log(JSON.parse(class_details));
let dialog = new frappe.ui.Dialog({
this.class_dialog = new frappe.ui.Dialog({
title: __("New Class"),
fields: [
{
@@ -403,23 +399,27 @@ const open_class_dialog = (e) => {
label: __("Title"),
fieldname: "title",
reqd: 1,
default: class_info && class_info.title,
},
{
fieldtype: "Date",
label: __("Start Date"),
fieldname: "start_date",
reqd: 1,
default: class_info && class_info.start_date,
},
{
fieldtype: "Date",
label: __("End Date"),
fieldname: "end_date",
reqd: 1,
default: class_info && class_info.end_date,
},
{
fieldtype: "Small Text",
label: __("Description"),
fieldname: "description",
default: class_info && class_info.description,
},
],
primary_action_label: __("Save"),
@@ -427,7 +427,7 @@ const open_class_dialog = (e) => {
create_class(values);
},
});
dialog.show();
this.class_dialog.show();
};
const create_class = (values) => {
@@ -438,14 +438,17 @@ const create_class = (values) => {
start_date: values.start_date,
end_date: values.end_date,
description: values.description,
name: class_info && class_info.name,
},
callback: (r) => {
if (r.message) {
frappe.show_alert({
message: __("Class Created"),
message: class_info
? __("Class Updated")
: __("Class Created"),
indicator: "green",
});
dialog.hide();
this.class_dialog.hide();
window.location.href = `/classes/${r.message.name}`;
}
},

View File

@@ -62,7 +62,7 @@
{% macro ClassSections(class_info, class_courses, class_students, published_courses) %}
<div class="mt-4">
<button class="btn btn-secondary btn-sm pull-right" id="create-class" data-class="{{ json.dumps(class_info) }}">
<button class="btn btn-secondary btn-sm pull-right" id="create-class">
{{ _("Edit") }}
</button>
@@ -286,8 +286,8 @@
{%- block script %}
{{ super() }}
{% if is_moderator %}
<script>
{% if is_moderator %}
frappe.boot.user = {
"can_create": [],
"can_select": ["User"],
@@ -299,8 +299,9 @@
return name.toLowerCase().replace(/ /g, "-");
}
}
{% endif %}
let class_info = {{ class_info | json }};
</script>
{% endif %}
{{ include_script('controls.bundle.js') }}
{% endblock %}

View File

@@ -30,6 +30,9 @@
{%- block script %}
{{ super() }}
{{ include_script('controls.bundle.js') }}
<script>
let class_info = null;
</script>
{% endblock %}
{% macro ClassCards(classes) %}