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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/xxas-edit-data-object.xml',
'<View showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" title="Edit data object" defaultFormHandler="xxas_data_objects_pkg.edit_data_object">
  <EditFields>
    <Hidden id="OBJECT_ID"/>
    <TextInput id="DISPLAY_NAME" label="Name" required="true"/>
    <Combolist id="APPLICATION_ID" label="Application" listProvider="REST:form-field/applications?q={searchText}" longlist="true" visible="true"  refreshOnChange="true" required="true"/>
    <Combolist id="DATABASE_OBJECT_NAME" label="Database object name" required="true" listProvider="REST:data-objects/database-objects/${field.APPLICATION_ID}?q={searchText}" longlist="true" refreshOnChange="true" />
    <TextInput id="OBJ_NAME" label="Code" required="true" enabled="false"/>
    <TextInput id="DESCRIPTION" label="Description" required="true"/>
    <Poplist id="PK1_COLUMN_NAME" label="Primay key column1" required="true" listProvider="REST:data-objects/columns/${field.OBJECT_ID}"/>
    <Poplist id="PK2_COLUMN_NAME" label="Primay key column2" listProvider="REST:data-objects/columns/${field.OBJECT_ID}"/>
    <Poplist id="PK3_COLUMN_NAME" label="Primay key column3" listProvider="REST:data-objects/columns/${field.OBJECT_ID}"/>
    <Poplist id="PK4_COLUMN_NAME" label="Primay key column4" listProvider="REST:data-objects/columns/${field.OBJECT_ID}"/>
    <Poplist id="PK5_COLUMN_NAME" label="Primay key column5" listProvider="REST:data-objects/columns/${field.OBJECT_ID}"/>
    <TextArea  id="VIEW_SQL" label="View SQL" enabled="false" visible="false" maxLength="4000"/>
  </EditFields>
</View>' );
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/xxas-edit-data-object.xml'); 
END;
/
COMMIT;
EXIT;
