0 votes
in Rock by KateQuinn (6.8k points)
edited

Modals are a fun way to interact with a user, and a create a sophisticated effect when viewed on a page. How do you code a modal using lava, html, css and jquery?

Example:

enter image description here

enter image description here

**This post references the customizations we did on the public profiles for Southbrook Church. I have attached their lava file if you would like to view the entire thing.

2 Answers

0 votes
by KateQuinn (6.8k points)
edited
 
Best answer

There are two parts to modal: the displayed content (modal), and the trigger that tells the browser to display it.

1.) The code for the modal itself should be written into a place that makes logical sense in the flow of information. The person profile lava is looping through family members (Group Member objects.), and adds a modal for each:

<div class="modal fade" id="{{ familyMember.Person.FullName | ToCssClass }}Missions" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">

<div class="modal-dialog" role="document">
<div class="modal-content">                           
<div class="modal-header">
                                
<button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                
<h4 class="modal-title" id="myModalLabel">{{ familyMember.Person.FullName }}: Missions</h4>
                              
</div>                            
<div class="modal-body">
                                                                
{% comment %} Check for child membership in fundraiser group type{% endcomment %}
                                
{% assign externalsite = 'Global' | Attribute:'PublicApplicationRoot' %}                                
{% assign missionMembers = familyMember.Person | Groups:'31','All' %}                               
{% assign size = missionMembers | Size %}                               
{% if size != 0 and size != null and size != empty %}
                                    
{% comment %}cycle through Group Member objects and create impersonation token link to their profile{% endcomment %}
                                    
{% for member in missionMembers %}                                      
{% assign groupId = member.GroupId %}
                                        
<li class="list-group-item">
                                          <a href="{{ externalsite }}/page/638?GroupId={{ groupId }}&GroupMemberId={{ member.Id }}&rckipid={{ familyMember.Person | PersonTokenCreate:1440,10,null }}" class="js-group-item" >{{ member.Group.Name }}</a> 
                                        </li>
                                    
{% endfor %}                                
{% endif %}                 
                              
</div>
                              
<div class="modal-footer">                              
<button type="button" class="btn btn-default" data-dismiss="modal">Close</button>                                                             
</div>
                            
</div>                      
</div>                  
</div>
                    
{% comment %}end Mission Trip modal structure{% endcomment %}   

2.) The Trigger: we will now add a button that uses html attributes to toggle the modal when the button is clicked. In the first line of the modal structure, we set a unique Id using a special lava filter: 'ToCssClass'. Everyone will have their own modal that the code named after them.

<div class="modal fade" id="{{ familyMember.Person.FullName | ToCssClass }}Missions" ...

Now we can specify which modal should get triggered based on the data-toggle and data-target attributes (not the same as rock attributes)

<div class="row">
                                            <div class="col-md-12 text-right">
                                                <button class="btn btn-primary btn-reg" type="button" href="#" data-toggle="modal" data-target="#{{ familyMember.Person.FullName | ToCssClass }}Missions" >Missions</button>
                                            </div>
                                        </div>
0 votes
by KateQuinn (6.8k points)
edited

And here is the full lava file, since I don't think we can do attachments here:

{% comment %}{% include '~/Assets/Lava/PublicProfile.lava' %}{% endcomment %}
{% comment %}{% include '~~/Assets/Lava/PublicProfileCustom2022.lava' %}{% endcomment %}

<!-- Delete these three lines to go live with Missions button-->
{% assign secure = CurrentPerson | Group:'2','Active' %}
{% assign adminMembership = secure | Size %}
{% if adminMembership == empty %}
    {% include '~~/Assets/Lava/PublicProfileCustom2022.lava' %}
{% else %}
<!-- Delete previous three lines, and last line at the end, and update custom lava file -->

{% assign flag = false %}


{%- comment -%}
    This is the default lava template for the PublicProfileEdit block
    Available Lava Fields:

    ViewOnly - If this is true, the Edit button should not be visible
    CurrentPerson - The Person that we are viewing (and the person that is logged in)
    Family - (Rock.Model.Group) The family that is currently selected (the person could be in multiple families)
    ShowFamilyMembers - If this is true, family members should be listed
    FamilyMembers -  (List of Rock.Model.GroupMember) The family members (of the selected family), not including the currentperson
    Families = (List of Rock.Model.Group) The families that this person is in

    AddressTypeValueId - (DefinedValueCache Id) The address type defined value Id that is displayed
    Address = (Rock.Model.GroupLocation) The address to be displayed

    ShowPhoneNumbers - If this is true, phone numbers should be shown
    DisplayedPhoneTypeValueIds - (List of DefinedValueCache Ids) - The Phone Type defined values ids that should be shown
    PhoneNumbers (List of Rock.Model.PhoneNumber)) - The phone numbers that can be displayed

    RequestChangesPageUrl - The URL to use when they press the Request Changes button
    RequestChangesText - The text to shown on the Request Changes button

    FamilyAttributes - (List of AttributeCache) - The family attributes that should be displayed
    PersonAttributesAdults - (List of AttributeCache) - The person attributes that should be displayed for Adults
    PersonAttributesChildren - (List of AttributeCache) - The person attributes that should be displayed for Children
{%- endcomment -%}

<style>
    .btn-reg {
        margin-bottom:10px;
        border-radius: 16px;
        background-color: #008FBE;
        
    }
    
    .btn-reg:hover {
      background-color: #002f86;
    }
    
    div.grid__item.one-half.hard.anchored-flush.floating__item{
        float:right;
    }
    div.grid__item.floating__item.anchored-one-half.left.portable-centered.handheld-centered.hard.flush.inner{
    float:right;
    min-width:380px;
    }
</style>

{%- assign childRoleGuid = 'c8b1814f-6aa7-4055-b2d7-48fe20429cb9' -%}
{%- assign familyCount = Families | Size -%}
{%- assign threeMonths = 'Now' | | DateAdd:-3,'M' -%}

<!-- <script src="iziModal.min.js" type="text/javascript"></script> -->
<script>
    $(function () {
        $(".js-personphoto a").fluidbox();
    });
    
</script>

    <div class="person-profile mb-5">
        {% comment %} Person Info {% endcomment %}
        <div class="row d-flex align-items-center mb-4">
            {% comment %} Photo {% endcomment %}
            <div class="col-xs-4 col-sm-3">
                <div class="photo js-personphoto">
                    <a href="{{ CurrentPerson.PhotoUrl }}" aria-label="View Fullsize Photo"><img src="{{ CurrentPerson.PhotoUrl }}&maxwidth=200&maxheight=200" class="rounded-circle" alt=""></a>
                </div>
            </div>

            <div class="col-xs-8 col-sm-9">
                {% comment %} Person Name, and dropdown of families (if more than 1) {% endcomment %}
                <h2 class="mt-0 h1 font-weight-bold title name">
                    {{ CurrentPerson.FullName }}
                    {% if familyCount > 1 %}
                        <div class="pull-right">
                            <select name="selectFamily" onchange="{{ Family.Id | Postback:'SelectFamily' }}" class="form-control">
                                <option value="{{ Family.Id }}" selected="selected">{{ Family.Name }}</option>
                                {% for family in Families %}
                                    {% if family.Id != Family.Id %}
                                        <option value="{{ family.Id }}">{{ family.Name }}</option>
                                    {% endif %}
                                {% endfor %}
                            </select>
                        </div>
                    {% endif %}
                </h2>

                <ul class="person-demographics list-unstyled">
                    <li>
                        {% if CurrentPerson.Age %}
                            {{ CurrentPerson.Age }} {{ 'year' | PluralizeForQuantity:CurrentPerson.Age }} old <small>({{ CurrentPerson.BirthDate | Date:'sd' }})</small><br>
                        {% endif %}
                    </li>
                    <li>
                        {% if CurrentPerson.Gender != "Unknown" %}{{ CurrentPerson.Gender }}{% endif %}
                    </li>
                    <li>
                        {% if CurrentPerson.MaritalStatusValueId %}
                            {% assign maritalStatusValue = CurrentPerson.MaritalStatusValueId | FromCache:'DefinedValue' %}
                            {% if CurrentPerson.AnniversaryDate %}
                                {% assign marriedYears = CurrentPerson.AnniversaryDate | DateDiff:CurrentPerson.NextAnniversary,'Y' | Minus:1 %}
                                {% assign marriedDate = CurrentPerson.AnniversaryDate | Date:'M/d' %}
                                {{ maritalStatusValue.Value }} {{ marriedYears }} {{ 'yr' | PluralizeForQuantity:marriedYears }} <small>({{ marriedDate }})</small>
                            {% else %}
                                {{ maritalStatusValue }}
                            {% endif %}
                        {% endif %}
                    </li>
                    <li>
                        {{ CurrentPerson.GradeFormatted }}
                    </li>
                </ul>
            </div>
        </div>

        <div class="row">
            <div class="col-xs-12">
                <h3 class="font-weight-bold">Contact Information</h3>
            </div>
            <div class="col-md-6">
                <dl class="mb-4">
                    {% if Address %}
                    {% assign addressTypeValue = AddressTypeValueId | FromCache:'DefinedValue' %}
                    <dt>{{ addressTypeValue.Value }} Address</dt>
                    <dd>{{ Address.Location.FormattedHtmlAddress }}</dd>
                    {% endif %}
                </dl>

                <dl class="mb-4">
                    {% if CurrentPerson.Email != '' %}
                        <dt>
                            Email
                        </dt>
                        <dd>
                            {{ CurrentPerson.Email }}
                        </dd>
                    {% endif %}
                </dl>
            </div>

            <div class="col-sm-6">
                {% if ShowPhoneNumbers %}
                    {%- assign phoneNumberCount = CurrentPerson.PhoneNumbers | Size -%}
                    <dl class="mb-4">
                        <dt>{{ 'Phone' | PluralizeForQuantity:phoneNumberCount }}</dt>

                        {% if phoneNumberCount > 0 %}
                        <dd>
                            <ul class="phone-list list-unstyled">
                            {% for phoneNumber in CurrentPerson.PhoneNumbers %}
                                {% assign numberTypeValue = phoneNumber.NumberTypeValueId | FromCache:'DefinedValue' %}
                                {% assign displayPhoneType = DisplayedPhoneTypeValueIds | Contains:numberTypeValue.Id %}
                                {% if displayPhoneType %}
                                    <li>{{ phoneNumber.NumberFormatted }} <span class="small">{{ numberTypeValue.Value }} {% if phoneNumber.IsUnlisted %}Unlisted{% endif %}</span></li>
                                {% endif %}
                            {% endfor %}
                            </ul>
                        </dd>
                        {% else %}
                            <dd class="text-muted">No Phone Numbers Provided</dd>
                        {% endif %}
                    </dl>
                {% endif %}
            </div>
        </div>

        {% if CurrentPerson.AgeClassification == 'Child' %}
            {% assign personAttributes = PersonAttributesChildren %}
        {% else %}
            {% assign personAttributes = PersonAttributesAdults %}
        {% endif %}

        {% if personAttributes %}
            <div class="row">
            {%- comment -%}loop thru Attributes so we can get the attribute value without checking security{%- endcomment -%}
            {%- for personAttribute in personAttributes -%}
                {%- for attribute in CurrentPerson.AttributeValues -%}
                    {%- if attribute.AttributeKey == personAttribute.Key -%}
                        {%- if attribute.ValueFormatted != '' -%}
                        <div class="col-md-6">
                            <dl class="mb-4">
                                <dt>{{ attribute.AttributeName }}</dt>
                                <dd>{{ attribute.ValueFormatted }}</dd>
                            </dl>
                        </div>
                        {%-endif-%}
                    {%-endif-%}
                {%- endfor -%}
            {%- endfor -%}
            </div>
        {% endif %}

        {%- comment -%}loop thru Attributes to see if there are any non-blank ones{%- endcomment%}
        {% assign showFamilyAttributes = false %}
        {% for familyAttribute in FamilyAttributes %}
            {% for attribute in Family.AttributeValues %}
                {% if attribute.AttributeKey == familyAttribute.Key %}
                    {% if attribute.ValueFormatted != '' %}
                        {% assign showFamilyAttributes = true %}
                        {% break %}
                    {% endif %}
                {% endif %}
            {% endfor %}
        {% endfor %}

        {% if showFamilyAttributes %}
            <div class="row">

            <div class="col-md-12">
                <h3 class="font-weight-bold">Family Information</h3>
            </div>

            {%- comment -%}loop thru Attributes so we can get the attribute value without checking security{%- endcomment -%}
            {% for familyAttribute in FamilyAttributes %}
                {% for attribute in Family.AttributeValues %}
                    {% if attribute.AttributeKey == familyAttribute.Key %}
                        {% if attribute.ValueFormatted != '' %}
                        <div class="col-md-6">
                            <dl class="mb-4">
                                <dt>{{ attribute.AttributeName }}</dt>
                                <dd>{{ attribute.ValueFormatted }}</dd>
                            </dl>
                        </div>
                        {%endif%}
                    {%endif%}
                {% endfor %}
            {% endfor %}

            </div>
        {% endif %}

        {% unless ViewOnly %}
            <a class="btn btn-primary" onclick="{{ CurrentPerson.Guid | Postback:'EditPerson' }}">Update Profile</a>
        {% endunless %}
    </div>
    
    

     {% comment %} Family Info {% endcomment %}
    {% if ShowFamilyMembers %}

        <div class="family-member-profiles">
            <h3 class="mb-0">{{ Family.Name }}</h3>
            <hr class="mt-3 mb-5" />
            {% for familyMember in FamilyMembers %}
                
                    <div class="modal fade" id="{{ familyMember.Person.FullName | ToCssClass }}" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                          <div class="modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">{{ familyMember.Person.FullName }}: Registrations</h4>
                              </div>
                              <div class="modal-body">
                                
                                {% assign externalsite = 'Global' | Attribute:'PublicApplicationRoot' %}
                                {% assign allAliases = familyMember.Person.Aliases | Select:'Id' %}
                                
                                {% for all in allAliases %}
                                    {% registrationregistrant where:'PersonAliasId == {{ all }}' %}
                                        {% for r in registrationregistrantItems %}
                                            {% registration id:'{{ r.RegistrationId }}' %}
                                                {% assign registrar = registration.PersonAliasId | PersonByAliasId %}
                                                    {% if registration.CreatedDateTime > threeMonths %}
                                                        <li class="list-group-item">
                                                          <a href="{{ externalsite }}Registration?RegistrationId={{ registration.Id }}&rckipid={{ registrar | PersonTokenCreate:60,null,596 }}" class="js-group-item" >{{ registration.RegistrationInstance.Name }}</a> 
                                                            {% if registration.BalanceDue > 0 %} <label class='label label-warning'>{{ 'Global' | Attribute:'CurrencySymbol' }}</label> {% endif %}
                                                        </li>
                                                    {% endif %}
                                            {% endregistration %}
                                        {% endfor %}
                                    {% endregistrationregistrant %}
                                {% endfor %}

                              </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                
                              </div>
                            </div>
                          </div>
                        </div>
                    {% comment %}end Registration modal structure{% endcomment %}
                
                
                    <div class="modal fade" id="{{ familyMember.Person.FullName | ToCssClass }}Missions" tabindex="-1" role="dialog" aria-labelledby="myModalLabel">
                        <div class="modal-dialog" role="document">
                            <div class="modal-content">
                              <div class="modal-header">
                                <button type="button" class="close" data-dismiss="modal" aria-label="Close"><span aria-hidden="true">&times;</span></button>
                                <h4 class="modal-title" id="myModalLabel">{{ familyMember.Person.FullName }}: Missions</h4>
                              </div>
                              <div class="modal-body">
                                
                                {% comment %} Check for child membership in fundraiser group type{% endcomment %}
                                {% assign externalsite = 'Global' | Attribute:'PublicApplicationRoot' %}
                                {% assign missionMembers = familyMember.Person | Groups:'31','All' %}
                                {% assign size = missionMembers | Size %}
                                {% if size != 0 and size != null and size != empty %}
                                    {% comment %}cycle through Group Member objects and create impersonation token link to their profile{% endcomment %}
                                    {% for member in missionMembers %}
                                        {% assign groupId = member.GroupId %}
                                        <li class="list-group-item">
                                          <a href="{{ externalsite }}/page/638?GroupId={{ groupId }}&GroupMemberId={{ member.Id }}&rckipid={{ familyMember.Person | PersonTokenCreate:1440,10,null }}" class="js-group-item" >{{ member.Group.Name }}</a> 
                                        </li>
                                    {% endfor %}
                                {% endif %}                 
                              </div>
                              <div class="modal-footer">
                                <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
                                
                              </div>
                            </div>
                        </div>
                    </div>
                    {% comment %}end Mission Trip modal structure{% endcomment %}   

                
                <div class="row {{ Family.GroupTypeId | FromCache:'GroupType' | Property:'GroupMemberTerm' | ToCssClass }} mb-3">
                    <div class="col-xs-3 col-sm-2">
                        <div class="photo js-personphoto">
                            <a href="{{ familyMember.Person.PhotoUrl }}" aria-label="View Fullsize Photo"><img src="{{ familyMember.Person.PhotoUrl }}&maxwidth=200&maxheight=200" class="rounded-circle" alt=""></a>
                        </div>
                    </div>
                    <div class="col-xs-9 col-sm-10">
                        <div class="row">
                            <div class="col-xs-12">
                                <h4 class="mt-0 font-weight-bold">{{ familyMember.Person.FullName }}</h4>
                            </div>
                            <div class="col-md-4 mb-4">
                                <ul class="person-demographics list-unstyled">
                                    {% if familyMember.Person.Age %}
                                        <li>
                                            {{ familyMember.Person.Age }} {{ 'yr' | PluralizeForQuantity:familyMember.Person.Age }} old
                                            <small>({{ familyMember.Person.BirthDate | Date:'sd' }})</small>
                                        </li>
                                    {% endif %}
                                    {% if familyMember.Person.GradeFormatted != '' %}
                                        <li>
                                            {{ familyMember.Person.GradeFormatted }}
                                        </li>
                                    {% endif %}
                                    {% if familyMember.Person.Gender != "Unknown" %}
                                        <li>
                                            {{ familyMember.Person.Gender }}
                                        </li>
                                    {% endif %}
                                    {% if familyMember.Person.MaritalStatusValueId %}
                                        <ul class="person-demographics list-unstyled">
                                            <li>
                                                {% assign maritalStatusValue = familyMember.Person.MaritalStatusValueId | FromCache:'DefinedValue' %}
                                                {% if familyMember.Person.AnniversaryDate %}
                                                    {% assign marriedYears = familyMember.Person.AnniversaryDate | DateDiff:familyMember.Person.NextAnniversary,'Y' | Minus:1 %}
                                                    {% assign marriedDate = familyMember.Person.AnniversaryDate | Date:'M/d' %}
                                                    {{ maritalStatusValue.Value }} {{ marriedYears }} {{ 'yr' | PluralizeForQuantity:marriedYears }} <small>({{ marriedDate }})</small>
                                                {% else %}
                                                    {{ maritalStatusValue }}
                                                {% endif %}
                                            </li>
                                        </ul>
                                    {% endif %}
                                </ul>
                            </div>
                            <div class="col-md-4 mb-4">
                                {% capture contactInfo %}

                                    {% if ShowPhoneNumbers %}
                                        {%- assign phoneCount = familyMember.Person.PhoneNumbers | Size -%}
                                        {% if phoneCount > 0 %}
                                            <ul class="phone-list list-unstyled">
                                            {% for phoneNumber in familyMember.Person.PhoneNumbers %}
                                                {% assign numberTypeValue = phoneNumber.NumberTypeValueId | FromCache:'DefinedValue' %}
                                                {% assign displayPhoneType = DisplayedPhoneTypeValueIds | Contains:numberTypeValue.Id %}
                                                {% if displayPhoneType %}
                                                    <li>{{ phoneNumber.NumberFormatted }}<small>{{ numberTypeValue }} {% if phoneNumber.IsUnlisted %}Unlisted{% endif %}</small></li>
                                                {% endif %}
                                            {% endfor %}
                                            </ul>
                                        {% endif %}
                                    {% endif %}

                                    {{ familyMember.Person.Email }}
                                {% endcapture %}
                                {%- assign contactInfo = contactInfo | Trim  -%}
                                {% if contactInfo != '' %}
                                    <span class="d-block"><strong>Contact Info</strong></span>
                                    {{ contactInfo }}
                                {% endif %}
                            </div>
                            
                            <div class="col-md-4 mb-4">
                                {%- comment -%}Add buttons for registration and group schedule toolbox here{%- endcomment -%}
                                <div class="row">
                                    <div class="col-md-12 text-right">
                                        <button class="btn btn-primary btn-reg" type="button" href="#" data-toggle="modal" data-target="#{{ familyMember.Person.FullName | ToCssClass }}" >Registration(s)</button>
                                    </div>
                                </div>
                                <div class="row">
                                    <div class="col-md-12 text-right">
                                        <a class="btn btn-primary btn-reg" href="https://www.southbrookministries.org/ScheduleToolbox?rckipid={{ familyMember.Person | PersonTokenCreate:60,null,703 }}">Group Schedule(s)</a>
                                    </div>
                                </div>
                                
                                {% if familyMember.Person.AgeClassification == 'Child' %}
                                {% assign missionMembers = familyMember.Person | Groups:'31','All' %}
                                {% assign size = missionMembers | Size %}
                                    {% if size != 0 and size != null and size != empty %}
                                        <div class="row">
                                            <div class="col-md-12 text-right">
                                                <button class="btn btn-primary btn-reg" type="button" href="#" data-toggle="modal" data-target="#{{ familyMember.Person.FullName | ToCssClass }}Missions" >Missions</button>
                                            </div>
                                        </div>
                                    {% endif %}
                                {% endif %}
                           </div>
                        </div>

                        {% if familyMember.GroupRole.Guid == childRoleGuid %}
                            {% assign personAttributes = PersonAttributesChildren %}
                        {% else %}
                            {% assign personAttributes = PersonAttributesAdults %}
                        {% endif %}

                        {% if personAttributes %}
                            <div class="row">
                            {%- comment -%}loop thru Attributes so we can get the attribute value without checking security{%- endcomment -%}
                            {%- for personAttribute in personAttributes -%}
                                {%- for attribute in familyMember.Person.AttributeValues -%}
                                    {%- if attribute.AttributeKey == personAttribute.Key -%}
                                        {%- if attribute.ValueFormatted != '' -%}
                                            <div class="col-sm-6 col-md-4">
                                                <dl class="mb-4">
                                                    <dt>{{ attribute.AttributeName }}</dt>
                                                    <dd>
                                                        {{ attribute.ValueFormatted }}
                                                    </dd>
                                                </dl>
                                            </div>
                                        {%- endif -%}
                                    {%- endif -%}
                                {%- endfor -%}
                            {%- endfor -%}
                            </div>
                        {%- endif -%}
                        
                        

                        {% unless ViewOnly %}
                            <div class="row">
                                <div class="col-md-12 text-right">
                                    <a class="btn btn-default btn-sm btn-square" onclick="{{ familyMember.Person.Guid | Postback:'EditPerson' }}" title="Edit {{ familyMember.Person.FullName | Escape }}"><i class="fa fa-pencil"></i></a>
                                </div>
                            </div>
                        {% endunless %}
                    </div>
                </div>
                <hr class="my-5 {% if forloop.last %}mb-3{% endif %}" />
            {% endfor %}
        </div>

        <div class="family-member-actions text-sm-right">
            {% unless ViewOnly %}
                <a class="btn btn-primary btn-xs" onclick="{{ Family.Guid | Postback:'AddGroupMember' }}"> Add New {{ Family.GroupTypeId | FromCache:'GroupType' | Property:'GroupMemberTerm' }}</a>
            {% endunless %}

            {% if RequestChangesPageUrl != '' %}
                <a class="btn btn-primary btn-xs" href="{{ RequestChangesPageUrl }}">{{ RequestChangesText }}</a>
            {% endif %}
        </div>

    {% endif %}
    
    
<!-- Delete this line -->
{% endif %}
Welcome! Here you can ask questions and receive answers (hopefully) from other members of our team.
...