{extends "manage/manage.tpl.html"}

{block "manage_content"}

<script type="text/javascript">
    <!--
    function validateForm()
    {
        if (Eventum.getField('issue_auto_creation').filter(':checked').val() == 'enabled') {
            var field = Eventum.getField('options[category]');
            if (field.length && !Validation.hasOneSelected(field)) {
                Validation.selectField('options[category]');
                alert('{t escape=js}Please choose the default category.{/t}');
                return false;
            }
            var field = Eventum.getField('options[priority]');
            if (field.length && !Validation.hasOneSelected(field)) {
                Validation.selectField('options[priority]');
                alert('{t escape=js}Please choose the default priority.{/t}');
                return false;
            }
        }
        return true;
    }
    function disableFields()
    {
        var bool = Eventum.getField('issue_auto_creation').filter(':checked').val() != 'enabled';
        if (bool) {
            var bgcolor = '#CCCCCC';
        } else {
            var bgcolor = '#FFFFFF';
        }
        Eventum.getField('options[only_known_customers]').attr('disabled', bool).css('background-color', bgcolor);
        Eventum.getField('options[category]').attr('disabled', bool).css('background-color', bgcolor);
        Eventum.getField('options[priority]').attr('disabled', bool).css('background-color', bgcolor);
        Eventum.getField('options[users][]').attr('disabled', bool).css('background-color', bgcolor);
    }
    $().ready(function() {
        disableFields();
        Eventum.getField('issue_auto_creation').change(disableFields);
        $('#auto_creation_form').submit(validateForm);
    });
    //-->
</script>

<form id="auto_creation_form" method="post">
    <input type="hidden" name="cat" value="update">
    <input type="hidden" name="ema_id" value="{$ema_id}">
    <table class="bordered">
        <tr class="title">
            <th colspan="2">
                {t}Auto-Creation of Issues{/t}
                <div class="right">({t}Associated Project{/t}: {$prj_title|escape:"html"})</div>
            </th>
        </tr>
        <tr>
            <th width="130" nowrap>
                {t}Auto-Creation of Issues{/t} *
            </th>
            <td width="80%">
                <label><input type="radio" name="issue_auto_creation" value="enabled" {if $info.ema_issue_auto_creation == 'enabled'}checked{/if}>
                    {t}Enabled{/t}</label>&nbsp;&nbsp;
                <label><input type="radio" name="issue_auto_creation" value="disabled" {if $info.ema_issue_auto_creation == 'disabled'}checked{/if}>
                {t}Disabled{/t}</label>
            </td>
        </tr>
        {if $uses_customer_integration}
        <tr>
            <th width="130" nowrap>
                {t}Only for Known Customers?{/t} *
            </th>
            <td width="80%">
                <input type="radio" name="options[only_known_customers]" value="yes" {if $options.only_known_customers == 'yes'}checked{/if}>
                <label>{t}Yes{/t}</label>&nbsp;&nbsp;
                <input type="radio" name="options[only_known_customers]" value="no" {if $options.only_known_customers == 'no'}checked{/if}>
                <label>{t}No{/t}</label>
            </td>
        </tr>
        {else}
        <input type="hidden" name="options[only_known_customers]" value="no">
        {/if}
        {if $cats|@count > 0}
        <tr>
            <th width="130">
                {t}Default Category{/t}: *
            </th>
            <td>
                <select name="options[category]" tabindex="2">
                    <option value="-1">{t}Please choose a category{/t}</option>
                    {html_options options=$cats selected=$options.category}
                </select>
                {include file="error_icon.tpl.html" field="options[category]"}
            </td>
        </tr>
        {/if}
        {if $priorities|@count > 0}
        <tr>
            <th width="130">
                {t}Default Priority{/t}: *
            </th>
            <td>
                <select name="options[priority]" tabindex="3">
                    <option value="-1">{t}Please choose a priority{/t}</option>
                    {section name="i" loop=$priorities}
                    <option value="{$priorities[i].pri_id}" {if $priorities[i].pri_id == $options.priority}selected{/if}>{$priorities[i].pri_title}</option>
                    {/section}
                </select>
                {include file="error_icon.tpl.html" field="options[priority]"}
            </td>
        </tr>
        {/if}
        <tr>
            <th width="150">
                {t}Assignment{/t}:
            </th>
            <td>
                <select name="options[users][]" multiple size="3" tabindex="4">
                    {html_options options=$users selected=$options.users|default:-1}
                </select>
                {include file="error_icon.tpl.html" field="options[users][]"}
            </td>
        </tr>
        <tr class="buttons">
            <td colspan="2">
                <input type="submit" value="{t}Update Setup{/t}">
                <input type="reset" value="{t}Reset{/t}">
            </td>
        </tr>
    </table>
</form>
{/block}
