<?xml version="1.0" encoding="utf-8"?>
<openerp>
    <data>
        <!--Survey send invitation by email: template -->
        <record id="email_template_survey" model="email.template">
            <field name="name">Survey - Send by Email</field>
            <field name="model_id" ref="model_survey_survey" />
            <field name="auto_delete" eval="True" />
            <field name="body_html">
                <![CDATA[
                <div style="font-family: 'Lucida Grande', Ubuntu, Arial, Verdana, sans-serif; font-size: 12px; color: rgb(34, 34, 34); ">
                    <p>Hello,</p>
                    <p>We are conducting a survey, and your response would be appreciated.</p>
                    <p><a href="__URL__">Please, click here to start survey</a></p>
                    <p>Thanks for your participation!</p>
                </div>
                ]]>
            </field>
        </record>

        <!-- Replace the default mass-mailing wizard in base with the composition wizard -->
        <act_window name="Partner Survey Mailing" res_model="survey.mail.compose.message" src_model="res.partner" view_mode="form" multi="True" target="new" key2="client_action_multi" id="survey.action_partner_survey_mail" context="{'default_use_template': True, 'default_template_id': ref('email_template_survey')}" />

        <!-- Composition form (context['survey_resent_token'], if True, hide share option, emails list and partner_ids) -->
        <record model="ir.ui.view" id="survey_email_compose_message">
            <field name="name">survey.mail.compose.message.form</field>
            <field name="model">survey.mail.compose.message</field>
            <field name="arch" type="xml">
                <form string="Compose Email">
                    <field name="composition_mode" invisible="1"/>
                    <field name="model" invisible="1"/>
                    <field name="res_id" invisible="1"/>
                    <field name="parent_id" invisible="1"/>
                    <group col="2">
                        <field name="survey_id" readonly="context.get('default_survey_id')" on_change="onchange_survey_id(survey_id)" />
                        <field name="public" widget="radio" invisible="context.get('survey_resent_token')" />
                    </group>
                    <group col="1" invisible="context.get('survey_resent_token')" attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}" class="oe_survey_email_public">
                        <div>
                            You can share your survey web public link and/or send private invitations to your audience. People can answer once per invitation, and whenever they want with the public web link (in this case, the "Public in website" setting must be enabled).
                        </div>
                        <div>Copy, paste and share the web link below to your audience.</div>
                        <code><field name="public_url"/></code>
                        <div>Copy and paste the HTML code below to add this web link to any webpage.</div>
                        <code><field name="public_url_html" /></code>
                    </group>
                    <group col="1" attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">
                        <group col="2">
                            <field invisible="context.get('survey_resent_token')" name="partner_ids" widget="many2many_tags_email" placeholder="Add list of existing contacts..." context="{'force_email':True, 'show_email':True}" />
                            <field invisible="context.get('survey_resent_token')" name="multi_email" placeholder="Add list of email of recipients (will not converted in partner), separated by commas, semicolons or newline..." on_change="onchange_multi_email(multi_email)" />
                            <field name="subject" placeholder="Subject..."/>
                        </group>
                        <field name="body" />
                        <group col="2">
                            <div>
                                <label for="attachment_ids" />
                                <field name="attachment_ids" widget="many2many_binary" />
                            </div>
                            <div class="oe_survey_date_deadline">
                                <label for="date_deadline" />
                                <field name="date_deadline" />
                            </div>
                        </group>
                    </group>
                    <footer attrs="{'invisible':[('public','in',['email_private', 'email_public_link'])]}">
                        <button string="Close" class="oe_link" special="cancel" />
                    </footer>
                    <footer attrs="{'invisible':['|',('public','=',False),('public','in',['public_link'])]}">
                        <button string="Send" name="send_mail" type="object" class="oe_highlight" />
                        or
                        <button string="Cancel" class="oe_link" special="cancel" />
                        <group class="oe_right" col="1">
                            <div>
                                Use template
                                <field name="template_id" nolabel="1" on_change="onchange_template_id(template_id, composition_mode, model, res_id, context)" />
                            </div>
                            <button icon="/email_template/static/src/img/email_template_save.png" type="object" name="save_as_template" string="Save as new template" class="oe_link" help="Save as a new template" />
                        </group>
                    </footer>
                </form>
            </field>
        </record>
    </data>
</openerp>
