# You must use a tab-size of 4 spaces to edit this file.
---

# The menu_positions table is used for the hierarchical panel for selecting
# new menu node positions.
# It has an entry for every menu section, every menu node, and dupicate entries for
# everything which work as "child" selectors.
# Having to make a table for this is a big hack; at some point we should improve or rewrite
# the selection interface and remove the need for this table.

zenario__menu:
    panels:
        menu_position:
            back_link: false
            db_items:
                table: |
                    [[DB_PREFIX]]menu_positions AS mp
                    INNER JOIN [[DB_PREFIX]]menu_sections AS ms
                       ON ms.id = mp.section_id
                    LEFT JOIN [[DB_PREFIX]]menu_nodes AS mi
                       ON mi.id = mp.menu_id
                    LEFT JOIN [[DB_PREFIX]]menu_text AS mt
                       ON mt.menu_id = mi.id
                      AND mt.language_id = [[FOCUSED_LANGUAGE_ID]]
                    LEFT JOIN [[DB_PREFIX]]content_items AS c
                       ON mi.equiv_id = c.equiv_id
                      AND mi.content_type = c.type
                      AND c.language_id = [[FOCUSED_LANGUAGE_ID]]
                id_column: mp.tag
                client_side: true
                max_limit: 1000
            
            refiners:
                create:
                    title: Select a position to create a menu node
                move:
                    title: Select a position to move to
                existing:
                    title: Select a position
                    sql: |
                        mp.is_dummy_child = 0
            
            panel_type: hierarchy_with_lazy_load
            reorder:
                column: order_by
                hierarchy_view_mode: parent_ids_and_ordinals
                lazy_load: true
            
            hierarchy:
                column: parent_id
                db_column: mp.parent_tag
            
            disable_periodic_refresh: true
            label_format_for_picked_items: "[[menu_path]]"
            columns:
                parent_id:
                    db_column: mp.parent_tag
                section_id:
                    db_column: mp.section_id
                order_by:
                    db_column: IF (mp.is_dummy_child = 1, '~~~~~~~~~', IFNULL(mi.ordinal, ms.section_name))
                ordinal:
                    db_column: mi.ordinal
                menu_id:
                    db_column: mp.menu_id
                parent_menu_id: {}
                is_dummy_child:
                    db_column: mp.is_dummy_child
                is_first: {}
                name:
                    title: Name/Text
                    db_column: IF (mi.id IS NULL, ms.section_name, mt.name)
                    show_by_default: true
                    searchable: true
                    search_column: mt.name
                redundancy:
                    db_column: mi.redundancy
                target_loc:
                    db_column: mi.target_loc
                internal_target:
                    db_column: "mi.target_loc = 'int' AND mi.equiv_id"
                equiv_id:
                    db_column: mi.equiv_id
                content_type:
                    db_column: mi.content_type
                target:
                    title: Target
                    db_column: |
                        IF (mi.target_loc = 'int',
                            IF (c.id IS NOT NULL,
                                CONCAT(c.type, '_', c.id),
                                CONCAT(mi.content_type, '_', mi.equiv_id)),
                            IF (mi.target_loc = 'ext',
                                mt.ext_url,
                                NULL
                            )
                        )
                    item_link: content_item_or_url
                    show_by_default: true
                menu_path:
                    title: Path