[IMP] website_slides: open rating composer in fullscreen mode
Purpose ======= Currently we can write a review in the slide fullscreen view. But if we click on the button "review", we are redirected to the reviews page. Instead, we want to open the rating composer and to stay in the page. Task-2322583
This commit is contained in:
@@ -513,49 +513,14 @@ class WebsiteSlides(WebsiteProfile):
|
||||
'slide_types': slide_types,
|
||||
'sorting': actual_sorting,
|
||||
'search': search,
|
||||
# chatter
|
||||
'rating_avg': channel.rating_avg,
|
||||
'rating_count': channel.rating_count,
|
||||
# display data
|
||||
'user': request.env.user,
|
||||
'pager': pager,
|
||||
'is_public_user': request.website.is_public_user(),
|
||||
# display upload modal
|
||||
'enable_slide_upload': 'enable_slide_upload' in kw,
|
||||
** self._slide_channel_prepare_review_values(channel),
|
||||
}
|
||||
if not request.env.user._is_public():
|
||||
last_message = request.env['mail.message'].search([
|
||||
('model', '=', channel._name),
|
||||
('res_id', '=', channel.id),
|
||||
('author_id', '=', request.env.user.partner_id.id),
|
||||
('message_type', '=', 'comment'),
|
||||
('is_internal', '=', False)
|
||||
], order='write_date DESC', limit=1)
|
||||
if last_message:
|
||||
last_message_values = last_message.read(['body', 'rating_value', 'attachment_ids'])[0]
|
||||
last_message_attachment_ids = last_message_values.pop('attachment_ids', [])
|
||||
if last_message_attachment_ids:
|
||||
# use sudo as portal user cannot read access_token, necessary for updating attachments
|
||||
# through frontend chatter -> access is already granted and limited to current user message
|
||||
last_message_attachment_ids = json.dumps(
|
||||
request.env['ir.attachment'].sudo().browse(last_message_attachment_ids).read(
|
||||
['id', 'name', 'mimetype', 'file_size', 'access_token']
|
||||
)
|
||||
)
|
||||
else:
|
||||
last_message_values = {}
|
||||
last_message_attachment_ids = []
|
||||
values.update({
|
||||
'last_message_id': last_message_values.get('id'),
|
||||
'last_message': tools.html2plaintext(last_message_values.get('body', '')),
|
||||
'last_rating_value': last_message_values.get('rating_value'),
|
||||
'last_message_attachment_ids': last_message_attachment_ids,
|
||||
})
|
||||
if channel.can_review:
|
||||
values.update({
|
||||
'message_post_hash': channel._sign_token(request.env.user.partner_id.id),
|
||||
'message_post_pid': request.env.user.partner_id.id,
|
||||
})
|
||||
|
||||
# fetch slides and handle uncategorized slides; done as sudo because we want to display all
|
||||
# of them but unreachable ones won't be clickable (+ slide controller will crash anyway)
|
||||
@@ -618,6 +583,50 @@ class WebsiteSlides(WebsiteProfile):
|
||||
'allow_comment': bool(kw.get('allow_comment')),
|
||||
}
|
||||
|
||||
def _slide_channel_prepare_review_values(self, channel):
|
||||
values = {
|
||||
'rating_avg': channel.rating_avg,
|
||||
'rating_count': channel.rating_count,
|
||||
}
|
||||
|
||||
if not request.env.user._is_public():
|
||||
last_message = request.env['mail.message'].search([
|
||||
('model', '=', channel._name),
|
||||
('res_id', '=', channel.id),
|
||||
('author_id', '=', request.env.user.partner_id.id),
|
||||
('message_type', '=', 'comment'),
|
||||
('is_internal', '=', False)
|
||||
], order='write_date DESC', limit=1)
|
||||
|
||||
if last_message:
|
||||
last_message_values = last_message.read(['body', 'rating_value', 'attachment_ids'])[0]
|
||||
last_message_attachment_ids = last_message_values.pop('attachment_ids', [])
|
||||
if last_message_attachment_ids:
|
||||
# use sudo as portal user cannot read access_token, necessary for updating attachments
|
||||
# through frontend chatter -> access is already granted and limited to current user message
|
||||
last_message_attachment_ids = json.dumps(
|
||||
request.env['ir.attachment'].sudo().browse(last_message_attachment_ids).read(
|
||||
['id', 'name', 'mimetype', 'file_size', 'access_token']
|
||||
)
|
||||
)
|
||||
else:
|
||||
last_message_values = {}
|
||||
last_message_attachment_ids = []
|
||||
|
||||
values.update({
|
||||
'last_message_id': last_message_values.get('id'),
|
||||
'last_message': tools.html2plaintext(last_message_values.get('body', '')),
|
||||
'last_rating_value': last_message_values.get('rating_value'),
|
||||
'last_message_attachment_ids': last_message_attachment_ids,
|
||||
})
|
||||
if channel.can_review:
|
||||
values.update({
|
||||
'message_post_hash': channel._sign_token(request.env.user.partner_id.id),
|
||||
'message_post_pid': request.env.user.partner_id.id,
|
||||
})
|
||||
|
||||
return values
|
||||
|
||||
@http.route('/slides/channel/enroll', type='http', auth='public', website=True)
|
||||
def slide_channel_join_http(self, channel_id):
|
||||
# TDE FIXME: why 2 routes ?
|
||||
@@ -730,12 +739,13 @@ class WebsiteSlides(WebsiteProfile):
|
||||
|
||||
values['channel'] = slide.channel_id
|
||||
values = self._prepare_additional_channel_values(values, **kwargs)
|
||||
values.pop('channel', None)
|
||||
|
||||
values['signup_allowed'] = request.env['res.users'].sudo()._get_signup_invitation_scope() == 'b2c'
|
||||
|
||||
if kwargs.get('fullscreen') == '1':
|
||||
values.update(self._slide_channel_prepare_review_values(slide.channel_id))
|
||||
return request.render("website_slides.slide_fullscreen", values)
|
||||
|
||||
values.pop('channel', None)
|
||||
return request.render("website_slides.slide_main", values)
|
||||
|
||||
@http.route('''/slides/slide/<model("slide.slide"):slide>/pdf_content''',
|
||||
|
||||
@@ -18,8 +18,25 @@
|
||||
<a class="o_wslides_fs_toggle_sidebar d-flex align-items-center px-3" href="#" title="Lessons">
|
||||
<i class="fa fa-bars"/><span class="d-none d-md-inline-block ml-1">Lessons</span>
|
||||
</a>
|
||||
<a class="o_wslides_fs_review d-flex align-items-center px-3" t-att-href="slide.channel_id.website_url + '?active_tab=review'" title="Reviews" t-if="slide.channel_id.allow_comment">
|
||||
<i class="fa fa-pencil"/><span class="d-none d-md-inline-block ml-1">Write a review</span>
|
||||
<a class="o_wslides_fs_review d-flex align-items-center" title="Reviews" t-if="slide.channel_id.allow_comment">
|
||||
<t t-call="portal_rating.rating_stars_static_popup_composer">
|
||||
<t t-set="rating_avg" t-value="rating_avg"/>
|
||||
<t t-set="rating_total" t-value="rating_count"/>
|
||||
<t t-set="object" t-value="channel"/>
|
||||
<t t-set="token" t-value="channel.access_token"/>
|
||||
<t t-set="hash" t-value="message_post_hash"/>
|
||||
<t t-set="pid" t-value="message_post_pid"/>
|
||||
<t t-set="default_message" t-value="last_message"/>
|
||||
<t t-set="default_message_id" t-value="last_message_id"/>
|
||||
<t t-set="default_rating_value" t-value="last_rating_value"/>
|
||||
<t t-set="default_attachment_ids" t-value="last_message_attachment_ids"/>
|
||||
<t t-set="force_submit_url" t-value="'/slides/mail/update_comment' if last_message_id else False"/>
|
||||
<t t-set="disable_composer" t-value="not channel.can_review"/>
|
||||
<t t-set="_link_btn_classes" t-value="'d-inline-block text-white font-weight-light shadow-none'"/>
|
||||
<t t-set="icon" t-value="'fa fa-pencil'"/>
|
||||
<t t-set="_text_classes" t-value="'d-none d-md-inline-block'"/>
|
||||
<t t-set="hide_rating_avg" t-value="True"/>
|
||||
</t>
|
||||
</a>
|
||||
<a class="o_wslides_fs_share d-flex align-items-center px-3" href="#" title="Share">
|
||||
<i class="fa fa-share-alt"/><span class="d-none d-md-inline-block ml-1">Share</span>
|
||||
|
||||
Reference in New Issue
Block a user