[IMP] website_slides_survey: set slide name when setting survey

PURPOSE

This commit slightly modifies both the slide's backend form view and the
website form to use the certification (survey) title as default name for this
slide if it does not have a name configured yet.

We also removed dead onchange code as the survey_id field is not visible if
slide_category is not set to certification.

LINKS

Task-2810395

closes odoo/odoo#87672

Signed-off-by: Warnon Aurélien (awa) <awa@odoo.com>
This commit is contained in:
Patrick Hoste
2022-04-20 16:41:02 +02:00
parent 727249b3d8
commit ee0f4b1300
2 changed files with 10 additions and 7 deletions
@@ -30,6 +30,7 @@ class SlidePartnerRelation(models.Model):
class Slide(models.Model):
_inherit = 'slide.slide'
name = fields.Char(compute='_compute_name', readonly=False, store=True)
slide_category = fields.Selection(selection_add=[
('certification', 'Certification')
], ondelete={'certification': 'set default'})
@@ -46,17 +47,18 @@ class Slide(models.Model):
('check_certification_preview', "CHECK(slide_category != 'certification' OR is_preview = False)", "A slide of type certification cannot be previewed."),
]
@api.depends('survey_id')
def _compute_name(self):
for slide in self:
if not slide.name and slide.survey_id:
slide.name = slide.survey_id.title
@api.depends('slide_category')
def _compute_is_preview(self):
for slide in self:
if slide.slide_category == 'certification' or not slide.is_preview:
slide.is_preview = False
@api.onchange('survey_id')
def _on_change_survey_id(self):
if self.survey_id:
self.slide_category = 'certification'
@api.depends('slide_category', 'source_type')
def _compute_slide_type(self):
super(Slide, self)._compute_slide_type()
@@ -22,8 +22,9 @@ SlidesUpload.SlideUploadDialog.include({
* Will automatically set the title of the slide to the title of the chosen certification
*/
_onChangeCertification: function (ev) {
if (ev.added && ev.added.text) {
this.$("input#name").val(ev.added.text);
const $inputElement = this.$("input#name");
if (ev.added && ev.added.text && !$inputElement.val().trim()) {
$inputElement.val(ev.added.text);
}
},