zenario__user_forms:
    panels:
        crm_fields:
            priv: _PRIV_MANAGE_FORMS
            title: Form fields with CRM names
            db_items:
                table: |
                    [[DB_PREFIX]][[ZENARIO_USER_FORMS_PREFIX]]user_form_fields AS ff
                    INNER JOIN [[DB_PREFIX]][[ZENARIO_CRM_FORM_INTEGRATION_PREFIX]]crm_fields cf
                        ON ff.id = cf.form_field_id
                id_column: ff.id
            columns:
                id:
                    title: ID
                    format: id
                    db_column: ff.id
                    align_right: true
                    width: xxsmall
                    show_by_default: true
                ordinal:
                    title: Ordinal
                    db_column: cf.ord
                    align_right: true
                    width: xxsmall
                    show_by_default: true
                name:
                    title: Name
                    db_column: ff.name
                    searchable: true
                    show_by_default: true
                    width: xxlarge
            reorder:
                column: ordinal
            refiners:
                crm_field_name_and_form_id:
                    sql: |
                        ff.user_form_id = (
                            SELECT ff2.user_form_id
                            FROM [[DB_PREFIX]][[ZENARIO_USER_FORMS_PREFIX]]user_form_fields ff2
                            WHERE ff2.id = [[REFINER_ID]]
                        )
                        AND cf.name = (
                            SELECT cf2.name
                            FROM [[DB_PREFIX]][[ZENARIO_CRM_FORM_INTEGRATION_PREFIX]]crm_fields cf2
                            WHERE cf2.form_field_id = [[REFINER_ID]]
                        )
