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

  EXCEPTION
    WHEN e_does_not_exists THEN
      NULL;
  END;

  
  result := DBMS_XDB.createresource('/public/xxas/emp/view/autosetup.xml',
  
'<View title="Autosetup" defaultFormHandler="xxas_setup_pkg.autosetup_form_handler" submitLabel="Next" formHelp="This will create a new configuration. If you''ve already setup EmployeeCenter, please use the Import facility instead.">

  <EditFields>

      <Hidden id="AUTOSETUP_ID"/>
      <TextInput id="TENANT_ID" label="Tenant Id"/>
      <TextInput id="CLOUD_API_KEY" label="Applaud Cloud API key"/>
      <Combolist id="RESPONSIBILITIES" label="Responsibilities" required="true" allowNewValues="false"
                 listProvider="REST:tags/by-person?q={searchText}" longlist="true" multipleSelection="true" style="tags"/>
      <TextInput id="OBJECT_PREFIX" label="Setup prefix" required="true" description="We''ll prefix auto-generated Oracle setup like Menus, Functions, Messages, Fast Formula etc with this" emptyValue="4 characters max" maxChars="4"/>
      <TextInput id="TWITTER_USERNAME" label="Twitter username" description="We''ll use this to put a tweet stream on the home page" emptyValue="@MyTwitterUsername" maxChars="16"/>
      <TextInput id="NEWS_FEED_URL" label="News feed URL" description="We''ll use this to put a news feed on the home page" emptyValue="URL of RSS or Atom feed"/>
      
  </EditFields>

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