<!--#set global $pane="Categories"#-->
<!--#set global $help_uri = $confighelpuri + "categories"#-->
<!--#include $webdir + "/_inc_header_uc.tmpl"#-->
<div class="colmask">
    <div class="section">
        <div class="padTable">
            <a class="main-helplink" href="$help_uri" target="_blank"><span class="glyphicon glyphicon-question-sign"></span></a>
            <p>$T('explain-catTags2')<br/>$T('explain-catTags')</p>
            <hr>
            <h5 class="darkred"><strong>$T('explain-relFolder'):</strong> <span class="path">$defdir</span></h5>
            <!--#for $cur, $slot in enumerate($slotinfo)#-->
                <!--#set $cansort = $slot.name != '*' and $slot.name != ''#-->
                <form action="save" method="post" <!--#if $cansort#-->class="sorting-row"<!--#end if#-->>
                    <table class="catTable">
                        <!--#if $cur == 0#-->
                        <tr>
                            <th></th>
                            <th>$T('category')</th>
                            <th>$T('priority')</th>
                            <th>$T('mode')</th>
                            <th>$T('script')</th>
                            <th>$T('catFolderPath')</th>
                            <th colspan="2">$T('catTags')</th>
                        </tr>
                        <!--#end if#-->
                        <tr>
                            <td>
                                <span class="glyphicon glyphicon-option-vertical"></span>
                            </td>
                            <td>
                                <input type="hidden" name="apikey" value="$apikey" />
                                <input type="hidden" name="order" value="$slot.order" />
                                <input type="hidden" value="$slot.name" name="name" />
                                <!--#if $slot.name != '*'#-->
                                <input type="text" name="newname" value="$slot.name" size="10" />
                                <!--#else#-->
                                <input type="text" name="newname" value="$T('default')" disabled="disabled" size="10" />
                                <!--#end if#-->
                            </td>
                            <td>
                                <select name="priority">
                                    <!--#if $slot.name != '*'#-->
                                    <option value="-100" <!--#if $slot.priority==- 100 then 'selected="selected"' else ""#-->>$T('default')</option>
                                    <!--#end if#-->
                                    <option value="2" <!--#if $slot.priority==2 then 'selected="selected"' else ""#-->>$T('pr-force')</option>
                                    <option value="1" <!--#if $slot.priority==1 then 'selected="selected"' else ""#-->>$T('pr-high')</option>
                                    <option value="0" <!--#if $slot.priority==0 then 'selected="selected"' else ""#-->>$T('pr-normal')</option>
                                    <option value="-1" <!--#if $slot.priority==- 1 then 'selected="selected"' else ""#-->>$T('pr-low')</option>
                                    <option value="-2" <!--#if $slot.priority==- 2 then 'selected="selected"' else ""#-->>$T('pr-paused')</option>
                                </select>
                            </td>
                            <td>
                                <select name="pp">
                                    <!--#if $slot.name != '*'#-->
                                    <option value="" <!--#if $slot.pp=="" then 'selected="selected"' else ""#-->>$T('default')</option>
                                    <!--#end if#-->
                                    <option value="0" <!--#if $slot.pp=="0" then 'selected="selected"' else ""#-->>$T('pp-none')</option>
                                    <option value="1" <!--#if $slot.pp=="1" then 'selected="selected"' else ""#-->>$T('pp-repair')</option>
                                    <option value="2" <!--#if $slot.pp=="2" then 'selected="selected"' else ""#-->>$T('pp-unpack')</option>
                                    <option value="3" <!--#if $slot.pp=="3" then 'selected="selected"' else ""#-->>$T('pp-delete')</option>
                                </select>
                            </td>
                            <td>
                                <!--#if $scripts#-->
                                <select name="script">
                                    <!--#for $sc in $scripts#-->
                                        <!--#if not ($sc == 'Default' and $slot.name == '*')#-->
                                        <option value="$sc" <!--#if $slot.script.lower()==$sc.lower() then 'selected="selected"' else ""#-->>$Tspec($sc)</option>
                                        <!--#end if#-->
                                    <!--#end for#-->
                                </select>
                                <!--#else#-->
                                <select name="script" disabled>

                                </select>
                                <!--#end if#-->
                            </td>
                            <td class="nowrap">
                                <input type="text" name="dir" class="fileBrowserSmall" value="$slot.dir" size="20" data-initialdir="$defdir" data-title="$T('catFolderPath')" title="$T('explain-catTags2')" />
                            </td>
                            <td>
                                <input type="text" name="newzbin" value="$slot.newzbin" size="20" />
                            </td>
                            <td class="nowrap">
                                <button class="btn btn-default">
                                    <!--#if $cur == 1#-->
                                        <span class="glyphicon glyphicon-plus"></span> $T('button-add')
                                    <!--#else#-->
                                        <span class="glyphicon glyphicon-ok"></span> $T('button-save')
                                    <!--#end if#-->
                                </button>
                                <!--#if $cansort#-->
                                <button class="btn btn-default delCat" type="button"><span class="glyphicon glyphicon-trash"></span></button>
                                <!--#end if#-->
                            </td>
                        </tr>
                    </table>
                </form>
                <!--#if not $cansort#-->
                <hr>
                <!--#end if#-->
            <!--#end for#-->
        </div>
    </div>
</div>
<script type="text/javascript" src="${root}staticcfg/js/jquery-ui.min.js"></script>
<script type="text/javascript">
    jQuery(document).ready(function() {
        jQuery('.delCat').click(function() {
            var theForm = jQuery(this).closest("form");
            theForm.attr("action", "delete").submit();
        });

        // Add autocomplete and file-browser
        jQuery('.fileBrowserSmall').typeahead({appendTo: 'body'}).fileBrowser();

        // Make categories sortable
        jQuery('.padTable').sortable({
            items: '.sorting-row',
            containment: '.colmask',
            axis: 'y',
            update: function(event, ui) {
                jQuery('.Categories form.sorting-row').each(function(index, elm) {
                    // Update order of all elements
                    if(index !== elm.order.value) {
                        elm.order.value = index
                        // Submit changed order
                        var data = {}
                        jQuery(elm).extractFormDataTo(data);
                        jQuery.ajax({
                            type: "GET",
                            url: window.location.pathname + 'save',
                            data: data,
                            async: false // To prevent race-conditions when updating categories
                        })
                    }
                })
            }
        })
    });
</script>

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