{extends "base.tpl.html"}
{block "title"}#{$issue_id} - Post Note{/block}

{block "content"}
{if $post_result|default:'' != ''}
<script type="text/javascript">
    <!--
    {if $garlic_prefix|default:'' != ''}
    Eventum.clearAutoSave('{$garlic_prefix|escape}');
    {/if}
    {if $core.current_user_prefs.close_popup_windows}
        setTimeout('Eventum.close_and_refresh()', 2000);
    {/if}
    //-->
</script>
<br />
{if not $core.current_user_prefs.close_popup_windows}
<center>
    <span><a href="javascript:void(null);" onClick="Eventum.close_and_refresh();">{t}Continue{/t}</a></span>
</center>
{/if}
{else}

<script type="text/javascript">
    <!--
    function validateForm()
    {
        if (Validation.isFieldWhitespace('title')) {
            Validation.errors[Validation.errors.length] = new Option('{t escape=js}Title{/t}', 'title');
        }
        if (Validation.isFieldWhitespace('note')) {
            Validation.errors[Validation.errors.length] = new Option('{t escape=js}Body{/t}', 'note');
        }

        var now = new Date();
        var d1 = Eventum.makeDate('date');
        if (d1 > now) {
            alert('{t}Start time in the future.{/t}');
            return false;
        }
        var d2 = Eventum.makeDate('date2');
        if (d2 > now) {
            alert('{t}End time in the future.{/t}');
            return false;
        }
        return true;
    }
    function clearExtraRecipients()
    {
        $('select[name=' + Eventum.escapeSelector('note_cc[]') + ']').val('');
    }
    var old_message = '';
    function setSignature()
    {

        var signature = "{$core.current_user_prefs.email_signature|replace:'"':'\"'|replace:"\r":""|replace:"\n":'\n'}";

        var note = $('#note');
        if ($('#add_email_signature').is(":checked")) {
            old_message = note.val()
            note.val(note.val() + "\n" + signature);
        } else {
            note.val(old_message);
        }
    }

    $().ready(function() {
        $('#clear_note_cc').click(clearExtraRecipients);
        $('#add_email_signature').click(setSignature);

        var $post_note_form = $('#post_note_form');
        var field_keys = ['garlic', $post_note_form.find('input[name=issue_id]').val(),
            $post_note_form.find('input[name=parent_id]').val(), $post_note_form.data('sup-id')];

        var garlic_prefix = field_keys.join('_');
        $('#garlic_prefix').val(garlic_prefix);

        $post_note_form.garlic({
           getPath: function ( $elem ) {
               return garlic_prefix + '_' + $elem.attr('name');
           }
        });

        $('#reset').click(function()
        {
            Eventum.clearAutoSave(garlic_prefix);
            window.close();
        })
    });
    //-->
</script>


<form class="validate" data-validation-function='validateForm' id="post_note_form" name="post_note_form" method="post" data-sup-id="{$sup_id|default:''}" data-destroy="false">
    <input type="hidden" name="cat" value="post_note">
    <input type="hidden" name="parent_id" value="{$parent_note_id|default:''}">
    <input type="hidden" name="issue_id" value="{$issue_id}">
    <input type="hidden" name="garlic_prefix" value="" id="garlic_prefix">
    <table class="bordered internal">
        <tr class="title">
            <th colspan="2">
                {t}Post New Internal Note{/t}
            </th>
        </tr>
        <tr>
            <th width="140">
                {t}From{/t}
            </th>
            <td>
                {$from|escape:"html"}
            </td>
        </tr>
        <tr>
            <th>
                {t}Recipients{/t}
            </th>
            <td>
                <a href="{$core.rel_url}view.php?id={$issue_id}" title="{t}view issue details{/t}">{t 1=$issue_id}Issue #%1{/t}</a>
                {t 1=$subscribers.staff}Notification List (Members: %1){/t}
            </td>
        </tr>
        <tr>
            <th>
                {t}Title{/t} *
            </th>
            <td>
                <input type="text" name="title" size="50" value="{$reply_subject|escape:"html"}">
                {include file="error_icon.tpl.html" field="title"}
            </td>
        </tr>
        <tr>
            <td colspan="2">
                <textarea id="note" name="note" rows="16" style="width: 97%">{$note.not_body|default:""|escape:"html"}{if $core.current_user_prefs.auto_append_note_sig}


{$core.current_user_prefs.email_signature|escape:"html"}{/if}</textarea>
                {include file="error_icon.tpl.html" field="note"}
            </td>
        </tr>
        <tr>
            <th valign="top">
                {t}Extra Note Recipients{/t}
            </th>
            <td>
                <select multiple name="note_cc[]"
                        data-placeholder="{t}Choose Recipients…{/t}" class="chosen-select"
                         data-storage="false"
                        >
                    {html_options options=$users}
                </select>
            </td>
        </tr>
        <tr>
            <th>
                {t}Add Extra Recipients To Notification List?{/t}
            </th>
            <td>
                <label><input type="radio" name="add_extra_recipients" value="yes" data-storage="false"> {t}Yes{/t}</label>
                <label><input type="radio" name="add_extra_recipients" value="no" checked data-storage="false"> {t}No{/t}</label>
            </td>
        </tr>
        <tr>
            <th>
                {t}New Status for Issue{/t} #{$issue_id}:
            </th>
            <td>
                <select name="new_status" data-storage="false">
                    <option value=""></option>
                    {html_options options=$statuses}
                </select>
            </td>
        </tr>
        <tr>
            <th>
                {t}Time Spent{/t}:
            </th>
            <td>
                <input type="text" size="5" name="time_spent" onChange="Eventum.calcDateDiff(this.form, 0)" data-storage="false">
                <select name="time_category" data-storage="false">
                    {html_options options=$time_categories selected=$note_category_id}
                </select>
                <span><i>({t}in minutes{/t})</i></span>
                {include file="error_icon.tpl.html" field="time_spent"}
            </td>
        </tr>
        <tr>
            <th nowrap>{t}Time Summary{/t}</th>
            <td>
                <input type="text" name="time_summary" size="40" data-storage="false">{include file="error_icon.tpl.html" field="time_summary"}
            </td>
        </tr>
        <tr>
            <th nowrap>{t}Work started{/t}:</th>
            <td>
                {html_select_date start_year='-1' day_value_format='%02d' field_array='date' prefix='' time=$core.current_user_datetime all_extra=' onChange="Eventum.calcDateDiff(this.form, 1, this.name)"'}&nbsp;
                {html_select_time minute_interval=5 field_array='date' prefix='' all_extra=' onChange="Eventum.calcDateDiff(this.form, 1, this.name)"' display_seconds=false time=$core.current_user_datetime}
                <a href="javascript:void(null);" onClick="Eventum.updateTimeFields($('form#post_note_form'), 'date[Year]', 'date[Month]', 'date[Day]', 'date[Hour]', 'date[Minute]');Eventum.calcDateDiff($('form#post_note_form'), 11)">
                  <i class="fa fa-refresh" aria-hidden="true"></i>
                </a>
            </td>
        </tr>
        <tr>
            <th nowrap>{t}Work ended{/t}:</th>
            <td>
                {html_select_date start_year='-1' day_value_format='%02d' field_array='date2' prefix='' time=$core.current_user_datetime all_extra=' onChange="Eventum.calcDateDiff(this.form, 2, this.name)"'}&nbsp;
                {html_select_time minute_interval=5 field_array='date2' prefix='' all_extra=' class="default" onChange="Eventum.calcDateDiff(this.form, 2, this.name)"' display_seconds=false time=$core.current_user_datetime}
                <a href="javascript:void(null);" onClick="Eventum.updateTimeFields($('form#post_note_form'), 'date2[Year]', 'date2[Month]', 'date2[Day]', 'date2[Hour]', 'date2[Minute]'); Eventum.calcDateDiff($('form#post_note_form'), 12)">
                  <i class="fa fa-refresh" aria-hidden="true"></i>
                </a>
            </td>
        </tr>
        {include file="include/issue_fields.tpl.html"}
        <tr class="buttons">
            <td colspan="2">
                <input name="main_submit_button" type="submit" value="{t}Post Internal Note{/t}">
                <input name="cancel" type="reset" value="{t}Cancel{/t}" id="reset">


                {if not $core.current_user_prefs.auto_append_note_sig and $core.current_user_prefs.email_signature}
                <div class="right">
                    <label>
                        <input type="checkbox" name="add_email_signature" value="yes" id="add_email_signature">
                        {t}Add Email Signature{/t}
                    </label>
                </div>
                {/if}
            </td>
        </tr>
        <tr>
            <td colspan="2">
                * {t}Required fields{/t}
            </td>
        </tr>
    </table>
</form>

{/if}
{/block}
