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

<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');
                switched = 1;
                break;
            case 'profiles':
                hideField('billing_profile');
                showField('billing_profiles','profile_add');
                if (typeof window['loadTimeline'] === "function") {
                    window['loadTimeline']('[% c.uri_for_action('/contract/billingmappings_ajax', [ contract.id ]) %]');
                }
                switched = 1;
                break;
            default:

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

[%
    helper.name = c.loc('Contract');
    IF edit_flag;
        helper.name = c.loc('Contract #[_1]', contract.id);
    END;
    helper.identifier = 'contract';
    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 = ajax_uri;

    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' },
            { name = c.loc('Terminate'), uri = "/contract/'+full.id+'/terminate", class = 'btn-small btn-secondary', icon = 'icon-remove' },
        ];
        IF c.license('reseller');
            helper.top_buttons = [
                { name = c.loc('Create Peering Contract'), uri = c.uri_for_action('/contract/peering_create'), icon = 'icon-star' },
                { name = c.loc('Create Reseller Contract'), uri = c.uri_for_action('/contract/reseller_create'), icon = 'icon-star' },
            ];
        ELSE;
            helper.top_buttons = [
                { name = c.loc('Create Peering Contract'), uri = c.uri_for_action('/contract/peering_create'), icon = 'icon-star' },
            ];
        END;
    END;

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