<%inherit file="/layout/wizard.html"/>
<%namespace file="/lib.html" import="csrf_hidden_input, wizard_cancel_delete, wizard_errors"/>

<div class="content alertStep2">
    <%include file="_steps.html" args="step=2"/>
    <form method="post" action="${make_url(['scheduledigestwizard', app, 'step2', 'update']) | h}">
        ${wizard_errors(header=_('Your alert settings could not be saved.'), errors=saved_search.errors)}
        ${csrf_hidden_input()}
        <input type="hidden" name="id" value="${saved_search.id | h}"/>
        <table>
            <tbody>
                <tr>
                    <td class="col1"><label for="">${_('Enable actions')}</label></td>
                    <td class="col2">
                        <ul>
                            <li>
                                <input type="checkbox" name="action.email.enabled" id="action_email_enabled" value="1" ${'checked="checked"' if saved_search.action.email.enabled else ''}/>
                                <label for="action_email_enabled">${_('Send email')}</label>
                                <ul class="email indent">
                                    <li>
                                        <p class="note">${_('To send email you must set a valid MTA in email alert settings. <a href="%s" class="spl-icon-external-link-xsm" target="_blank">Learn more</a>.</em>') % generateSelfHelpLink('learnmore.alert.email')}</p>
                                    </li>
                                    <li>
                                        <label for="action_email_to">${_('Addresses')}</label>
                                        <textarea name="action.email.to" id="action_email_to" placeholder="${_('Semi-colon separated list of email addresses')}">${saved_search.action.email.to or '' | h }</textarea>
                                    </li>
                                    <li>
                                        <label for="action_email_subject">${_('Subject')}</label>
                                        <input type="text" name="action.email.subject" id="action_email_subject" value="${saved_search.action.email.subject or '' | h}"/>
                                    </li>
                                    <li>
                                        <input type="checkbox" name="ui_include_enabled" id="ui_include_enabled" value="1" ${'checked="checked"' if saved_search.ui_include_enabled else ''}/>
                                        <label for="ui_include_enabled">${_('Include results')}</label>
                                        <select name="ui_include_type" style="width:80px;">
                                            <option value="csv"${' selected="selected"'if saved_search.ui_include_type=='csv' else ''}>${_('as CSV')}</option>
                                            <option value="inline"${' selected="selected"'if saved_search.ui_include_type=='inline' else ''}>${_('inline')}</option>
                                            % if saved_search.ui_allow_pdf:
                                                <option value="pdf"${' selected="selected"'if saved_search.ui_include_type=='pdf' else ''}>${_('as PDF')}</option>
                                            % endif
                                        </select>
                                    </li>
                                </ul>
                            </li>
                            <li>
                                <input type="checkbox" name="action.script.enabled" id="action_script_enabled" value="1" ${'checked="checked"' if saved_search.action.script.enabled else ''}/>
                                <label for="action_script_enabled">${_('Run a script')}</label>

                                <div class="script indent">
                                    <label>$SPLUNK_HOME/bin/scripts/</label>
                                    <input type="text" name="action.script.filename" value="${saved_search.action.script.filename or '' | h}" placeholder="${_('Script filename')}"/>
                                </div>
                            </li>
                        </ul>
                    </td>
                </tr>
            </tbody>
        </table>
    </form>
</div>

<ul class="buttons splClearfix">
    <li class="left">${wizard_cancel_delete(make_url(['scheduledigestwizard', app, 'delete']), saved_search.id)}</li>
    <li class="right"><button class="splButton-primary" type="submit" onclick="$(document.forms[0]).trigger('submit');"><span>${_('Next &#187;')}</span></button></li>
    <li class="right"><a href="${make_url(['scheduledigestwizard', app, 'step1', 'edit'], _qs=dict(id=saved_search.id)) | h}" class="splButton-secondary"><span>${_('&#171; Back')}</span></a></li>
</ul>

<script>
(function(){
    function CheckboxToggle($checkbox, $toggle){
        this.$checkbox = $checkbox;
        this.$toggle = $toggle;
        var that = this;
        $checkbox.bind('click', function() {
            that.setVisibility(this.checked);
        });
        this.setVisibility($checkbox[0].checked);
    }
    CheckboxToggle.prototype.setVisibility = function(isVisible) {
        if (isVisible) {
            this.$toggle.show();
        } else {
            this.$toggle.hide();
        }
    };
    new CheckboxToggle($('input[name="action.email.enabled"]'), $('.email'));
    new CheckboxToggle($('input[name="action.script.enabled"]'), $('.script'));
})()
</script>
