[% site_config.title = c.loc('Manage Sound Set [_1] [_2]', set_result.name, set_result.parent_id ? '(Parent: ' _ set_result.parent.name _ ')' : '') -%]

[% can_edit_handles = ((c.user.roles == 'subscriberadmin' && c.user.account_id == set_result.contract_id) || (c.user.roles != 'subscriberadmin' && !c.user.read_only)) ? 1 : 0 -%]

<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>
    <a class="btn btn-primary btn-large" href="[% c.uri_for('/sound') %]"><i class="icon-list"></i> [% c.loc('Sound Sets') %]</a>
    [% IF c.user.roles == "subscriberadmin" ||
          ((c.user.roles == "admin" || c.user.roles == "reseller") && !c.user.read_only)
    -%]
    <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/sound/handles_load_default', [c.req.captures.0]) %]"><i class="icon-star"></i> [% c.loc('Load Default Files') %]</a>
    [% END -%]
    </span>
</div>
[% back_created = 1 -%]

[% 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>

<div class="accordion" id="sound_groups">
[% FOREACH group IN sound_groups.pairs %]
<div class="accordion-group">
    <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#sound_groups" href="#collapse[% group.key %]">[% group.key %]</a>
    </div>
    <div class="accordion-body collapse" id="collapse[% group.key %]">
    <div class="accordion-inner">

<table class="table table-bordered table-striped table-highlight table-hover" id="sounds_table[% group.key %]">
    <thead>
        <tr>
            [% # one for description -%]
            <th>[% c.loc('Name') %]</th>
            <th>[% c.loc('Filename') %]</th>
            <th>[% c.loc('Loop') %]</th>
            [% IF set_result.parent_id -%]
            <th>[% c.loc('Use Parent') %]</th>
            [% END -%]
            [% # one for actions -%]
            <th></th>
        </tr>
    </thead>
    <tbody>
        [% FOREACH r IN group.value %]
            <tr class="sw_action_row">
                <td>
                  [% r.handle_name %]
                </td>
                <td>
                    [% r.file_id
                        ? r.filename
                            ? r.filename : c.loc("(empty)")
                        : ''
                    %]
                </td>
                <td>
                    <input type="checkbox" disabled="disabled" [% r.loopplay ? 'checked="checked"' : '' %]>
                </td>
                [% IF set_result.parent_id -%]
                <td>
                    <input type="checkbox" disabled="disabled" [% r.use_parent == 0 ? '' : 'checked="checked"' %]>
                </td>
                [% END -%]
                <td>
                    <div class="sw_actions pull-right">
                        [% IF r.filename.size -%]
                            [% IF can_edit_handles -%]
                            <a class="btn btn-small btn-primary" href="[% handles_base_uri _ "/" _ r.handle_id _ "/edit" %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                            <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% handles_base_uri _ "/" _ r.handle_id _ "/delete" %]"><i class="icon-edit"></i> [% c.loc('Delete') %]</a>
                            [% END -%]
                            <a class="btn btn-small btn-tertiary" href="[% c.uri_for_action('/sound/handles_download', [c.req.captures.0, r.handle_id]) %]"><i class="icon-play"></i> [% c.loc('Play') %]</a>
                        [% ELSIF r.file_id -%]
                            [% IF can_edit_handles -%]
                            <a class="btn btn-small btn-primary" href="[% handles_base_uri _ "/" _ r.handle_id _ "/edit" %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                            <a class="btn btn-small btn-secondary" data-confirm="Delete" href="[% handles_base_uri _ "/" _ r.handle_id _ "/delete" %]"><i class="icon-edit"></i> [% c.loc('Delete') %]</a>
                            [% END -%]
                        [% ELSIF can_edit_handles -%]
                            <a class="btn btn-small btn-primary" href="[% handles_base_uri _ "/" _ r.handle_id _ "/edit" %]"><i class="icon-edit"></i> [% c.loc('Add') %]</a>
                        [% END -%]
                    </div>
                </td>
            </tr>
        [% END %]
    </tbody>
</table>
    </div>
    </div>
</div>
[% END %]
</div>

[% IF edit_flag || edit_default_flag;
    PROCESS "helpers/modal.tt";
    modal_header(m.create_flag=0,
                 m.name = edit_default_flag ? c.loc('Default Files') : file_result.handle.name );
    form.render;
    modal_footer();
    END;
-%]
[% IF edit_flag || edit_default_flag -%]
<script>
    $(function () {
        $('#mod_edit').modal({keyboard: false, backdrop: 'static'});
        $('#mod_close').click(function(event) {
            window.location.href="[% handles_base_uri %]";
        });

    });
</script>
[% END -%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]

