/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2013 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/attachments.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/attachments.xml',
'<View title="Attachments" defaultFormHandler="xxas_attachment_pkg">

  <CreateFields>
    <Container>
      <Combolist id="ATTACHMENT_ENTITY" label="{message.XXAS_EMP_ENTITY}" visible="false" enabled="true" required="true" refreshOnChange="true" listProvider="VALUE_SET_NAME:Applaud Attachment Entities"/>
      <TextInput id="ATTACHMENT_PK1" label="Key 1" required="true" visible="false"/>
      <TextInput id="ATTACHMENT_PK2" label="Key 2" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK3" label="Key 3" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK4" label="Key 4" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK5" label="Key 5" required="false" visible="false"/>
      <Combolist id="CATEGORY_CODE" label="Category" visible="false" enabled="true" required="true" refreshOnChange="true" listProvider="VALUE_SET_NAME:Applaud Attachment Categories"/>
      <TextInput id="TITLE" label="{message.XXAS_RB_EMP_EXP_JT}" enabled="true" required="false" refreshOnChange="true"/>
      <TextInput id="DESCRIPTION" label="{message.XXAS_RB_EMP_EXP_DESC}" enabled="true" required="false" refreshOnChange="true"/>
      <Attachment id="ATTACHMENTS" entityName="PER_PEOPLE_F" label="{message.XXAS_RB_EMP_ATTACHMENTS}" enabled="true" required="true" maxAttachments="1"
                  pk1Field="ATTACHMENT_PK1" pk2Field="ATTACHMENT_PK2" pk3Field="ATTACHMENT_PK3" pk4Field="ATTACHMENT_PK4" pk5Field="ATTACHMENT_PK5"/>
    </Container>         
  </CreateFields>

  <EditFields>
    <Container>
      <Combolist id="ATTACHMENT_ENTITY" label="{message.XXAS_EMP_ENTITY}" visible="false" enabled="true" required="true" refreshOnChange="true" listProvider="VALUE_SET_NAME:Applaud Attachment Entities"/>
      <TextInput id="ATTACHMENT_PK1" label="Key 1" required="true" visible="false"/>
      <TextInput id="ATTACHMENT_PK2" label="Key 2" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK3" label="Key 3" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK4" label="Key 4" required="false" visible="false"/>
      <TextInput id="ATTACHMENT_PK5" label="Key 5" required="false" visible="false"/>
      <Combolist id="CATEGORY_CODE" label="Category" visible="false" enabled="true" required="true" refreshOnChange="true" listProvider="VALUE_SET_NAME:Applaud Attachment Categories"/>
      <TextInput id="TITLE" label="{message.XXAS_RB_EMP_EXP_JT}" enabled="true" required="false" refreshOnChange="true"/>
      <TextInput id="DESCRIPTION" label="{message.XXAS_RB_EMP_EXP_DESC}" enabled="true" required="false" refreshOnChange="true"/>
      <Attachment id="ATTACHMENTS" label="{message.XXAS_RB_EMP_ATTACHMENTS}" enabled="true" required="true" maxAttachments="1"
                  attachmentIdField="INSTANCE_PK1_VALUE"
                  pk1Field="ATTACHMENT_PK1" pk2Field="ATTACHMENT_PK2" pk3Field="ATTACHMENT_PK3" pk4Field="ATTACHMENT_PK4" pk5Field="ATTACHMENT_PK5"/>
    </Container>
  </EditFields>
  
</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/attachments.xml');
END;
/
COMMIT;
EXIT;
