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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/performance-plan.xml',
'<View title="Performance plan" defaultFormHandler="xxas_perf_plans_pkg.insert_row_form_handler" submitLabel="{messages.XXAS_RB_COM_SAVE}" formHelp="A performance plan is a container for a set of goals and, optionally, one or more review periods. You can enrol everyone into a plan or use an Enrollment formula to enrol a group of individuals. A user must be in at least one plan to set goals and have review documents.">
  <EditFields>
    <Container>
      <Hidden id="PERF_PLAN_ID"/>
      <Hidden id="ASSIGNMENT_ID"/>
      <TextInput id="TITLE" label="Title" required="true" emptyValue="Ex: 2017 performance plan" description="This is shown to users"/>
      <Date id="PLAN_START_DATE" label="Start date" required="true" visible="true" description="The first day of the plan"/>
      <Date id="PLAN_END_DATE" label="End date" required="true" visible="true" description="The last day of the plan"/>
      <Poplist id="STATUS_CODE" label="Status" enabled="true" listProvider="LOOKUP_TYPE:XXAS_PERF_PLAN_STATUS" visible="false"/>
      <Poplist id="ENROLLMENT_FORMULA_NAME" label="Enrollment formula" listProvider="VALUE_SET_NAME:XXAS_PERF_ENROLL_FORMULA" required="true" visible="true" description="Restrict enrollment according to eligibility defined in this formula."/>
      <Poplist id="USE_GRAPHICAL_RATING" label="Use graphical ratings" enabled="true" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
      <TextInput id="ICON_NAME"  label="Icon name" visible="true" required="true" hideIf="model.USE_GRAPHICAL_RATING.value != &apos;Y&apos;"/>
      <TextInput id="ICON_COLOR" label="Icon color" visible="true"  required="true" hideIf="model.USE_GRAPHICAL_RATING.value != &apos;Y&apos;"/>
      <Poplist id="GOAL_RATING_LOOKUP_TYPE"  label="Lookup for rating goals" visible="true" required="false" listProvider="VALUE_SET_NAME:XXAS_LOOKUP_TYPES" longlist="true"/>
      <Poplist id="COMPETENCY_RATING_LOOKUP_TYPE"  label="Lookup for rating competencies" visible="true" required="false" listProvider="VALUE_SET_NAME:XXAS_LOOKUP_TYPES" longlist="true"/>
    </Container>
    <Container id="REVIEWS_GRP" label="Review periods" description="Optionally include one or more review templates in this plan, such as a mid-year review and an end-of-year review.">
      <MultiRow id="REVIEWS" required="true" formulaName="XXAS_PERF_PLAN_EDIT" xdbUri="/public/xxas/emp/view/performance-plan-review.xml" createAllowed="true" createLabel="Add review period"/>
    </Container>
  </EditFields>
</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/performance-plan.xml');
END;
/
COMMIT;
EXIT;
