/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2016 Applaud Solutions UK Ltd                |
 |                             All rights reserved                            |
 *===========================================================================*/

SET VERIFY OFF
SET FEEDBACK OFF
WHENEVER OSERROR  EXIT FAILURE ROLLBACK
WHENEVER SQLERROR EXIT FAILURE ROLLBACK

CREATE OR REPLACE VIEW xxas_block_list_v
AS
SELECT b.menu_id
      ,b.function_id
      ,b.function_name
	  ,b.seeded_block_flag
      ,b.entry_sequence
      ,b.prompt
      ,b.object_id
      ,b.obj_name
	  ,decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pHideIf'),null,'N','Y') RESTRICT_DEVICE
      ,(xxas_block_pkg.get_restrictions(b.function_parameters)) RESTRICTIONS
      ,b.description
      ,b.function_icon
      ,b.security_type type_of_security
      ,upper(b.block_type) block_type
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pStamp')) stamp
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pFullWidth')) full_width
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pRestProvider') rest_provider
      ,xxas_com_msg_pkg.get_string(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pNoDataMessage')) no_data_text
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pNoDataMessage') no_data_message
      ,xxas_com_msg_pkg.get_string(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pDescriptionMessage')) list_desc
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pBackgroundColor') background_color
      ,xxas_util_pkg.boolean_to_flag(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pLimitItems')) limit_list_items
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pDefaultItemsPerPage') items_per_page
      ,nvl(xxas_com_msg_pkg.get_string(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pMoreItemsAvailableLinkMessage')),xxas_com_msg_pkg.get_string('XXAS_COM_MORE_ITEMS_TEXT')) more_items_available_text
      ,xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pMoreItemsAvailableLinkMessage') more_items_available_message
      ,CASE WHEN xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pItemWidth') = 'large' 
            THEN 'Y'
            ELSE 'N' 
       END item_large_grid
      ,CASE WHEN instr(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pLayoutType'),'row')  > 0 
            THEN 'Y' 
            ELSE 'N' 
       END show_row_layout
      ,CASE WHEN instr(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pLayoutType'),'grid')  > 0 
            THEN 'Y' 
            ELSE 'N' 
        END show_grid_layout
      ,CASE WHEN instr(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pLayoutType'),'grid-mini')  > 0 
            THEN 'Y' 
            ELSE 'N' 
       END show_minigrid_layout
      ,p.context_handler page_object_handler
      ,p.object_id_format page_object_id_format
      ,p.published_flag page_published_flag
      ,CASE WHEN p.layout = 'columns2'
            THEN 'Y'
            WHEN p.layout = 'columns3'
            THEN 'Y'
            ELSE 'N'
       END  is_page_column_layout
      ,p.layout page_layout
	  ,CASE WHEN p.layout = 'columns3' 
			THEN decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pBlockSize'),'two-third','Two-third','full-width','Full width','One-third') 
			ELSE NULL
		END BLOCK_SIZE
      ,decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pSearchAttributes'),null,'N','Y') SEARCH_FLAG
      ,(select xxas_block_pkg.get_search_details(xxas_com_sec_pkg.get_parameter_value(parameters,'pSearchAttributes'))
        from fnd_form_functions
        where function_id = b.function_id) search_details
      ,decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pFacets'),null,'N','Y') FILTER_FLAG 
      ,cast(multiset(
               select ab.field,
                      ab.typ,
                      ab.title
               from XMLTable('//value/*'
                        PASSING (select xxas_block_pkg.get_filter_details(xxas_com_sec_pkg.get_parameter_value(parameters,'pFacets'))
                                 from fnd_form_functions
                                 where function_id = b.function_id)
                        COLUMNS FIELD VARCHAR2(100)   PATH '/XXAS_FILTER_DETAILS/FILTER_FIELD',
                                TITLE VARCHAR2(100)   PATH '/XXAS_FILTER_DETAILS/FILTER_TITLE',
                                TYP   VARCHAR2(10)    PATH '/XXAS_FILTER_DETAILS/FILTER_TYPE'
                            ) ab
                    ) as XXAS_FILTER_FIELDS_TBL) FILTER_DETAILS
      ,decode(xxas_com_sec_pkg.get_parameter_value(b.function_parameters,'pSorts'),null,'N','Y') SORT_FLAG    
      ,cast(multiset(
               select ab.field,
                      ab.title,
                      ab.direction,
                      ab.sel_def
               from XMLTable('//value/*'
                        PASSING (select xxas_block_pkg.get_sort_details(xxas_com_sec_pkg.get_parameter_value(parameters,'pSorts'))
                                 from fnd_form_functions
                                 where function_id = b.function_id)
                        COLUMNS FIELD      VARCHAR2(30)   PATH '/XXAS_SORT_DETAILS/SORT_FIELD',
                                TITLE      VARCHAR2(100)  PATH '/XXAS_SORT_DETAILS/SORT_TITLE',
                                DIRECTION  VARCHAR2(100)  PATH '/XXAS_SORT_DETAILS/SORT_DIRECTION',
                                SEL_DEF    VARCHAR2(10)   PATH '/XXAS_SORT_DETAILS/SORT_TYPE'
                            ) ab
                    ) as XXAS_SORT_FIELDS_TBL) SORT_DETAILS
       FROM xxas_blocks_v b
           ,xxas_pages_v p
       WHERE  b.block_type = 'list'
       AND b.menu_id = p.menu_id;

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_BLOCK_LIST_V'
   ,p_description            => 'Applaud Block List');
END;
/

COMMIT;
EXIT;

