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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

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

  <EditFields>
      <Hidden id="PAGE_OBJECT_HANDLER"/>
      <Hidden id="PAGE_OBJECT_ID_FORMAT"/>
      <Hidden id="IS_PAGE_COLUMN_LAYOUT"/>
	  <Hidden id="PAGE_LAYOUT"/>
      <Hidden id="MENU_ID"/>
      <Hidden id="FUNCTION_ID"/>
      <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="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;"/> 
	  <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="SINGLE_OR_RANDOM" label="{message.XXAS_BK_SINGLE_OR_RANDOM}" enabled="true" required="true" 
       listProvider="LOOKUP_TYPE:XXAS_BLOCK_ADVERT_TYPES" value="S"/>
      <Poplist id="STATIC_OR_DYNAMIC" label="{message.XXAS_BK_STATIC_OR_DYNAMIC}" enabled="true" required="true" 
       listProvider="LOOKUP_TYPE:XXAS_BLOCK_ADVERT_STYLES" value="S" hideIf="model.SINGLE_OR_RANDOM.value.id != &apos;S&apos;"/>
      <TextInput id="DYNAMIC_FUNCTION_NAME" label="{message.XXAS_BK_DYNAMIC_FUNCTION_NAME}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;S&apos;"/>
      <TextInput id="FILENAME" label="{message.XXAS_BK_FILENAME}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <TextInput id="LINE1" label="{message.XXAS_BK_LINE1}" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <Hidden id="LINE1_MESSAGE"/>
      <TextInput id="LINE2" label="{message.XXAS_BK_LINE2}" required="false" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos; || !model.LINE1.value"/>
      <Hidden id="LINE2_MESSAGE"/>
      <Poplist id="TYPE_OF_LINK" label="{message.XXAS_BK_TYPE_OF_LINK}" required="true" 
       listProvider="LOOKUP_TYPE:XXAS_BLOCK_ADVERT_LINK_TYPES" hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="N"/>
      <Poplist id="OPEN_IN_MODAL" label="Open in modal" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" 
       hideIf="model.TYPE_OF_LINK.value.id != &apos;P&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" />
      <Combolist id="PAGE" label="{message.XXAS_BK_PAGE}" listProvider="REST:advert-page-links?q={searchText}" longlist="true" required="true" 
       hideIf="model.TYPE_OF_LINK.value.id != &apos;P&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <TextInput id="URL" label="{message.XXAS_BK_ADVERT_URL}" required="true" hideIf="model.TYPE_OF_LINK.value.id != &apos;U&apos;"/>
      <Poplist id="SHOW_BUTTON" label="{message.XXAS_BK_SHOW_BUTTON}" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" 
       positiveBooleanValue="Y" value="N" hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <Hidden id="BUTTON_LABEL_MESSAGE"/>
      <TextInput id="BUTTON_LABEL" label="{message.XXAS_BK_BUTTON_LABEL}" required="true" 
       hideIf="model.SHOW_BUTTON.value != &apos;Y&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <TextInput id="TEXT_COLOR" label="{message.XXAS_BK_TEXT_COLOR}" required="true" 
       hideIf="model.SHOW_BUTTON.value != &apos;Y&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="rgba(255,255,255,1.0)"/>
      <TextInput id="TEXT_BG_COLOR" label="{message.XXAS_BK_TEXT_BG_COLOR}" required="true" 
       hideIf="model.SHOW_BUTTON.value != &apos;Y&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="rgba(255,255,255,0.8)"/>
      <Number id="TEXTBOX_WIDTH_PERCENT" label="{message.XXAS_BK_TEXTBOX_WIDTH_PERCENT}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <Number id="TEXTBOX_X_WIDTH_PERCENT" label="{message.XXAS_BK_TEXTBOX_X_WIDTH_PER}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="0"/>
      <Poplist id="TEXTBOX_Y_WIDTH_PERCENT" label="{message.XXAS_BK_TEXTBOX_Y_WIDTH_PER}" required="true" listProvider="VALUE_SET_NAME:XXAS_ADVERT_ALIGNMENT_VS"
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="0"/>
      <Poplist id="TEXT_ALIGNMENT" label="{message.XXAS_BK_TEXT_ALIGNMENT}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="LEFT" 
       listProvider="LOOKUP_TYPE:XXAS_BLOCK_ADVERT_TEXT_ALIGN"/>
      <Number id="TEXTBOX_BOTTOM_MARGIN" label="{message.XXAS_BK_TEXTBOX_BOTTOM_MARGIN}" required="true" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;" value="5" 
       description="Enter in em units"/>
      <Poplist id="TEXTBOX_PADDING" label="{message.XXAS_BK_TEXTBOX_PADDING}" showAsBoolean="true" 
       listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" value="Y" 
       hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>
      <Poplist id="ADVERT_PADDING" label="{message.XXAS_BK_ADVERT_PADDING}" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" 
       positiveBooleanValue="Y" value="N" hideIf="model.SINGLE_OR_RANDOM.value.id == &apos;R&apos; || model.STATIC_OR_DYNAMIC.value.id == &apos;D&apos;"/>

  </EditFields>

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