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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/vacancy-application.xml',
'<View title="Vacancy application" defaultFormHandler="xxas_vacancy_pkg.commit_form_data">

  <CreateFields>

    <Container id="TRAIN_STEP1" label="Train Step 1 - Your details and documents" description="Train-step level help">
      <Container id="BASIC" label="Basic Details" description="Placeholder help text">
        <Poplist id="TITLE" label="Title" listProvider="LOOKUP_TYPE:TITLE"/>
        <TextInput id="FIRST_NAME" label="First Name"/>
        <TextInput id="LAST_NAME" label="Last Name" required="true"/>
        <TextInput id="EMAIL" label="Email Address" required="true"/>
        <Poplist id="COUNTRY" label="Country" listProvider="LOOKUP_TYPE:COUNTRIES"/>
        <TextInput id="POSTCODE" label="Post Code"/>
        <TextInput id="HOUSENUMBER" label="House or Flat Number"/>
        <TextInput id="HOME_NUM" label="Home Number"/>
        <TextInput id="MOBILE_NUM" label="Mobile Number"/>
      </Container>
      <Container id="APPL_DET" label="Application Details" description="Placeholder help text">
        <Poplist id="WHERE" label="Where did you first see the vacancy?" listProvider="LOOKUP_TYPE:YES_NO"/>
        <Poplist id="CRIMINAL_CONVICTIONS" label="Do you have any criminal convictions?" listProvider="LOOKUP_TYPE:YES_NO"/>
      </Container>
    </Container>
    
    <Container id="TRAIN_STEP2" label="Train Step 2 - More details" description="Train-step level 2 help">
      <Container id="BASIC" label="Basic Details again" description="Placeholder help text">
        <Poplist id="TITLE" label="Title" listProvider="LOOKUP_TYPE:TITLE"/>
        <TextInput id="LAST_NAME" label="Last Name" required="true"/>
        <TextInput id="EMAIL" label="Email Address" required="true"/>
        <Poplist id="COUNTRY" label="Country" listProvider="LOOKUP_TYPE:COUNTRIES"/>
        <TextInput id="POSTCODE" label="Post Code"/>
        <TextInput id="HOUSENUMBER" label="House or Flat Number"/>
        <TextInput id="HOME_NUM" label="Home Number"/>
        <TextInput id="MOBILE_NUM" label="Mobile Number"/>
      </Container>
      <Container id="APPL_DET" label="Application Details again" description="Placeholder help text">
        <Poplist id="WHERE" label="Where did you first see the vacancy?" listProvider="LOOKUP_TYPE:YES_NO"/>
        <Poplist id="CRIMINAL_CONVICTIONS" label="Do you have any criminal convictions?" listProvider="LOOKUP_TYPE:YES_NO"/>
      </Container>
    </Container>
    
  </CreateFields>

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