Some checks failed
pre-commit / pre-commit (pull_request) Failing after 1m40s
* Show a stored file (after navigating back) the same way as a freshly selected one: a "filename + Remove file" chip, input hidden until removal. * Keep the stored file when a page is re-submitted without a new selection (instead of overwriting it with a skipped answer). * "Remove file" now sends a sentinel to actually delete the stored file, so the removal persists across navigation.
82 lines
3.8 KiB
XML
82 lines
3.8 KiB
XML
<?xml version="1.0" encoding="utf-8"?>
|
|
<odoo>
|
|
|
|
<!-- Extend question_container (form view during survey filling) -->
|
|
<template
|
|
id="question_container_inh_type_file"
|
|
inherit_id="survey.question_container"
|
|
>
|
|
<xpath expr="//t[@t-call='survey.question_matrix']" position="after">
|
|
<t t-if="question.question_type == 'file'">
|
|
<t t-call="survey_extra_fields.question_file"/>
|
|
</t>
|
|
</xpath>
|
|
</template>
|
|
|
|
<template id="question_file" name="Question: File">
|
|
<div class="o_survey_comment_container p-0">
|
|
<t t-set="existing_fname" t-value="answer_lines and answer_lines[0].value_file_fname"/>
|
|
<t t-if="survey_form_readonly">
|
|
<p t-if="existing_fname" class="mb-1">
|
|
<i class="fa fa-paperclip me-1"/><t t-out="answer_lines[0].value_file_fname"/>
|
|
</p>
|
|
</t>
|
|
<t t-else="">
|
|
<!-- Uploaded file display, shown both for a fresh selection and when a
|
|
file was already stored server-side (e.g. navigating back). The raw
|
|
file input is hidden until the user clicks "Remove file". -->
|
|
<span t-attf-class="o_survey_file_selected d-inline-flex align-items-center #{'' if existing_fname else 'd-none'}">
|
|
<i class="fa fa-paperclip me-1"/>
|
|
<span class="o_survey_file_name"><t t-out="existing_fname or ''"/></span>
|
|
<button type="button" class="btn btn-link btn-sm text-danger o_survey_file_clear ms-2 py-0">
|
|
<i class="fa fa-times me-1"/>Remove file
|
|
</button>
|
|
</span>
|
|
<input
|
|
type="file"
|
|
t-attf-class="o_survey_question_file #{'d-none' if existing_fname else ''}"
|
|
t-att-name="question.id"
|
|
t-att-data-question-type="question.question_type"
|
|
t-att-accept="question.allowed_extensions or None"
|
|
t-att-data-max-file-size="question.max_file_size or None"
|
|
t-att-data-allowed-extensions="question.allowed_extensions or None"
|
|
/>
|
|
</t>
|
|
</div>
|
|
</template>
|
|
|
|
<!-- Extend print/review page to show file answers -->
|
|
<template
|
|
id="survey_page_print_inh_type_file"
|
|
inherit_id="survey.survey_page_print"
|
|
>
|
|
<xpath expr="//div[hasclass('o_survey_question_error')]" position="before">
|
|
<t t-if="question.question_type == 'file'">
|
|
<t t-if="answer_lines">
|
|
<t t-set="answer_line" t-value="answer_lines[0]"/>
|
|
<t t-if="answer_line.skipped">
|
|
<div class="row g-0">
|
|
<div class="col-12 col-md-6 col-lg-4 rounded ps-4 o_survey_question_skipped">
|
|
<input type="text"
|
|
class="form-control fst-italic o_survey_question_file bg-transparent rounded-0 p-0"
|
|
value="Skipped"/>
|
|
</div>
|
|
</div>
|
|
</t>
|
|
<t t-elif="answer_line.value_file_fname">
|
|
<div class="row g-0">
|
|
<div class="col-12 col-md-6 col-lg-4">
|
|
<a t-attf-href="/survey/file/#{survey.access_token}/#{answer.access_token}/#{answer_line.id}"
|
|
target="_blank">
|
|
<i class="fa fa-download me-1"/><t t-out="answer_line.value_file_fname"/>
|
|
</a>
|
|
</div>
|
|
</div>
|
|
</t>
|
|
</t>
|
|
</t>
|
|
</xpath>
|
|
</template>
|
|
|
|
</odoo>
|