Creating a BBIS part so that the ADF doesn’t need hard coded values (GUIDs and URLs)

We got our ADF developed by Blackbaud and had issues with the need to hard code GUIDs and URLs. The hard coded values looked something similar to this.

var BBI = BBI || {
    // update these values when updating changelog
    Config: {
        version: 1.5,
        updated: '01/15/2016',
        isEditView: !!window.location.href.match('pagedesign'),
        responsive: true
    },


    Defaults: {
        rootpath: BLACKBAUD.api.pageInformation.rootPath,
        pageId: BLACKBAUD.api.pageInformation.pageId,


        designationQueryId: 'DADA4C7E-DFA7-4E83-A440-988DBAE3F16A',
        MerchantAccountId: 'BC69375B-EF5D-4849-9204-726CCD165730',
        paymentPartUrl: 'http://yoursite/payment',


        // ADF - Custom Attributes
        handlingNotesGUID: '10197036-033D-4BD4-9474-3F9895A9F98F',
        pledgeGiftGUID: '2C7579EF-7C56-4E97-8A51-F281358544AD'
    },


    Methods: {
        //methods in here such as pageInit, etc.
    }
}

So to get rid of those hard coded GUIDs I decided to create a new BBIS part that was on every page and that rendered those GUIDs to a new JS namespace. Then that namespace was referenced through the code above.

In the new BBIS part the editor gave the ability for a user to select the designation query, merchant account, payment part page, and the attributes to use for the handling notes and pledge gift.

In the display part we rendered the new JS like so.

Partial Public Class ADFModifierDisplay
    Inherits BBNCExtensions.Parts.CustomPartDisplayBase

    Private _content As ADFModifierProperties
    Private _scriptName = "ADF Modifier for page {0}"

    Protected Overrides Sub OnPreRender(e As EventArgs)
        Dim pageID = API.Pages.CurrentPage.Id
        Dim script = "var SCU = SCU || { Defaults: { "

        If(pageID > 0) Then
            With MYCONTENT
                Dim paymentPartUrl = URLBuilder.GetSitePageLinkBuilder(.PAYMENTPARTID).ToString()

                script += "designationQueryId: '" + .DESIGNATIONQUERYID.ToString() + "', "
                script += "MerchantAccountId: '" + .MERCHANTACCOUNTID.ToString() + "', "
                script += "paymentPartUrl: '" + paymentPartUrl + "', "
                script += "handlingNotesGUID: '" + .HANDLINGNOTESATTRIBUTEID.ToString() + "', "
                script += "pledgeGiftGUID: '" + .PLEDGEGIFTATTRIBUTEID.ToString() + "'"
            End With

            script += "}};"

            If(Not String.IsNullOrWhiteSpace(script)) Then
                ScriptManager.RegisterClientScriptBlock(Me.Page, Me.GetType(), String.Format(_scriptName, pageID), script, False)
            End If
        End If
    End Sub

    Private ReadOnly Property MYCONTENT As ADFModifierProperties
        Get
            If _content Is Nothing Then
                _content = Me.Content.GetContent(GetType(ADFModifierProperties))
                If _content Is Nothing Then
                _content = New ADFModifierProperties
                End If
            End If
            Return _content
        End Get
    End Property
End Class

The new BBIS part was added to the template/layout so that they were on every page. Then the JS that was created by the Blackbaud designer was changed to reference the newly rendered JS, like so.

Defaults: {
    rootpath: BLACKBAUD.api.pageInformation.rootPath,
    pageId: BLACKBAUD.api.pageInformation.pageId,

    designationQueryId: SCU.Defaults.designationQueryId,
    MerchantAccountId: SCU.Defaults.MerchantAccountId,
    paymentPartUrl: SCU.Defaults.paymentPartUrl,

    // ADF - Custom Attributes
    handlingNotesGUID: SCU.Defaults.handlingNotesGUID,
    pledgeGiftGUID: SCU.Defaults.pledgeGiftGUID
}

No more hard coded values and everything is easily configured between environments without having to the change the JS.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s