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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/xxas-data-object.xml',
'<View showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" title="Add data object" defaultFormHandler="xxas_data_objects_pkg.add_data_object">
  <EditFields>
    <Hidden id="PERSON_ID"/>
    <Hidden id="OBJECT_ID"/>
    <Hidden id="PK1_COLUMN_TYPE"/>
    <Hidden id="PK2_COLUMN_TYPE"/>
    <Hidden id="PK3_COLUMN_TYPE"/>
    <Hidden id="PK4_COLUMN_TYPE"/>
    <Hidden id="PK5_COLUMN_TYPE"/>
    <Poplist id="OBJECT_SOURCE" label="Type" enabled="true" listProvider="LOOKUP_TYPE:XXAS_OBJECTS_SOURCE" visible="true" required="true" refreshOnChange="true"/>
    
    <!--Combolist id="SELECTED_OBJECT" label="Object" listProvider="REST:data-objects/database-objects?q={searchText}" longlist="true" refreshOnChange="true" required="true" emptyValue="Start typing to select object"  visible="false"/-->
    <Combolist id="SELECTED_OBJECT" label="Object" listProvider="REST:data-objects/obj-list?q={searchText}" longlist="true" refreshOnChange="true" required="true" emptyValue="Start typing to select object"  visible="false"/>
    <TextInput id="DISPLAY_NAME" label="Name" required="true" visible="false"/>
    <Combolist id="APPLICATION_ID" label="Application" listProvider="REST:form-field/applications?q={searchText}" longlist="true" visible="false" required="true" emptyValue="Start typing to select application"/>
    <TextInput id="DATABASE_OBJECT_NAME" label="Database object name" required="true"  visible="false"/>
    <!--TextInput id="CODE" label="Code" required="true" visible="false"/-->
    <!--TextInput id="DESCRIPTION" label="Description" required="true"/-->
    <TextArea  id="VIEW_SQL" label="View SQL" required="true" maxChars="4000" visible="false"/>
    <TextInput id="PK1_COLUMN_NAME" label="Primay key column1" required="true" visible="false"/>
    <TextInput id="PK2_COLUMN_NAME" label="Primay key column2"  visible="false"/>
    <TextInput id="PK3_COLUMN_NAME" label="Primay key column3"  visible="false"/>
    <TextInput id="PK4_COLUMN_NAME" label="Primay key column4"  visible="false"/>
    <TextInput id="PK5_COLUMN_NAME" label="Primay key column5"  visible="false"/>
    <Poplist id="E_PK1_COLUMN_NAME" label="Primay key column1" required="true" listProvider="REST:data-objects/columns/${field.SELECTED_OBJECT}" visible="false"/>
    <Poplist id="E_PK2_COLUMN_NAME" label="Primay key column2" listProvider="REST:data-objects/columns/${field.SELECTED_OBJECT}" visible="false"/>
    <Poplist id="E_PK3_COLUMN_NAME" label="Primay key column3" listProvider="REST:data-objects/columns/${field.SELECTED_OBJECT}" visible="false"/>
    <Poplist id="E_PK4_COLUMN_NAME" label="Primay key column4" listProvider="REST:data-objects/columns/${field.SELECTED_OBJECT}" visible="false"/>
    <Poplist id="E_PK5_COLUMN_NAME" label="Primay key column5" listProvider="REST:data-objects/columns/${field.SELECTED_OBJECT}" visible="false"/>
  </EditFields>
</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/xxas-data-object.xml');
END;
/
COMMIT;
EXIT;
