/* $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/orgmgr.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/orgmgr.xml',
'<View objectType="XXAS_ORG_MGR" title="Organization manager" defaultFormHandler="">

  <CreateFields>
    <TextInput id="ORGANIZATION_NAME" label="{message.XXAS_MSS_ORGANIZATION_NAME}" enabled="false" visible="true"/>
    <Hidden id="ORGANIZATION_ID"/>
    <TextInput id="DR_CUR_MANAGER" label="{message.XXAS_MSS_DR_CUR_MANAGER}" enabled="false" visible="true"/>
    <Combolist id="DR_NEW_MANAGER" label="{message.XXAS_MSS_DR_NEW_MANAGER}" enabled="true" visible="true" listProvider="REST:peoplesearch/dir-reportee?q={searchText}" longlist="true" required="false" 
	 hideIf="model.RELATION_GRP.ORG_UPDATE_NEW_MANAGER.value == &apos;N&apos; &amp;&amp; model.TERM_GRP.PEND_REQ.value == &apos;N&apos;"/>
    <Hidden id="DR_PERSON_ID"/>
    <Date id="START_DATE" label="{message.XXAS_MSS_START_DATE}" enabled="true" visible="true" required="true" 
     hideIf="model.RELATION_GRP.ORG_UPDATE_NEW_MANAGER.value == &apos;N&apos; &amp;&amp; model.TERM_GRP.PEND_REQ.value == &apos;N&apos;"/>
    <Date id="END_DATE" label="{message.XXAS_MSS_END_DATE}" enabled="true" visible="true" required="false" 
     hideIf="model.RELATION_GRP.ORG_UPDATE_NEW_MANAGER.value == &apos;Y&apos; &amp;&amp; model.TERM_GRP.PEND_REQ.value == &apos;N&apos;"/>
    <Hidden id="ORG_INFORMATION_ID"/>
    <Hidden id="REPORTING_NAME"/>
    <Hidden id="CUR_START_DATE"/>
    <Hidden id="CUR_END_DATE"/>
    <Hidden id="ORG_OBJECT_VERSION_NUMBER"/>
  </CreateFields>

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