[% site_config.title = c.loc('Rewrite Rules for [_1]', set_result.name) -%]

<div class="row">
    <span>
        <a class="btn btn-primary btn-large" href="[% c.uri_for('/back') %]"><i class="icon-arrow-left"></i> [% c.loc('Back') %]</a>
    </span>
    [% back_created = 1 -%]
    <span>
        <a class="btn btn-primary btn-large" href="[% c.uri_for('/rewrite/') %]"><i class="icon-list"></i> [% c.loc('Rewrite Rule Sets') %]</a>
    </span>
    [% UNLESS c.user.read_only -%]
    <span>
    <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/rewrite/rules_create', [c.req.captures.0]) %]"><i class="icon-star"></i> [% c.loc('Create Rewrite Rule') %]</a>
    </span>
    [% END -%]
</div>

[% IF messages -%]
<div class="row">
    [% FOREACH m IN messages -%]
        <div class="alert alert-[% m.type %]">[% m.text %]</div>
    [% END -%]
</div>
[% END -%]

<div class="ngcp-separator"></div>
[% MACRO show_rules BLOCK -%]
<table class="table table-bordered table-striped table-highlight table-hover">
    <thead>
        <tr>
            <th></th>
            <th>[% c.loc('Match Pattern') %]</th>
            <th>[% c.loc('Replacement Pattern') %]</th>
            <th>[% c.loc('Description') %]</th>
            <th>[% c.loc('Enabled') %]</th>
            <th class="ngcp-actions-column"></th>
        </tr>
    </thead>
    <tbody>
    [% FOR r IN m_rules %]
        <tr class="sw_action_row">
            <td>
                    <a href="[% c.uri_for_action('/rewrite/rules_root',[set_result.id], 'move' => r.id, 'where' => 'up') %]">
                        <i class="icon-arrow-up"></i>
                    </a>
                    <a href="[% c.uri_for_action('/rewrite/rules_root',[set_result.id], 'move' => r.id, 'where' => 'down') %]">
                        <i class="icon-arrow-down"></i>
                    </a>
            </td>
            <td>[% r.match_pattern %]</td>
            <td>[% r.replace_pattern %]</td>
            <td>[% r.description %]</td>
            <td>[% r.enabled ? c.loc('yes') : c.loc('no') %]</td>
            <td class="ngcp-actions-column">
            [% UNLESS c.user.read_only -%]
                <div class="sw_actions pull-right">
                    [%- FILTER null;
                            backuritmp=c.req.uri;
                            backuritmp.query_param_delete('back');
                            backuritmp.query_param_delete('move');
                            backuritmp.query_param_delete('where');
                        END;
                    %]
                    <a class="btn btn-small btn-primary" data-backuri="[%-backuritmp-%]" href="[% c.uri_for_action('/rewrite/rules_edit',[set_result.id, r.id]) %]">
                        <i class="icon-edit"></i> [% c.loc('Edit') %]
                    </a>
                    <a data-confirm="Delete" class="btn btn-small btn-secondary" href="[% c.uri_for_action('/rewrite/rules_delete',[set_result.id, r.id]) %]">
                        <i class="icon-trash"></i> [% c.loc('Delete') %]
                    </a>
                </div>
            [% END -%]
            </td>
        </tr>
    [% END %]
    </tbody>
</table>
[% END -%]

<div class="accordion" id="rewrite_rules">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_icaller">[% c.loc('Inbound Rewrite Rules for Caller') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_icaller">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.caller_in) %]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_icallee">[% c.loc('Inbound Rewrite Rules for Callee') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_icallee">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.callee_in) %]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_ocaller">[% c.loc('Outbound Rewrite Rules for Caller') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_ocaller">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.caller_out) %]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_ocallee">[% c.loc('Outbound Rewrite Rules for Callee') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_ocallee">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.callee_out) %]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_lnpcaller">[% c.loc('LNP Rewrite Rules for Caller') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_lnpcaller">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.caller_lnp) %]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#rewrite_rules" href="#collapse_lnpcallee">[% c.loc('LNP Rewrite Rules for Callee') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_lnpcallee">
            <div class="accordion-inner">
                [% show_rules(m_rules = rules.callee_lnp) %]
            </div>
        </div>
    </div>
</div>

[% IF edit_flag || create_flag -%]
[%
    PROCESS "helpers/modal.tt";
    modal_header(m.name = c.loc('Rule'),
                 m.create_flag = create_flag);
    form.render();
    modal_footer();
    modal_script(m.close_target = rules_uri);
-%]
[% END -%]


[% # vim: set tabstop=4 syntax=html expandtab: -%]
