# You must use a tab-size of 4 spaces to edit this file.
---
zenario__locations:
    panel:
        title: Locations
        no_items_message: No locations exist
        
        panel_type: google_map_or_list
        lat_column: latitude
        lng_column: longitude
        double_click_item_button: rename_location
        
        slidedown_view_microtemplate: zenario_grid_view_location
        refiners:
            without_location_id:
                sql: 'l.id NOT IN [[COMBINE_ITEMS]]'
            children_of_location:
                sql: 'l.parent_id = [[REFINER_ID]]'
            parent_locations:
                sql: '(l.parent_id = 0 OR l.parent_id IS NULL) AND l.id IN (SELECT parent_id FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]locations AS l2)'
            sector_locations:
                sql: 'l.id IN (SELECT location_id FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]location_sector_score_link WHERE sector_id IN [[REFINER_IDS]])'
            map:
                sql: 'l.id = l.id'
            
            #These are set in zenario_organization_manager preFillOrganizerPanel
            #Need to be here because other modules use these that are unrelated (i.e. zenario_user_timers)
            zenario_organization_manager__organizations:
                sql: ''
            zenario_organization_manager__simple_locations:
                sql: ''
        db_items:
            table: |
                [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]locations AS l
                LEFT JOIN [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]location_images AS i
                   ON l.id = i.location_id
            
                LEFT JOIN [[DB_PREFIX]]files AS f
                   ON i.image_id = f.id
            id_column: l.id
        default_sort_column: description
        columns:
            id:
                title: ID
                format: id
                db_column: l.id
                show_by_default: false
                searchable: true
                width: xxsmall
                align_right: true
            external_id:
                title: External number
                db_column: l.external_id
                show_by_default: false
                hidden: false
                searchable: true
                width: small
                align_right: true
            path:
                title: Path
                show_by_default: false
                searchable: true
                width: xlarge
                hidden: false
            parent_customer:
                hidden: false
            location_full_name:
                hidden: false
            description:
                title: Name
                db_column: l.description
                show_by_default: true
                searchable: true
                width: large
                always_show: true
            address_line_1:
                title: Address 1
                db_column: l.address1
                show_by_default: false
                searchable: true
                hidden: false
            address_line_2:
                title: Address 2
                db_column: l.address2
                show_by_default: false
                searchable: true
                hidden: false
            locality:
                title: Locality
                db_column: l.locality
                show_by_default: false
                searchable: true
                hidden: false
            city:
                title: City
                db_column: l.city
                show_by_default: true
                searchable: true
                hidden: false
            state:
                title: State
                db_column: l.state
                show_by_default: false
                searchable: true
                hidden: false
            postcode:
                title: Postcode
                db_column: l.postcode
                show_by_default: false
                searchable: true
                hidden: false
            country_code:
                db_column: l.country_id
                show_by_default: false
                searchable: true
                ascii_only: true
                hidden: false
            country:
                title: Country
                db_column: c.english_name
                table_join: |
                    [[DB_PREFIX]][[ZENARIO_COUNTRY_MANAGER_PREFIX]]country_manager_countries c
                                                ON
                                                    l.country_id = c.id
                show_by_default: true
                searchable: true
                hidden: false
            region:
                title: Region
                table_join: |
                    [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]location_region_link AS lrl1
                                                ON
                                                    l.id = lrl1.location_id
                                                LEFT JOIN
                                                    [[DB_PREFIX]][[ZENARIO_COUNTRY_MANAGER_PREFIX]]country_manager_regions r
                                                ON
                                                    lrl1.region_id = r.id
                db_column: "GROUP_CONCAT(DISTINCT r.name ORDER BY lrl1.id DESC SEPARATOR ', ')"
                search_column: r.name
                show_by_default: false
                searchable: true
                hidden: false
            latitude:
                title: Latitude
                db_column: l.latitude
                show_by_default: false
                hidden: false
            longitude:
                title: Longitude
                db_column: l.longitude
                show_by_default: false
                hidden: false
            timezone:
                title: Timezone
                db_column: l.timezone
                show_by_default: false
                hidden: false
                format: enum
                searchable: false
                empty_value: Use default
            status:
                title: Status
                db_column: l.status
                always_show: true
                hidden: false
                format: enum
                values:
                    pending: Pending
                    active: Active
                    suspended: Suspended
                width: xsmall
            content_item:
                title: Descriptive page
                item_link: content_item
                db_column: "CONCAT(l.content_type,'_',l.equiv_id)"
                show_by_default: false
                hidden: false
            sectors:
                title: Sectors
                db_column: |
                    (
                                                SELECT GROUP_CONCAT(DISTINCT s.name ORDER BY s.name SEPARATOR ', ')
                                                FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]location_sector_score_link AS lssl
                                                INNER JOIN [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]sectors s
                                                   ON lssl.sector_id = s.id
                                                WHERE l.id = lssl.location_id 
                                            )
                show_by_default: false
                hidden: false
            sticky_flag:
                title: Primary Sector
                db_column: |
                    (
                                                SELECT sts.name
                                                FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]location_sector_score_link AS lssl
                                                INNER JOIN [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]sectors sts
                                                   ON lssl.sector_id = sts.id
                                                WHERE lssl.location_id = l.id 
                                                AND lssl.sticky_flag = 1
                                                LIMIT 1
                                            )
                searchable: false
                hidden: false
            parent_name:
                db_column: |
                    IF (pl.description IS NULL,
                                                IF ((
                                                    SELECT COUNT(*)
                                                    FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]locations AS cl
                                                    WHERE cl.parent_id = l.id
                                                ) = 0,
                                                    '[Not in hierarchy]',
                                                    '[Top-level location]'
                                                ),
                                                pl.description
                                            )
                title: Child of
                table_join: |
                    [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]locations AS pl 
                                            ON pl.id = l.parent_id
                show_by_default: false
                hidden: false
            number_of_children:
                db_column: |
                    (
                                                SELECT COUNT(DISTINCT cl.id)
                                                FROM [[DB_PREFIX]][[ZENARIO_LOCATION_MANAGER_PREFIX]]locations AS cl
                                                WHERE cl.parent_id = l.id
                                                  AND cl.parent_id IS NOT NULL
                                                  AND cl.parent_id != 0
                                            )
                title: Child locations
                show_by_default: false
                hidden: false
            image_usage:
                db_column: f.usage
                hidden: false
            checksum:
                db_column: f.checksum
                hidden: false
            last_edited:
                title: Date/time last edited
                db_column: l.last_edited
                format: datetime
                show_by_default: false
                hidden: false
            last_edited_by:
                title: Last edited by
                db_column: l.last_edited_admin_id
                show_by_default: false
                format: enum
                hidden: false
            last_updated_via_import:
                title: Date/time last updated from import
                db_column: l.last_updated_via_import
                format: datetime
                show_by_default: false
                hidden: false
            on_map:
                title: On map
                db_column: '(l.latitude AND l.longitude)'
                show_by_default: true
                format: yes_or_no
                width: xsmall
                ord: 999
                hidden: false
        quick_filter_buttons:
                    all:
                        ord: 1
                        label: 'All'
                        column: status
                        remove_filter: true
                    active:
                        ord: 2
                        label: 'Active'
                        column: status
                        value: active
                    suspended:
                        ord: 3
                        label: 'Suspended'
                        column: status
                        value: suspended
                    
        item:
            css_class: zenario_location_manager_location
            link:
                path: zenario__locations/panel
                branch: true
                refiner: children_of_location
        collection_buttons:
            create_location:
                priv: _PRIV_MANAGE_LOCATIONS
                ord: 1
                label: Create a location
                css_class: zenario_create_a_new
                hide_in_select_mode: true
                admin_box:
                    path: zenario_location_manager__location
                    create_another: true
            add_location:
                priv: _PRIV_MANAGE_LOCATIONS
                ord: 1
                label: Add a location to this sector
                pick_items:
                    path: zenario__locations/panel
                    target_path: zenario__locations/panel
                    min_path: zenario__locations/panel
                    multiple_select: true
                    one_to_one_choose_phrase: Add selected location to this sector
                    one_to_many_choose_phrase: Add selected locations to this sector
                    request:
                        action: add_location
                only_show_on_refiner: sector_locations
            add_child_location:
                priv: _PRIV_MANAGE_LOCATIONS
                css_class: add
                ord: 0
                label: Add child location here
                multiple_select: false
                only_show_on_refiner: children_of_location
                hide_in_select_mode: true
                pick_items:
                    path: zenario__locations/panel
                    one_to_one_choose_phrase: Add child
                    one_to_many_choose_phrase: Add child locations
                    target_path: zenario__locations/panel
                    min_path: zenario__locations/panel
                    max_path: zenario__locations/panel
                    multiple_select: true
                    request:
                        action: add_child_location
            
            # User dataset import buttons
            import_dropdown:
                label: Import
                hide_when_children_are_not_visible: true
                ord: 999992
            import:
                priv: _PRIV_EXPORT_LOCATIONS
                label: Start import wizard
                parent: import_dropdown
                hide_on_filter: true
                hide_on_refiner: true
                hide_in_select_mode: true
                admin_box:
                    path: zenario_import
                    key:
                        dataset: ''
            donwload_sample_file:
                priv: _PRIV_EXPORT_LOCATIONS
                label: Download sample file
                parent: import_dropdown
                hide_on_filter: true
                hide_on_refiner: true
                hide_in_select_mode: true
                admin_box:
                    path: zenario_download_sample_file
                    key:
                        dataset: ''
            export:
                priv: _PRIV_EXPORT_LOCATIONS
                label: Export
                hide_in_select_mode: true
                admin_box:
                    path: zenario_export_dataset
                    pass_matched_ids: true
                    key:
                        dataset: ''
                ord: 999993
            
            settings_dropdown:
                css_class: organizer_settings_dropdown
                ord: 999999
                hide_when_children_are_not_visible: true
                label: ⚙
            settings:
                priv: _PRIV_VIEW_SITE_SETTING
                label: Settings for locations
                parent: settings_dropdown
                hide_in_select_mode: true
                admin_box:
                    path: site_settings
                    key:
                        id: zenario_location_manager__site_settings_group
            
        item_buttons:
            rename_location:
                priv: _PRIV_MANAGE_LOCATIONS
                ord: 1
                label: Edit location
                hide_in_select_mode: true
                admin_box:
                    path: zenario_location_manager__location
            edit_multiple_locations:
                priv: _PRIV_MANAGE_LOCATIONS
                ord: 1
                label: Edit multiple...
                hide_in_select_mode: true
                multiple_select: true
                multiple_select_only: true
                admin_box:
                    path: zenario_location_manager__locations_multiple_edit
            view_in_hierarchy:
                css_class: locations
                hide_in_select_mode: true
                tooltip: View location in hierarchy
                navigation_path: true
                without_columns_set:
                    traits.not_in_hierarchy: true
            
            view_dropdown:
                label: View
                multiple_select: true
                hide_when_children_are_not_visible: true
            action_dropdown:
                label: Actions
                multiple_select: true
                hide_when_children_are_not_visible: true
            
            mark_as_pending:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Mark as pending
                hide_in_select_mode: true
                multiple_select: true
                visible_if_for_all_selected_items: |
                    item.status === 'active' || item.status === 'suspended'
                ajax:
                    confirm:
                        message: 'Are you sure you wish to mark the location "[[description]]" as pending?'
                        multiple_select_message: Are you sure you wish mark the selected locations as pending?
                        button_message: Mark as pending
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: mark_location_as_pending
            geocode:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Geocode map co-ordinates
                hide_in_select_mode: true
                multiple_select: true
                ajax:
                    request:
                        action: geocode_locations
            activate:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Activate
                hide_in_select_mode: true
                multiple_select: true
                visible_if_for_all_selected_items: |
                    item.status === 'pending' || item.status === 'suspended'
                ajax:
                    confirm:
                        message: 'Are you sure you wish to activate the location "[[description]]"?'
                        multiple_select_message: Are you sure you wish to activate the selected locations?
                        button_message: Activate
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: activate_location
            suspend:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Suspend
                hide_in_select_mode: true
                multiple_select: true
                visible_if_for_all_selected_items: |
                    item.status === 'pending' || item.status === 'active'
                ajax:
                    confirm:
                        message: 'Are you sure you wish to suspend the location "[[description]]"?'
                        multiple_select_message: Are you sure you wish to suspend the selected locations?
                        button_message: Suspend
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: suspend_location
            delete_location:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Delete
                multiple_select: true
                ajax:
                    confirm:
                        message: |
                            Are you sure you wish to delete the selected location?
                            
                            If this location has child locations, these will be made orphans.
                        multiple_select_message: |
                            Are you sure you wish to delete the selected locations?
                            
                            If any of the selected locations have child locations, these will be made orphans.
                        button_message: Delete
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: delete_location
                hide_in_select_mode: true
            convert_to_simple_place:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Convert to simple place
                ajax:
                    confirm:
                        message: |
                            Are you sure you wish to convert the selected location to a simple place?
                        button_message: Convert
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: convert_to_simple_place
                visible_if: zenarioA.running.zenario_organization_manager
                only_show_on_refiner: zenario_organization_manager__organizations
                hide_in_select_mode: true
            convert_multiple_to_simple_place:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Convert selected to simple places
                multiple_select: true
                multiple_select_only: true
                ajax:
                    confirm:
                        message: |
                            Are you sure you wish to convert the selected locations to simple places?
                        button_message: Convert
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: convert_to_simple_place
                visible_if: zenarioA.running.zenario_organization_manager
                only_show_on_refiner: zenario_organization_manager__organizations
                hide_in_select_mode: true
            convert_to_organization:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Convert to [[organization_singular_en]]
                ajax:
                    confirm:
                        message: |
                            Are you sure you wish to convert the selected location to an [[organization_singular_en]]?
                        button_message: Convert
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: convert_to_organization
                visible_if: zenarioA.running.zenario_organization_manager
                only_show_on_refiner: zenario_organization_manager__simple_locations
                hide_in_select_mode: true
            convert_multiple_to_organization:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: action_dropdown
                label: Convert selected to [[organization_plural_en]]
                multiple_select: true
                multiple_select_only: true
                ajax:
                    confirm:
                        message: |
                            Are you sure you wish to convert the selected locations to [[organization_plural_en]]?
                        button_message: Convert
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: convert_to_organization
                visible_if: zenarioA.running.zenario_organization_manager
                only_show_on_refiner: zenario_organization_manager__simple_locations
                hide_in_select_mode: true
            
            upload_image:
                priv: _PRIV_MANAGE_LOCATIONS
                parent: images_dropdown
                label: Attach image
                hide_in_select_mode: true
                tooltip: |
                    Upload an image|
                                            You may upload a .gif, a .jpeg, a .jpg or a .png images.<br/>
                upload:
                    fileExt: '*.gif;*.jpg;*.jpeg;*.png'
                    fileDesc: Images
                    request:
                        upload_image: true
                without_columns_set:
                    traits.has_image: true
            images:
                parent: images_dropdown
                label: View images
                hide_in_select_mode: true
                link:
                    path: zenario__locations/location_images/panel
                    branch: true
                    refiner: location_images
            remove_location:
                priv: _PRIV_MANAGE_LOCATIONS
                ord: 9999
                label: Remove selected location from sector
                only_show_on_refiner: sector_locations
                ajax:
                    confirm:
                        message: 'Are you sure you wish to remove the location "[[description]]" from this sector?'
                        button_message: Remove
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: remove_location
                multiple_select: true
                hide_in_select_mode: true
            set_parent:
                priv: _PRIV_MANAGE_LOCATIONS
                name: Assign location a parent
                hide_in_select_mode: true
                multiple_select: true
                combine_items:
                    path: zenario__locations/panel/refiners/without_location_id////
                    one_to_one_choose_phrase: Assign parent
                    target_path: zenario__locations/panel
                    min_path: zenario__locations/panel
                    max_path: zenario__locations/panel
                    request:
                        action: assign_new_parent
            remove_child:
                priv: _PRIV_MANAGE_LOCATIONS
                name: Make location an orphan
                multiple_select: false
                only_show_on_refiner: children_of_location
                hide_in_select_mode: true
                ajax:
                    confirm:
                        message: 'Are you sure you wish to make the location "[[description]]" an orphan?'
                        button_message: 'Yes'
                        cancel_button_message: Cancel
                        message_type: warning
                    request:
                        action: make_orphan
