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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/xxas-form-basic.xml',
'<View showSubmit="true" submitLabel="{message.XXAS_RB_COM_SAVE}" title="Form basic settings" defaultFormHandler="xxas_forms_pkg.save_form_basic_settings" >

  <EditFields>
      <Hidden id="FORM_ID"/>
      <TextInput id="FORM_TITLE" label="Name" required="true" visible="true"/>
      <TextInput id="XDB_URI" label="XDB URI" required="true" visible="true" enabled="false"/>
      <Poplist id="USE_FSH" label="Use recommended form submission handling" visible="true" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" value="Y"/>
      <TextInput id="DEFAULT_FORM_HANDLER" label="Form Handler" visible="true" hideIf="model.USE_FSH.value != &apos;Y&apos;"/>   
	  <TextInput id="POST_HREF" label="POST to REST API" value="forms/{blockFunctionId}" visible="true" description="If you implement your own form submission, you will need to manually handle security, refresh on change and other events."
       hideIf="(!(model.USE_FSH.value) || (model.USE_FSH.value != &apos;N&apos;))"/>
      <Poplist id="SHOW_SUBMIT" label="Show submit button" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" />
      <TextInput id="SUBMIT_LABEL" label="Submit button label" visible="true" hideIf="model.SHOW_SUBMIT.value != &apos;Y&apos;"/>
      <Icon id="SUBMIT_ICON" label="Submit button icon" emptyValue="Search for icon" required="false" maxChars="30" hideIf="model.SHOW_SUBMIT.value != &apos;Y&apos;"/>
      <ColorPicker id="SUBMIT_COLOR" label="Submit button color" required="false" allowEmpty="true" preferredFormat="hex" hideIf="model.SHOW_SUBMIT.value != &apos;Y&apos;"/> 
      <TextArea id="FORM_HELP" label="Instructional text" visible="true"/>
      <Poplist id="AUTO_SAVE" label="Autosave" required="true" value="CSA" listProvider="LOOKUP_TYPE:XXAS_AUTO_SAVE_TYPES" refreshOnChange="true"/>
      <TextInput id="AUTO_SAVE_MESSAGE" label="Autosave text" required="true" visible="true" value="{message.XXAS_COM_CHNG_SAVE}" hideIf="!(model.AUTO_SAVE.value) || (model.AUTO_SAVE.value.id != &apos;SSA&apos;)"/>
      <Number id="AUTO_SAVE_TIMEOUT" label="Autosave frequency" required="true" visible="true" description="Specify in ms. For example, the value of 3000 is 3 seconds" hideIf="!(model.AUTO_SAVE.value) || (model.AUTO_SAVE.value.id != &apos;SSA&apos;)"/>
      <Poplist id="LOGIN_FORM" label="This is a login form" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" refreshOnChange="true" positiveBooleanValue="Y" />
      <Poplist id="BASIC_AUTH_UN" label="Username field" required="true" listProvider="REST:form/${field.FORM_ID}/auth-fields/TEXTINPUT" hideIf="model.LOGIN_FORM.value != &apos;Y&apos;"/>
      <Poplist id="BASIC_AUTH_PW" label="Password field" required="true" listProvider="REST:form/${field.FORM_ID}/auth-fields/PASSWORD" hideIf="model.LOGIN_FORM.value != &apos;Y&apos;"/>
      <Poplist id="SEND_TOKEN" label="Send token" showAsBoolean="true" listProvider="LOOKUP_TYPE:YES_NO" positiveBooleanValue="Y" hideIf="model.LOGIN_FORM.value != &apos;Y&apos;"/>
      <Poplist id="TOKEN_FIELD" label="Token field" required="true" listProvider="REST:form/${field.FORM_ID}/auth-fields/TEXTINPUT" hideIf="model.SEND_TOKEN.value != &apos;Y&apos;"/>
    
  </EditFields>

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