/* $Id$ */
/*============================================================================*
 |                 Copyright (c) 2017 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/copy-time.xml');

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/copy-time.xml',
'<View title="Copy Time" showSubmit="true" submitLabel="{message.XXAS_RB_COM_COPY}" defaultFormHandler="xxas_timecard_entry_pkg.copy_time_form_handler">
  <EditFields>

    <Hidden id="PERIOD_ID"/>
    <Hidden id="PERSON_ID"/>
    <Hidden id="ASSIGNMENT_ID"/>
    <Hidden id="MGR_PERSON_ID"/>
    <Hidden id="SOURCE_BLOCK"/>
    <Hidden id="SAVED_SEARCH_ID"/>
    <Hidden id="CALLED_VIEW"/>

    <Container id="FROM_GRP" label="{message.XXAS_TCM_COPY_TIME_FROM}">

     <Hidden id="EMP_CV_FROM_PERSON_ID"/>
     <Combolist id="FROM_PERSON_ID" label="{message.XXAS_TCM_COPY_TIME_PERSON}" emptyValue="{message.XXAS_TCM_COPY_TIME_SEARCH_EMP}" 
      listProvider="REST:calendar-event/search/loggedinemp-or-dir-reportee-only?q={searchText}&amp;savedSearchId=${fieldNR.SAVED_SEARCH_ID}&amp;managerId=${fieldNR.MGR_PERSON_ID}"
      required="true" longlist="true" visible="true" enabled="true" hideIf="!model.CALLED_VIEW.value || 
      model.CALLED_VIEW.value == &apos;EMP&apos;" triggerName="TCM_COPY_TIME_FROM_PERIODS" triggerMethod="POST"/>

     <Combolist id="FROM_PERIOD_ID" label="{message.XXAS_TCM_COPY_TIME_PERIOD}"
      listProvider="REST:timecard-entry/copy-time/from-periods?q={searchText}&amp;fromPersonId=${field.EMP_CV_FROM_PERSON_ID}
      &amp;calledView=${field.CALLED_VIEW}&amp;toPeriodId=${fieldNR.TO_PERIOD_ID}" required="true" longlist="false" visible="true" enabled="true" 
      hideIf="!model.FROM_GRP.FROM_PERSON_ID.value &amp;&amp; !model.FROM_GRP.EMP_CV_FROM_PERSON_ID.value" triggerName="TCM_PER_FROM_PERIOD_SUMMARY" triggerMethod="POST"/>

    </Container>

    <Container id="TO_GRP" label="{message.XXAS_TCM_COPY_TIME_TO}">

     <Hidden id="EMP_CV_TO_PERSON_ID"/>
     <Combolist id="TO_PERSON_ID" label="{message.XXAS_TCM_COPY_TIME_PERSON}" emptyValue="{message.XXAS_TCM_COPY_TIME_SEARCH_EMP}" 
      listProvider="REST:calendar-event/search/loggedinemp-or-dir-reportee-only?q={searchText}&amp;savedSearchId=${fieldNR.SAVED_SEARCH_ID}&amp;managerId=${fieldNR.MGR_PERSON_ID}"
      required="true" longlist="true" visible="true" enabled="true" hideIf="!model.CALLED_VIEW.value || 
      model.CALLED_VIEW.value == &apos;EMP&apos;" triggerName="TCM_COPY_TIME_TO_PERIODS" triggerMethod="POST"/>

     <Combolist id="TO_PERIOD_ID" label="{message.XXAS_TCM_COPY_TIME_PERIOD}"
      listProvider="REST:timecard-entry/copy-time/to-periods?q={searchText}&amp;toPersonId=${field.EMP_CV_TO_PERSON_ID}
      &amp;calledView=${field.CALLED_VIEW}&amp;fromPeriodId=${fieldNR.FROM_PERIOD_ID}" required="true" longlist="false" visible="true" enabled="true" 
      hideIf="!model.TO_GRP.TO_PERSON_ID.value &amp;&amp; !model.TO_GRP.EMP_CV_TO_PERSON_ID.value" triggerName="TCM_PER_TO_PERIOD_SUMMARY" triggerMethod="POST"/>

    </Container>

  </EditFields>

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