portal_chatter.xml 9.25 KB
<templates id="template" xml:space="preserve">

    <t t-name="portal.chatter_message_count">
        <t t-set="count" t-value="widget.get('message_count')"/>
        <div class="o_message_counter">
            <t t-if="count">
                <span class="fa fa-comments" />
                <span class="o_message_count"> <t t-esc="count"/></span>
                <t t-if="count == 1">comment</t>
                <t t-else="">comments</t>
            </t>
            <t t-else="">
                There are no comments for now.
            </t>
        </div>
    </t>

    <!--
        Widget PortalComposer (standalone)

        required many options: token, res_model, res_id, ...
    -->
    <t t-name="portal.Composer">
        <div class="o_portal_chatter_composer" t-if="widget.options['allow_composer']">
            <t t-set="discussion_url" t-value="window.encodeURI(window.location.href.split('#')[0] + '#discussion')"/>
            <t t-if="!widget.options['display_composer']">
                <h4>Leave a comment</h4>
                <p>You must be <a t-attf-href="/web/login?redirect=#{discussion_url}">logged in</a> to post a comment.</p>
            </t>
            <t t-if="widget.options['display_composer']">
                <div class="media">
                    <img alt="Avatar" class="o_portal_chatter_avatar" t-attf-src="/web/image/res.partner/#{widget.options['partner_id']}/image_128/50x50"
                         t-if="!widget.options['is_user_public'] or !widget.options['token']"/>
                    <div class="media-body">
                        <form class="o_portal_chatter_composer_form" t-attf-action="/mail/chatter_post" method="POST">
                            <input type="hidden" name="csrf_token" t-att-value="widget.options['csrf_token']"/>
                            <div class="mb32">
                                <textarea rows="4" name="message" class="form-control" placeholder="Write a message..."></textarea>
                                <input type="hidden" name="res_model" t-att-value="widget.options['res_model']"/>
                                <input type="hidden" name="res_id" t-att-value="widget.options['res_id']"/>
                                <input type="hidden" name="token" t-att-value="widget.options['token']" t-if="widget.options['token']"/>
                                <input type='hidden' name="pid" t-att-value="widget.options['pid']" t-if="widget.options['pid']"/>
                                <input type='hidden' name="hash" t-att-value="widget.options['hash']" t-if="widget.options['hash']"/>
                                <input type="hidden" name="sha_in" t-att-value="widget.options['sha_in']" t-if="widget.options['sha_in']"/>
                                <input type="hidden" name="sha_time" t-att-value="widget.options['sha_time']" t-if="widget.options['sha_time']"/>
                                <input type="hidden" name="redirect" t-att-value="discussion_url"/>
                                <input type="hidden" name="attachment_ids" class="o_portal_chatter_attachment_ids"/>
                                <input type="hidden" name="attachment_tokens" class="o_portal_chatter_attachment_tokens"/>
                                <div class="alert alert-danger mt8 mb0 o_portal_chatter_composer_error" style="display:none;" role="alert">
                                    Oops! Something went wrong. Try to reload the page and log in.
                                </div>
                                <div class="o_portal_chatter_attachments mt-3"/>
                                <div class="mt8">
                                    <button t-attf-class="o_portal_chatter_composer_btn btn btn-primary" type="submit">Send</button>
                                    <button class="o_portal_chatter_attachment_btn btn btn-secondary" type="button" title="Add attachment">
                                        <i class="fa fa-paperclip"/>
                                    </button>
                                </div>
                            </div>
                        </form>
                        <form class="d-none">
                            <input type="file" class="o_portal_chatter_file_input" multiple="multiple"/>
                        </form>
                    </div>
                </div>
            </t>
        </div>
    </t>

    <t t-name="portal.Chatter.Attachments">
        <div t-if="attachments.length" class="row">
            <div t-foreach="attachments" t-as="attachment" class="col-lg-2 col-md-3 col-sm-6">
                <div class="o_portal_chatter_attachment mb-2 position-relative text-center" t-att-data-id="attachment.id">
                    <button t-if="showDelete and attachment.state == 'pending'" class="o_portal_chatter_attachment_delete btn btn-sm btn-outline-danger" title="Delete">
                        <i class="fa fa-times"/>
                    </button>
                    <a t-attf-href="/web/content/#{attachment.id}?download=true&amp;access_token=#{attachment.access_token}" target="_blank">
                        <div class='oe_attachment_embedded o_image' t-att-title="attachment.name" t-att-data-mimetype="attachment.mimetype"/>
                        <div class='o_portal_chatter_attachment_name'><t t-esc='attachment.name'/></div>
                    </a>
                </div>
            </div>
        </div>
    </t>

    <!--
        Widget PortalChatter, and subtemplates
    -->

    <t t-name="portal.chatter_messages">
        <div class="o_portal_chatter_messages">
            <t t-foreach="widget.get('messages') || []" t-as="message">
                <div class="media o_portal_chatter_message" t-att-id="'message-' + message.id">
                    <img class="o_portal_chatter_avatar" t-att-src="message.author_avatar_url" alt="avatar"/>
                    <div class="media-body">
                        <t t-call="portal.chatter_internal_toggle" t-if="widget.options['is_user_employee']"/>

                        <div class="o_portal_chatter_message_title">
                            <h5 class='mb-1'><t t-esc="message.author_id[1]"/></h5>
                            <p class="o_portal_chatter_puslished_date"><t t-esc="message.published_date_str"/></p>
                        </div>
                        <t t-raw="message.body"/>

                        <div class="o_portal_chatter_attachments">
                            <t t-call="portal.Chatter.Attachments">
                                <t t-set="attachments" t-value="message.attachment_ids"/>
                            </t>
                        </div>
                    </div>
                </div>
            </t>
        </div>
    </t>

    <!-- Chatter: internal toggle widget -->
    <t t-name="portal.chatter_internal_toggle">
        <div t-attf-class="float-right o_portal_chatter_js_is_internal #{message.is_internal and 'o_portal_message_internal_on' or 'o_portal_message_internal_off'}"
                t-att-data-message-id="message.id"
                t-att-data-is-internal="message.is_internal">
            <button class="btn btn-danger"
                title="Currently restricted to internal employees, click to make it available to everyone viewing this document.">Employees Only</button>
            <button class="btn btn-success"
                title="Currently available to everyone viewing this document, click to restrict to internal employees.">Visible</button>
        </div>
    </t>

    <t t-name="portal.pager">
        <div class="o_portal_chatter_pager">
            <t t-if="!_.isEmpty(widget.get('pager'))">
                <ul class="pagination" t-if="widget.get('pager')['pages'].length &gt; 1">
                    <li t-if="widget.get('pager')['page'] != widget.get('pager')['page_previous']" t-att-data-page="widget.get('pager')['page_previous']" class="page-item o_portal_chatter_pager_btn">
                        <a href="#" class="page-link"><i class="fa fa-chevron-left" role="img" aria-label="Previous" title="Previous"/></a>
                    </li>
                    <t t-foreach="widget.get('pager')['pages']" t-as="page">
                        <li t-att-data-page="page" t-attf-class="page-item #{page == widget.get('pager')['page'] ? 'o_portal_chatter_pager_btn active' : 'o_portal_chatter_pager_btn'}">
                            <a href="#" class="page-link"><t t-esc="page"/></a>
                        </li>
                    </t>
                    <li t-if="widget.get('pager')['page'] != widget.get('pager')['page_next']" t-att-data-page="widget.get('pager')['page_next']" class="page-item o_portal_chatter_pager_btn">
                        <a href="#" class="page-link"><i class="fa fa-chevron-right" role="img" aria-label="Next" title="Next"/></a>
                    </li>
                </ul>
            </t>
        </div>
    </t>

    <t t-name="portal.Chatter">
        <div class="o_portal_chatter p-0">
            <div class="o_portal_chatter_header">
                <t t-call="portal.chatter_message_count"/>
            </div>
            <hr t-if="widget.options['allow_composer']"/>
            <div class="o_portal_chatter_composer"/>
            <hr/>
            <t t-call="portal.chatter_messages"/>
            <div class="o_portal_chatter_footer">
                <t t-call="portal.pager"/>
            </div>
        </div>
    </t>

</templates>