
/* /mass_mailing/static/src/js/mailing_portal_subscription.js */
odoo.define('@mass_mailing/js/mailing_portal_subscription',['@web/legacy/js/public/public_widget'],function(require){'use strict';let __exports={};const publicWidget=require("@web/legacy/js/public/public_widget")[Symbol.for("default")];publicWidget.registry.MailingPortalSubscription=publicWidget.Widget.extend({custom_events:{'blocklist_add':'_onBlocklistAdd','blocklist_remove':'_onBlocklistRemove','feedback_sent':'_onFeedbackSent','subscription_updated':'_onSubscriptionUpdated',},selector:'#o_mailing_portal_subscription',start:function(){this.customerData={...document.getElementById('o_mailing_portal_subscription').dataset};this.customerData.documentId=parseInt(this.customerData.documentId||0);this.customerData.mailingId=parseInt(this.customerData.mailingId||0);this.lastAction=this.customerData.lastAction;this.$bl_elem=this.$('#o_mailing_subscription_blocklist');this.$feedback_elem=this.$('#o_mailing_subscription_feedback');this.$form_elem=this.$('#o_mailing_subscription_form');this._attachBlocklist();this._attachFeedback();this._attachForm();this._updateDisplay();return this._super.apply(this,arguments);},_attachBlocklist:function(){if(this.$bl_elem.length){this.blocklistWidget=new publicWidget.registry.MailingPortalSubscriptionBlocklist(this,{customerData:this.customerData});this.blocklistWidget.attachTo(this.$bl_elem);}},_attachFeedback:function(){if(this.$feedback_elem.length){this.feedbackWidget=new publicWidget.registry.MailingPortalSubscriptionFeedback(this,{customerData:this.customerData});this.feedbackWidget.attachTo(this.$feedback_elem);this.feedbackWidget._setLastAction(this.lastAction);}},_attachForm:function(){if(this.$form_elem.length){this.formWidget=new publicWidget.registry.MailingPortalSubscriptionForm(this,{customerData:this.customerData});this.formWidget.attachTo(this.$form_elem);}},_onActionDone:function(callKey){this.lastAction=callKey;this._updateDisplay();},_onBlocklistAdd:function(event){const callKey=event.data.callKey;this.customerData.isBlocklisted=event.data.isBlocklisted;if(callKey==='blocklist_add'){this.customerData.feedbackEnabled=true;}
this._onActionDone(callKey);},_onBlocklistRemove:function(event){const callKey=event.data.callKey;this.customerData.isBlocklisted=false;if(callKey==='blocklist_remove'){this.customerData.feedbackEnabled=false;}
this._onActionDone(callKey);},_onFeedbackSent:function(event){const callKey=event.data.callKey;this.lastAction=callKey;},_onSubscriptionUpdated:function(event){const callKey=event.data.callKey;if(callKey==='subscription_updated_optout'){this.customerData.feedbackEnabled=true;}
else if(callKey==='subscription_updated'){this.customerData.feedbackEnabled=false;}
this._onActionDone(callKey);},_updateDisplay:function(){if(!this.customerData.feedbackEnabled&&this.$feedback_elem.length){this.$feedback_elem.addClass('d-none');}else if(this.$feedback_elem.length){this.$feedback_elem.removeClass('d-none');}
if(this.formWidget){this.formWidget._setBlocklisted(this.customerData.isBlocklisted);this.formWidget._setReadonly(this.customerData.isBlocklisted);}
if(this.feedbackWidget){this.feedbackWidget._setLastAction(this.lastAction);this.feedbackWidget._updateDisplay(true,false);}},});__exports[Symbol.for("default")]=publicWidget.registry.MailingPortalSubscription;return __exports;});odoo.define(`mailing.PortalSubscription`,['@mass_mailing/js/mailing_portal_subscription'],function(require){return require('@mass_mailing/js/mailing_portal_subscription')[Symbol.for("default")];});;

/* /mass_mailing/static/src/js/mailing_portal_subscription_blocklist.js */
odoo.define('@mass_mailing/js/mailing_portal_subscription_blocklist',['@web/core/network/rpc_service','@web/core/utils/render','@web/legacy/js/public/public_widget'],function(require){'use strict';let __exports={};const{jsonrpc}=require("@web/core/network/rpc_service");const{renderToElement}=require("@web/core/utils/render");const publicWidget=require("@web/legacy/js/public/public_widget")[Symbol.for("default")];publicWidget.registry.MailingPortalSubscriptionBlocklist=publicWidget.Widget.extend({events:{'click #button_blocklist_add':'_onBlocklistAddClick','click #button_blocklist_remove':'_onBlocklistRemoveClick',},init:function(parent,options){this.customerData=options.customerData;return this._super.apply(this,arguments);},start:function(){this._updateDisplay();return this._super.apply(this,arguments);},_onBlocklistAddClick:async function(event){event.preventDefault();return await jsonrpc('/mailing/blocklist/add',{document_id:this.customerData.documentId,email:this.customerData.email,hash_token:this.customerData.hashToken,mailing_id:this.customerData.mailingId,}).then((result)=>{if(result===true){this.customerData.isBlocklisted=true;}
this._updateDisplay();this._updateInfo(result===true?'blocklist_add':'error');this.trigger_up('blocklist_add',{'callKey':result===true?'blocklist_add':result,'isBlocklisted':result===true?true:this.customerData.isBlocklisted,},);});},_onBlocklistRemoveClick:async function(event){event.preventDefault();return await jsonrpc('/mailing/blocklist/remove',{document_id:this.customerData.documentId,email:this.customerData.email,hash_token:this.customerData.hashToken,mailing_id:this.customerData.mailingId,}).then((result)=>{if(result===true){this.customerData.isBlocklisted=false;}
this._updateDisplay();this._updateInfo(result===true?'blocklist_remove':'error');this.trigger_up('blocklist_remove',{'callKey':result===true?'blocklist_remove':result,'isBlocklisted':result===true?false:this.customerData.isBlocklisted,},);});},_updateDisplay:function(){const buttonAddNode=document.getElementById('button_blocklist_add');const buttonRemoveNode=document.getElementById('button_blocklist_remove');if(this.customerData.blocklistEnabled&&this.customerData.blocklistPossible&&!this.customerData.isBlocklisted){buttonAddNode.classList.remove('d-none');}else{buttonAddNode.classList.add('d-none');}
if(this.customerData.isBlocklisted){buttonRemoveNode.classList.remove('d-none');}else{buttonRemoveNode.classList.add('d-none');}},_updateInfo:function(infoKey){const updateInfo=document.getElementById('o_mailing_subscription_update_info');if(infoKey!==undefined){const infoContent=renderToElement("mass_mailing.portal.blocklist_update_info",{infoKey:infoKey,});updateInfo.innerHTML=infoContent.innerHTML;if(['blocklist_add','blocklist_remove'].includes(infoKey)){updateInfo.classList.add('text-success');updateInfo.classList.remove('text-danger');}
else{updateInfo.classList.add('text-danger');updateInfo.classList.remove('text-success');}
updateInfo.classList.remove('d-none');}
else{updateInfo.classList.add('d-none');}},});__exports[Symbol.for("default")]=publicWidget.registry.MailingPortalSubscriptionBlocklist;return __exports;});odoo.define(`mailing.PortalSubscriptionBlocklist`,['@mass_mailing/js/mailing_portal_subscription_blocklist'],function(require){return require('@mass_mailing/js/mailing_portal_subscription_blocklist')[Symbol.for("default")];});;

/* /mass_mailing/static/src/js/mailing_portal_subscription_feedback.js */
odoo.define('@mass_mailing/js/mailing_portal_subscription_feedback',['@web/core/l10n/translation','@web/core/network/rpc_service','@web/legacy/js/public/public_widget','@web/core/utils/render'],function(require){'use strict';let __exports={};const{_t}=require("@web/core/l10n/translation");const{jsonrpc}=require("@web/core/network/rpc_service");const publicWidget=require("@web/legacy/js/public/public_widget")[Symbol.for("default")];const{renderToElement}=require("@web/core/utils/render");publicWidget.registry.MailingPortalSubscriptionFeedback=publicWidget.Widget.extend({events:{'click #button_feedback':'_onFeedbackClick','click .o_mailing_subscription_opt_out_reason':'_onOptOutReasonClick',},init:function(parent,options){this.customerData=options.customerData;this.allowFeedback=false;this.lastAction=false;return this._super.apply(this,arguments);},start:function(){this._updateDisplay(true,false);return this._super.apply(this,arguments);},_onFeedbackClick:async function(event){event.preventDefault();const formData=new FormData(document.querySelector('div#o_mailing_subscription_feedback form'));const optoutReasonId=parseInt(formData.get('opt_out_reason_id'));return await jsonrpc('/mailing/feedback',{csrf_token:formData.get('csrf_token'),document_id:this.customerData.documentId,email:this.customerData.email,feedback:formData.get('feedback'),hash_token:this.customerData.hashToken,last_action:this.lastAction,mailing_id:this.customerData.mailingId,opt_out_reason_id:optoutReasonId,}).then((result)=>{if(result===true){this._updateDisplay(false,true);this._updateInfo('feedback_sent');}
else{this._updateDisplay(false,false);this._updateInfo(result);}
this.trigger_up('feedback_sent',{'callKey':result===true?'feedback_sent':result},);});},_onOptOutReasonClick:function(event){this.allowFeedback=$(event.currentTarget).data('isFeedback');this._updateDisplay()},_setLastAction:function(lastAction){this.lastAction=lastAction;if(this.lastAction==='blocklist_add'){document.querySelector('div#o_mailing_subscription_feedback p').innerHTML=_t('Please let us know why you want to be in our block list.');}
else{document.querySelector('div#o_mailing_subscription_feedback p').innerHTML=_t('Please let us know why you updated your subscription.');}},_updateDisplay:function(cleanFeedback,setReadonly){const feedbackArea=document.querySelector('div#o_mailing_subscription_feedback textarea');const feedbackButton=document.getElementById('button_feedback');const feedbackReasons=document.querySelectorAll('div#o_mailing_subscription_feedback input');const feedbackInfo=document.getElementById('o_mailing_subscription_feedback_info');if(this.allowFeedback){feedbackArea.classList.remove('d-none');}else{feedbackArea.classList.add('d-none');}
if(setReadonly){feedbackArea.setAttribute('disabled','disabled');feedbackButton.setAttribute('disabled','disabled');feedbackReasons.forEach(node=>node.setAttribute('disabled','disabled'));}
else{feedbackArea.removeAttribute('disabled');feedbackButton.removeAttribute('disabled');feedbackReasons.forEach(node=>node.removeAttribute('disabled'));}
if(cleanFeedback){feedbackArea.value='';feedbackInfo.innerHTML="";}},_updateInfo:function(infoKey){const feedbackInfo=document.getElementById('o_mailing_subscription_feedback_info');if(infoKey!==undefined){const infoContent=renderToElement("mass_mailing.portal.feedback_update_info",{infoKey:infoKey,});feedbackInfo.innerHTML=infoContent.innerHTML;feedbackInfo.classList.add(infoKey==='feedback_sent'?'text-success':'text-danger');feedbackInfo.classList.remove('d-none',infoKey==='feedback_sent'?'text-danger':'text-success');}
else{feedbackInfo.classList.add('d-none');}},});__exports[Symbol.for("default")]=publicWidget.registry.MailingPortalSubscriptionFeedback;return __exports;});odoo.define(`mailing.PortalSubscriptionFeedback`,['@mass_mailing/js/mailing_portal_subscription_feedback'],function(require){return require('@mass_mailing/js/mailing_portal_subscription_feedback')[Symbol.for("default")];});;

/* /mass_mailing/static/src/js/mailing_portal_subscription_form.js */
odoo.define('@mass_mailing/js/mailing_portal_subscription_form',['@web/core/network/rpc_service','@web/core/utils/render','@web/legacy/js/public/public_widget'],function(require){'use strict';let __exports={};const{jsonrpc}=require("@web/core/network/rpc_service");const{renderToFragment}=require("@web/core/utils/render");const publicWidget=require("@web/legacy/js/public/public_widget")[Symbol.for("default")];publicWidget.registry.MailingPortalSubscriptionForm=publicWidget.Widget.extend({events:{'click #button_form_send':'_onFormSend',},init:function(parent,options){this.customerData=options.customerData;return this._super.apply(this,arguments);},start:function(){const def=this._super.apply(this,arguments);this.listInfo=[...document.querySelectorAll('#o_mailing_subscription_form_manage input')].map(node=>{const listInfo={id:parseInt(node.getAttribute('value')),member:node.dataset.member==='1',name:node.getAttribute('title'),opt_out:node.getAttribute('checked')!=='checked',};return listInfo;});return def;},_onFormSend:async function(event){event.preventDefault();const formData=new FormData(document.querySelector('div#o_mailing_subscription_form form'));const mailingListOptinIds=formData.getAll('mailing_list_ids').map(id_str=>parseInt(id_str));return await jsonrpc('/mailing/list/update',{csrf_token:formData.get('csrf_token'),document_id:this.customerData.documentId,email:this.customerData.email,hash_token:this.customerData.hashToken,lists_optin_ids:mailingListOptinIds,mailing_id:this.customerData.mailingId,}).then((result)=>{const has_error=['error','unauthorized'].includes(result);let callKey;if(has_error){callKey='error';}
else{callKey=(parseInt(result)>0)?'subscription_updated_optout':'subscription_updated';this._updateDisplay(mailingListOptinIds);}
this._updateInfo(has_error?'error':'subscription_updated');this.trigger_up('subscription_updated',{'callKey':callKey},);});},_setBlocklisted:function(isBlocklisted){if(isBlocklisted){document.getElementById('o_mailing_subscription_form_blocklisted').classList.remove('d-none');document.getElementById('o_mailing_subscription_form_manage').classList.add('d-none');}
else{document.getElementById('o_mailing_subscription_form_blocklisted').classList.add('d-none');document.getElementById('o_mailing_subscription_form_manage').classList.remove('d-none');}},_setReadonly:function(isReadonly){const formInputNodes=document.querySelectorAll('#o_mailing_subscription_form_manage input');const formButtonNode=document.getElementById('button_form_send');if(isReadonly){formInputNodes.forEach(node=>{node.setAttribute('disabled','disabled')});formButtonNode.setAttribute('disabled','disabled');formButtonNode.classList.add('d-none');}else{formInputNodes.forEach(node=>{node.removeAttribute('disabled')});formButtonNode.removeAttribute('disabled');formButtonNode.classList.remove('d-none');}},_updateDisplay:function(listOptinIds){this.listInfo.forEach((listItem)=>{listItem.member=listItem.member||listOptinIds.includes(listItem.id);listItem.opt_out=!listOptinIds.includes(listItem.id);});const formContent=renderToFragment("mass_mailing.portal.list_form_content",{listsMember:this.listInfo.filter(item=>item.member===true),listsProposal:this.listInfo.filter(item=>item.member===false),});const manageForm=document.getElementById('o_mailing_subscription_form_manage');manageForm.replaceChildren(formContent);const formReadonlyContent=renderToFragment("mass_mailing.portal.list_form_content_readonly",{listsOptin:this.listInfo.filter(item=>item.opt_out===false),});const readonlyForm=document.getElementById('o_mailing_subscription_form_blocklisted');readonlyForm.replaceChildren(formReadonlyContent);},_updateInfo:function(infoKey){const updateInfo=document.getElementById('o_mailing_subscription_update_info');if(infoKey!==undefined){const infoContent=renderToFragment("mass_mailing.portal.list_form_update_info",{infoKey:infoKey,});updateInfo.replaceChildren(infoContent);updateInfo.classList.add(infoKey==='error'?'text-danger':'text-success');updateInfo.classList.remove('d-none');}
else{updateInfo.classList.add('d-none');}},});__exports[Symbol.for("default")]=publicWidget.registry.MailingPortalSubscriptionForm;return __exports;});odoo.define(`mailing.PortalSubscriptionForm`,['@mass_mailing/js/mailing_portal_subscription_form'],function(require){return require('@mass_mailing/js/mailing_portal_subscription_form')[Symbol.for("default")];});

                    /*******************************************
                    *  Templates                               *
                    *******************************************/

                    odoo.define('mass_mailing.mailing_assets.bundle.xml', ['@web/core/registry'], function(require){
                        'use strict';
                        const { registry } = require('@web/core/registry');
                        registry.category(`xml_templates`).add(`mass_mailing.mailing_assets`, `<?xml version="1.0" encoding="UTF-8"?>
<templates xml:space="preserve">
<t t-name="mass_mailing.portal.blocklist_update_info">
        <span>
            <t t-if="infoKey == 'blocklist_add'">
                <i class="fa fa-check me-1"/>
                <span>Email added to our blocklist</span>
            </t>
            <t t-elif="infoKey == 'blocklist_remove'">
                <i class="fa fa-check me-1"/>
                <span>Email removed from our blocklist</span>
            </t>
            <t t-else="">
                <i class="fa fa-exclamation-triangle me-1"/>
                <span>An error occurred. Please retry later.</span>
            </t>
        </span>
    </t>
<t t-name="mass_mailing.portal.feedback_update_info">
        <span>
            <t t-if="infoKey == 'feedback_sent'">
                <i class="fa fa-check me-1"/>
                <span>Sent. Thanks you for your feedback!</span>
            </t>
            <t t-else="">
                <i class="fa fa-exclamation-triangle me-1"/>
                <span>An error occurred. Please retry later or contact us.</span>
            </t>
        </span>
    </t>
<t t-name="mass_mailing.portal.list_form_content">
        <p t-if="listsMember.length">
            Choose your mailing subscriptions
        </p>
        <ul id="o_mailing_subscription_form_lists" t-if="listsMember.length" class="list-group">
            <li t-foreach="listsMember" t-as="mailing_list" t-key="mailing_list_key" class="list-group-item d-flex align-items-center">
                <input type="checkbox" name="mailing_list_ids" t-att-data-member="1" t-att-value="mailing_list['id']" t-att-checked="mailing_list['opt_out'] ? undefined : 'checked'" t-att-title="mailing_list['name']"/>
                <span class="ms-1" t-out="mailing_list['name']"/>
                <span class="o_mailing_list_unsubscribed ms-auto">
                    <t t-if="mailing_list['opt_out']">
                        Not subscribed
                    </t>
                    <t t-else="">
                        Subscribed
                    </t>
                </span>
            </li>
        </ul>
        <p t-if="listsProposal.length">
            You may also be interested in
        </p>
        <ul id="o_mailing_subscription_form_lists_additional" t-if="listsProposal.length" class="list-group">
            <li t-foreach="listsProposal" t-as="mailing_list" t-key="mailing_list_key" class="list-group-item">
                <input type="checkbox" name="mailing_list_ids" t-att-value="mailing_list['id']" t-att-title="mailing_list['name']"/>
                <span class="ms-1" t-out="mailing_list['name']"/>
            </li>
        </ul>
    </t>


    <t t-name="mass_mailing.portal.list_form_content_readonly">
        <p>
            Your email is currently <strong>in our block list</strong>.
            <t t-if="listsOptin.length">
                You will not receive any news from those mailing lists you are a member of:
            </t>
            <t t-else="">
                You will not hear from us anymore.
            </t>
        </p>
        <ul class="list-group mb-4" t-if="listsOptin.length">
            <t t-foreach="listsOptin" t-as="mailing_list" t-key="mailing_list_key">
                <li class="list-group-item d-flex align-items-center">
                    <strong t-out="mailing_list['name']"/>
                </li>
            </t>
        </ul>
    </t>


    <t t-name="mass_mailing.portal.list_form_update_info">
        <t t-if="infoKey == 'subscription_updated'">
            <i class="fa fa-check me-1"/>
            <span>Membership updated</span>
        </t>
        <t t-else="">
            <i class="fa fa-exclamation-triangle me-1"/>
            <span>An error occurred. Please retry later.</span>
        </t>
    </t>

</templates>`);
                    });