<?xml version="1.0" encoding="utf-8"?><finScript version="1.00" exportedUtcDate="2021-02-10T03:05:37.0000000"><CreatedUserId>Admin</CreatedUserId><CreatedUtcDate>2020-12-01T01:01:13.0340000</CreatedUtcDate><UpdatedUserId>Admin</UpdatedUserId><UpdatedUtcDate>2021-01-20T02:43:38.2480000</UpdatedUtcDate><ScriptId>ILE</ScriptId><Description>Information List Edit</Description><ScriptType>HtmlWidget</ScriptType><Active>true</Active><AllowUI>false</AllowUI><Category /><Code>' HtmlWidget_InformationListEdit
Option Explicit On
Option Strict On

' #################################################################
' Information List Edit form HTML Widget
'
' Version: 1.00 (20/01/2021)
'
' Usage: System-supplied HTML Widget
' #################################################################

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

' Standard Parameters
Private mDuplicateRecordId As String
Private mInformationListId 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
    mInformationListId = .GetString("InformationListId") ' Always use Startup Parameters since the Information List Id may be updated
  End With
  With mCombinedParameters
    mDuplicateRecordId = .GetString("DuplicateRecordId")
    mPage = .GetString("Page")
    mReadOnly = .GetBoolean("ReadOnly")
  End With

  ' Validate
  If finBL.CloudConnectFunctions.CloudConnectSettings.ExcludeAdministrationTools Then
    Main = False
    finBL.Error.ErrorBegin("Administration tools are excluded from being accessed from finPOWER Connect Cloud.")
  ElseIf Not finBL.CurrentUser.Permissions.Allow("Admin.InformationLists") Then
    Main = False
    finBL.Error.ErrorBegin("You do not have permission to add or update Information Lists.")
  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 Information List.
''' &lt;/summary&gt;
Private Function GetInformationList(ByRef informationList As finInformationList) As Boolean

  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate

  ' Create and Load Information List
  If Success Then
    ' Create Information List
    InformationList = finBL.CreateInformationList()

    ' Load Information List
    If Len(mDuplicateRecordId) &lt;&gt; 0 Then
      ' New record (by duplicating existing)
      Success = informationList.Load(mDuplicateRecordId)
      If Success Then informationList.Duplicate()
    ElseIf Len(mInformationListId) = 0 Then
      ' New record
    Else
      Success = informationList.Load(mInformationListId)
    End If
  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 FormInitialisationInfo As FormInitialisationInfo
  Dim InformationList As finInformationList
  Dim Item As finInformationListItem
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Validate
  If Not finBL.CurrentUser.Permissions.Allow("Admin.InformationLists") OrElse Not finBL.CurrentUser.Permissions.Allow("Cloud.Form.InformationLists") Then
    Success = False
    finBL.Error.ErrorBegin("You do not have permission to edit Information Lists.")
  End If

  ' Get Information List
  If Success Then
    Success = GetInformationList(InformationList)
  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
      .Pk = InformationList.Pk
      .Timestamp = InformationList.Timestamp

      ' Page Permissions (defined here since they are used below)
      .AllowPageGeneral = True
      .AllowPageList = True

      ' General
      .InformationListId = InformationList.InformationListId ' Always need to return Information List Id
      If .AllowPageGeneral Then
        .Description = InformationList.Description

        .Mandatory = InformationList.Mandatory
        .LimitToList = InformationList.LimitToList
        .UniqueValues = InformationList.UniqueValues
        .MaxLength = InformationList.MaxLength
        .AllowAltValues = InformationList.AllowAltValues
        .MaxLengthAltValue = InformationList.MaxLengthAltValue
      End If

      ' List
      If .AllowPageList Then
        .DefaultValue = InformationList.DefaultValue

        .List = New List(Of InformationListItem)
        For Each Item In InformationList.Items
          .List.Add(New InformationListItem(Item))
        Next
      End If

      ' Other
      .IsSystemList = InformationList.IsSystemList

      ' Permissions

      ' Lists

      ' Configuration
      .HideOtherPages = mCombinedParameters.GetBoolean("HideOtherPages", False)
      .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 Information List.
''' &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 InformationList As finInformationList
  Dim InformationListItem As InformationListItem
  Dim Item As finInformationListItem
  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 Information List
  If Success Then
    Success = GetInformationList(InformationList)
  End If

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

  ' Update and Save
  ' NOTE: Recheck Permissions in addition to the 'AllowPage' properties before updating to prevent spoofing
  If Success Then
    ' Begin Transaction
    If finBL.Database.TransactionBegin() Then
      ' Update Information List
      With InformationList
        ' General
        If Record.AllowPageGeneral Then
          .InformationListId = Record.InformationListId
          .Description = Record.Description

          .Mandatory = Record.Mandatory
          .LimitToList = Record.LimitToList
          .UniqueValues = Record.UniqueValues
          .MaxLength = Record.MaxLength
          .AllowAltValues = Record.AllowAltValues
          .MaxLengthAltValue = Record.MaxLengthAltValue
        End If

        ' List
        If Record.AllowPageList Then
          .DefaultValue = Record.DefaultValue

          .Items.Clear()
          For Each InformationListItem In Record.List
            Item = InformationList.Items.CreateItem()
            Item.Value = InformationListItem.Value
            Item.ValueAlt = InformationListItem.ValueAlt
            .Items.Add(Item)
          Next
        End If
      End With

      ' Save
      If Success Then
        Success = InformationList.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;
'''  Validate a Wizard page.
''' &lt;/summary&gt;
''' &lt;param name="returnValue"&gt;
'''  A JSON object; "true" if validation passed, otherwise, information as to why validation failed.
''' &lt;/param&gt;
Private Function WizardValidate(parametersJson As String,
                                ByRef returnValue As String) As Boolean

  Dim Data As Object
  Dim FailedControlId As String
  Dim FailedMessage As String
  Dim PageId As String
  Dim Success As Boolean

  ' Assume Success
  Success = True

  ' Get Parameters
  ' NOTE: Use the module mCombinedParameters since this contains Startup and event Parameters in a single Key/Value List
  With mCombinedParameters
    PageId = .GetString("PageId")
  End With

  ' Validate Page
  Select Case PageId
    Case "General"
      ' General
  End Select

  ' Finalise
  If Success Then
    Success = finBL.Runtime.WebUtilities.SerialiseObjectToJsonString(New WizardValidateResponse(Data, FailedMessage, FailedControlId), returnValue)
  End If

  Return Success

End Function


''' &lt;summary&gt;
'''  Wizard Initialisation Information.
''' &lt;/summary&gt;
''' &lt;remarks&gt;
'''  This object is also used to save the Employment.
''' &lt;/remarks&gt;
Public Class FormInitialisationInfo

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

  ' Record
  Public Pk As Integer
  Public Timestamp As Integer

  ' General
  Public InformationListId As String
  Public Description As String

  Public Mandatory As Boolean
  Public LimitToList As Boolean
  Public UniqueValues As Boolean
  Public MaxLength As Integer
  Public AllowAltValues As Boolean
  Public MaxLengthAltValue As Integer

  ' List
  Public DefaultValue As String
  Public List As List(Of InformationListItem)

  ' Other
  Public IsSystemList As Boolean

  ' Permissions
  Public AllowPageGeneral As Boolean
  Public AllowPageList As Boolean

  ' Lists

  ' Configuration
  Public HideOtherPages As Boolean
  Public PromptOnSave As Boolean

End Class


''' &lt;summary&gt;
'''  Information List Item.
''' &lt;/summary&gt;
Public Class InformationListItem

  Public Value As String
  Public ValueAlt As String

  Public Sub New()
  End Sub

  Public Sub New(informationListitem As finInformationListItem)

    With informationListitem
      Me.Value = .Value
      Me.ValueAlt = .ValueAlt
    End With

  End Sub

  ' Prevent Serialisation for Not Applicable Properties
  Public Function ShouldSerializeValueAlt() As Boolean
    Return Len(Me.ValueAlt) &lt;&gt; 0
  End Function

End Class

''' &lt;summary&gt;
'''  Validation details.
''' &lt;/summary&gt;
Public Class WizardValidateResponse

  Public Data As Object
  Public FailedMessage As String
  Public FailedControlId As String

  Public Sub New(data As Object,
                 failedMessage As String,
                 failedControlId As String)

    Me.Data = data
    Me.FailedMessage = failedMessage
    Me.FailedControlId = failedControlId

  End Sub

End Class</Code><Language>VisualBasic</Language><Notes>System-supplied HTML Widget to edit an Information List.</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="General"&gt;General&lt;/li&gt;
        &lt;li tabId="List"&gt;List&lt;/li&gt;
      &lt;ul&gt;
    &lt;/div&gt;
  &lt;/header&gt;


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

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label id="lblCodeAndName"&gt;Code and Description&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtInformationListId"&gt;Code:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtInformationListId"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="txtDescription"&gt;Description:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="txtDescription"/&gt;&lt;/td&gt;
        &lt;/tr&gt;

        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;label&gt;List behaviour&lt;/label&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkMandatory" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkLimitToList" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkUniqueValues" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th&gt;&lt;label for="numMaxLength"&gt;Max Length:&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numMaxLength"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th colspan="2"&gt;&lt;input id="chkAllowAltValues" type="checkbox"/&gt;&lt;/th&gt;
        &lt;/tr&gt;
        &lt;tr&gt;
          &lt;th class="indent1"&gt;&lt;label for="numMaxLengthAltValue"&gt;Max&amp;nbsp;Length:&amp;nbsp;&lt;/label&gt;&lt;/th&gt;
          &lt;td&gt;&lt;input id="numMaxLengthAltValue"/&gt;&lt;/td&gt;
        &lt;/tr&gt;
      &lt;/table&gt;
    &lt;/div&gt;



    &lt;!-- List --&gt;
    &lt;div id="pageList"&gt;
      &lt;div style="display:flex; flex-direction:column; position:absolute; top:0; left:0; right:0; bottom:0; padding:4px"&gt;
        &lt;div&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&gt;Default List Value&lt;/label&gt;&lt;/th&gt;
            &lt;/tr&gt;
            &lt;tr&gt;
              &lt;th&gt;&lt;label for="txtDefaultValue"&gt;Default Value:&lt;/label&gt;&lt;/th&gt;
              &lt;td&gt;&lt;input id="txtDefaultValue"/&gt;&lt;/td&gt;
            &lt;/tr&gt;

            &lt;tr&gt;
              &lt;th colspan="2"&gt;&lt;label id="lblList"&gt;List entries&lt;/label&gt;&lt;/th&gt;
            &lt;/tr&gt;
          &lt;/table&gt;
        &lt;/div&gt;
        &lt;div style="position:relative; flex-grow:1; max-width:1024px; margin-left:8px"&gt;
          &lt;div id="gridList" class="is-dock-fill"&gt;&lt;/div&gt;
        &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;

  &lt;/div&gt;


  &lt;!-- Form Footer --&gt;
  &lt;footer&gt;
    &lt;button id="cmdActions"/&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 mRecord_List;

var mOriginalJson;

// Controls
var C = {
  //   General
  lblCodeAndName: null,
  txtInformationListId: null,
  txtDescription: null,

  chkMandatory: null,
  chkLimitToList: null,
  chkUniqueValues: null,
  numMaxLength: null,
  chkAllowAltValues: null,
  numMaxLengthAltValue: null,

  //   List
  txtDefaultValue: null,

  lblList: null,
  gridList: null,
}

// Form
var frmMain;
var tabDetails;

// Buttons
var cmdCancel;
var cmdFinish;

// Other

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

  // --------
  // Controls
  // --------
  //   General
  C.lblCodeAndName = widget.UI.Label("lblCodeAndName", {});
  C.txtInformationListId = widget.UI.TextBox("txtInformationListId", {
    allowBlank: false,
    maxLength: 25,
    width: widget.UI.FIELD_WIDTH_CODE_20,
  });
  C.txtDescription = widget.UI.TextBox("txtDescription", {
    allowBlank: false,
    maxLength: 50,
  });

  C.chkMandatory = widget.UI.CheckBox("chkMandatory", {
    caption: "Mandatory?",
  });
  C.chkLimitToList = widget.UI.CheckBox("chkLimitToList", {
    caption: "Limit to List?",
  });
  C.chkUniqueValues = widget.UI.CheckBox("chkUniqueValues", {
    caption: "List items must be unique?",
  });
  C.numMaxLength = widget.UI.NumberBox("numMaxLength", {
    allowBlank: false,
    decimals: 0,
    minValue: 1,
    maxValue: 255,
  });
  C.chkAllowAltValues = widget.UI.CheckBox("chkAllowAltValues", {
    caption: "Allow alternate/ display list values?",

    onChange: chkAllowAltValues_Change,
  });
  C.numMaxLengthAltValue = widget.UI.NumberBox("numMaxLengthAltValue", {
    allowBlank: false,
    decimals: 0,
    minValue: 1,
    maxValue: 255,
  });

  //   List
  C.txtDefaultValue = widget.UI.TextBox("txtDefaultValue", {
    allowBlank: true,
    maxLength: 50,
  });

  C.lblList = widget.UI.Label("lblList", {
    tooltipText: "Use the 'Copy' button to set the Default Value to the current row's value.",
  });

  // Grids
  C.gridList = widget.UI.Grid("gridList", {
    docked: true,
    stickyHeader: true,
    rowNumbering: true,
    allowAddRows: true,
    allowMultiRowSelect: true,
    maxNewRows: 200,

    onAction: gridList_Action,
    onAfterRowActivate: gridList_AfterRowActivate,
    onBeforeCellUpdate: gridList_BeforeCellUpdate,
    onInitialiseRow: gridList_InitialiseRow,
    onRowAdd: gridList_RowAdd,
    onRowDrilldown: gridList_RowDrilldown,
  });

  // 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("fail: " + message);
      Fields_Load();
    }
  );
}

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

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

    // Hide other Pages
    if (mRecord.HideOtherPages) {
      tabDetails.ShowSingleTab(mRecord.PageId);
    }
  }
  else {
    tabDetails.SelectedTabId("General");
  }

  // Page Permissions
  if (!mRecord.AllowPageGeneral) tabDetails.TabVisible("General", false);
  if (!mRecord.AllowPageList) tabDetails.TabVisible("List", false);

  // Load Fields
  Fields_Load();

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

  // Define Actions
  var actions = [];
  frmMain.ActionsDefine(actions, "cmdActions", Form_ExecuteAction);
}

// ===========
// Load Fields
// ===========
function Fields_Load() {
  if (mRecord) {
    // General
    C.txtInformationListId.Text(mRecord.InformationListId);
    C.txtDescription.Text(mRecord.Description);

    C.chkMandatory.Value(mRecord.Mandatory);
    C.chkLimitToList.Value(mRecord.LimitToList);
    C.chkUniqueValues.Value(mRecord.UniqueValues);
    C.numMaxLength.Value(mRecord.MaxLength);
    C.chkAllowAltValues.Value(mRecord.AllowAltValues);
    C.numMaxLengthAltValue.Value(mRecord.MaxLengthAltValue);

    // List
    C.txtDefaultValue.Text(mRecord.DefaultValue);
    if (mRecord_List) gridList_Refresh();
  }

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

  // Update Controls

  // Update fields
  Fields_Update();

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

// ===========
// Save Fields
// ===========
function Fields_Save() {
  // General
  mRecord.InformationListId = C.txtInformationListId.Text();
  mRecord.Description = C.txtDescription.Text();

  mRecord.Mandatory = C.chkMandatory.Value();
  mRecord.LimitToList = C.chkLimitToList.Value();
  mRecord.UniqueValues = C.chkUniqueValues.Value();
  mRecord.MaxLength = C.numMaxLength.Value();
  mRecord.AllowAltValues = C.chkAllowAltValues.Value();
  mRecord.MaxLengthAltValue = C.numMaxLengthAltValue.Value();

  // List
  mRecord.DefaultValue = C.txtDefaultValue.Text();
}

// =============
// Update Fields
// =============
function Fields_Update() {
  // Heading
  if (mRecord) {
    if (mRecord.InformationListId) {
      widget.SetHeading("Information List (" + mRecord.InformationListId + ")");
    }
    else {
      widget.SetHeading("New Information List");
    }
  }  

  // Lists
  if (mRecord) {
  }

  // Controls
  if (mRecord) {
    if (mRecord.IsSystemList) {
      C.txtInformationListId.ReadOnly(true);
      C.txtDescription.ReadOnly(true);
      C.chkUniqueValues.ReadOnly(true);
      C.numMaxLength.ReadOnly(true);
      C.chkAllowAltValues.ReadOnly(true);
      C.numMaxLengthAltValue.ReadOnly(true);
    }

    chkAllowAltValues_Change();
  }

  // Pages
  if (mRecord) {
    // NOTE: Even though many pages are updated in tabDetails_Refresh, we must update them here to ensure controls are hidden since this is not a wizard and all pages are validated on "Finish"
    pageGeneral_Refresh();
    pageList_Refresh();
  }

  // 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();

    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 "General":
      // General
      C.txtDescription.WidthResizeFromParent();
      break;

    case "List":
      // List
      C.txtDefaultValue.WidthResizeFromParent();
      break;
  }
}

// ===========
// Refresh Tab
// ===========
function tabDetails_Refresh() {
   // Load details
  switch (tabDetails.SelectedTabId()) {
    case "General":
      pageGeneral_Refresh();
      break;

    case "List":
      pageList_Refresh();
      break;

    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 + "'");
  }
}

// ====================
// 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;
   }
}

// =============
// 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));
  //params.GendersList = null;

  // 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(C.txtInformationListId.Text());
    },

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

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

// ===========
// pageGeneral
// ===========
function pageGeneral_Refresh() {
  if (!mRecord) return;

  // Controls
}

// ========
// pageList
// ========
function pageList_Refresh() {
  if (!mRecord) return;

  // Controls
  C.gridList.ColumnVisible("ValueAlt", C.chkAllowAltValues.Value());
  C.gridList.VirtualDataRefresh(mRecord_List, true, { retainSelectedRows: true });
}

// ========
// gridList
// ========
function gridList_Refresh() {
  // Add Columns
  C.gridList.ClearColumns();
  C.gridList.AddColumnDrilldown("Drilldown_Default", { icon: "Copy" });
  C.gridList.AddColumnString("Value", { caption: "Value", allowEdit: true });
  C.gridList.AddColumnString("ValueAlt", { caption: "Alternate/ Display Value", allowEdit: true });

  // Actions
  var actions = [];
  actions.push({ actionId: "DeleteRow", tooltipText: "Remove row(s)", icon: "Delete" });
  actions.push({});
  actions.push({ actionId: "RowMoveUp", tooltipText: "Move current row up", icon: "Grid_Row_MoveUp" });
  actions.push({ actionId: "RowMoveDown", tooltipText: "Move current row down", icon: "Grid_Row_MoveDown" });
  actions.push({});
  actions.push({ actionId: "SortAscending", tooltipText: "Sort entire list or selected rows in ascending order", icon: "Sort_Ascending" });
  actions.push({ actionId: "SortDescending", tooltipText: "Sort entire list or selected rows in descending order", icon: "Sort_Descending" });
  C.gridList.Actions().Define(actions);

  // Refresh
  C.gridList.VirtualDataRefresh(mRecord_List);

  // Activate First Row
  C.gridList.ActivateFirstDataRow();
}

function gridList_InitialiseRow(e) {
  var item = mRecord_List[e.row.listIndex];

  // Update cells
  e.row.AutoBind(item);

  // Validation colouring
  e.row.invalid = false;
  e.row.invalidMessage = "";
  if (item.Value &amp;&amp; C.numMaxLength.Value() &amp;&amp; item.Value.length &gt; C.numMaxLength.Value()) {
    e.row.invalid = true;
    e.row.invalidMessage = "Value too long.";
  }
  if (C.chkAllowAltValues.Value() &amp;&amp; item.ValueAlt &amp;&amp; C.numMaxLengthAltValue.Value() &amp;&amp; item.ValueAlt.length &gt; C.numMaxLengthAltValue.Value()) {
    e.row.invalid = true;
    if (e.row.invalidMessage) {
      e.row.invalidMessage = "Value and Alternate Value too long.";
    }
    else {
      e.row.invalidMessage = "Alternate Value too long.";
    }
  }
}

function gridList_BeforeCellUpdate(e) {
  var item = mRecord_List[e.row.listIndex];

  switch(e.columnKey) {
    case "Value":
      item.Value = e.newValue;
      break;

    case "ValueAlt":
      item.ValueAlt = e.newValue;
      break;
  }

  // Refresh row to update styles
  e.refreshRow = true;
}

function gridList_RowAdd(e) {
  // Create item
  var item = {
    Value: "",
    ValueAlt: ""
  };

  // Add
  mRecord_List.push(item);
}

function gridList_Action(actionId) {
  switch (actionId.toUpperCase()) {
    case "DELETEROW":
      // Delete Row(s)
      // NOTE: This action is also called automatically by the grid if delete is pressed and a row but no cells are selected
      C.gridList.RemoveSelectedRowsAndCollectionItems();
      C.gridList.Focus();

      // Refresh Buttons
      gridList_RefreshButtons();
      break;

    case "ROWMOVEDOWN":
      C.gridList.RowMoveDown();
      break;

    case "ROWMOVEUP":
      C.gridList.RowMoveUp();
      break;

    case "SORTASCENDING":
      var sortAltValue = false;
      if (C.chkAllowAltValues.Value()) {
        widget.UI.MsgBoxConfirm("Do you want to sort using the 'Alternate Value' column?\n\nNOTE: Click 'No' to sort using the 'Value' column.", { heading: "Sort List", captionOk: "Yes", captionCancel: "No" },
          function () {
            gridList_Action_Sort(false, true);
          },

          function () {
            gridList_Action_Sort(false, false);
          }
        );
      }
      else {
        gridList_Action_Sort(false, false);
      }
      break;

    case "SORTDESCENDING":
      if (C.chkAllowAltValues.Value()) {
        widget.UI.MsgBoxConfirm("Do you want to sort using the 'Alternate Value' column?\n\nNOTE: Click 'No' to sort using the 'Value' column.", { heading: "Sort List", captionOk: "Yes", captionCancel: "No" },
          function () {
            gridList_Action_Sort(true, true);
          },

          function () {
            gridList_Action_Sort(true, false);
          }
        );
      }
      else {
        gridList_Action_Sort(true, false);
      }
      break;

    default:
      window.alert("Unhandled grid action '" + actionId + "'.");
      break;
  }
}

function gridList_Action_Sort(descending, altValue) {
  // Find sort range
  var startIndex = 0;
  var endIndex = mRecord_List.length - 1;
  var indexes = C.gridList.GetSelectedRowIndexes();
  if (indexes.length &gt; 1) {
    startIndex = indexes[0];
    endIndex = indexes[indexes.length - 1];
  }

  // Create a temporary array (for handing start and end indexes)
  var arrTemp = [];
  for (var i = startIndex; i &lt;= endIndex; i++) {
    arrTemp.push(mRecord_List[i]);
  }

  // Sort
  arrTemp.sort(function (a, b) {
    var valueA, valueB;
    if (altValue) {
      valueA = a.ValueAlt.toUpperCase();
      valueB = b.ValueAlt.toUpperCase();
    }
    else {
      valueA = a.Value.toUpperCase();
      valueB = b.Value.toUpperCase();
    }

    if (valueA &lt; valueB) {
      if (descending) {
        return 1;
      }
      else {
        return -1;
      }
    }
    if (valueA &gt; valueB) {
      if (descending) {
        return -1;
      }
      else {
        return 1;
      }
    }
    else {
      return 0;
    }
  });

  // Replace sorted range in original array
  for (var i = 0; i &lt; arrTemp.length; i++) {
    mRecord_List[startIndex + i] = arrTemp[i];
  }

  // Refresh Grid
  C.gridList.VirtualDataRefresh(mRecord_List, true, { retainSelectedRows: true });
}

function gridList_RefreshButtons() {
  if (C.gridList.ActiveDataRowListIndex() == -1) {
    C.gridList.Actions().SetEnabled("DeleteRow", false);
    C.gridList.Actions().SetEnabled("RowMoveUp", false);
    C.gridList.Actions().SetEnabled("RowMoveDown", false);
  }
  else {
    C.gridList.Actions().SetEnabled("DeleteRow", true);
    C.gridList.Actions().SetEnabled("RowMoveUp", C.gridList.ActiveDataRowListIndex() &gt; 0);
    C.gridList.Actions().SetEnabled("RowMoveDown", C.gridList.ActiveDataRowListIndex() &lt; mRecord_List.length - 1);
  }
  C.gridList.Actions().SetEnabled("SortAscending", mRecord_List.length &gt; 1);
  C.gridList.Actions().SetEnabled("SortDescending", mRecord_List.length &gt; 1);

  C.gridList.RefreshButtons();
}

function gridList_AfterRowActivate(e) {
  // Refresh Buttons
  gridList_RefreshButtons();
}

function gridList_RowDrilldown(e) {
  switch(e.columnKey) {
    case "Drilldown_Default":
      C.txtDefaultValue.Text(mRecord_List[C.gridList.ActiveDataRowListIndex()].Value);
      break;
  }
}

// =================
// chkAllowAltValues
// =================
function chkAllowAltValues_Change(sender, e) {
  C.numMaxLengthAltValue.VisibleRow(C.chkAllowAltValues.Value());
}
&lt;/script&gt;</TemplateText><TemplateTextBookmarks /><TimeoutSeconds>60</TimeoutSeconds><UniqueId>No7NqubaC0mhw+VNtze0uw</UniqueId><AllowRefresh>true</AllowRefresh><Caption>Information List</Caption><HtmlWidgetMaxHeight>800</HtmlWidgetMaxHeight><HtmlWidgetMaxWidth>800</HtmlWidgetMaxWidth><HtmlWidgetNeverApplyStyling>false</HtmlWidgetNeverApplyStyling><HtmlWidgetResourceCssSummaryPage2>false</HtmlWidgetResourceCssSummaryPage2><HtmlWidgetResourceCssWidget>true</HtmlWidgetResourceCssWidget><HtmlWidgetResourceJQuery>true</HtmlWidgetResourceJQuery><HtmlWidgetResourceJQueryVersion /><Icon /><JavaScriptDebugger>None</JavaScriptDebugger><RestrictedOriginsListEnabled>false</RestrictedOriginsListEnabled><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="HideOtherPages" type="Boolean"><BlankTip /><Caption>Hide pages other than the one being edited?</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><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="InformationListId" type="List"><BlankTip /><Caption /><StandaloneOnly>false</StandaloneOnly><TooltipText /><DefaultValueExpression /><Enabled>true</Enabled><HideDescription>false</HideDescription><IndentLevel>0</IndentLevel><Mandatory>true</Mandatory><NonPersistable>false</NonPersistable><ReadOnly>false</ReadOnly><ReadOnly2>false</ReadOnly2><Value /><Visible>true</Visible><List>RANGE.InformationLists</List><LimitToList>false</LimitToList><MaxLength>0</MaxLength><Rows>1</Rows></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>General,List</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>