﻿<?xml version="1.0" encoding="utf-8"?>
  <finScript version="1.00" exportedUtcDate="2026-05-11T00:00:00.0000000">
    <CreatedUserId>Admin</CreatedUserId>
    <CreatedUtcDate>2026-05-11T00:00:00.0000000</CreatedUtcDate>
    <UpdatedUserId>Admin</UpdatedUserId>
    <UpdatedUtcDate>2026-05-11T00:00:00.0000000</UpdatedUtcDate>
    <ScriptId>HWBasiqCC</ScriptId>
    <Description>Cost Centre Edit (Basiq)</Description>
    <ScriptType>HtmlWidget</ScriptType>
    <Active>true</Active>
    <AllowUI>false</AllowUI>
    <Bookmarks />
    <Category />
    <Code>' HtmlWidget_CostCentreEdit_Basiq
Option Explicit On
Option Strict On

' #################################################################
' Cost Centre Edit (Basiq) form HTML Widget
'
' Version: 1.00 (11/05/2026)
'
' Usage: System-supplied HTML Widget
' #################################################################
' Version        Date  User     Job       Description
' -------  ----------  -------  --------  -------------------------
'    1.00  11/05/2026  ISS      J036896   Created
' #################################################################

' Constants
Private Const FORM_KEY As String = "CostCentres"

' Objects
Private mCombinedParameters As ISKeyValueList
Private mParameters As ISKeyValueList
Private mStartupParameters As ISKeyValueList

' Standard Parameters
Private mCostCentreId As String
Private mPage As String
Private mReadOnly As Boolean

Public Function Main(eventId As String,
                     parametersJson As String,
                     startUpParametersJson As String,
                     hostingContext As isefinHtmlWidgetHostingContext,
                     requestInfo As finScriptRequestInfo,
                     ByRef returnValue As String) As Boolean

  ' Assume Success
  Main = True

  ' Get Parameters
  mParameters = finBL.CreateKeyValueList()
  mParameters.FromSimpleJsonString(parametersJson)
  mStartupParameters = finBL.CreateKeyValueList()
  mStartupParameters.FromSimpleJsonString(startUpParametersJson)

  ' Get Combined Parameters (Startup Parameters updated with event Parameters)
  mCombinedParameters = mStartupParameters.Clone()
  mCombinedParameters.UpdateFromKeyValueList(mParameters, True)

  ' Get Standard Parameters
  With mStartupParameters
    mCostCentreId = .GetString("CostCentreId") ' Always use Startup Parameters since the Cost Centre Id may be updated
    If Len(mCostCentreId) = 0 Then mCostCentreId = .GetString("Id")
  End With
  With mCombinedParameters
    mPage = .GetString("Page")
    mReadOnly = .GetBoolean("ReadOnly")
  End With

  ' Validate
  If Not finBL.HtmlWidgetUtilities.HasPermissionToViewFormKey(FORM_KEY) Then
    Main = False
  ElseIf Not finBL.CostCentreFunctions.IsServiceAvailable("Basiq") Then
    Main = False
    finBL.Error.ErrorBegin("This service is not available.")
  ElseIf Len(mCostCentreId) = 0 Then
    Main = False
    finBL.Error.ErrorBegin("Cost Centre Id not specified.")
  End If

  ' Handle Events
  If Main Then
    Select Case eventId
      Case ""
        ' Main event, i.e., return initial HTML content (excluding html and body tags)
        returnValue = ScriptInfo.TemplateText

      Case "Finish"
        ' Finish wizard
        Main = Finish(parametersJson, requestInfo, returnValue)

     Case "GetInitialisationInfo"
        ' Get Initialisation Information required for this wizard
        Main = GetInitialisationInfo(returnValue)

      Case Else
        Main = False
        finBL.Error.ErrorBeginFormat("Unhandled event '{0}'", eventId)
    End Select
  End If

End Function

''' &lt;summary&gt;
'''  Load Cost Centre.
''' &lt;/summary&gt;
Private Function GetCostCentre(ByRef costCentre As finCostCentre) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Create and Load Cost Centre
  If Success Then
    ' Create Cost Centre
    costCentre = finBL.CreateCostCentre()

    ' Load Cost Centre
    Success = CostCentre.Load(mCostCentreId)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Get Initialisation Information required for this wizard.
''' &lt;/summary&gt;
Public Function GetInitialisationInfo(ByRef response As String) As Boolean

  Dim CostCentre As finCostCentre
  Dim FormInitialisationInfo As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Get Cost Centre
  If Success Then
    Success = GetCostCentre(CostCentre)
  End If

  ' Get Initialisation Info
  If Success Then
    FormInitialisationInfo = New FormInitialisationInfo()
    With FormInitialisationInfo
      ' Form
      .PageId = mPage
      If finBL.Database.IsReadOnly OrElse mReadOnly Then
        .ReadOnly = True
      Else
        .ReadOnly = False
      End If

      ' Record
      .CostCentreId = CostCentre.CostCentreId
      .Pk = CostCentre.Pk
      .Timestamp = CostCentre.Timestamp

      ' Page Permissions (defined here since they are used below)
      ' NOTE: Not applicable to this form

      ' Service
      .UseService = CostCentre.Basiq.UseService

      ' Credentials
      .RequestUrlProduction = CostCentre.Basiq.CredentialsProduction.RequestUrl
      .RequestUrlProductionBlankTip = ISServiceBasiq.DefaultRequestUrl
      .ApiKeyProduction = CostCentre.Basiq.CredentialsProduction.ApiKey
      .WebhookTargetUrlProduction = CostCentre.Basiq.CredentialsProduction.WebhookTargetUrl
      .WebhookTargetUrlProductionBlankTip = finBL.CreditBureau.Service_Basiq.SuggestedWebhookUrl()
      .WebhookIdProduction = CostCentre.Basiq.CredentialsProduction.WebhookId
      .WebhookSecretProduction = CostCentre.Basiq.CredentialsProduction.WebhookSecret

      ' Test Credentials
      .RequestUrlTest = CostCentre.Basiq.CredentialsTest.RequestUrl
      .RequestUrlTestBlankTip = ISServiceBasiq.DefaultRequestUrlTest
      .ApiKeyTest = CostCentre.Basiq.CredentialsTest.ApiKey
      .WebhookTargetUrlTest = CostCentre.Basiq.CredentialsTest.WebhookTargetUrl
      .WebhookTargetUrlTestBlankTip = finBL.CreditBureau.Service_Basiq.SuggestedWebhookUrl()
      .WebhookIdTest = CostCentre.Basiq.CredentialsTest.WebhookId
      .WebhookSecretTest = CostCentre.Basiq.CredentialsTest.WebhookSecret

      ' Options
      .EnableBankAccountEnquiry = CostCentre.Basiq.OptionsBankAccountEnquiry.EnableBankAccountEnquiry
      .OptionsRequestedDays = CostCentre.Basiq.OptionsBankAccountEnquiry.RequestedDays
      .OptionsRedirectUrl = CostCentre.Basiq.OptionsBankAccountEnquiry.RedirectUrl
      .OptionsReportCodes = CostCentre.Basiq.OptionsBankAccountEnquiry.ReportCodes
      .OptionsReportCodesBlankTip = ISServiceBasiq.DefaultReportCodes

      .OptionsEmailDocumentId = CostCentre.Basiq.OptionsBankAccountEnquiry.EmailDocumentId
      .OptionsSmsDocumentId = CostCentre.Basiq.OptionsBankAccountEnquiry.SmsDocumentId

      ' Permissions

      ' Lists

      ' List Filters
      .DocumentFilter = finBL.Documents.GetDataViewFilter_BankAccountEnquiry()

      ' Configuration
      .PromptOnSave = finBL.CloudConnectFunctions.CloudConnectSettings.PromptOnSave
    End With
  End If

  ' Response
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(FormInitialisationInfo, response)
  End If

  Return Success

End Function

''' &lt;summary&gt;
'''  Finish, i.e., Save Cost Centre.
''' &lt;/summary&gt;
''' &lt;param name="parametersJson"&gt;
'''  A JSON formatted record (FormInitialisationInfo) object.
''' &lt;/param&gt;
Private Function Finish(parametersJson As String,
                        requestInfo As finScriptRequestInfo,
                        ByRef returnValue As String) As Boolean

  Dim CostCentre As finCostCentre
  Dim obj As Object
  Dim Record As FormInitialisationInfo
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Parse Parameters
  If finBL.Runtime.WebUtilities.DeserialiseJsonStringToObject(parametersJson, GetType(FormInitialisationInfo), obj) Then
    Record = DirectCast(obj, FormInitialisationInfo)
  Else
    Success = False
  End If

  ' Get Cost Centre
  If Success Then
    Success = GetCostCentre(CostCentre)
  End If

  ' Validate
  If Success Then
    If Record.Timestamp &lt;&gt; CostCentre.Timestamp Then
      Success = False
      finBL.Error.ErrorBegin("This record has been updated by another User.")
    End If
  End If

  ' Update and Save
  If Success Then
    ' Begin Transaction
    If finBL.Database.TransactionBegin() Then
      ' Update Cost Centre
      With CostCentre.Basiq
        ' Service
        .UseService = Record.UseService

        ' Credentials
        .CredentialsProduction.RequestUrl = Record.RequestUrlProduction
        .CredentialsProduction.ApiKey = Record.ApiKeyProduction
        .CredentialsProduction.WebhookTargetUrl = Record.WebhookTargetUrlProduction

        ' Test Credentials
        .CredentialsTest.RequestUrl = Record.RequestUrlTest
        .CredentialsTest.ApiKey = Record.ApiKeyTest
        .CredentialsTest.WebhookTargetUrl = Record.WebhookTargetUrlTest

        ' Options
        .OptionsBankAccountEnquiry.EnableBankAccountEnquiry = Record.EnableBankAccountEnquiry
        .OptionsBankAccountEnquiry.RequestedDays = Record.OptionsRequestedDays
        .OptionsBankAccountEnquiry.RedirectUrl = Record.OptionsRedirectUrl
        .OptionsBankAccountEnquiry.ReportCodes = Record.OptionsReportCodes

        .OptionsBankAccountEnquiry.EmailDocumentId = Record.OptionsEmailDocumentId
        .OptionsBankAccountEnquiry.SmsDocumentId = Record.OptionsSmsDocumentId
      End With

      ' Save
      If Success Then
        Success = CostCentre.Save()
      End If

      ' Commit/ Rollback Transaction
      If Success Then
        finBL.Database.TransactionCommit()
      Else
        finBL.Database.TransactionRollback()
      End If
    Else
      Success = False
    End If
  End If

  Return Success

End Function



''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
Public Class FormInitialisationInfo

  ' Form
  Public PageId As String
  Public [ReadOnly] As Boolean

  ' Record
  Public CostCentreId As String
  Public Pk As Integer
  Public Timestamp As Integer

  ' Service
  Public UseService As Boolean

  ' Credentials
  Public RequestUrlProduction As String
  Public RequestUrlProductionBlankTip As String
  Public ApiKeyProduction As String
  Public WebhookTargetUrlProduction As String
  Public WebhookTargetUrlProductionBlankTip As String
  Public WebhookIdProduction As String
  Public WebhookSecretProduction As String

  ' Test Credentials
  Public RequestUrlTest As String
  Public RequestUrlTestBlankTip As String
  Public ApiKeyTest As String
  Public WebhookTargetUrlTest As String
  Public WebhookTargetUrlTestBlankTip As String
  Public WebhookIdTest As String
  Public WebhookSecretTest As String

  ' Options
  Public EnableBankAccountEnquiry As Boolean
  Public OptionsRequestedDays As Integer
  Public OptionsRedirectUrl As String
  Public OptionsReportCodes As String
  Public OptionsReportCodesBlankTip As String

  Public OptionsEmailDocumentId As String
  Public OptionsSmsDocumentId As String

  ' Permissions

  ' Lists

  ' List Filters
  Public DocumentFilter As String

  ' Configuration
  Public PromptOnSave As Boolean

End Class</Code>
    <Language>VisualBasic</Language>
    <Notes>System-supplied HTML Widget to edit the "Basiq" page of a Cost Centre.</Notes>
    <PermissionKeyExecute />
    <RunWithoutPrompts>false</RunWithoutPrompts>
    <TemplateText>&lt;div id="frmMain" class="is-widget-content" style="visibility:hidden"&gt;

  &lt;!-- Form Header --&gt;
  &lt;header&gt;
    &lt;!-- Tabs --&gt;
    &lt;div id="tabDetails" class="is-tabs"&gt;
      &lt;ul&gt;
        &lt;li tabId="Service"&gt;Service&lt;/li&gt;
        &lt;li tabId="Credentials"&gt;Credentials&lt;/li&gt;
        &lt;li tabId="TestCredentials"&gt;Test Credentials&lt;/li&gt;
        &lt;li tabId="Options"&gt;Options&lt;/li&gt;
      &lt;/ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;


  &lt;!-- Pages --&gt;
  &lt;div class="is-widget-form-body"&gt;
    &lt;!-- Service --&gt;
    &lt;div id="pageService"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblService"&gt;Use the Basiq Service?&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkUseService" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Credentials --&gt;
    &lt;div id="pageCredentials"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblRequestUrlProduction"&gt;Production Service Request URL&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtRequestUrlProduction"&gt;Request URL:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRequestUrlProduction"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCredentialsProduction"&gt;Production API Credentials&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtApiKeyProduction"&gt;API Key:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtApiKeyProduction"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblWebhookUrlProduction"&gt;Webhook Target URL&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookUrlProduction"&gt;Webhook:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookUrlProduction"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblWebhookSubscriptionProduction"&gt;Webhook Subscription Details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookIdProduction"&gt;Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookIdProduction"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookSecretProduction"&gt;Secret:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookSecretProduction"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Test Credentials --&gt;
    &lt;div id="pageTestCredentials"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblRequestUrlTest"&gt;Test Service Request URL&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtRequestUrlTest"&gt;Request URL:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtRequestUrlTest"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCredentialsTest"&gt;Test API Credentials&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtApiKeyTest"&gt;API Key:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtApiKeyTest"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblWebhookUrlTest"&gt;Webhook Target URL&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookUrlTest"&gt;Webhook:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookUrlTest"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblWebhookSubscriptionTest"&gt;Webhook Subscription Details&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookIdTest"&gt;Id:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookIdTest"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtWebhookSecretTest"&gt;Secret:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtWebhookSecretTest"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- Options --&gt;
    &lt;div id="pageOptions"&gt;
      &lt;table class="is-form"&gt;
        &lt;colgroup&gt;
          &lt;col style="width:8em" /&gt;
          &lt;col /&gt;
        &lt;/colgroup&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblOptionsBankAccountEnquiry"&gt;Bank Account Enquiry options and defaults&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkEnableBankAccountEnquiry" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numOptionsRequestedDays"&gt;Requested&amp;nbsp;days:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numOptionsRequestedDays" type="number"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtOptionsRedirectUrl" title="The URL to which the user will be redirected after completing the bank account enquiry. Enter it in the Basiq Dashboard under Customise UI, Flow settings, Redirect URL."&gt;Redirect URL:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtOptionsRedirectUrl" title="The URL to which the user will be redirected after completing the bank account enquiry. Enter it in the Basiq Dashboard under Customise UI, Flow settings, Redirect URL."/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblOptionsReports"&gt;Define the Reports available on the Bank Account Enquiry wizard&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtOptionsReportCodes"&gt;Report Codes:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;textarea id="txtOptionsReportCodes" rows="4"&gt;&lt;/textarea&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblOptionsDocuments"&gt;Define the Documents used to send a request to a Client&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboOptionsEmailDocument"&gt;Email:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboOptionsEmailDocument"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="cboOptionsSmsDocument"&gt;SMS:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="cboOptionsSmsDocument"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;
  &lt;/div&gt;

  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdCancel" class="is-button"&gt;Cancel&lt;/button&gt;
    &lt;button id="cmdFinish" class="is-button ok"&gt;Save&lt;/button&gt;
  &lt;/footer&gt;

&lt;/div&gt;


&lt;script&gt;
// Properties
var mRecord;

var mOriginalJson;

// Controls
var C = {
  //   Service
  lblService: null,
  chkUseService: null,

  //   Credentials
  lblRequestUrlProduction: null,
  txtRequestUrlProduction: null,

  lblCredentialsProduction: null,
  txtApiKeyProduction: null,

  lblWebhookUrlProduction: null,
  txtWebhookUrlProduction: null,

  lblWebhookSubscriptionProduction: null,
  txtWebhookIdProduction: null,
  txtWebhookSecretProduction: null,

  //   Test Credentials
  lblRequestUrlTest: null,
  txtRequestUrlTest: null,

  lblCredentialsTest: null,
  txtApiKeyTest: null,

  lblWebhookUrlTest: null,
  txtWebhookUrlTest: null,

  lblWebhookSubscriptionTest: null,
  txtWebhookIdTest: null,
  txtWebhookSecretTest: null,

  //   Options
  lblOptionsBankAccountEnquiry: null,
  chkEnableBankAccountEnquiry: null,
  numOptionsRequestedDays: null,
  txtOptionsRedirectUrl: null,

  lblOptionsReports: null,
  txtOptionsReportCodes: null,

  lblOptionsDocuments: null,
  cboOptionsEmailDocument: null,
  cboOptionsSmsDocument: null,
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

// Other

// ==========
// Initialise
// ==========
$(function () {
  // Mobile optimisations
  $(window).resize(Form_Resize);

  // --------
  // Controls
  // --------
  //   Service
  C.lblService = widget.UI.Label("lblService", {});
  C.chkUseService = widget.UI.CheckBox("chkUseService", {
    caption: "Use Service?",

    onChange: chkUseService_Change,
  });

  //   Credentials
  C.lblRequestUrlProduction = widget.UI.Label("lblRequestUrlProduction", {});
  C.txtRequestUrlProduction = widget.UI.TextBox("txtRequestUrlProduction", {
    maxLength: 200,
  });

  C.lblCredentialsProduction = widget.UI.Label("lblCredentialsProduction", {});
  C.txtApiKeyProduction = widget.UI.TextBox("txtApiKeyProduction", {
    maxLength: 250,
    password: true,
    passwordRevealOnFocus: true,
  });

  C.lblWebhookUrlProduction = widget.UI.Label("lblWebhookUrlProduction", {});
  C.txtWebhookUrlProduction = widget.UI.TextBox("txtWebhookUrlProduction", {
    maxLength: 255,
  });

  C.lblWebhookSubscriptionProduction = widget.UI.Label("lblWebhookSubscriptionProduction", {});
  C.txtWebhookIdProduction = widget.UI.TextBox("txtWebhookIdProduction", {
    maxLength: 50,
    readOnly: true,
  });
  C.txtWebhookSecretProduction = widget.UI.TextBox("txtWebhookSecretProduction", {
    maxLength: 255,
    password: true,
    passwordRevealOnFocus: true,
    readOnly: true,
  });

  //   Test Credentials
  C.lblRequestUrlTest = widget.UI.Label("lblRequestUrlTest", {});
  C.txtRequestUrlTest = widget.UI.TextBox("txtRequestUrlTest", {
    maxLength: 200,
  });

  C.lblCredentialsTest = widget.UI.Label("lblCredentialsTest", {});
  C.txtApiKeyTest = widget.UI.TextBox("txtApiKeyTest", {
    maxLength: 250,
    password: true,
    passwordRevealOnFocus: true,
  });

  C.lblWebhookUrlTest = widget.UI.Label("lblWebhookUrlTest", {});
  C.txtWebhookUrlTest = widget.UI.TextBox("txtWebhookUrlTest", {
    maxLength: 255,
  });

  C.lblWebhookSubscriptionTest = widget.UI.Label("lblWebhookSubscriptionTest", {});
  C.txtWebhookIdTest = widget.UI.TextBox("txtWebhookIdTest", {
    maxLength: 50,
    readOnly: true,
  });
  C.txtWebhookSecretTest = widget.UI.TextBox("txtWebhookSecretTest", {
    maxLength: 255,
    password: true,
    passwordRevealOnFocus: true,
    readOnly: true,
  });

  //   Options
  C.lblOptionsBankAccountEnquiry = widget.UI.Label("lblOptionsBankAccountEnquiry", {});
  C.chkEnableBankAccountEnquiry = widget.UI.CheckBox("chkEnableBankAccountEnquiry", {
    caption: "Enable Bank Account Enquiry?",
  });
  C.numOptionsRequestedDays = widget.UI.NumberBox("numOptionsRequestedDays", {
    minValue: 30,
    maxValue: 730,
    decimals: 0,
    showSeparators: false,
    width: widget.UI.FIELD_WIDTH_CODE_5
  });
  C.txtOptionsRedirectUrl = widget.UI.TextBox("txtOptionsRedirectUrl", {
    maxLength: 200,
  });

  C.lblOptionsReports = widget.UI.Label("lblOptionsReports", {});
  C.txtOptionsReportCodes = widget.UI.TextBox("txtOptionsReportCodes", {
    maxLength: 1000,
    multiline: true,
  });

  C.lblOptionsDocuments = widget.UI.Label("lblOptionsDocuments", {});
  C.cboOptionsEmailDocument = widget.UI.DBCombo("cboOptionsEmailDocument", {
    limitToList: true
  });
  C.cboOptionsSmsDocument = widget.UI.DBCombo("cboOptionsSmsDocument", {
    limitToList: true
  });

  // Grids

  // Create Widget form
  // NOTE: Hide by default for a cleaner startup
  frmMain = new widget.UI.Form("frmMain", { visible: false });

  // Create Tabs
  tabDetails = new widget.UI.Tabs("tabDetails", {
    style: "normal",
    onSelectedTabChanged: tabDetails_Refresh,
  });

  // Handle resize
  $(window).resize(Form_Resize);

  // Disable Close Button (this causes the 'FormClose' notification action to be invoked instead)
  widget.DisableCloseButton();
  widget.ActionNotificationHandle(Widget_NotificationHandler);

  // Handle Wizard Buttons
  cmdCancel = $("#cmdCancel");
  cmdFinish = $("#cmdFinish");
  cmdCancel.click(tabDetails_Cancel);
  cmdFinish.click(Form_ExecuteAction_Finish);

  // Reset
  Form_Reset();
});

// ==========
// Reset Form
// ==========
function Form_Reset() {
  // Resize
  Form_Resize();

  // Load Record (i.e., initialise wizard)
  Record_Load();
}

// ===========
// Load Record
// ===========
function Record_Load() {
  // Initialise
  mRecord = null;

  // Hide content
  frmMain.Visible(false);

  // Block UI
  widget.UI.Block("Initialising, please wait...");

  // Load Initialisation details
  widget.GetString("GetInitialisationInfo", {},
    // Success
    Record_Load_Done,

    // Fail
    function (message) {
      widget.UI.MsgBoxAlert(message);
      Fields_Load();
    }
  );
}

function Record_Load_Done(data) {
  // Initialise
  mRecord = JSON.parse(data);

  // Set Tab
  if (mRecord &amp;&amp; mRecord.PageId) {
    tabDetails.SelectedTabId(mRecord.PageId);

    // Hide other Pages: not applicable for Cost Centre widgets.
  }
  else {
    tabDetails.SelectedTabId("Service");
  }

  // Page Permissions
  // NOTE: Not applicable to this form

  // Load Fields
  Fields_Load();

  // Save Fields (so UserData is in correct format for mOriginalJson)
  Fields_Save();

  // Save original JSON for Form_IsDirty
  mOriginalJson = JSON.stringify(mRecord);
}

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // Service
    C.chkUseService.Value(mRecord.UseService);

    // Credentials
    C.txtRequestUrlProduction.Text(mRecord.RequestUrlProduction);
    C.txtApiKeyProduction.Text(mRecord.ApiKeyProduction);
    C.txtWebhookUrlProduction.Text(mRecord.WebhookTargetUrlProduction);
    C.txtWebhookIdProduction.Text(mRecord.WebhookIdProduction);
    C.txtWebhookSecretProduction.Text(mRecord.WebhookSecretProduction);

    // Test Credentials
    C.txtRequestUrlTest.Text(mRecord.RequestUrlTest);
    C.txtApiKeyTest.Text(mRecord.ApiKeyTest);
    C.txtWebhookUrlTest.Text(mRecord.WebhookTargetUrlTest);
    C.txtWebhookIdTest.Text(mRecord.WebhookIdTest);
    C.txtWebhookSecretTest.Text(mRecord.WebhookSecretTest);

    // Options
    C.chkEnableBankAccountEnquiry.Value(mRecord.EnableBankAccountEnquiry);
    C.numOptionsRequestedDays.Value(mRecord.OptionsRequestedDays);
    C.txtOptionsRedirectUrl.Text(mRecord.OptionsRedirectUrl);
    C.txtOptionsReportCodes.Text(mRecord.OptionsReportCodes);
    C.cboOptionsEmailDocument.Text(mRecord.OptionsEmailDocumentId);
    C.cboOptionsSmsDocument.Text(mRecord.OptionsSmsDocumentId);
  }

  // Unblock UI
  widget.UI.Unblock();

  // Update Controls

  // Update fields
  Fields_Update();

  // Refresh Tab
  tabDetails_Refresh();
  tabDetails_Resize();
}

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // Service
  mRecord.UseService = C.chkUseService.Value();

  // Credentials
  mRecord.RequestUrlProduction = C.txtRequestUrlProduction.Text();
  mRecord.ApiKeyProduction = C.txtApiKeyProduction.Text();
  mRecord.WebhookTargetUrlProduction = C.txtWebhookUrlProduction.Text();

  // Test Credentials
  mRecord.RequestUrlTest = C.txtRequestUrlTest.Text();
  mRecord.ApiKeyTest = C.txtApiKeyTest.Text();
  mRecord.WebhookTargetUrlTest = C.txtWebhookUrlTest.Text();

  // Options
  mRecord.EnableBankAccountEnquiry = C.chkEnableBankAccountEnquiry.Value();
  mRecord.OptionsRequestedDays = C.numOptionsRequestedDays.Value();
  mRecord.OptionsRedirectUrl = C.txtOptionsRedirectUrl.Text();
  mRecord.OptionsReportCodes = C.txtOptionsReportCodes.Text();
  mRecord.OptionsEmailDocumentId = C.cboOptionsEmailDocument.Text();
  mRecord.OptionsSmsDocumentId = C.cboOptionsSmsDocument.Text();
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    if (mRecord.CostCentreId) {
      widget.SetHeading("&lt;HTML&gt;&lt;b&gt;Basiq:&lt;/b&gt; Cost Centre (" + mRecord.CostCentreId + ")");
    }
    else {
      widget.SetHeading("New Cost Centre");
    }
  }

  // Information Lists
  if (mRecord) {
  }

  // Lists
  if (mRecord) {
    C.cboOptionsEmailDocument.RefreshFromStandardRange("Documents", mRecord.DocumentFilter, false, mRecord.OptionsEmailDocumentId);
    C.cboOptionsSmsDocument.RefreshFromStandardRange("Documents", mRecord.DocumentFilter, false, mRecord.OptionsSmsDocumentId);
  }

  // Controls
  if (mRecord) {
    C.txtRequestUrlProduction.BlankTip(mRecord.RequestUrlProductionBlankTip);
    C.txtRequestUrlTest.BlankTip(mRecord.RequestUrlTestBlankTip);
    C.txtWebhookUrlProduction.BlankTip(mRecord.WebhookTargetUrlProductionBlankTip);
    C.txtWebhookUrlTest.BlankTip(mRecord.WebhookTargetUrlTestBlankTip);
    C.txtOptionsReportCodes.BlankTip(mRecord.OptionsReportCodesBlankTip);

    // Trigger change events
    chkUseService_Change();
  }

  // Pages
  if (mRecord) {
  }

  // Read-Only?
  if (mRecord &amp;&amp; mRecord.ReadOnly) {
    cmdFinish.prop("disabled", true);
    frmMain.FormReadOnly(C, true);
  }

  // Show content
  frmMain.Visible(mRecord != null);

  // Resize Tab
  tabDetails_Resize();
}

// ===========
// Resize Form
// ===========
function Form_Resize() {
  // Mobile Optimisations
  var el = $(".mobile-indent th.indent1, .mobile-indent th.no-indent1");
  if (window.innerWidth &lt; 500) {
    el.addClass("no-indent1").removeClass("indent1");
  }
  else {
    el.addClass("indent1").removeClass("no-indent1");
  }

  // General

  // Tab
  tabDetails_Resize();
}

// ========
// Is Dirty
// ========
function Form_IsDirty() {
  if (mRecord) {
    // Save Fields
    Fields_Save();

    // Is Dirty?
    return mOriginalJson != JSON.stringify(mRecord);
  }
  else {
    return false;
  }
}

// ==============
// Wizard Buttons
// ==============
function tabDetails_Cancel() {
  if (Form_IsDirty()) {
    // Confirm
    widget.UI.MsgBoxConfirm("Are you sure you want to close this form without saving your changes?", { heading: "Close Form" }, tabDetails_Cancel_Finalise);
  }
  else {
    // Cancel immediately
    tabDetails_Cancel_Finalise();
  }
}

function tabDetails_Cancel_Finalise() {
  if (widget.CanClose()) {
    widget.Close();
  }
  else {
    widget.Reset();
  }
}

// ==========
// Resize Tab
// ==========
function tabDetails_Resize() {
  switch (tabDetails.SelectedTabId()) {
    case "Credentials":
      // Credentials
      C.txtRequestUrlProduction.WidthResizeFromParent();
      C.txtApiKeyProduction.WidthResizeFromParent();
      C.txtWebhookUrlProduction.WidthResizeFromParent();
      C.txtWebhookIdProduction.WidthResizeFromParent();
      C.txtWebhookSecretProduction.WidthResizeFromParent();
      break;

    case "TestCredentials":
      // Test Credentials
      C.txtRequestUrlTest.WidthResizeFromParent();
      C.txtApiKeyTest.WidthResizeFromParent();
      C.txtWebhookUrlTest.WidthResizeFromParent();
      C.txtWebhookIdTest.WidthResizeFromParent();
      C.txtWebhookSecretTest.WidthResizeFromParent();
      break;

    case "Options":
      // Options
      C.txtOptionsRedirectUrl.WidthResizeFromParent();
      C.txtOptionsReportCodes.WidthResizeFromParent();
      break;
  }
}

// ===========
// Refresh Tab
// ===========
function tabDetails_Refresh() {
   // Load details
  switch (tabDetails.SelectedTabId()) {
    default:
      break;
  }

  // Resize
  tabDetails_Resize();

  // Focus
  switch (tabDetails.SelectedTabId()) {
    default:
      tabDetails.FocusFirst();
      break;
  }
}

// =================
// Execute an Action
// =================
function Form_ExecuteAction(actionId, data) {
  switch(actionId) {
    default:
      window.alert("Unhandled action '" + actionId + "'");
  }
}

// =============
// Finish Action
// =============
function Form_ExecuteAction_Finish() {
  // Assume Success
  var Ok = true;

  // Validate
  Ok = tabDetails.Validate();

  // Prompt
  if (Ok) {
    if (mRecord.PromptOnSave) {
      // Confirm
      widget.UI.MsgBoxConfirm("Are you sure you want to save this record?",
                              { heading: "Save" },
                              Form_ExecuteAction_FinishPost);

    }
    else {
      // Save without prompting
      Form_ExecuteAction_FinishPost();
    }
  }
}

function Form_ExecuteAction_FinishPost() {
  // Disable Form
  widget.UI.Block("Saving, please wait...");

  // Create Parameters
  // NOTE: We will simply update mRecord, clone this and send back (less some information)
  Fields_Save();
  var params = JSON.parse(JSON.stringify(mRecord));

  // Finish
  widget.GetString("Finish", params,
    function (data) {
      // Close Form
      widget.Close();

      // Refresh Parent (to show updated details)
      // NOTE: Pass in Record Id just in case this has changed
      widget.RefreshParent(mRecord.CostCentreId);
    },

    function (data) {
      // Show Error
      widget.UI.MsgBoxAlert(data);

      // Enable Form
      widget.UI.Unblock();
    }
  );
}

// ====================
// Notification Handler
// ====================
function Widget_NotificationHandler(actionId, data) {
   switch(actionId) {
     case "FormClose":
      // Form Close button is disabled so act as if 'Cancel' has been clicked
      tabDetails_Cancel();
      break;
   }
}

// ==============
// Control Events
// ==============
function chkUseService_Change(sender, e) {
  // Handled
  if (e) e.ChangeHandled = true;

  if (C.chkUseService.Value()) {
    // set all tabs to be visible
    tabDetails.ShowAllTabs();
  } else {
    // only show the Service tab
    tabDetails.ShowSingleTab("Service");
  }
}
&lt;/script&gt;</TemplateText>
    <TemplateTextBookmarks />
    <UniqueId>BsqCCw7Xkd0KPmR3vNhTYA</UniqueId>
    <AllowRefresh>true</AllowRefresh>
    <Caption>Cost Centre</Caption>
    <HtmlWidgetAllowInitialEventCaching>false</HtmlWidgetAllowInitialEventCaching>
    <HtmlWidgetMaxHeight>800</HtmlWidgetMaxHeight>
    <HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth>
    <HtmlWidgetDarkModeNotSupported>false</HtmlWidgetDarkModeNotSupported>
    <HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling>
    <HtmlWidgetResourceChartsApex>false</HtmlWidgetResourceChartsApex>
    <HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2>
    <HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget>
    <HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery>
    <HtmlWidgetResourceJQueryVersion />
    <HtmlWidgetShowParameterEntry>false</HtmlWidgetShowParameterEntry>
    <HtmlWidgetSpecialEventGetFolderCount>false</HtmlWidgetSpecialEventGetFolderCount>
    <HtmlWidgetSpecialEventShowAsSummaryPage>false</HtmlWidgetSpecialEventShowAsSummaryPage>
    <HtmlWidgetSummaryPageObjectType>None</HtmlWidgetSummaryPageObjectType>
    <Icon>CostCentre</Icon>
    <RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled>
    <RunAsAdministrator>false</RunAsAdministrator>
    <WebServiceName />
    <WebServiceAllowAnonymous>false</WebServiceAllowAnonymous>
    <WebServiceSendDebugInformation>false</WebServiceSendDebugInformation>
    <ShowInMenu>None</ShowInMenu>
    <ParametersType>Custom</ParametersType>
    <Parameters>
      <ISParameterDefs version="1.00">
        <Parameters>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Form options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>Configuration options.</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="" type="SectionStart">
            <BlankTip />
            <Caption>TESTING</Caption>
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <SectionColumns>1</SectionColumns>
            <Visible>true</Visible>
          </Parameter>
          <Parameter name="CostCentreId" type="Range">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <LimitToList>false</LimitToList>
            <MaxLength>10</MaxLength>
            <RangeSingle>true</RangeSingle>
            <RangeType>Standard</RangeType>
            <RangeLookupSource>CostCentres</RangeLookupSource>
            <RangeLookupSqlWhere />
          </Parameter>
          <Parameter name="Page" type="List">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <Mandatory>false</Mandatory>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value />
            <Visible>true</Visible>
            <List>Service,Credentials,TestCredentials,Options</List>
            <LimitToList>false</LimitToList>
            <MaxLength>0</MaxLength>
            <Rows>1</Rows>
          </Parameter>
          <Parameter name="ReadOnly" type="Boolean">
            <BlankTip />
            <Caption />
            <StandaloneOnly>false</StandaloneOnly>
            <TooltipText />
            <DefaultValueExpression />
            <Enabled>true</Enabled>
            <HideDescription>false</HideDescription>
            <IndentLevel>0</IndentLevel>
            <NonPersistable>false</NonPersistable>
            <ReadOnly>false</ReadOnly>
            <ReadOnly2>false</ReadOnly2>
            <Value>False</Value>
            <Visible>true</Visible>
          </Parameter>
        </Parameters>
      </ISParameterDefs>
    </Parameters>
  </finScript>