Snippet: Benevolence Record Keeping

  • By Michael Garrison 3 Years Ago

(Or, "Customizing the Display of Person Attributes")

One of the things our church does, like many churches, is provide support for people who need financial support and assistance with physical needs. Obviously there are protocols in place for determining amount and frequency, and developing those is quite out of the scope of this post. But as part of our drive to make Rock our one-stop-shop for record-keeping, we have started storing benevolence recipients in Rock together with the date and record of the support we were able to grant.

This is easy enough to set up- we took all the usual steps:

  • Create a custom Attribute Category. We called it Benevolence, set it to Entity Type of Person and gave it the fa-money icon.

  • Create a custom Person Attribute; we called it Benevolence Granted. We used the Key Value List field type so we could store an arbitrary number of events. The key is the date so we set the "Key Prompt" to Date (MM/DD/YYYY). Then we set the "Label Prompt" to Amount so our staff would know to record the gift there. It's assigned to the Benevolence category, and we assigned it the fa-dollar icon

  • Then we created a custom Attribute Values block in the B1 zone of the Extended Attributes profile page, assigning it the Benevolence category. You could of course create this block anywhere in their profile you want to.

  • Set security as desired- (you may not want all of your staff to be able to see who was given assistance).

Here's the trick

Try out your new block now, and you'll see that the "Key Value List" attribute displays either a less-than-useful x key/value pair(s) label, or a better but still less-than-glanceable comma-separated list of keys and values (depending on your version of Rock), rather than something resembling the nice editing dialogue. So we'll use use some JavaScript/JQuery and Lava to display the information in a more legible format.

Go back to the Block Properties and flip over to the Advanced Settings.

Add this to your Pre-HTML field:

<script>  
    var CustomBenevolence='';

{% assign rawValue = Context.Person | Attribute:'BenevolenceGranted','RawValue' %}
{% assign splitValues = rawValue | Split: '|' %}

{% for pairValues in splitValues %}
    {% assign values = pairValues | Split:'^' %}
    CustomBenevolence += '<div class="form-group static-control"><label class="control-label">{{ values | First }}</label><p class="form-control-static">{{ values | Last }}</p></div>';
{% endfor %}

</script>  

This uses Lava to get at the actual data, HTML-formats it the way we want it to show up, and stores the string as a JavaScript variable.

Now set your Post-HTML input to this:

<div id='BenevolenceSrc'><script>document.write(CustomBenevolence);</script></div>  
<script>$('#BenevolenceSrc').prev().find("fieldset.attribute-values").html('').append( $('#BenevolenceSrc') );</script>  

When the page gets to this point, JQuery will wipe out the current contents of the attribute-values fieldset element and write our string in its' place. Mission Accomplished!

Note that your edit icon shows up as usual so that authorized users can add/delete/edit the values through the native Rock interface. The only trick is after an edit, the JavaScript doesn't run again so it will return to the default Key/Value display until the page is loaded again. Still, that's easy enough to explain to your users, and now you've got a nice glanceable display for authorized people to check.

On the left is the native editing view, which we haven't touched, and on the right is the view we created, which is how it will look whenever someone loads the page with this block on it:

Editing view and final view

Thanks to the Rock community and devs who helped me through the Lava codes initially which I hadn't been familiar with, and for helping me again when I didn't realize that v3 of Rock had broken them =)


@mikejed
Spark Development Network
Flagstaff, AZ

Michael Garrison recently left his job in Architecture to become one of the "new guys" at Spark (the "Core Team"), but he's still helping out Christ's Church of Flagstaff and other non-profits with tech needs in his off-hours, trying to make computers do what computers do best, so that people are freed to do what we do best: relate with people!