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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/candidateapplication.xml',
'<View submitLabel="Submit Application" title="Candidate application" defaultFormHandler="xxas_applicant_pkg.save_application_form">

  <CreateFields>

    <Container id="BASIC" label="Basic Details" layout="FORM">
      <Hidden id="PERSON_ID"/>
      <Hidden id="VACANCY_ID"/>
      <Poplist id="TITLE" label="{message.XXAS_RB_EMP_EXP_JT}" required="false" listProvider="LOOKUP_TYPE:TITLE"/>
      <TextInput id="FIRST_NAME" label="First Name" required="true"/>
      <TextInput id="LAST_NAME" label="Last Name" required="true"/>
      <TextInput id="EMAIL_ADDRESS" label="Email" enabled="false"/>          
    </Container>

    <TextInput id="NATIONAL_IDENTIFIER" label="National Insurance Number" required="true" enabled="false" />
  
    <Container id="ADDRESS" label="Address" layout="FORM">
      <Flexfield applicationId="800" descriptiveFlexfieldName="Address Structure"/>
    </Container>
    
    <Container id="PHONE_NUMBERS_GRP" label="Phone Numbers" layout="TABULAR">
      <MultiRow id="PHONE_NUMBERS" createAllowed="false" xdbUri="/public/xxas/emp/view/applicantphonenumbers.xml"/>
    </Container>	
     
    <!--Container id="PHONE_NUMBERS" label="Phone Numbers" layout="TABULAR">
      <TextInput id="CELL" label="Personal Mobile"/>          
      <TextInput id="LAND" label="Landline"/>          
    </Container-->

    <Container id="DOCUMENTS_GRP" label="Resume &amp; Supporting Documents" layout="TABULAR">
      <File id="CV_DOCUMENT_ID" label="Resume" buttonText="Upload your Resume" fileInfoProvider="xxas_applicant_pkg.get_document_info"/>
      <Poplist id="XXX_NO_RESUME" label="I don''t have a Resume" showAsBoolean="true" positiveBooleanValue="Y" listProvider="LOOKUP_TYPE:YES_NO" description="Tick this to type in previous employers, education, qualifications and schools manually" hideIf="model.DOCUMENTS_GRP.CV_DOCUMENT_ID.value !== false &amp;&amp; !!model.DOCUMENTS_GRP.CV_DOCUMENT_ID.value"/>
      <File id="COV_LET_DOCUMENT_ID" label="Covering Letter" buttonText="Upload a Covering Letter" fileInfoProvider="xxas_applicant_pkg.get_document_info"/>
      <!--MultiRow id="DOCUMENTS" createAllowed="true" xdbUri="/public/xxas/emp/view/applicantdocs.xml"/-->
    </Container>	
    
   <Container id="PREVIOUS_EMPLOYERS_GRP" label="Previous Employers" layout="TABULAR" hideIf="model.DOCUMENTS_GRP.XXX_NO_RESUME.value != &apos;Y&apos;">
      <MultiRow id="PREVIOUS_EMPLOYERS" createAllowed="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/candidatepreviousemployers.xml"/>
    </Container>
    
    <Container id="FURTHER_EDUCATION_GRP" label="Further Education and Qualifications" layout="TABULAR" hideIf="model.DOCUMENTS_GRP.XXX_NO_RESUME.value != &apos;Y&apos;">
      <MultiRow id="FURTHER_EDUCATION" createAllowed="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/candidatefurthered.xml"/>
    </Container>

    <Container id="SCHOOL_GRP" label="School" layout="TABULAR" hideIf="model.DOCUMENTS_GRP.XXX_NO_RESUME.value != &apos;Y&apos;">
      <MultiRow id="SCHOOL" createAllowed="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/candidateschool.xml"/>
    </Container>

    <Container id="APPLICATION_DETAILS" label="Application Details" layout="FORM">         
      <Poplist id="SOURCE_TYPE" label="Where did you first see the vacancy?" listProvider="LOOKUP_TYPE:REC_TYPE" required="true"/>
      <TextInput id="SOURCE_VALUE1" label="Employee 1" required="true" emptyValue="Enter employee number or work email" hideIf="!model.APPLICATION_DETAILS.SOURCE_TYPE.value || model.APPLICATION_DETAILS.SOURCE_TYPE.value.id != &apos;ER&apos;"/>          
      <TextInput id="SOURCE_VALUE2" label="Employee 2" required="false" emptyValue="Enter employee number or work email"
      hideIf="!model.APPLICATION_DETAILS.SOURCE_TYPE.value || model.APPLICATION_DETAILS.SOURCE_TYPE.value.id != &apos;ER&apos;"/>          
      <Poplist id="XXX_ATTRIBUTE9" label="Do you have any criminal convictions that are not &apos;spent&apos;?" required="true" listProvider="LOOKUP_TYPE:YES_NO"/>
      <TextInput id="XXX_ATTRIBUTE10" label="Please provide details including date, nature of penalty" required="true" hideIf="!model.APPLICATION_DETAILS.XXX_ATTRIBUTE9.value.id || model.APPLICATION_DETAILS.XXX_ATTRIBUTE9.value.id === &apos;N&apos;"/>
      <Poplist id="XXX_ATTRIBUTE6" label="Are you legally allowed to live and work in the UK?" required="true" listProvider="LOOKUP_TYPE:YES_NO"/>
      <Poplist id="XXX_ATTRIBUTE7" label="Have you reached normal school leaving age?" required="true" listProvider="LOOKUP_TYPE:YES_NO"/>
    </Container>
    
    <Container id="EEO" label="Equal Employment Opportunities" layout="FORM">       
      <Poplist id="SEX" label="Gender" listProvider="LOOKUP_TYPE:SEX"/>
      <Flexfield applicationId="800" descriptiveFlexfieldName="Person Developer DF" descriptiveFlexContextCode="GB"/>
      <Flexfield applicationId="800" descriptiveFlexfieldName="PER_PEOPLE"/>
    </Container>

    <Hidden id="OLM_ASSESS_START_TS" visible="false"/>
    <Hidden id="TEST_ID"/>

    <Container id="OLM_GRP" label="OLM Assessment">
      <MultiRow id="OLM_ASSESSMENT" xdbUri="/public/xxas/emp/view/candolmassessquestions.xml"/>
    </Container>

  </CreateFields>

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