[% UNLESS framed -%]
[% site_config.title = c.loc('Reseller Details for [_1]', reseller.first.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>
        <a class="btn btn-primary btn-large" href="[% c.uri_for_action('/reseller/resellers_preferences_root', [c.req.captures.0]) %]"><i class="icon-list"></i> [% c.loc('Preferences') %]</a>
    </span>
</div>

[% back_created = 1 -%]
[% END -%]

<div class="row">
    [% FOREACH m IN messages -%]
        <div class="alert alert-[% m.type %]">[% m.text %]</div>
    [% END -%]
    [% IF reseller.first.status != "active" -%]
        <div class="alert">[% c.loc('Reseller is <b>[_1]</b>', reseller.first.status) %]</div>
    [% END -%]
[% messages = [] -%]
</div>

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

<div class="accordion" id="reseller_details">
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_reseller">[% c.loc('Reseller Base Information') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_reseller">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Reseller');
    helper.identifier = 'Reseller';
    helper.messages = messages;
    helper.dt_columns = reseller_dt_columns;
    helper.paginate = 'false';
    helper.filter = 'false';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/reseller/reseller_single', c.req.captures );
    helper.base_uri = c.uri_for_action('/reseller/root');

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/reseller/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_contract">[% c.loc('Reseller Contract') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_contract">
            <div class="accordion-inner">
        [% IF reseller.first.contract.max_subscribers.defined && subscriber_count < reseller.first.contract.max_subscribers -%]
            <div class="alert alert-info">
            [% c.loc('[_1] of maximum [_2] subscribers (including PBX groups) created', subscriber_count, reseller.first.contract.max_subscribers) %]
            </div>
        [% ELSIF reseller.first.contract.max_subscribers.defined -%]
            <div class="alert">
            [% c.loc('Maximum number of [_1] subscribers (including PBX groups) created', reseller.first.contract.max_subscribers) %]
            </div>
        [% END -%]
[%
    helper.name = c.loc('Contract');
    helper.identifier = "Contract";
    helper.messages = messages;
    helper.dt_columns = contract_dt_columns;
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.paginate = 'false';
    helper.filter = 'false';
    helper.ajax_uri = c.uri_for_action('/contract/reseller_ajax_contract_filter', [reseller.first.contract_id] );
    helper.base_uri = c.uri_for_action('/contract/root');

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/contract/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_contact">[% c.loc('Reseller Contact') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_contact">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Contact');
    helper.messages = messages;
    helper.dt_columns = contact_dt_columns;
    helper.close_target = c.uri_for('');
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.paginate = 'false';
    helper.filter = 'false';
    helper.ajax_uri = c.uri_for_action('/reseller/reseller_contacts', c.req.captures );
    helper.base_uri = c.uri_for_action('/contact/root');

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/contact/'+full.id+'/edit/noreseller", class = 'btn-small btn-primary', icon = 'icon-edit' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_admin">[% c.loc('Administrator Logins') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_admin">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Administrator');
    helper.identifier = 'Administrator';
    helper.messages = messages;
    helper.dt_columns = admin_dt_columns;
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/reseller/reseller_admin', c.req.captures );

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/administrator/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = "/administrator/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_domain">[% c.loc('Domains') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_domain">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Domain');
    helper.identifier = 'Domain';
    helper.messages = messages;
    helper.dt_columns = domain_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for('/domain/ajax/filter_reseller', reseller.first.id);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Delete'), uri = "/domain/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-trash' },
            { name = c.loc('Preferences'), uri = "/domain/'+full.id+'/preferences", class = 'btn-small btn-tertiary', icon = 'icon-list' },
        ];
    ELSE;
        helper.dt_buttons = [
            { name = c.loc('Preferences'), uri = "/domain/'+full.id+'/preferences", class = 'btn-small btn-tertiary', icon = 'icon-list' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>


    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_profile">[% c.loc('Billing Profiles') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_profile">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Billing Profile');
    helper.identifier = 'profiles';
    helper.messages = messages;
    helper.dt_columns = profile_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for('/billing/ajax/filter_reseller', reseller.first.id);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/billing/'+full[\"id\"]+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Terminate'), uri = "/billing/'+full[\"id\"]+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-remove', condition => 'full.contract_cnt == "0" && full.package_cnt == "0"' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>


    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_network">[% c.loc('Billing Networks') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_network">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Billing Network');
    helper.identifier = 'networks';
    helper.messages = messages;
    helper.dt_columns = network_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for('/network/ajax/filter_reseller', reseller.first.id);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/network/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Terminate'), uri = "/network/'+full[\"id\"]+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-remove', condition => 'full.contract_cnt == "0" && full.package_cnt == "0"' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_package">[% c.loc('Profile Packages') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_package">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Profile Package');
    helper.identifier = 'packages';
    helper.messages = messages;
    helper.dt_columns = package_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for('/package/ajax/filter_reseller', reseller.first.id);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/package/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = "/package/'+full[\"id\"]+'/delete", class = 'btn-small btn-secondary', icon = 'icon-remove', condition => 'full.contract_cnt == "0" && full.voucher_cnt == "0"' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>


    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_customer">[% c.loc('Customers') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_customer">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Customer');
    helper.identifier = "Customer";
    helper.messages = messages;
    helper.dt_columns = customer_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/customer/ajax_reseller_filter', c.req.captures );

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/customer/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Terminate'), uri = "/customer/'+full.id+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-remove' },
            { name = c.loc('Details'), uri = "/customer/'+full.id+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' },
        ];
    ELSE;
        helper.dt_buttons = [
            { name = c.loc('Details'), uri = "/customer/'+full.id+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]
            </div>
        </div>
    </div>
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_branding">[% c.loc('Branding') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_branding">
            <div class="accordion-inner">

            [% UNLESS c.user.read_only -%]
            <span>
                <a href="[% c.uri_for_action('/reseller/edit_branding_css', c.req.captures) %]" class="btn btn-large btn-primary"><i class="icon-edit"></i>[% c.loc('Edit Branding') %]</a>
                [% IF branding.logo -%]
                <a href="[% c.uri_for_action('/reseller/delete_branding_logo', c.req.captures) %]" class="btn btn-large btn-primary"><i class="icon-trash"></i>[% c.loc('Delete Logo') %]</a>
                [% END -%]
            </span>
            <div class="ngcp-separator"></div>
            [% END -%]

            [% IF branding.defined -%]
                [% IF branding.logo.defined -%]
                    <h3>Custom Logo</h3>
                    <img src="[% c.uri_for_action('/reseller/get_branding_logo', c.req.captures) %]">
                    <p>
                        [% c.loc("You can use the logo by adding the following CSS to the Custom CSS below:") %]
<pre>
#header .brand {
    background: url([% c.uri_for_action('/reseller/get_branding_logo', c.req.captures) %]) no-repeat 0 0;
    background-size: 280px 32px;
}
</pre>
                    </p>
                [% ELSE -%]
                    [% c.loc('No logo uploaded.') %]
                [% END -%]


                <h3>[% c.loc('Custom CSS') %]</h3>
                <p>
                <pre style="color:#000">
[% branding.css %]
                </pre>
                </p>
                <h3>[% c.loc('CSC Primary Color: ') %]
                <div class="color-box" style="background-color: [% branding.csc_color_primary %]">
                    &nbsp;
                </div>
                <div style="display: inline-block;">[% branding.csc_color_primary %]</div>
                </h3>
                <h3>[% c.loc('CSC Secondary Color: ') %]
                <div class="color-box" style="background-color: [% branding.csc_color_secondary %]">
                    &nbsp;
                </div>
                <div style="display: inline-block;">[% branding.csc_color_secondary %]</div>
                </h3>
            [% ELSE -%]
                [% c.loc('No branding specified, using standard branding.') %]
            [% END -%]

            </div>
        </div>
    </div>

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_intemplate">[% c.loc('Invoice Templates') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_intemplate">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Invoice Template');
    helper.identifier = "InvoiceTemplate";
    helper.messages = messages;
    helper.dt_columns = tmpl_dt_columns;
    helper.paginate = 'true';
    helper.filter = 'true';
    helper.close_target = close_target;
    helper.create_flag = create_flag;
    helper.edit_flag = edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/invoicetemplate/reseller_ajax', [c.req.captures.0] );

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = "/invoicetemplate/'+full.id+'/editinfo", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Edit Template'), uri = "/invoicetemplate/'+full.id+'/editcontent", class = 'btn-small btn-tertiary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = "/invoicetemplate/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-remove' },
        ];
        helper.top_buttons = [
            { name = c.loc('Create Invoice Template'), uri = c.uri_for('/invoicetemplate/create', c.req.captures.0), class = 'btn-small btn-primary', icon = 'icon-star' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]


            </div>
        </div>
    </div>

    [% IF c.config.general.ngcp_type != 'spce' -%]
    [% IF c.license('phonebook') -%]
    [% IF c.user.roles == "admin" || c.user.roles == "reseller" -%]
    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_phonebook">[% c.loc('Phonebook') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_phonebook">
            <div class="accordion-inner">

[%
    helper.name = c.loc('Phonebook');
    helper.identifier = 'phonebook';
    helper.messages = messages;
    helper.length_change = 1;
    helper.create_flag = phonebook_create_flag;
    helper.edit_flag = phonebook_edit_flag;
    helper.form_object = form;
    helper.dt_columns = phonebook_dt_columns;
    helper.ajax_uri = c.uri_for_action('/reseller/phonebook_ajax', [ c.req.captures.0 ]);
    helper.tmpuri = c.uri_for_action('/reseller/phonebook_root', [ c.req.captures.0 ]);

    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Edit'), uri = helper.tmpuri _ "/'+full.id+'/edit", class = 'btn-small btn-primary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri = helper.tmpuri _ "/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-remove' },
        ];
        helper.top_buttons = [
            { name = c.loc('Create Phonebook Entry'), uri = c.uri_for_action('/reseller/phonebook_create', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
            { name = c.loc('Download CSV'), uri = c.uri_for_action('/reseller/phonebook_download_csv', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
            { name = c.loc('Upload CSV'), uri = c.uri_for_action('/reseller/phonebook_upload_csv', c.req.captures), class = 'btn-small btn-primary', icon = 'icon-star' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
%]

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

    <div class="accordion-group">
        <div class="accordion-heading">
            <a class="accordion-toggle" data-toggle="collapse" data-parent="#reseller_details" href="#collapse_timeset">[% c.loc('Time sets') %]</a>
        </div>
        <div class="accordion-body collapse" id="collapse_timeset">
            <div class="accordion-inner">
[%
    helper.name = c.loc('Time sets');
    helper.identifier = "TimeSets";
    helper.dt_columns = timeset_dt_columns;
    helper.messages = messages;
    helper.close_target = close_target;
    helper.create_flag = timeset_create_flag;
    helper.edit_flag = timeset_edit_flag;
    helper.form_object = form;
    helper.ajax_uri = c.uri_for_action('/reseller/timeset_ajax', [c.req.captures.0] );
    helper.tmpuri = c.uri_for_action('/reseller/timeset_root', [ c.req.captures.0 ]);
    UNLESS c.user.read_only;
        helper.dt_buttons = [
            { name = c.loc('Events'), uri = "/timeset/'+full.id+'/event", class = 'btn-small btn-tertiary', icon = 'icon-th-list' },
            { name = c.loc('Download'), uri = "/timeset/'+full.id+'/download", class = 'btn-small btn-primary', icon = 'icon-th-list' },
            { name = c.loc('Edit'), uri = helper.tmpuri _ "/'+full.id+'/edit", class = 'btn-small btn-tertiary', icon = 'icon-edit' },
            { name = c.loc('Delete'), uri =  helper.tmpuri _ "/'+full.id+'/delete", class = 'btn-small btn-secondary', icon = 'icon-remove' },
        ];
        helper.top_buttons = [
            { name = c.loc('Create Time Set'), uri = c.uri_for_action('/reseller/timeset_create', [c.req.captures.0]), class = 'btn-small btn-primary', icon = 'icon-star' },
        ];
    END;

    PROCESS 'helpers/datatables.tt';
-%]


            </div>
        </div>
    </div>

    [% END -%]
    [% END -%]

</div>

[% IF edit_flag || create_flag -%]
[%PROCESS 'helpers/modal.tt' -%]
[% END -%]
[% IF branding_edit_flag == 1 -%]
[%
    IF form.has_for_js;
        form.render_repeatable_js;
    END;
    PROCESS "helpers/modal.tt";
    modal_header(m.edit_flag = branding_edit_flag,
                 m.name = "Reseller Branding");
    branding_form.render;
    modal_footer();
    modal_script(m.close_target = close_target);
-%]
<script type="text/javascript" src="/js/spectrum.min.js"></script>
<link rel="stylesheet" type="text/css" href="/css/spectrum.min.css" />
<script>
    $(document).ready(function() {
        $('.ngcp-csc-color-primary').spectrum({
          type: "component",
          showInput: true
        });
        $('.ngcp-csc-color-secondary').spectrum({
          type: "component",
          showInput: true
        });
    });
</script>
[% END -%]

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