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

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



DECLARE 

  e_dir_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_dir_exists, -31003);

  e_does_not_exists EXCEPTION;
  PRAGMA EXCEPTION_INIT(e_does_not_exists , -31001);

  result boolean;
  
BEGIN

  BEGIN

    result := DBMS_XDB.createfolder('/public/xxas/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/');
    result := DBMS_XDB.createfolder('/public/xxas/emp/view/');

  EXCEPTION
    WHEN e_dir_exists THEN
      NULL;
  END;

  
  BEGIN

    DBMS_XDB.DeleteResource('/public/xxas/emp/view/changemanager.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/changemanager.xml',
'<View showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" title="Change manager" defaultFormHandler="xxas_change_manager_pkg.submit_change_manager_request">

  <EditFields>

    <Container id="BASIC_DET_GRP" label="{message.XXAS_MSS_BASIC_DET_GRP}" visible="false">
      <Hidden id="PERSON_ID"/>
      <Hidden id="ASSIGNMENT_ID"/>
      <Hidden id="TRANSACTION_ID"/>
      <Hidden id="TRANSACTION_STEP_ID"/>
      <Hidden id="IS_MANAGER"/>
      <Hidden id="DIRECT_REPORTS_COUNT"/>
      <Hidden id="PEND_REQ"/>
      <Hidden id="HAS_FUTURE_DATED_RECORDS"/>
      <Hidden id="EFFECTIVE_START_DATE"/>
      <Hidden id="EFFECTIVE_END_DATE"/>
    </Container>

    <Container id="NEW_MGR_GRP" label="{message.XXAS_MSS_NEW_MGR_GRP}" visible="true" enabled="true">
      <ListItem id="APPROVERS" style="row" listFunction="xxas_selfservice_workflow_pkg.get_workflow_details2" visible="false"/>
      <Poplist id="EFFECTIVE_DATE_OPTION" label="{message.XXAS_MSS_EFFECTIVE_DATE_OPTION}" visible="true" required="true" listProvider="LOOKUP_TYPE:XXAS_MSS_EFFECTIVE_DATE_OPTION" enabled="true"/>
      <Date id="EFFECTIVE_FROM_LDW" enabled="true" label="{message.XXAS_MSS_EFFECTIVE_DATE}" visible="true" required="true" hideIf="!model.NEW_MGR_GRP.EFFECTIVE_DATE_OPTION.value || model.NEW_MGR_GRP.EFFECTIVE_DATE_OPTION.value.id == &apos;A&apos;"/>
      <Date id="EFFECTIVE_FROM_FAD" enabled="false" label="{message.XXAS_MSS_EFFECTIVE_DATE}" visible="false" hideIf="!model.NEW_MGR_GRP.EFFECTIVE_DATE_OPTION.value || model.NEW_MGR_GRP.EFFECTIVE_DATE_OPTION.value.id == &apos;E&apos;"/>
      <Combolist id="NEW_MANAGER" label="{message.XXAS_MSS_NEW_MANAGER}" enabled="true" listProvider="REST:peoplesearch/dir-reportee?q={searchText}" longlist="true" required="true"/>
    </Container>

    <Container id="REASSIGN_GRP" label="{message.XXAS_MSS_REASSIGN_GRP}" hideIf="model.BASIC_DET_GRP.IS_MANAGER.value == &apos;N&apos;">

      <Poplist id="REASSIGN_INDIVIDUAL_DRS" label="{message.XXAS_MSS_REASSIGN_IND_DRS}" listProvider="LOOKUP_TYPE:YES_NO" enabled="true"
       value="N" showAsBoolean="true" positiveBooleanValue="Y" hideIf="model.BASIC_DET_GRP.PEND_REQ.value == &apos;Y&apos;"/>
      <Date id="EFFECTIVE_DATE_DR" label="{message.XXAS_MSS_EFFECTIVE_DATE_DR}" enabled="true" visible="false" required="true"
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;Y&apos; || model.BASIC_DET_GRP.PEND_REQ.value == &apos;Y&apos;"/>
      <Combolist id="NEW_MANAGER_DR" label="{message.XXAS_MSS_NEW_MANAGER_DR}" enabled="true" listProvider="REST:peoplesearch/dir-reportee?q={searchText}" longlist="true" required="true"
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;Y&apos; || model.BASIC_DET_GRP.PEND_REQ.value == &apos;Y&apos;"/>

      <MultiRow id="DIRECT_REPORTS" xdbUri="/public/xxas/emp/view/directreports.xml" visible="true" 
       hideIf="model.REASSIGN_GRP.REASSIGN_INDIVIDUAL_DRS.value == &apos;N&apos; &amp;&amp; model.BASIC_DET_GRP.PEND_REQ.value == &apos;N&apos;"/>

    </Container>

    <Container id="NEW_DIR_GRP" label="{message.XXAS_MSS_NEW_DIR_GRP}">
      <MultiRow id="NEW_DIRECT_REPORTS" createAllowed="true" createLabel="Add Report" visible="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/newdirectreports.xml"/>
    </Container>

    <Container id="ADDL_INFO_GRP" label="{message.XXAS_MSS_ADDL_INFO_GRP}">
      <TextInput id="COMMENTS_TO_APPROVER" label="{message.XXAS_RB_TCM_APPR_CMNTS}" enabled="true" required="false"/>
    </Container>

    <Container id="ATTACH_GRP" label="{message.XXAS_RB_EMP_ATTACHMENTS}">
      <Attachment id="ATTACHMENTS" label="{message.XXAS_RB_EMP_ATTACHMENTS}" enabled="true" required="false" entityName="PQH_SS_ATTACHMENT" pk1Field="INSTANCE_PK2_VALUE" categoryCode="MISC"/>
    </Container>

  </EditFields>

</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/changemanager.xml');
END;
/
COMMIT;
EXIT;
