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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/xxas-form-field.xml',
'<View title="Form Fields" defaultFormHandler="xxas_forms_pkg.edit_form_field" showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}">
  <EditFields>
    <Hidden id="XDB_URI"/>
    <Hidden id="FORM_ID"/>
    <Hidden id="CONTAINER_EXISTS"/>
    <Poplist id="FIELD_TYPE" label="{message.XXAS_RB_NOTE_TYPE}" enabled="true" listProvider="LOOKUP_TYPE:XXAS_FIELDS" visible="true" required="true" refreshOnChange="true"/>
    <Number id="DISPLAY_SEQUENCE" label="Display sequence" visible="true"/>
    <Poplist id="CONTAINER" label="{message.XXAS_FORMS_CONTAINER_L}" enabled="true" listProvider="REST:form-field/form-containers/${field.FORM_ID}" visible="true"/>
    <TextInput id="FIELD_ID" label="{message.XXAS_FORMS_ID_L}" required="true" description="Unique field ID in ALL CAPS separated by _(underscore)"/>
    <TextInput id="VALUE_GENERATOR" label="{message.XXAS_FORMS_VAL_GEN_L}" visible="true" emptyValue="SEQUENCE:MY_SEQUENCE_NAME_S" description="Not usually required; the value is automatically set to the next value in the specified sequence."/>
    <TextInput id="LABEL" label="{message.XXAS_FORMS_LABEL_L}" visible="true" required="true"/>
    <TextInput id="DESCRIPTION" label="{message.XXAS_RB_COM_DESC}" visible="true" description="This provides on-screen help and appears next to the field"/>
    <Poplist id="STYLE" label="{message.XXAS_FORMS_STYLE_L}" enabled="true" required="false" visible="true" listProvider="LOOKUP_TYPE:XXAS_FORM_STYLE"/>
    <Poplist id="VISIBLE" label="{message.XXAS_FORMS_VISIBLE_L}" enabled="true" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true" value="Y"/>
    <Poplist id="REQUIRED" label="{message.XXAS_FORMS_REQUIRED_L}" enabled="true" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
    <Poplist id="REFRESH_ON_CHANGE" label="{message.XXAS_FORMS_REFRESH_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
    <Number id="MAX_LENGTH" label="{message.XXAS_FORMS_MAX_LENGTH_L}" visible="true"/>
    <TextInput id="SERVICE_NAME" label="{message.XXAS_FORMS_SRVC_NAME_L}" visible="true"/>
    <TextInput id="PLACE_HOLDER" label="{message.XXAS_FORMS_PLACEHOLDER_L}" visible="true"/>
    <TextInput id="HIDEIF" label="{message.XXAS_FORMS_HIDE_L}" visible="true" emptyValue="model.FIELD_ID.value == &#39;123&#39;" description="This is a simple javascript expression that can dynamically hide fields without the need for ROC"/>
    <Poplist id="WEIGHT" label="{message.XXAS_FORMS_WEIGHT_L}" listProvider="VALUE_SET_NAME:Applaud Button Weights" visible="true"/>
    <Poplist id="COLOR" label="{message.XXAS_RB_EMP_COLOR}" listProvider="VALUE_SET_NAME:Applaud Button Colors" visible="true"/>
    <Poplist id="ENABLED" label="{message.XXAS_FORMS_ENABLED_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true" value="Y"/>
    <TextInput id="LIST_FUNCTION" label="{message.XXAS_FORMS_LIST_FUN_L}" required="true" visible="true"/>
    <Poplist id="RICH_TEXT" label="{message.XXAS_FORMS_RICH_TXT_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
    <TextInput id="POST_TO_HREF" label="{message.XXAS_FORMS_HREF_L}" visible="true"/>
    <TextInput id="POST_NEW_TO_HREF" label="{message.XXAS_FORMS_POST_TO_HREF_L}" visible="true" description="By default this uses a REST API that stores files in fnd_lobs"/>
    <TextInput id="BUTTON_TEXT" label="{message.XXAS_FORMS_BUTTON_TEXT_L}" visible="true"/>
    <TextInput id="FILE_NAME" label="{message.XXAS_FORMS_FILE_NAME_L}" visible="true"/>
    <TextInput id="FILE_HREF" label="{message.XXAS_FORMS_FILE_HREF_L}" visible="true"/>
    <Poplist id="FILE_TYPES" label="{message.XXAS_FORMS_FILE_TYPES_L}" listProvider="LOOKUP_TYPE:XXAS_COM_MIME_TYPE_MAP" visible="true"/>
    <TextInput id="FILE_INFO_PROVIDER" label="{message.XXAS_FORMS_FILE_INFO_PRO_L}" visible="true"/>
    <Number id="DECIMAL_PRECISION" label="{message.XXAS_FORMS_DEC_PRECISION_L}" visible="true"/>
    <Poplist id="DATE_FORMAT" label="{message.XXAS_FORMS_WEIGHT_L}" listProvider="LOOKUP_TYPE:Date Format" visible="true"/>
    <TextInput id="LIST_PROVIDER" label="List provider" visible="true"/>
    <Poplist id="LIST_PROVIDER_TYPE" label="{message.XXAS_FORMS_LIST_PROV_TYPE_L}" listProvider="LOOKUP_TYPE:XXAS_LIST_PROVIDER_TYPE" visible="true" refreshOnChange="true"/>    
    <Poplist id="LOOKUP_TYPE" label="{message.XXAS_FORMS_LOOKUP_L}" listProvider="VALUE_SET_NAME:XXAS_LOOKUP_TYPES" longlist="true" visible="true" required="true" />
    <Poplist id="VALUE_SET" label="{message.XXAS_FORMS_VALUE_SET_L}" listProvider="VALUE_SET_NAME:XXAS_VALUE_SETS" longlist="true" visible="true" required="true" />
    <TextInput id="REST_API" label="{message.XXAS_REST_API}" visible="true" required="true"/>
    <Poplist id="POSITIVE_BOOLEAN_VALUE" label="{message.XXAS_FORMS_BOOLEAN_VAL_L}" listProvider="REST:form-field/list-values-edit/${field.LIST_PROVIDER},${field.FORM_ID},${field.FIELD_ID}" visible="true"/>
    <Poplist id="LONG_LIST" label="{message.XXAS_FORMS_LONGLIST_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true" />
    <TextInput id="NO_DATA_MESSAGE" label="{message.XXAS_FORMS_NO_DATA_MSG_L}" visible="true" hideIf="model.LONG_LIST.value != &quot;Y&quot;"/>
    <Number id="QUESTION_REF_ID" label="{message.XXAS_FORMS_QUESTION_REF_ID_L}" visible="true"/>
    <TextInput id="VALUE" label="{message.XXAS_FORMS_DEFAULT_VALUE_L}" visible="true" emptyValue="Default value, if any"/>
    <TextInput id="ICON" label="{message.XXAS_FORMS_ICON}" visible="true" description="Icon to be displayed for rating. e.g. starfilled, thumbsup, staroutlined"/>
    <Poplist id="MULTI_COLOR" label="{message.XXAS_FORMS_MULTI_COLOR}" description="Advanced users: select to use the Description of each value from the List provider as the icon color when active. Not supported for Lookup Types" visible="true" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" hideIf="model.LIST_PROVIDER_TYPE.value.id == &apos;LOOKUP_TYPE&apos;"/>
    <TextInput id="ICON_COLOR" label="{message.XXAS_FORMS_ICON_COLOR}" description="Color of each rating icon when active" visible="true" hideIf="model.MULTI_COLOR.value == &quot;Y&quot;"/>
    <TextInput id="MIN" label="{message.XXAS_FORMS_MIN}" visible="true" description="When specified a user cannot select a rating lower than this value"/>
    <TextInput id="MAX" label="{message.XXAS_FORMS_MAX}" visible="true" description="When specified a user cannot select a rating higher than this value"/>
    <TextInput id="MIN_LABEL" label="{message.XXAS_FORMS_MIN_LABEL}" visible="true" description="Label to indicate the minimum, eg, Min"/>
    <TextInput id="MAX_LABEL" label="{message.XXAS_FORMS_MAX_LABEL}" visible="true" description="Label to indicate the maximum, eg, Max"/>
    <Poplist id="MULTIROW_XDB_URI" label="{message.XXAS_FORMS_XDB_URI_L}" visible="true" listProvider="REST:form-field/form-paths"/> 
    <Poplist id="CREATE_ALLOWED" label="{message.XXAS_FORMS_CREATE_ALLOWED_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
    <TextInput id="CREATE_LABEL" label="{message.XXAS_FORMS_CREATE_LABEL_L}" visible="true"/>
    <Number id="MIN_ROWS" label="{message.XXAS_FORMS_MIN_ROWS_L}" visible="true"/>
    <Number id="MAX_ROWS" label="{message.XXAS_FORMS_MAX_ROWS_L}" visible="true"/>
    <Poplist id="INCLUDE_EMPTY_ROW" label="{message.XXAS_FORMS_INC_EMPTY_ROW_L}" listProvider="LOOKUP_TYPE:YES_NO" showAsBoolean="true" positiveBooleanValue="Y" visible="true"/>
    <Combolist id="APPLICATION_ID" label="{message.XXAS_FORMS_APPL_ID_L}" listProvider="REST:form-field/applications?q={searchText}" longlist="true" visible="true"  refreshOnChange="true" required="true"/>
    <Combolist id="FLEXFIELD" label="{message.XXAS_FORMS_FLEXFIELD_NAME_L}" listProvider="REST:form-field/flexfield/${field.APPLICATION_ID}?q={searchText}" longlist="true"  refreshOnChange="true" required="true"/>
    <!--TextInput id="FLEX_CODE" label="{message.XXAS_FORMS_FLEX_CODE_L}" visible="true" required="true"/-->
    <Poplist id="FLEX_CODE" label="{message.XXAS_FORMS_FLEX_CODE_L}" visible="true" required="true" listProvider="REST:form-field/flex-code/${field.FLEXFIELD}"/>
    <TextInput id="FLEX_STRUCTURE_CODE" label="{message.XXAS_FORMS_FLEX_STRUCT_CODE_L}" visible="true"/>
    <TextInput id="DESCRIPTIVE_FLEX_CONTEXT_CODE" label="{message.XXAS_FORMS_DESCF_CONTEXT_L}" visible="true"/>
    <TextInput id="COLUMN_NAME_PREFIX" label="{message.XXAS_FORMS_COL_NAME_PREFIX_L}" visible="true"/>
    <TextInput id="ATTACHMENT_TITLE" label="{message.XXAS_FORMS_ATTACH_TITLE_L}" visible="true"/>
    <Number id="MAX_ATTACHMENTS" label="{message.XXAS_FORMS_MAX_ATTACH_L}" visible="true"/>
    <Combolist id="ENTITY_NAME" label="{message.XXAS_FORMS_ENTITY_NAME_L}" required="true" listProvider="REST:form-field/attachment-entities" longlist="true" visible="true"/>
    <Poplist id="CATEGORY_CODE" label="{message.XXAS_FORMS_CAT_CODE_L}" required="true" listProvider="REST:form-field/category-code" />
    <TextInput id="ATTACHMENT_DESCRIPTION" label="{message.XXAS_FORMS_ATTC_DESC_L}" visible="true"/>
    <TextInput id="PK1FIELDNAME" label="{message.XXAS_FORMS_PK1FIELDNAME_L}" visible="true"/>
    <TextInput id="PK2FIELDNAME" label="{message.XXAS_FORMS_PK2FIELDNAME_L}" visible="true"/>
    <TextInput id="PK3FIELDNAME" label="{message.XXAS_FORMS_PK3FIELDNAME_L}" visible="true"/>
    <TextInput id="PK4FIELDNAME" label="{message.XXAS_FORMS_PK4FIELDNAME_L}" visible="true"/>
    <TextInput id="PK5FIELDNAME" label="{message.XXAS_FORMS_PK5FIELDNAME_L}" visible="true"/>
  </EditFields>
</View>' ); 

  xxas_forms_pkg.update_forms_resource('/public/xxas/emp/view/xxas-form-field.xml');

END;
/
COMMIT;
EXIT;
