feat: assignment url

This commit is contained in:
Jannat Patel
2023-08-30 13:01:45 +05:30
parent 018c26b885
commit 4a76f42e35
5 changed files with 72 additions and 16 deletions

View File

@@ -39,7 +39,8 @@
<div class="align-self-center">
<button class="btn btn-primary btn-sm btn-save-assignment" {% if assignment.name %} data-assignment="{{ assignment.name }}" {% endif %}
<button class="btn btn-primary btn-sm btn-save-assignment"
data-assignment="{{ assignment.name }}" data-type="{{ assignment.type }}"
{% if submission.name %} data-submission="{{ submission.name }}" {% endif %}>
{{ _("Save") }}
</button>
@@ -53,7 +54,7 @@
<article class="field-parent">
{% if submission.name and is_moderator %}
<div class="field-group">
<div class="field-label">
<div class="bold-heading">
{{ _("Student Name") }}
</div>
{{ submission.member_name }}
@@ -61,14 +62,15 @@
{% endif %}
<div class="field-group">
<div class="field-label">
<div class="bold-heading">
{{ _("Question")}}
</div>
{{ assignment.question }}
</div>
{% if assignment.type != "URL" %}
<div class="field-group">
<div class="field-label">
<div class="bold-heading">
{{ _("Submit")}}
</div>
<div class="field-description">
@@ -88,6 +90,19 @@
</span>
</div>
</div>
{% else %}
{{ submission }}
<div class="field-group">
<div class="bold-heading">
{{ _("Submit")}}
</div>
<div class="field-description">
{{ _("Enter a URL") }}
</div>
<input id="assignment-url" type="text" class="field-input" placeholder="https://"
{% if submission.answer %} value="{{ submission.answer }}" {% endif %}>
</div>
{% endif %}
{% if is_moderator %}
<div class="field-group">

View File

@@ -47,12 +47,26 @@ const upload_file = (e) => {
};
const save_assignment = (e) => {
let file = $("#assignment-preview a").attr("href");
if (!file) {
frappe.throw({
title: __("No File"),
message: __("Please upload a file."),
});
let data = $(e.currentTarget).data("type");
let answer,
file = "";
if (data == "URL") {
answer = $("#assignment-url").val();
if (!answer) {
frappe.throw({
title: __("No URL"),
message: __("Please enter a URL."),
});
}
} else {
file = $("#assignment-preview a").attr("href");
if (!file) {
frappe.throw({
title: __("No File"),
message: __("Please upload a file."),
});
}
}
frappe.call({
@@ -61,6 +75,7 @@ const save_assignment = (e) => {
assignment: $(e.currentTarget).data("assignment"),
submission: $(e.currentTarget).data("submission") || "",
assignment_attachment: file,
answer: answer,
status: $("#status").val(),
comments: $("#comments").val(),
},

View File

@@ -23,7 +23,15 @@ def get_context(context):
context.submission = frappe.db.get_value(
"LMS Assignment Submission",
submission,
["name", "assignment_attachment", "comments", "status", "member", "member_name"],
[
"name",
"assignment_attachment",
"answer",
"comments",
"status",
"member",
"member_name",
],
as_dict=True,
)
if not context.is_moderator and frappe.session.user != context.submission.member: