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

    EXCEPTION
      WHEN e_does_not_exists THEN
        NULL;
    END;

    
    result := DBMS_XDB.createresource('/public/xxas/emp/view/block-flexible.xml',
  '<View submitLabel="{message.XXAS_RB_COM_SAVE}" title="Flexible block" defaultFormHandler="xxas_block_pkg.post_block_update">

    <EditFields>
	 <Container>
		<Hidden id="MENU_ID"/>
		<Hidden id="FUNCTION_ID"/>
		<Hidden id="PAGE_OBJECT_HANDLER"/>
    <Hidden id="PAGE_OBJECT_ID_FORMAT"/>
		<Hidden id="IS_PAGE_COLUMN_LAYOUT"/>
         <Hidden id="PAGE_LAYOUT"/>
    <Combolist id="BLOCK_TYPE" label="{message.XXAS_BK_BLOCK_TYPE}" listProvider="LOOKUP_TYPE:XXAS_BLOCK_TYPES" enabled="false"/>
    <TextInput id="PROMPT" label="{message.XXAS_BK_PROMPT}" required="false" maxChars="60"/>
    <TextInput id="DESCRIPTION" label="{message.XXAS_BK_DESCRIPTION}" required="false" maxChars="240"/>
    <Number id="ENTRY_SEQUENCE" label="{message.XXAS_BK_ENTRY_SEQUENCE}" required="true"/>
    <Poplist id="STAMP" label="{message.XXAS_BK_STAMP}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" value="N" positiveBooleanValue="Y" 
     description="Force this block&apos;s order to the top"/>
    <Poplist id="LIMIT_LIST_ITEMS" label="{message.XXAS_COM_LIMIT_THE_ITEMS}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" value="N" positiveBooleanValue="Y"/>
    <Number id="ITEMS_PER_PAGE" label="{message.XXAS_COM_ITEMS_PER_PAGE}" required="true" value="6" description="A SHOW MORE link will be displayed when more items are available" hideIf="model.LIMIT_LIST_ITEMS.value != &apos;Y&apos;"/>
    <Hidden id="MORE_ITEMS_AVAILABLE_MESSAGE" label="More items available message"/>
    <TextInput id="MORE_ITEMS_AVAILABLE_TEXT" label="{message.XXAS_COM_MORE_ITEMS_LINK_TEXT}" value="SHOW MORE" description="By default link text shown as &apos;SHOW MORE&apos;. Change here to show a different link text." required="false" maxChars="20" hideIf="model.LIMIT_LIST_ITEMS.value != &apos;Y&apos;"/>
    <Poplist id="FULL_WIDTH" label="{message.XXAS_BK_FULL_WIDTH}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" value="N" positiveBooleanValue="Y" 
    description="Force the block to full-width so it spans its columns" hideIf="model.PAGE_LAYOUT.value != &apos;columns2&apos;"/>
    <Poplist id="BLOCK_SIZE" label="Block width" listProvider="VALUE_SET_NAME:XXAS_BLOCK_SIZE" 
       required="true" value="One-third" hideIf="model.PAGE_LAYOUT.value != &apos;columns3&apos;"/>
    <ColorPicker id="BACKGROUND_COLOR" label="{message.XXAS_COM_BACKGROUND_COLOR}" required="false" allowEmpty="true" preferredFormat="hex"/> 
    <Icon id="FUNCTION_ICON" label="{message.XXAS_BK_FUNCTION_ICON}" required="false" maxChars="30"/>
    <TextInput id="FUNCTION_NAME" label="{message.XXAS_BK_FUNCTION_NAME}" enabled="false"/>
    <Combolist id="TYPE_OF_SECURITY" label="{message.XXAS_BK_TYPE_OF_SECURITY}" listProvider="LOOKUP_TYPE:XXAS_BLOCK_SECURITY_TYPES" required="true" value="RD" 
     hideIf="!model.PAGE_OBJECT_ID_FORMAT.value"/>
    <Combolist id="OBJECT_ID" label="{message.XXAS_BK_OBJECT_ID}" listProvider="REST:objects?q={searchText}" longlist="true" required="true" 
     hideIf="!model.TYPE_OF_SECURITY.value || model.TYPE_OF_SECURITY.value.id == &apos;RO&apos;"/>
    <Poplist id="RESTRICT_DEVICE" label="Restrict devices" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" />
    <Combolist id="RESTRICTIONS" label="Hide on" multipleSelection="true" listProvider="VALUE_SET_NAME:XXAS_DEVICE_RESTRICTIONS_VS" 
     hideIf="model.RESTRICT_DEVICE.value != &apos;Y&apos;"/>
		<Poplist id="LAYOUT" label="{message.XXAS_BK_FLEX_LAYOUT}" listProvider="LOOKUP_TYPE:XXAS_FLEXIBLE_LAYOUTS" required="true"/>
		<Hidden id="DATA_FUNCTION_ID" label="Data function"/>
		<Combolist id="DATA_OBJECT_ID" label="{message.XXAS_BK_FLEX_DATA_SOURCE}" listProvider="REST:objects?q={searchText}" longlist="true" required="false" hideIf="model.LAYOUT.value.id == &apos;HTML&apos; || model.LAYOUT.value.id == NULL"/>
		<TextInput id="ORDER_BY" label="{message.XXAS_BK_FLEX_ORDER_BY}" hideIf="model.LAYOUT.value.id == &apos;HTML&apos; || model.LAYOUT.value.id == NULL || !model.DATA_OBJECT_ID.value"/>
		<Poplist id="SHOW_JOINING_COLUMNS" label="{message.XXAS_BK_FLEX_SHOW_JOIN_COL}" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" required="false" showAsBoolean="true"  hideIf="!model.DATA_OBJECT_ID.value"/>
		<Poplist id="PERSON_ID_COLUMN_NAME" label="{message.XXAS_BK_FLEX_PERSON_ID}" listProvider="REST:data-object-columns/${field.DATA_OBJECT_ID}" value="PERSON_ID" hideIf="model.SHOW_JOINING_COLUMNS.value != &apos;Y&apos;"/>
		<Poplist id="ASSIGNMENT_ID_COLUMN_NAME" label="{message.XXAS_BK_FLEX_ASSIGNMENT_ID}" listProvider="REST:data-object-columns/${field.DATA_OBJECT_ID}" default="ASSIGNMENT_ID" hideIf="model.SHOW_JOINING_COLUMNS.value != &apos;Y&apos;"/>
		<Poplist id="TRANSACTION_ID_COLUMN_NAME" label="{message.XXAS_BK_FLEX_TRANSACTION_ID}" listProvider="REST:data-object-columns/${field.DATA_OBJECT_ID}" default="TRANSACTION_ID" hideIf="model.SHOW_JOINING_COLUMNS.value != &apos;Y&apos;"/>
		<Poplist id="PARTY_ID_COLUMN_NAME" label="{message.XXAS_BK_FLEX_PARTY_ID}" listProvider="REST:data-object-columns/${field.DATA_OBJECT_ID}" default="PARTY_ID" hideIf="model.SHOW_JOINING_COLUMNS.value != &apos;Y&apos;"/>
		<Combolist id="VIEW_FORMULA_NAME" label="{message.XXAS_BK_FLEX_FORMULA}" listProvider="REST:form-formulas?q={searchText}" longlist="true" required="true"/>
		<Hidden id="NO_DATA_MESSAGE" label="No Data Message" />
		<TextArea id="NO_DATA_TEXT" label="{message.XXAS_BK_NO_DATA_TEXT}" default="{text of message XXAS_RB_EMP_NO_INFO}" maxChars="1700" description="Supports HTML tags" hideIf="model.LAYOUT.value.id == &apos;HTML&apos;"/>
		<Poplist id="VIEW_ONLY_MODE" label="{message.XXAS_BK_VIEW_ONLY_MODE}" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" required="false" showAsBoolean="true" value = "N" hideIf="!model.DATA_OBJECT_ID.value || model.LAYOUT.value.id == &apos;HTML&apos; || model.LAYOUT.value.id == NULL"/>
		<Combolist id="FORM" label="{message.XXAS_BK_FORM}" listProvider="VALUE_SET_NAME:Applaud_Forms" required="true" longlist="true" refreshOnChange="true" hideIf="!model.DATA_OBJECT_ID.value || model.VIEW_ONLY_MODE.value == &apos;Y&apos; || model.LAYOUT.value.id == &apos;HTML&apos;" />
		<TextInput id="FORM_HANDLER" label="{message.XXAS_BK_FORM_HANDLER}" required="true" hideIf="!model.DATA_OBJECT_ID.value || model.VIEW_ONLY_MODE.value == &apos;Y&apos; || model.LAYOUT.value.id == &apos;HTML&apos;"/>
		<Combolist id="EDIT_FORMULA_NAME" label="{message.XXAS_BK_EDIT_FORMULA_NAME}" listProvider="REST:form-formulas?q={searchText}" longlist="true" required="false" hideIf="!model.DATA_OBJECT_ID.value || model.VIEW_ONLY_MODE.value == &apos;Y&apos; || model.LAYOUT.value.id == &apos;HTML&apos;"/>   
	    <Combolist id="CALLED_FROM_FUNCTION_ID" label="{message.XXAS_BK_FLEX_FORM_FUNC}" listProvider="VALUE_SET_NAME:Applaud Workflow Processes" longlist="true" hideIf="!model.DATA_OBJECT_ID.value || model.VIEW_ONLY_MODE.value == &apos;Y&apos; || model.LAYOUT.value.id == &apos;HTML&apos;"/>
	    <Poplist id="MODAL_WIDTH" visible="true" label="{message.XXAS_BK_FLEX_MODAL_WIDTH}" listProvider="VALUE_SET_NAME:Applaud Modal Width"/>
      <Combolist id="EIT_STRUCTURES" label="{message.XXAS_BK_FLEX_EIT}" listProvider="VALUE_SET_NAME:Applaud EIT Structures" longlist="true" 
		 hideIf="!(model.FORM.value.id == &apos;/public/xxas/emp/view/personeit.xml&apos; || model.FORM.value.id == &apos;/public/xxas/custom/emp/view/personeit.xml&apos;)"/>
		<Combolist id="ASG_EIT_STRUCTURES" label="Assignment EIT" listProvider="VALUE_SET_NAME:Applaud ASG EIT Structures" longlist="true" 
		 hideIf="!(model.FORM.value.id == &apos;/public/xxas/emp/view/asgeit.xml&apos; || model.FORM.value.id == &apos;/public/xxas/custom/emp/view/asgeit.xml&apos;)"/>
		<Combolist id="SIT_STRUCTURES" label="{message.XXAS_BK_FLEX_SIT}" listProvider="VALUE_SET_NAME:Applaud SIT Structures" longlist="true" 
		 hideIf="!(model.FORM.value.id == &apos;/public/xxas/emp/view/personsit.xml&apos; || model.FORM.value.id == &apos;/public/xxas/custom/emp/view/personsit.xml&apos;)"/> 
     </Container>
     
	 <Container id="SEARCH_FILTER_SORT" label="Search, filters and sort">
      <Poplist id="SEARCH_FLAG" label="Include search" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" />
      <Combolist id="SEARCH_DETAILS" label="Searchable fields" style="tags" longlist="true" multipleSelection="true" listProvider="REST:flexible-fields?q={searchText}"
       emptyValue="Select field" hideIf="model.SEARCH_FILTER_SORT.SEARCH_FLAG.value != &apos;Y&apos;"/>
      <Poplist id="FILTER_FLAG" label="Include filters" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" />
      <MultiRow id="FILTER_DETAILS" createAllowed="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/flexible_filter.xml" 
       hideIf="model.SEARCH_FILTER_SORT.FILTER_FLAG.value != &apos;Y&apos;" visible="true"/>
      <Poplist id="SORT_FLAG" label="Include sorts" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" />
      <MultiRow id="SORT_DETAILS" createAllowed="true" includeEmptyRow="true" xdbUri="/public/xxas/emp/view/flexible_sort.xml" 
       hideIf="model.SEARCH_FILTER_SORT.SORT_FLAG.value != &apos;Y&apos;" visible="true"/>
     </Container>

 </EditFields>

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