feat: edit class
This commit is contained in:
@@ -160,10 +160,14 @@ def authenticate():
|
|||||||
|
|
||||||
|
|
||||||
@frappe.whitelist()
|
@frappe.whitelist()
|
||||||
def create_class(title, start_date, end_date, description):
|
def create_class(title, start_date, end_date, description=None, name=None):
|
||||||
class_details = frappe.get_doc(
|
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,
|
"title": title,
|
||||||
"start_date": start_date,
|
"start_date": start_date,
|
||||||
"end_date": end_date,
|
"end_date": end_date,
|
||||||
|
|||||||
@@ -391,11 +391,7 @@ const reorder_chapter = (e) => {
|
|||||||
};
|
};
|
||||||
|
|
||||||
const open_class_dialog = (e) => {
|
const open_class_dialog = (e) => {
|
||||||
let class_details = $(e.currentTarget).data("class");
|
this.class_dialog = new frappe.ui.Dialog({
|
||||||
console.log(class_details);
|
|
||||||
console.log(decodeURIComponent(class_details));
|
|
||||||
console.log(JSON.parse(class_details));
|
|
||||||
let dialog = new frappe.ui.Dialog({
|
|
||||||
title: __("New Class"),
|
title: __("New Class"),
|
||||||
fields: [
|
fields: [
|
||||||
{
|
{
|
||||||
@@ -403,23 +399,27 @@ const open_class_dialog = (e) => {
|
|||||||
label: __("Title"),
|
label: __("Title"),
|
||||||
fieldname: "title",
|
fieldname: "title",
|
||||||
reqd: 1,
|
reqd: 1,
|
||||||
|
default: class_info && class_info.title,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldtype: "Date",
|
fieldtype: "Date",
|
||||||
label: __("Start Date"),
|
label: __("Start Date"),
|
||||||
fieldname: "start_date",
|
fieldname: "start_date",
|
||||||
reqd: 1,
|
reqd: 1,
|
||||||
|
default: class_info && class_info.start_date,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldtype: "Date",
|
fieldtype: "Date",
|
||||||
label: __("End Date"),
|
label: __("End Date"),
|
||||||
fieldname: "end_date",
|
fieldname: "end_date",
|
||||||
reqd: 1,
|
reqd: 1,
|
||||||
|
default: class_info && class_info.end_date,
|
||||||
},
|
},
|
||||||
{
|
{
|
||||||
fieldtype: "Small Text",
|
fieldtype: "Small Text",
|
||||||
label: __("Description"),
|
label: __("Description"),
|
||||||
fieldname: "description",
|
fieldname: "description",
|
||||||
|
default: class_info && class_info.description,
|
||||||
},
|
},
|
||||||
],
|
],
|
||||||
primary_action_label: __("Save"),
|
primary_action_label: __("Save"),
|
||||||
@@ -427,7 +427,7 @@ const open_class_dialog = (e) => {
|
|||||||
create_class(values);
|
create_class(values);
|
||||||
},
|
},
|
||||||
});
|
});
|
||||||
dialog.show();
|
this.class_dialog.show();
|
||||||
};
|
};
|
||||||
|
|
||||||
const create_class = (values) => {
|
const create_class = (values) => {
|
||||||
@@ -438,14 +438,17 @@ const create_class = (values) => {
|
|||||||
start_date: values.start_date,
|
start_date: values.start_date,
|
||||||
end_date: values.end_date,
|
end_date: values.end_date,
|
||||||
description: values.description,
|
description: values.description,
|
||||||
|
name: class_info && class_info.name,
|
||||||
},
|
},
|
||||||
callback: (r) => {
|
callback: (r) => {
|
||||||
if (r.message) {
|
if (r.message) {
|
||||||
frappe.show_alert({
|
frappe.show_alert({
|
||||||
message: __("Class Created"),
|
message: class_info
|
||||||
|
? __("Class Updated")
|
||||||
|
: __("Class Created"),
|
||||||
indicator: "green",
|
indicator: "green",
|
||||||
});
|
});
|
||||||
dialog.hide();
|
this.class_dialog.hide();
|
||||||
window.location.href = `/classes/${r.message.name}`;
|
window.location.href = `/classes/${r.message.name}`;
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
|
|||||||
@@ -62,7 +62,7 @@
|
|||||||
{% macro ClassSections(class_info, class_courses, class_students, published_courses) %}
|
{% macro ClassSections(class_info, class_courses, class_students, published_courses) %}
|
||||||
<div class="mt-4">
|
<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") }}
|
{{ _("Edit") }}
|
||||||
</button>
|
</button>
|
||||||
|
|
||||||
@@ -286,8 +286,8 @@
|
|||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
|
|
||||||
{% if is_moderator %}
|
|
||||||
<script>
|
<script>
|
||||||
|
{% if is_moderator %}
|
||||||
frappe.boot.user = {
|
frappe.boot.user = {
|
||||||
"can_create": [],
|
"can_create": [],
|
||||||
"can_select": ["User"],
|
"can_select": ["User"],
|
||||||
@@ -299,8 +299,9 @@
|
|||||||
return name.toLowerCase().replace(/ /g, "-");
|
return name.toLowerCase().replace(/ /g, "-");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
</script>
|
|
||||||
{% endif %}
|
{% endif %}
|
||||||
|
let class_info = {{ class_info | json }};
|
||||||
|
</script>
|
||||||
|
|
||||||
{{ include_script('controls.bundle.js') }}
|
{{ include_script('controls.bundle.js') }}
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|||||||
@@ -30,6 +30,9 @@
|
|||||||
{%- block script %}
|
{%- block script %}
|
||||||
{{ super() }}
|
{{ super() }}
|
||||||
{{ include_script('controls.bundle.js') }}
|
{{ include_script('controls.bundle.js') }}
|
||||||
|
<script>
|
||||||
|
let class_info = null;
|
||||||
|
</script>
|
||||||
{% endblock %}
|
{% endblock %}
|
||||||
|
|
||||||
{% macro ClassCards(classes) %}
|
{% macro ClassCards(classes) %}
|
||||||
|
|||||||
Reference in New Issue
Block a user