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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/dor.xml',
'<View submitLabel="{message.XXAS_RB_COM_SAVE}" title="Documents of record" defaultFormHandler="xxas_dor_pkg.form_post_handler">
   <EditFields>
     
	 <ListItem id="APPROVERS" style="row" listFunction="xxas_selfservice_workflow_pkg.get_workflow_details2"/>
     <Hidden id="DOCUMENT_EXTRA_INFO_ID"/>
     <Hidden id="PERSON_ID"/>
	 <Hidden id="OBJECT_VERSION_NUMBER"/>
	 <Hidden id="TRANSACTION_ID"/>
     <Combolist id="TERRITORY_CODE" label="{message.XXAS_DOR_COUNTRY_NAME}" listProvider="REST:dor/countries?q={searchText}" enabled="true" longlist="true" refreshOnChange="true"/>
     <Hidden id="TERRITORY_CODE_SET"/>
	 <Combolist id="DOCUMENT_TYPE_ID" label="{message.XXAS_DOR_DOC_TYPE}" enabled="true" refreshOnChange="true" required="true"/>
     <TextInput id="CATEGORY_NAME" label="{message.XXAS_DOR_CAT}" listProvider="REST:dor/categories?documentTypeId=${field.DOCUMENT_TYPE_ID}" enabled="false" required="true"/>
     <TextInput id="SUB_CATEGORY_NAME" label="{message.XXAS_DOR_SUBCAT}" hideIf="model.SUB_CATEGORY_NAME.value == '' ''" enabled="false"/>
     <Date id="DATE_FROM" label="{message.XXAS_DOR_VALID_FROM}" required="true"/>
	 <Date id="DATE_TO" label="{message.XXAS_DOR_VALID_TO}" required="false" description="{message.XXAS_DOR_VALID_TO_HELP_TEXT}"/> 
	 <TextInput id="DOCUMENT_NUMBER" label="{message.XXAS_DOR_DOC_NUM}" required="false" maxChars="60"/>
     <TextInput id="ISSUED_BY" label="{message.XXAS_DOR_ISSUED_BY}" required="false" description=
	 "{message.XXAS_DOR_ISSUED_BY_HELP_TEXT}" />
     <TextInput id="ISSUED_AT" label="{message.XXAS_DOR_ISSUED_AT}" required="false" description=
	 "{message.XXAS_DOR_ISSUED_AT_HELP_TEXT}"/>
     <Date id="ISSUED_DATE" label="{message.XXAS_DOR_ISSUED_DATE}" required="false" maxChars="240"/>
	 <TextInput id="ISSUING_AUTHORITY" label="{message.XXAS_DOR_ISSUED_AUTH}" required="false" description=
	 "{message.XXAS_DOR_ISSUED_AUTH_HELP_TEXT}"/>
	 <TextInput id="COMMENTS" maxChars="240" label="{message.XXAS_RB_TCM_APPR_CMNTS}" />
	 <TextInput id="VERIFIED_BY_USER_NAME" label="{message.XXAS_DOR_VERIFIED_BY}" required="false" maxChars="240"/>
	 <Date id="VERIFIED_DATE" label="{message.XXAS_DOR_VERIFIED_DATE}" required="false"/>
	 <Flexfield applicationId="800" descriptiveFlexfieldName="Extra Document Info DDF" />
	 <Flexfield applicationId="800" descriptiveFlexfieldName="HR_DOCUMENT_EXTRA_INFO" />
	 <MultiRow id="ATTACHMENTS" includeEmptyrow="true" required="true" createAllowed="true" toBeInSingleRow="true" createLabel="{message.XXAS_EMP_ABS_EVENT_ADD_ATTACH}" xdbUri="/public/xxas/emp/view/dor-attach.xml"/>
	 
  </EditFields>

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