[%  site_config.title = c.loc('Customers') -%]

<script>
function hideField(id,iddId) {
    $("[name='" + id + "']").parents('.control-group').addClass("hidden");
    $("[name='" + id + ".id']").parents('.control-group').addClass("hidden");
    $("[id='" + id + ".0']").parents('.control-group').addClass("hidden");
    if (iddId) {
        $("[id='" + iddId + "']").parents('.control-group').addClass("hidden");
    }
    $("[name='" + id + ".create']").parents('.control-group').addClass("hidden");
}
function showField(id,iddId) {
    $("[name='" + id + "']").parents('.control-group').removeClass("hidden");
    $("[name='" + id + ".id']").parents('.control-group').removeClass("hidden");
    $("[id='" + id + ".0']").parents('.control-group').removeClass("hidden");
    if (iddId) {
        $("[id='" + iddId + "']").parents('.control-group').removeClass("hidden");
    }
    $("[name='" + id + ".create']").parents('.control-group').removeClass("hidden");
}
function switchBillingProfileDefinition(field) {
    var switched = 0;
    if (field) {
        switch (field.value) {
            case 'id':
                showField('billing_profile');
                hideField('billing_profiles','profile_add');
                hideField('profile_package');
                switched = 1;
                break;
            case 'profiles':
                hideField('billing_profile');
                showField('billing_profiles','profile_add');
                hideField('profile_package');
                if (typeof window['loadTimeline'] === "function") {
                    window['loadTimeline']('[% c.uri_for_action('/customer/billingmappings_ajax', [ contract.id ]) %]');
                }
                switched = 1;
                break;
            case 'package':
                hideField('billing_profile');
                hideField('billing_profiles','profile_add');
                showField('profile_package');
                switched = 1;
                break;
            default:

                break;
        }
    }
    if (!switched) {
        hideField('billing_profile');
        hideField('billing_profiles','profile_add');
        hideField('profile_package');
    }
}
$( document ).ready(function() {
    switchBillingProfileDefinition(document.getElementById('billing_profile_definition'));
});
</script>

[%
    helper.name = c.loc('Customer');
    helper.identifier = 'Customer';
    helper.data = contracts;
    helper.messages = messages;
    helper.dt_columns = contract_dt_columns;
    helper.length_change = 1;

    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');

    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' },
        ];
        helper.top_buttons = [
            { name = c.loc('Create Customer'), uri = c.uri_for_action('/customer/create'), icon = 'icon-star' },
        ];
    ELSE;
        helper.dt_buttons = [
            { name = c.loc('Details'), uri = "/customer/'+full.id+'/details", class = 'btn-small btn-tertiary', icon = 'icon-list' },
        ];
    END;

    IF helper.edit_flag; helper.name = c.loc('Customer #[_1]',contract.id); END;

    PROCESS 'helpers/datatables.tt';
-%]
[% # vim: set tabstop=4 syntax=html expandtab: -%]
