[% UNLESS helper.skip_head == 1 -%]
<div class="row">
    [% FOR button IN helper.top_buttons -%]
    <span>
    <a class="btn btn-primary btn-large" href="[% button.uri %]"><i class="[% button.icon %]"></i> [% button.name %]</a>
    </span>
    [% END -%]
</div>

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

<div class="ngcp-separator"></div>

<div class="accordion" id="preference_groups">
[% END -%]

[% FOREACH group IN helper.pref_groups %]
<div class="accordion-group">
    <div class="accordion-heading">
        <a class="accordion-toggle" data-toggle="collapse" data-parent="#preference_groups" href="#collapse[% group.id %]">[% c.loc(group.name) %]</a>
    </div>
    <div class="accordion-body collapse" id="collapse[% group.id %]">
    <div class="accordion-inner">

<table class="table table-bordered table-striped table-highlight table-hover" id="preferences_table[% group.id %]">
    <thead>
        <tr>
            [% # one for description -%]
            <th></th>
            [% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
            <th>[% c.loc('Attribute') %]</th>
            [% END -%]
            <th>[% c.loc('Name') %]</th>
            <th>[% c.loc('Value') %]</th>
            [% # one for actions -%]
            <th class="span3"></th>
        </tr>
    </thead>
    <tbody>
        [% FOREACH r IN group.prefs %]
            [% NEXT IF r.voip_preference_groups_id != group.id %]
            <tr class="sw_action_row">
                <td>
                    <a href="#" onclick="$.msgbox(
                        '[% c.loc(r.description.remove('[\[\]]')).squote | html %]',
                        {
                            type:'info',
                            buttons:[
                                {type:'cancel',value:'Close'}
                            ]
                        }); return false;"><i class="icon-question-sign"></i></a>
                </td>
                [% UNLESS c.user.roles == 'subscriber' || c.user.roles == 'subscriberadmin' -%]
                <td>[% r.attribute | html %]</td>
                [% END -%]
                <td>
                  [% c.loc(r.label||" ") %]
                </td>
                <td>
                    [% IF r.attribute == "rewrite_rule_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.rewrite_rule_sets -%]
                            <option [% (r.rwrs_id.defined && r.rwrs_id == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "cdr_export_sclidui_rwrs" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.rewrite_rule_sets -%]
                            <option [% (r.rwrs_id.defined && r.rwrs_id == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "header_rule_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.header_rule_sets -%]
                            <option [% (r.value == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "ncos" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR level IN helper.ncos_levels -%]
                            <option [% (r.ncos_id.defined && r.ncos_id == level.id) ? 'selected="selected"' : '' %]>[% level.level | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "adm_ncos" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR level IN helper.ncos_levels -%]
                            <option [% (r.adm_ncos_id.defined && r.adm_ncos_id == level.id) ? 'selected="selected"' : '' %]>[% level.level | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "adm_cf_ncos" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR level IN helper.ncos_levels -%]
                            <option [% (r.adm_cf_ncos_id.defined && r.adm_cf_ncos_id == level.id) ? 'selected="selected"' : '' %]>[% level.level | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "ncos_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.ncos_sets -%]
                            <option [% (r.ncos_set_id.defined && r.ncos_set_id == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "adm_ncos_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.ncos_sets -%]
                            <option [% (r.adm_ncos_set_id.defined && r.adm_ncos_set_id == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "adm_cf_ncos_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.ncos_sets -%]
                            <option [% (r.adm_cf_ncos_set_id.defined && r.adm_cf_ncos_set_id == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "emergency_mapping_container" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR container IN helper.emergency_mapping_containers -%]
                            <option [% (r.emergency_mapping_container_id.defined && r.emergency_mapping_container_id == container.id) ? 'selected="selected"' : '' %]>[% container.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "sound_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.sound_sets -%]
                            <option [% (r.value.defined && r.value == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "contract_sound_set" -%]
                        <select autocomplete="off" disabled="disabled">
                            <option>&nbsp;</option>
                        [% FOR set IN helper.contract_sound_sets -%]
                            <option [% (r.value.defined && r.value == set.id) ? 'selected="selected"' : '' %]>[% set.name | html %]</option>
                        [% END -%]
                        </select>
                    [% ELSIF r.attribute == "allowed_ips" -%]
                        [% FOR ipnet IN r.allowed_ips_rs.all -%]
                            [% ipnet.ipnet | html -%]<br/>
                        [% END -%]
                    [% ELSIF r.attribute == "man_allowed_ips" -%]
                        [% FOR ipnet IN r.man_allowed_ips_rs.all -%]
                            [% ipnet.ipnet | html -%]<br/>
                        [% END -%]

                    [% ELSIF r.data_type == "boolean" %]
                        <input type="checkbox" autocomplete="off" disabled="disabled"
                            [% IF r.value %]checked="checked"[% END %]/>
                    [% ELSIF r.data_type == "string" || r.data_type == "int" || r.data_type == "blob" %]
                        [% IF r.max_occur == 1 %]
                            [% r.value | html %]
                        [% ELSE %]
                            [% FOR value IN r.value -%]
                                [% IF value.substr(0,1) == '#' -%]
                                    <span class="ngcp-entry-disabled">[% value.substr(1) | html %]</span>
                                [% ELSE -%]
                                    [% value | html %]
                                [% END -%]
                                <br/>
                            [% END %]
                        [% END %]
                    [% ELSIF r.data_type == "enum" %]
                        <select autocomplete="off" disabled="disabled">
                        [% FOREACH e IN r.enums %]
                            <option [% IF r.value == e.value || (!r.value.defined && e.default_val == 1 && !e.value.defined) || (!r.value.defined && !e.value.defined) %]selected="selected"[% END %]>[% e.label | html %]</option>
                        [% END %]
                        </select>
                    [% END %]
                </td>
                <td class="ngcp-actions-column">
                    <div class="sw_actions pull-right">
                        [% UNLESS (c.user.roles == "admin" || c.user.roles == "reseller") && c.user.read_only -%]
                        <a class="btn btn-small btn-primary" href="[% helper.base_uri _ "/" _ r.id _ "/edit" %]"><i class="icon-edit"></i> [% c.loc('Edit') %]</a>
                        [%IF r.dynamic && !helper.no_edit_meta %]
                        <a class="btn btn-small btn-primary" href="[% helper.base_uri _ "/" _ r.id _ "/editmeta" %]"><i class="icon-edit"></i> [% c.loc('Edit Meta') %]</a>
                        <a class="btn btn-secondary btn-small" href="[% helper.base_uri _ "/" _ r.id _ "/delete" %]"  data-confirm="Delete"><i class="icon-remove"></i> [% c.loc('Delete') %]</a>
                        [% END -%]
                        [% END -%]
                    </div>
                </td>
            </tr>
        [% END %]
    </tbody>
</table>

    </div>
    </div>
</div>
[% END %]
</div>

[% IF helper.edit_preference -%]

[%
    PROCESS "helpers/modal.tt";
    modal_header(m.create_flag=0,
                 m.name = c.loc("Preference '") _ c.loc(helper.preference_meta.label) _"'");
-%]

    [% IF helper.preference_meta.data_type == "blob" %]
        <script>
            $(document).ready(function() {
                $(".ngcp-blob-data-area").hide();
                $(".ngcp-blob-show-data").click(function() {
                    $(".ngcp-blob-data-area").toggle();
                    if ($(".ngcp-blob-data-area").is(':visible')) {
                        $(".ngcp-blob-show-data").attr('value', 'Hide Data');
                    } else {
                        $(".ngcp-blob-show-data").attr('value', 'Show Data');
                    }
                });
            });
        </script>
    [% END %]
    [% IF helper.preference_meta.attribute == "allowed_ips" %]
        <div class="modal-body">
        [% FOREACH net IN helper.aip_grp_rs.all %]
            <div class="row-fluid">
                <input type="text" value="[% net.ipnet %]" autocomplete="off" disabled="disabled"></input>
            <a class="btn btn-primary pull-right" href="?delete_aig=[% net.id %]"><i class="icon-trash"></i></a>
          </div>
        [% END %]
        <form action="[% helper.form.action %]" method="post">
            [% helper.form.field(helper.preference_meta.attribute).render %]
            <span class="pull-right">[% helper.form.field("add").render %]</span>
        </form>
        </div>
    [% ELSIF helper.preference_meta.attribute == "man_allowed_ips" %]
        <div class="modal-body">
        [% FOREACH net IN helper.man_aip_grp_rs.all %]
            <div class="row-fluid">
                <input type="text" value="[% net.ipnet %]" autocomplete="off" disabled="disabled"></input>
            <a class="btn btn-primary pull-right" href="?delete_man_aig=[% net.id %]"><i class="icon-trash"></i></a>
          </div>
        [% END %]
        <form action="[% helper.form.action %]" method="post">
            [% helper.form.field(helper.preference_meta.attribute).render %]
            <span class="pull-right">[% helper.form.field("add").render %]</span>
        </form>
        </div>
    [% ELSIF helper.preference_meta.max_occur != 1 %]
        <div class="modal-body">
        [% FOREACH v IN helper.preference_values %]
            <div class="row-fluid">
            [% IF v.disabled %]
                <input type="text" value="[% v.value %]" autocomplete="off" disabled="disabled" class="ngcp-entry-disabled"/>
            [% ELSE %]
                <input type="text" value="[% v.value %]" autocomplete="off" disabled="disabled"/>
            [% END %]
            <a class="btn btn-primary pull-right" href="?delete=[% v.id %]"><i class="icon-trash"></i></a>
            [% IF v.disabled %]
                <a class="btn btn-primary pull-right" style="margin:0 5px 0 5px" href="?activate=[% v.id %]"><i class="icon-ok"></i></a>
            [% ELSE %]
                <a class="btn btn-primary pull-right" style="margin:0 5px 0 5px" href="?deactivate=[% v.id %]"><i class="icon-ban-circle"></i></a>
            [% END %]
          </div>
        [% END %]
        <form action="[% helper.form.action %]" method="post">
            [% helper.form.field(helper.preference_meta.attribute).render %]
            <span class="pull-right">[% helper.form.field("add").render %]</span>
        </form>
        </div>
    [% ELSE %]
        [% helper.form.render -%]
    [% END %]

[%
    modal_footer();
-%]
<script>
    $(function () {
        $('#mod_edit').modal({keyboard: false, backdrop: 'static'});
        $('#mod_close').click(function(event) {
            window.location.href="[% helper.base_uri %]";
        });

    });
</script>
[% END -%]

[% IF helper.create_flag == 1 || helper.editmeta_flag == 1 -%]
[%
    IF helper.form.has_for_js;
        helper.form.render_repeatable_js;
    END;
    PROCESS "helpers/modal.tt";
    modal_header(m.create_flag=helper.create_flag,
                 m.duplicate_flag=helper.duplicate_flag,
                 m.edit_flag=helper.editmeta_flag,
                 m.name = helper.name);
    helper.form.render;
    modal_footer();
    modal_script(m.close_target = helper.close_target);
-%]
[% END -%]

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