/* $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_TAGS_V
AS
SELECT 'flexible' "type"
       ,v.prompt "line1"
       ,v.prompt
       ,v.description
       ,v.entry_sequence
       ,null "line2"
       ,null "line3"
       ,lower(f.web_icon) function_icon
       ,xxas_rslt_cache_pkg.resolve_color_name
         (xxas_com_sec_pkg.get_parameter_value(parameters, 'pColor')) color
       ,b.function_id
       ,b.menu_id
       ,b.function_id || '_' || v.function_id "objectId"
       ,v.function_id link_function_id
	   ,f.function_name
       ,'block-edit-link' "pageId"
       ,xxas_com_sec_pkg.get_function_id(
	    xxas_com_sec_pkg.get_parameter_value(parameters, 'pNavigateTo')) func_name
       ,xxas_com_sec_pkg.get_parameter_value(parameters, 'pRespKey') resp_key
       ,xxas_com_sec_pkg.get_parameter_value(f.parameters,'pGroups') groups
       ,xxas_com_sec_pkg.get_parameter_value(parameters, 'pUrl') url
       ,CASE WHEN xxas_com_sec_pkg.get_parameter_value(parameters, 'pUrl') is not null
             THEN 'URL'
             WHEN xxas_com_sec_pkg.get_parameter_value(parameters, 'pPageId') is not null
             THEN 'Applaud page'
             ELSE 'Oracle Function'
        END type_of_link
         ,xxas_com_sec_pkg.get_parameter_value(parameters, 'pPageId') page_id
          ,xxas_com_sec_pkg.get_parameter_value(parameters, 'pObjectId') object_id
       ,CASE WHEN nvl(b.tag_groups,1) = nvl(xxas_com_sec_pkg.get_parameter_value(f.parameters,'pGroups'),1)
             THEN 'balanced'
             ELSE 'assertive'
        END "statusColor"
      ,CASE WHEN xxas_com_sec_pkg.get_parameter_value(parameters,'pContextType')='SSHR'
            THEN 'Y'
            ELSE 'N'
      END action
      ,xxas_block_pkg.validate_sshr_function(xxas_com_sec_pkg.get_parameter_value(parameters, 'pRespKey')
                             ,xxas_com_sec_pkg.get_parameter_value(parameters, 'pNavigateTo') 
                              , parameters) validate_sshr
      ,xxas_com_sec_pkg.get_parameter_value(parameters,'pNewTabOrWindow') new_browser
      ,decode(xxas_com_sec_pkg.get_parameter_value(parameters,'pSecurityGroupID'),null,9999,0,9999
      ,xxas_com_sec_pkg.get_parameter_value(parameters,'pSecurityGroupID')) security_group
        FROM fnd_menu_entries_vl v
           , fnd_form_functions f 
           , fnd_menus m
           , xxas_block_links_v b
      WHERE  m.menu_name = nvl(xxas_com_sec_pkg.get_function_parameter(b.function_name,'pLinksMenuName')
	                     , fnd_profile.value('XXAS_COM_REG_ACTIONS_MENU'))
        AND v.menu_id = m.menu_id
        AND f.function_id = v.function_id;

BEGIN
  xxas_fnd_dictionary_pkg.add_view
   (p_application_short_name => xxas_util_pkg.app
   ,p_view_name              => 'XXAS_TAGS_V'
   ,p_description            => 'Applaud Block link tags view');
END;
/

COMMIT;
EXIT;

