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

  EXCEPTION  
    WHEN e_does_not_exists THEN
      NULL;
  END;
  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/template-step.xml',
'<View title="Template step" defaultFormHandler="xxas_perf_review_templates_pkg.step_form_post_handler" submitLabel="{message.XXAS_RB_COM_SAVE}" showSubmit="true">
  <EditFields>
    <Container id="STEP_DETAILS">
      <Hidden id="PERF_REVIEW_TEMPL_STEP_ID"/>
      <Hidden id="PERF_REVIEW_TEMPLATE_ID"/>
      <TextInput id="STEP_TITLE" label="{message.XXAS_BK_PROMPT}" required="true" emptyValue="Ex: Self-appraisal" description="This is shown to users"/>
      <TextArea id="STEP_DESCRIPTION" label="{message.XXAS_PERF_ON_SCR_ADVICE}" emptyValue="Guidance on completing this step; HTML tags are supported." maxChars="2000" />
      <Poplist id="STAGE_CODE" label="{message.XXAS_PERF_STAGE}" listProvider="LOOKUP_TYPE:XXAS_PERF_REVIEW_TS_STAGES" required="true" description="Use &lt;strong&gt;Review&lt;/strong&gt; for editing the document; use &lt;strong&gt;Signatures&lt;/strong&gt; for final signatures."/>
      <Number id="SEQUENCE" label="{message.XXAS_PERF_SEQUENCE}" required="true" emptyValue="Ex: 1" description="A number indicating the order sequence of this step. 1 is first."/>
      <Number id="STEP_DURATION_DAYS" label="{message.XXAS_PERF_MAX_DURATION}" emptyValue="Ex: 15" description="The maximum amount of time this step should take in elapsed calendar days. The due date is calculated from this."/>
      <Poplist id="INTERACTION_CODE" label="{message.XXAS_PERF_INTERACTION}" listProvider="LOOKUP_TYPE:XXAS_PERF_REVIEW_TS_INTERACT" required="true" value="S" description="&lt;strong&gt;Single participant&lt;/strong&gt; - just one person completes this step&lt;br/&gt; &lt;strong&gt;Iterative&lt;/strong&gt; - Multiple people are involved but only one person at a time. They transfer the document between them until the step is done&lt;br&gt;&lt;strong&gt;Parallel&lt;/strong&gt; - multiple people complete the step simultaneously"/>
      <Poplist id="GOAL_EDITING" label="{message.XXAS_PERF_GOALS}" listProvider="LOOKUP_TYPE:XXAS_PERF_GOAL_EDITING" required="true" />
      <Poplist id="GOAL_COMMENTING" label="{message.XXAS_PERF_GOAL_COMMENTS}" listProvider="LOOKUP_TYPE:XXAS_PERF_GOAL_COMMENTING" 
          required="true" hideIf="!model.STEP_DETAILS.GOAL_EDITING.value.id || model.STEP_DETAILS.GOAL_EDITING.value.id == &apos;X&apos;"/>
      <Poplist id="COMPETENCY_EDITING" label="{message.XXAS_PERF_COMPETENCIES}" listProvider="LOOKUP_TYPE:XXAS_PERF_COMP_EDITING" required="true" />
      <Poplist id="COMPETENCY_COMMENTING" label="{message.XXAS_PERF_COMP_COMMENTS}" listProvider="LOOKUP_TYPE:XXAS_PERF_COMP_COMMENTING" required="true" hideIf="!model.STEP_DETAILS.COMPETENCY_EDITING.value.id || model.STEP_DETAILS.COMPETENCY_EDITING.value.id == &apos;X&apos;"/>
      <Poplist id="QUESTIONNAIRE_EDITING" label="{message.XXAS_PERF_OVERALL}" listProvider="LOOKUP_TYPE:XXAS_PERF_QUEST_EDITING" required="true" />
      <Combolist id="SINGLE_PARTICIPANT_ID" label="{message.XXAS_PERF_PARTIC_ROLE}" visible="true" longlist="true" required="true" listProvider="REST:participants?q={searchText}" hideIf="model.STEP_DETAILS.INTERACTION_CODE.value.id != &apos;S&apos;" description="The single participant role who completes this step"/>
    </Container>
      
    <Container id="PARTIC_DETAILS" 
         hideIf="model.STEP_DETAILS.INTERACTION_CODE.value == null || model.STEP_DETAILS.INTERACTION_CODE.value.id == &apos;S&apos;" 
         label="{message.XXAS_PERF_PARTIC_ROLES}">
      <MultiRow id="PARTICIPANTS" xdbUri="/public/xxas/emp/view/step-participants.xml" formulaName="XXAS_PERF_TS_PARTIC"
                 includeEmptyRow="true" createAllowed="true" createLabel="{message.XXAS_PG_ADD_ROLE_T}"/>
    </Container>

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