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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;
  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/add_grantee.xml',
'<View  title="Add grantee" defaultFormHandler="xxas_grant_pkg.insert_row_grant">
  <CreateFields>
    <Hidden id="FUNCTION_ID"/>
    <Hidden id="OBJ_EXISTS_FLAG"/>
    <Poplist id="GRANTEE_KEY" label="{message.XXAS_PERF_GRANTEE}" required="true" enabled="true" visible="true" listProvider="LOOKUP_TYPE:XXAS_GRANTEE_TYPES" value="NR" refreshOnChange="true"/>
    <Poplist id="ROLE" label="{message.XXAS_ROLE}" required="true" enabled="true" visible="true" listProvider="REST:data-objects/roles" hideIf="model.GRANTEE_KEY.value.id != &apos;NR&apos;"/>
    <Combolist id="OBJECT_ID" label="{message.XXAS_OBJECT}" visible="true" enabled="false" longlist="true" listProvider="REST:data-objects?q={searchText}" hideIf="model.OBJ_EXISTS_FLAG.value == &apos;N&apos;"/>
    <Poplist id="OBJ_INS_ID" label="{message.XXAS_OBJ_IDS}" required="true" enabled="true" visible="true" listProvider="REST:data-objects/set/${field.OBJECT_ID}" refreshOnChange="true" hideIf="!(model.OBJECT_ID.value.id)"/>
    <TextArea id="PREDICATE" label="" visible="true" enabled="false" hideIf="(!(model.OBJECT_ID.value.id) || (model.OBJ_INS_ID.value.id===1) || (model.OBJ_INS_ID.value.id===9999))"/>
    <TextInput id="INS_NAME" label="Title" visible="true" required="true" hideIf="model.OBJ_INS_ID.value.id != 9999"/>
    <TextArea id="PRED" label="Predicate" visible="true" required="true" hideIf="model.OBJ_INS_ID.value.id != 9999"/>
  </CreateFields>
</View>' ); 
xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/add_grantee.xml');
END;
/
COMMIT;
EXIT;