/* $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_PARTICIPANTS_LIST_V
AS
  SELECT 'flexible' "type",
        xppv.perf_participant_id "PERF_PARTICIPANT_ID",
        xppv.perf_participant_id "id",
        xppv.participant "PARTICIPANT",
        xppv.participant "line1",
        xppv.provider_function "PROVIDER_FUNCTION",
        lower(xppv.provider_function) "line3",        
          XMLElement
            ("actions"
             ,XMLAttributes
                   ('true' as "json:force-array"
                   ,'http://json.org/' as "xmlns:json")
             ,CASE WHEN xxas_com_sec_pkg.test_instance('XXAS_DT_PERF_PARTIC_EDIT',xppv.perf_participant_id) = 'Y' THEN 
                   XMLElement("action"
                         ,XMLFOREST(xxas_com_msg_pkg.get_string('XXAS_RB_COM_EDIT') "title")
                         ,XMLFOREST('false' "bulkActionEnabled")
                         ,XMLFOREST('LINK' "operation")
                         ,XMLFOREST('edit-participant' "pageId")
                         ,XMLFOREST(xppv.perf_participant_id "objectId")
                         ,XMLFOREST('modal' "target")
                         ,XMLElement ("meta"
                                      ,XMLElement("options"
                                                  ,XMLFOREST('positive' "color")
                                                  ,XMLFOREST('med' "weight")
                                                 )
                                     )
                        ) END
             ,CASE WHEN xxas_com_sec_pkg.test_instance('XXAS_DT_PERF_PARTIC_DELETE',xppv.perf_participant_id) = 'Y' THEN
                   XMLElement("action"
                         ,XMLFOREST(xxas_com_msg_pkg.get_string('XXAS_RB_COM_DEL') "title")
                         ,XMLFOREST('false' "bulkActionEnabled")
                         ,XMLFOREST('DELETE' "operation")
                         ,XMLFOREST(xxas_com_rest_util_pkg.uri_from_path('participants')||'/'||xppv.perf_participant_id "href")
                         ,XMLElement ("meta"
                                      ,XMLElement("options"
                                                  ,XMLFOREST('assertive' "color")
                                                  ,XMLFOREST('med' "weight")
                                                 )
                                     )
                        )END
            ) "linked"     
   FROM xxas_perf_participants_v xppv
ORDER BY xppv.participant;


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

COMMIT;
EXIT;

