Multiple Filter Search in HubDb



{% if dynamic_page_hubdb_row %}

<div class="property_images">
{% set string_to_split = dynamic_page_hubdb_row.property_images|striptags %}
{% set names = string_to_split|split(',') %}
<ul {% if names|length > 1 %}class="hs-slider" {% endif %}>
{% for name in names %}
<li><img src="{{ name }}" alt="{{ dynamic_page_hubdb_row.property_name }}"></li>
{% endfor %}
</ul>
<div class="top-header-title-and-price">
<div class="top-header-title">
<h4>{{ dynamic_page_hubdb_row.property_name }}</h4>
</div>
<div class="top-header-price">
<h4>{{ dynamic_page_hubdb_row.property_price }}</h4>
</div>
</div>
</div>
<div class="property_tabber">
<ul>
<li><a class="active" href="#tab1">PROPERTY FACTS</a></li>
<li><a href="#tab2">DIRECTIONS</a></li>
<li><a href="#tab3">FLOORPLAN</a></li>
</ul>
<div class="property_tabber-content">
<div class="tab-pane active" id="tab1">
<div class="tab-pane-title">PROPERTY FACTS</div>
<div class="tab-pane-inner-content">
{{ dynamic_page_hubdb_row.property_facts }}
</div>
</div>
<div class="tab-pane" id="tab2">
<div class="tab-pane-title">DIRECTIONS</div>
<div class="tab-pane-inner-content">
{{ dynamic_page_hubdb_row.directions }}
</div>
</div>
<div class="tab-pane" id="tab3">
<div class="tab-pane-title">DIRECTIONS</div>
<div class="tab-pane-inner-content">
{% if dynamic_page_hubdb_row.floor_plan.url or dynamic_page_hubdb_row.floor_plan_2.url %}
{% if dynamic_page_hubdb_row.floor_plan.url %}
<img src="{{ dynamic_page_hubdb_row.floor_plan.url }}" alt="Floor Plan">
{% endif %}
{% if dynamic_page_hubdb_row.floor_plan_2.url %}
<img src="{{ dynamic_page_hubdb_row.floor_plan_2.url }}" alt="Floor Plan 2">
{% endif %}
{% else %}
<p>No floor plan available at this time</p>
{% endif %}
</div>
</div>
</div>
</div>
{% elif module.hubdb_table %}
<h2 class="filter-header-wrapper">Home Search</h2>
<div class="filter-wrapper">
<form id="form_id" method="get">
<div class="filter clearfix">
<div class="filter-col">
<select name="builders" form="form_id" onChange="this.form.submit()">
<option value="">Builders</option>
{% set types = hubdb_table_column(module.hubdb_table, "builders").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.builders %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="filter-col">
<select name="listing_type" form="form_id" onChange="this.form.submit()">
<option value="">Listing Type</option>
{% set types = hubdb_table_column(module.hubdb_table, "listing_type").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list%}
{% if choice.id == request.query_dict.listing_type%}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="filter-col">
<select name="bedrooms" form="form_id" onChange="this.form.submit()">
<option value="">Bedrooms</option>
{% set types = hubdb_table_column(module.hubdb_table, "bedrooms").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list %}
{% if choice.id == request.query_dict.bedrooms %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="filter-col">
<select name="sqft" form="form_id" onChange="this.form.submit()">
<option value="">Sqft</option>
{% set types = hubdb_table_column(module.hubdb_table, "sqft").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list %}
{% if choice.id == request.query_dict.sqft %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
</div>
<div class="filter-col">
<select name="price" form="form_id" onChange="this.form.submit()">
<option value="">Price</option>
{% set types = hubdb_table_column(module.hubdb_table, "price").options %}
{% for choice in types %}
{% set type_list = type_list~choice.id|list %}
{% if choice.id == request.query_dict.price %}
<option selected="selected" value="{{ choice.id }}">{{ choice.name }}</option>
{% else %}
<option value="{{ choice.id }}">{{ choice.name }}</option>
{% endif %}
{% endfor %}
</select>
<button class="bg-purple button ascendingOrder sort" data-sort="myorder:asc">-</button>
<button class="bg-purple button descendingOrder sort" data-sort="myorder:desc">+</button>

</div>

</div>
</form>
</div>

{% set queryparam = "" %}
{% if request.query_dict.builders in ["1", "2", "3", "4"] and request.query_dict.listing_type =="" and request.query_dict.bedrooms =="" and request.query_dict.price =="" and request.query_dict.sqft ==""%}
{% set queryparam = queryparam ~ "&builders="~request.query_dict.builders|urlencode %}
{% elif request.query_dict.builders in ["1", "2", "3", "4"] and request.query_dict.listing_type !="" and request.query_dict.bedrooms =="" and request.query_dict.price =="" and request.query_dict.sqft =="" %}
{% set queryparam = queryparam ~ "&builders="~request.query_dict.builders|urlencode ~ "&listing_type="~request.query_dict.listing_type|urlencode %}
{% elif request.query_dict.builders in ["1", "2", "3", "4"] and request.query_dict.listing_type !="" and request.query_dict.bedrooms !="" and request.query_dict.price =="" and request.query_dict.sqft =="" %}
{% set queryparam = queryparam ~ "&builders="~request.query_dict.builders|urlencode ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode %}
{% elif request.query_dict.builders in ["1", "2", "3", "4"] and request.query_dict.listing_type !="" and request.query_dict.bedrooms !="" and request.query_dict.sqft !="" and request.query_dict.price =="" %}
{% set queryparam = queryparam ~ "&builders="~request.query_dict.builders|urlencode ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode ~ "&sqft="~request.query_dict.sqft|urlencode %}
{% elif request.query_dict.builders in ["1", "2", "3", "4"] and request.query_dict.listing_type !="" and request.query_dict.bedrooms !="" and request.query_dict.sqft !="" and request.query_dict.price !="" %}
{% set queryparam = queryparam ~ "&builders="~request.query_dict.builders|urlencode ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode ~ "&sqft="~request.query_dict.sqft|urlencode ~ "&price="~request.query_dict.price|urlencode %}
{% elif request.query_dict.listing_type in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.bedrooms =="" and request.query_dict.sqft =="" and request.query_dict.price =="" %}
{% set queryparam = queryparam ~ "&listing_type="~request.query_dict.listing_type|urlencode %}
{% elif request.query_dict.bedrooms in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.listing_type =="" and request.query_dict.sqft =="" and request.query_dict.price =="" %}
{% set queryparam = queryparam ~ "&bedrooms="~request.query_dict.bedrooms|urlencode %}
{% elif request.query_dict.sqft in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.listing_type =="" and request.query_dict.bedrooms =="" and request.query_dict.price =="" %}
{% set queryparam = queryparam ~ "&sqft="~request.query_dict.sqft|urlencode %}
{% elif request.query_dict.price in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.listing_type =="" and request.query_dict.sqft =="" and request.query_dict.bedrooms =="" %}
{% set queryparam = queryparam ~ "&price="~request.query_dict.price|urlencode %}
{% elif request.query_dict.listing_type in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.price =="" and request.query_dict.sqft =="" and request.query_dict.bedrooms !="" %}
{% set queryparam = queryparam ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode %}
{% elif request.query_dict.listing_type in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.price =="" and request.query_dict.sqft !="" and request.query_dict.bedrooms !="" %}
{% set queryparam = queryparam ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode ~ "&sqft="~request.query_dict.sqft|urlencode %}
{% elif request.query_dict.listing_type in ["1", "2", "3", "4"] and request.query_dict.builders =="" and request.query_dict.price !="" and request.query_dict.sqft !="" and request.query_dict.bedrooms !="" %}
{% set queryparam = queryparam ~ "&listing_type="~request.query_dict.listing_type|urlencode ~ "&bedrooms="~request.query_dict.bedrooms|urlencode ~ "&sqft="~request.query_dict.sqft|urlencode ~ "&price="~request.query_dict.price|urlencode %}
{% endif %}

{% set table = hubdb_table_rows(module.hubdb_table, queryparam) %}
{% if table == [] %}
<p class='align-center'>Sorry, no listings found for that Search. Try changing your filter and search again.</p>
{% else %}
<div class="hs-home-wrapper clearfix">
{% for row in table %}
<div data-price="{{ row.property_price|replace(',', "")|replace('$', "") }}" data-id="{{ loop.index }}" class="hs-home-items flipInX {{ row.builders.name }} {{ row.listing_type.name }} {{ row.bedrooms.name }}-bad {{ row.sqft.name }} {{ row.price.name }}">
{% set string_to_split = row.property_images|striptags %}
{% set names = string_to_split|split(',') %}
<div class="hs-home-items-inner" style="background-image:linear-gradient( rgba(255, 255, 255, 0), rgba(0, 0, 0, 0.86) ){% for name in names %}{% if loop.first %}, url({{ name }}){% endif %}{% endfor %};">
{% if row.listing_type.name == "Spec" %}
<p class="spec">Spec - AVAILABLE NOW</p>
{% elif row.listing_type.name == "Plan" %}
<p class="plan">Plan - {{ row.plan }}</p>
{% endif %}
<div class="hs-home-items-inner-content">
{% set property_nameSp = row.property_name|trim %}
{% set propertys = property_nameSp|split('-') %}
<div class="hs-home-items-col-row1">
<p>{% for property in propertys %}{% if loop.first %} {{ property }}{% endif %}{% endfor %}<br><span class="pr">{{ row.property_price }}</span></p>
</div>
<div class="hs-home-items-col-row2">
<div class="hs-home-items-col-row2-col">
<p><span>{{ row.bedrooms.name }}</span><br>Bedrooms</p>
</div>
<div class="hs-home-items-col-row2-col">
<p><span>{{ row.bathrooms.name }}</span><br>Bathrooms</p>
</div>
<div class="hs-home-items-col-row2-col">
<p><span>{{ row.area }}</span><br>Sq. Ft.</p>
</div>
</div>
<div class="hs-home-items-col-row3">
<ul>
<li>
{% if row.builders.name == "Perry Homes" %}
<img src="//cdn2.hubspot.net/hubfs/3420226/Rosehill_Reserve_November2018_Theme/Images/31-MED.jpg" alt="Perry Homes">
{% elif row.builders.name == "Lennar" %}
<img src="//cdn2.hubspot.net/hubfs/3420226/Rosehill_Reserve_November2018_Theme/Images/644-MED.jpg" alt="Lennar">
{% elif row.builders.name == "M/I Homes" %}
<img src="//cdn2.hubspot.net/hubfs/3420226/Rosehill_Reserve_November2018_Theme/Images/398-MED.jpg" alt="M/I Homes">
{% endif %}
</li>
<li><a href="{{ request.path }}/{{ row.hs_path }}">Details</a></li>
</ul>
</div>
</div>
</div>
</div>
{% endfor %}
</div>
{% endif %}
{% endif %}

Js

function ascendingOrder() {
$(".hs-home-wrapper > div ").sort(sort_li).appendTo('.hs-home-wrapper');
function sort_li(a, b) {
return ($(b).data('price')) < ($(a).data('price')) ? 1 : -1;
}
}
function descendingOrder() {
$(".hs-home-wrapper > div ").sort(sort_li).appendTo('.hs-home-wrapper');
function sort_li(b, a) {
return ($(b).data('price')) < ($(a).data('price')) ? 1 : -1;
}
}
$('.ascendingOrder').click(function(e){
e.preventDefault()
e.stopPropagation();
ascendingOrder()
});
$('.descendingOrder').click(function(e){
e.preventDefault()
e.stopPropagation();
descendingOrder()
});

Comments

Popular posts from this blog

Pagination of multiple recent post blog

Service Filter

When You Want to open popup(first time load)