<!--#set global $pane="Email"#-->
<!--#set global $help_uri = $confighelpuri + "notifications"#-->
<!--#include $webdir + "/_inc_header_uc.tmpl"#-->

<!--#import apprise#-->

<!--#def show_notify_checkboxes($section_label)#-->
    <!--#for $type in $notify_types#-->
        <div class="field-pair">
            <label class="config wide" for="${section_label}_prio_$type">
                $T($notify_types[$type]).replace('/', ' / ')
            </label>
            <input type="checkbox" name="${section_label}_prio_$type" id="${section_label}_prio_$type" value="1" <!--#if $getVar($section_label + '_prio_' + $type) then 'checked="checked"' else ""#--> />
        </div>
    <!--#end for#-->
<!--#end def#-->

<!--#def show_cat_box($section_label)#-->
    <div class="col2-cats" <!--#if $getVar($section_label + '_enable') then '' else 'style="display:none"'#-->>
        <hr>
        <b>$T('affectedCat')</b><br/>
        <select name="${section_label}_cats" multiple="multiple" class="multiple_cats" size="$len($categories)">
            <!--#for $ct in $categories#-->
                <option value="$ct" <!--#if $ct in $getVar($section_label + '_cats') then 'selected="selected"' else ""#-->>$Tspec($ct)</option>
            <!--#end for#-->
        </select>
        <p>$T('defaultNotifiesAll')</p>
    </div>
<!--#end def#-->

<div class="colmask">
    <form action="saveNotify" method="post" name="fullform" class="fullform" autocomplete="off">
    <input type="hidden" id="apikey" name="apikey" value="$apikey" />
    <input type="hidden" name="output" value="json" />
    <input type="hidden" id="ajax" name="ajax" value="1" />
    <div class="section" id="email">
        <div class="col2">
            <h3>$T('cmenu-email') <a href="$help_uri#toc0" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
            <div class="col2-cats" <!--#if int($email_endjob) > 0 then '' else 'style="display:none"'#-->>
                <b>$T('affectedCat')</b><br/>
                <select name="email_cats" multiple="multiple" class="multiple_cats" size="$len($categories)">
                    <!--#for $ct in $categories#-->
                        <option value="$ct" <!--#if $ct in $email_cats then 'selected="selected"' else ""#-->>$Tspec($ct)</option>
                    <!--#end for#-->
                </select>
                <p>$T('defaultNotifiesAll')</p>
            </div>
        </div>
        <div class="col1">
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="email_endjob">$T('opt-email_endjob')</label>
                    <select name="email_endjob" id="email_endjob">
                        <option value="0" <!--#if int($email_endjob) == 0 then 'selected="selected"' else ""#--> >$T('email-never')</option>
                        <option value="1" <!--#if int($email_endjob) == 1 then 'selected="selected"' else ""#--> >$T('email-always')</option>
                        <option value="2" <!--#if int($email_endjob) == 2 then 'selected="selected"' else ""#--> >$T('email-errorOnly')</option>
                    </select>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_full">$T('opt-email_full')</label>
                    <input type="checkbox" name="email_full" id="email_full" value="1" <!--#if $email_full then 'checked="checked"' else ""#--> />
                    <span class="desc">$T('explain-email_full')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_rss">$T('opt-email_rss')</label>
                    <input type="checkbox" name="email_rss" id="email_rss" value="1" <!--#if $email_rss then 'checked="checked"' else ""#--> />
                    <span class="desc">$T('explain-email_rss')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_server">$T('opt-email_server')</label>
                    <input type="text" name="email_server" id="email_server" value="$email_server" />
                    <span class="desc">$T('explain-email_server') ($T('host'):$T('srv-port'))</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_to">$T('opt-email_to')</label>
                    <input type="text" name="email_to" id="email_to" value="$email_to" />
                    <span class="desc">$T('explain-email_to')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_from">$T('opt-email_from')</label>
                    <input type="text" name="email_from" id="email_from" value="$email_from" />
                    <span class="desc">$T('explain-email_from')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_account">$T('opt-email_account')</label>
                    <input type="text" name="email_account" id="email_account" value="$email_account" />
                    <span class="desc">$T('explain-email_account')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="email_pwd">$T('opt-email_pwd')</label>
                    <input type="text" name="email_pwd" id="email_pwd" value="$email_pwd" />
                    <span class="desc">$T('explain-email_pwd')</span>
                </div>
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_email" rel="$T('askTestEmail')"><span class="glyphicon glyphicon-envelope"></span> $T('link-testEmail')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
            </fieldset>
        </div>
    </div>
    <!--#if $have_ncenter#-->
    <div class="section">
        <div class="col2">
            <h3>$T('section-NC')</h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="ncenter_enable" id="ncenter_enable" value="1" <!--#if $ncenter_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="ncenter_enable"> $T('opt-ncenter_enable')</label></td>
                </tr>
            </table>
        </div>
        <div class="col1" <!--#if $ncenter_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                $show_notify_checkboxes('ncenter')
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_notif"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
               </div>
               <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
           </fieldset>
       </div>
    </div>
    <!--#end if#-->
    <!--#if $windows#-->
    <div class="section">
        <div class="col2">
            <h3>$T('section-AC')</h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="acenter_enable" id="acenter_enable" value="1" <!--#if $acenter_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="acenter_enable"> $T('opt-acenter_enable')</label></td>
                </tr>
            </table>
            $show_cat_box('acenter')
        </div>
        <div class="col1" <!--#if $acenter_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                $show_notify_checkboxes('acenter')
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_windows"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
               </div>
               <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
           </fieldset>
       </div>
    </div>
    <!--#end if#-->
    <!--#if $have_ntfosd#-->
    <div class="section">
        <div class="col2">
            <h3>$T('section-OSD') <a href="$help_uri#toc4" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="ntfosd_enable" id="ntfosd_enable" value="1" <!--#if $ntfosd_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="ntfosd_enable"> $T('opt-ntfosd_enable')</label></td>
                </tr>
            </table>
            $show_cat_box('ntfosd')
        </div>
        <div class="col1" <!--#if $ntfosd_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                $show_notify_checkboxes('ntfosd')
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_osd"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
               </div>
               <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
           </fieldset>
       </div>
    </div>
    <!--#end if#-->
    <div class="section" id="apprise">
        <div class="col2">
            <h3>Apprise <a href="$help_uri#apprise" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="apprise_enable" id="apprise_enable" value="1" <!--#if $apprise_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="apprise_enable"> $T('opt-apprise_enable')</label></td>
                </tr>
            </table>
            <p>$T('explain-apprise_enable')</p>
            <p><a href="https://appriseit.com/" target="_blank">Apprise documentation</a></p>
            <p>$T('version'): ${apprise.__version__}</p>

            $show_cat_box('apprise')
        </div>
        <div class="col1" <!--#if $apprise_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="apprise_urls">$T('opt-apprise_urls')</label>
                    <input type="text" name="apprise_urls" id="apprise_urls" value="$apprise_urls" />
                    <span class="desc">$T('explain-apprise_urls')</span>
                </div>
                <div class="field-pair">
                    <span class="desc">$T('explain-apprise_extra_urls')</span>
                </div>
                <!--#set $section_label = 'apprise'#-->
                <!--#for $type in $notify_types#-->
                    <div class="field-pair">
                        <label class="config" for="${section_label}_target_${type}">
                            $T($notify_types[$type]).replace('/', ' / ')
                        </label>
                        <input type="checkbox" name="${section_label}_target_${type}_enable" id="${section_label}_target_${type}_enable" value="1" <!--#if $getVar($section_label + '_target_' + $type + '_enable') then 'checked="checked"' else ""#--> />
                        <input type="text" name="${section_label}_target_${type}" id="${section_label}_target_${type}" value="$getVar($section_label + '_target_' + $type)"  placeholder="$T('opt-apprise_urls')" />
                    </div>
                <!--#end for#-->

                <div class="field-pair no-field-pair-bg">
                   <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                   <button class="btn btn-default" type="button" id="test_apprise"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
           </fieldset>
       </div>
    </div>
    <div class="section" id="nscript">
        <div class="col2">
            <h3>$T('section-NScript') <a href="$help_uri#nscript" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a></h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="nscript_enable" id="nscript_enable" value="1" <!--#if $nscript_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="nscript_enable"> $T('opt-nscript_enable')</label></td>
                </tr>
            </table>
            <em>$T('explain-nscript_enable')</em><br><a href="$help_uri#nscript" target="_blank">$T('readwiki')</a>
            $show_cat_box('nscript')
        </div>
        <div class="col1" <!--#if $nscript_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="nscript_script">$T('opt-nscript_script')</label>
                    <select name="nscript_script" id="nscript_script">
                        <!--#for $sc in $scripts#-->
                        <option value="$sc" <!--#if $nscript_script == $sc then 'selected="selected"' else ""#-->>$Tspec($sc)</option>
                        <!--#end for#-->
                    </select>
                    <span class="desc">$T('explain-nscript_script')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="nscript_parameters">$T('opt-nscript_parameters')</label>
                    <input type="text" name="nscript_parameters" id="nscript_parameters" value="$nscript_parameters" />
                    <span class="desc">$T('Optional') - $T('readwiki')</span>
                </div>
                $show_notify_checkboxes('nscript')
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_nscript"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
            </fieldset>
        </div>
    </div>
    <div class="section" id="prowl">
        <div class="col2">
            <h3>$T('section-Prowl')</h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="prowl_enable" id="prowl_enable" value="1" <!--#if $prowl_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="prowl_enable"> $T('opt-prowl_enable')</label></td>
                </tr>
            </table>
            <em>$T('explain-prowl_enable')</em>
            $show_cat_box('prowl')
        </div>
        <div class="col1" <!--#if $prowl_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="prowl_apikey">$T('opt-prowl_apikey')</label>
                    <input type="text" name="prowl_apikey" id="prowl_apikey" value="$prowl_apikey" />
                    <span class="desc">$T('explain-prowl_apikey')</span>
                </div>
                <!--#set $section_label = 'prowl'#-->
                <!--#for $type in $notify_types#-->
                    <div class="field-pair">
                        <label class="config" for="${section_label}_prio_$type">
                            $T($notify_types[$type]).replace('/', ' / ')
                        </label>
                        <select name="${section_label}_prio_$type" id="${section_label}_prio_$type">
                            <option value="-3" <!--#if $getVar($section_label + '_prio_' + $type) == -3 then 'selected="selected"' else ""#--> >$T('prowl-off')</option>
                            <option value="-2" <!--#if $getVar($section_label + '_prio_' + $type) == -2 then 'selected="selected"' else ""#--> >$T('prowl-very-low')</option>
                            <option value="-1" <!--#if $getVar($section_label + '_prio_' + $type) == -1 then 'selected="selected"' else ""#--> >$T('prowl-moderate')</option>
                            <option value="0"  <!--#if $getVar($section_label + '_prio_' + $type) == 0  then 'selected="selected"' else ""#--> >$T('prowl-normal')</option>
                            <option value="1"  <!--#if $getVar($section_label + '_prio_' + $type) == 1  then 'selected="selected"' else ""#--> >$T('prowl-high')</option>
                            <option value="2"  <!--#if $getVar($section_label + '_prio_' + $type) == 2  then 'selected="selected"' else ""#--> >$T('prowl-emergency')</option>
                        </select>
                    </div>
                <!--#end for#-->
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_prowl"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
            </fieldset>
        </div>
    </div>

    <div class="section" id="pushover">
        <div class="col2">
            <h3>$T('section-Pushover')</h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="pushover_enable" id="pushover_enable" value="1" <!--#if $pushover_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="pushover_enable"> $T('opt-pushover_enable')</label></td>
                </tr>
            </table>
            <em>$T('explain-pushover_enable')</em>
            $show_cat_box('pushover')
        </div>
        <div class="col1" <!--#if $pushover_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="pushover_token">$T('opt-pushover_token')</label>
                    <input type="text" name="pushover_token" id="pushover_token" value="$pushover_token" />
                    <span class="desc">$T('explain-pushover_token')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="pushover_userkey">$T('opt-pushover_userkey')</label>
                    <input type="text" name="pushover_userkey" id="pushover_userkey" value="$pushover_userkey" />
                    <span class="desc">$T('explain-pushover_userkey')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="pushover_device">$T('opt-pushover_device')</label>
                    <input type="text" name="pushover_device" id="pushover_device" value="$pushover_device" />
                    <span class="desc">$T('explain-pushover_device')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="pushover_emergency_retry">$T('opt-pushover_emergency_retry')</label>
                    <input type="text" name="pushover_emergency_retry" id="pushover_emergency_retry" value="$pushover_emergency_retry" />
                    <span class="desc">$T('explain-pushover_emergency_retry')</span>
                </div>
                <div class="field-pair">
                    <label class="config" for="pushover_emergency_expire">$T('opt-pushover_emergency_expire')</label>
                    <input type="text" name="pushover_emergency_expire" id="pushover_emergency_expire" value="$pushover_emergency_expire" />
                    <span class="desc">$T('explain-pushover_emergency_expire')</span>
                </div>
                <!--#set $section_label = 'pushover'#-->
                <!--#for $type in $notify_types#-->
                    <div class="field-pair">
                        <label class="config" for="${section_label}_prio_$type">
                            $T($notify_types[$type]).replace('/', ' / ')
                        </label>
                        <select name="${section_label}_prio_$type" id="${section_label}_prio_$type">
                            <option value="-3" <!--#if $getVar($section_label + '_prio_' + $type) == -3 then 'selected="selected"' else ""#--> >$T('pushover-off')</option>
                            <option value="-2" <!--#if $getVar($section_label + '_prio_' + $type) == -2 then 'selected="selected"' else ""#--> >$T('prowl-very-low')</option>
                            <option value="-1" <!--#if $getVar($section_label + '_prio_' + $type) == -1 then 'selected="selected"' else ""#--> >$T('pushover-low')</option>
                            <option value="0"  <!--#if $getVar($section_label + '_prio_' + $type) == 0  then 'selected="selected"' else ""#--> >$T('prowl-normal')</option>
                            <option value="1"  <!--#if $getVar($section_label + '_prio_' + $type) == 1  then 'selected="selected"' else ""#--> >$T('pushover-high')</option>
                            <option value="2"  <!--#if $getVar($section_label + '_prio_' + $type) == 2  then 'selected="selected"' else ""#--> >$T('prowl-emergency')</option>
                        </select>
                    </div>
                <!--#end for#-->
                <div class="field-pair no-field-pair-bg">
                    <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                    <button class="btn btn-default" type="button" id="test_pushover"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
            </fieldset>
        </div>
    </div>
    <div class="section" id="pushbullet">
        <div class="col2">
            <h3>$T('section-Pushbullet')</h3>
            <table>
                <tr>
                    <td><input type="checkbox" name="pushbullet_enable" id="pushbullet_enable" value="1" <!--#if $pushbullet_enable then 'checked="checked"' else ""#--> /></td>
                    <td><label for="pushbullet_enable"> $T('opt-pushbullet_enable')</label></td>
                </tr>
            </table>
            <em>$T('explain-pushbullet_enable')</em>
            $show_cat_box('pushbullet')
        </div>
        <div class="col1" <!--#if $pushbullet_enable then '' else 'style="display:none"'#-->>
            <fieldset>
                <div class="field-pair">
                    <label class="config" for="pushbullet_apikey">$T('opt-pushbullet_apikey')</label>
                    <input type="text" name="pushbullet_apikey" id="pushbullet_apikey" value="$pushbullet_apikey" />
                    <span class="desc">$T('explain-pushbullet_apikey')</span>
                </div>
                <!--#if 0#-->
                <div class="field-pair">
                    <label class="config" for="pushbullet_device">$T('opt-pushbullet_device')</label>
                    <input type="text" name="pushbullet_device" id="pushbullet_device" value="$pushbullet_device" />
                    <span class="desc">$T('explain-pushbullet_device')</span>
                </div>
                <!--#end if#-->
                $show_notify_checkboxes('pushbullet')
                <div class="field-pair no-field-pair-bg">
                   <button class="btn btn-default saveButton"><span class="glyphicon glyphicon-ok"></span> $T('button-saveChanges')</button>
                   <button class="btn btn-default" type="button" id="test_pushbullet"><span class="glyphicon glyphicon-comment"></span> $T('testNotify')</button>
                </div>
                <div class="field-pair result-box">
                    <div class="alert"></div>
                </div>
           </fieldset>
       </div>
    </div>
    </form>
</div><!-- /colmask -->

<script type="text/javascript">
jQuery(document).ready(function(){
    // Expand on enable
    jQuery('.col2 input[name$="enable"]').change(function() {
        if(this.checked) {
            jQuery(this).parents('.section').find('.col1').show()
            jQuery(this).parents('.col2').find('.col2-cats').show()
        } else {
            jQuery(this).parents('.section').find('.col1').hide()
            jQuery(this).parents('.col2').find('.col2-cats').hide()
        }
        jQuery('form').submit()
        addRowColor()
    })
    jQuery('#email_endjob').change(function() {
        if(jQuery(this).val() > 0) {
            jQuery(this).parents('.section').find('.col2-cats').show()
        } else {
            jQuery(this).parents('.section').find('.col2-cats').hide()
        }
    })

    /**
        Testing functions
    **/
    function testNotification(buttonObj) {
        // Confirm?
        if(jQuery(buttonObj).attr('rel')) {
            if(!confirm(jQuery(buttonObj).attr('rel'))) return false;
        }
        // Disable button and get the data
        jQuery(buttonObj).attr("disabled", "disabled")
        jQuery(buttonObj).find('span').toggleClass('glyphicon-comment glyphicon-refresh spin-glyphicon')
        var data = { mode: buttonObj.id, apikey: '$apikey', output: 'json' };
        jQuery(buttonObj).parents('.section').extractFormDataTo(data);

        // Clear up the box
        resultBox = jQuery(buttonObj).parents('.section').find('.result-box .alert');

        // Get the request
        jQuery.ajax({
            type: "GET",
            url: "../../api",
            data: data
        }).then(function(data) {
            // Remove disabled and make the box
            jQuery(buttonObj).removeAttr("disabled")
            jQuery(buttonObj).find('span').toggleClass('glyphicon-comment glyphicon-refresh spin-glyphicon')
            resultBox.removeClass('alert-success alert-danger').show()
            if(data.status) {
                resultBox.addClass('alert-success')
                resultBox.text('$T('notifications-notesent')')
                resultBox.prepend('<span class="glyphicon glyphicon-ok-sign"></span> ')
            } else {
                resultBox.addClass('alert-danger')
                resultBox.text(data.error)
                resultBox.prepend('<span class="glyphicon glyphicon-exclamation-sign"></span> ')
            }
        })
    }
    jQuery('#test_email, #test_notif, #test_windows, #test_apprise, #test_pushbullet, #test_pushover, #test_prowl, #test_osd, #test_nscript').click(function () {
        testNotification(this)
    })
});
</script>

<!--#include $webdir + "/_inc_footer_uc.tmpl"#-->
