search widget filtering and validation
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 12:26:44 +0000 (08:26 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 12:26:44 +0000 (08:26 -0400)
disabled the manufacturers dropdown if there are brands selected. removing manufacturers from the form
submission if there are brands. brands repopulate once all manufacturers are removed from the list
selection. all js code is in the list.view file in the theme

functions.php
glm-member-db/views/front/members/list.html

index 8e3fd4c..abb7dbc 100644 (file)
@@ -20,9 +20,11 @@ if (!function_exists('glm_quicksite_widget_init')) {
 
 }
 add_filter('manufacturer_ids', function(){
+//
 //    $ids = [3,11]; // Anthony's test ids - remove before go-live
     $ids = [165,143,140,178,149,224]; // ids of manufacturer categories on dev55
 //    $ids = [16,11,19]; // Laury's test ids - remove before go-live
+
    return $ids;
 });
 /**
index 232fe0c..bfe7966 100644 (file)
@@ -2,7 +2,7 @@
     {if $settings.list_map_show_opened}map-opened{else}map-closed{/if}
     {if $settings.list_show_search_filters_opened}filters-opened{else}filters-closed{/if}
 ">
-{$customQueryParams = apply_filters('glm-member-db-fields-front-list-query-params', '')}
+
 {include file='front/members/header.html'}
         {apply_filters('glm-member-db-front-members-list-pageTop', '')}
 <div class="glm-member-list-inner-wrapper">
@@ -70,7 +70,7 @@
                                 <hr>
                             </div>
                         </form>
-                        <form action="{$thisUrl}?glm_action=list" method="post" enctype="multipart/form-data">
+                        <form id="manufacturer-form" action="{$thisUrl}?glm_action=list" method="post" enctype="multipart/form-data">
                             {if $settings.list_show_search_category}
                                 <div>
                                     Manufacturers:
     <div class="glm-member-list-listing-container">
     {if $settings.list_show_search_alpha}
         <div class="glm-alpha-links">
-            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}{$customQueryParams}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if !$alphaSelected} glm-alpha-link-selected{/if}">All</a>
       {foreach $alphaList as $a}
-            <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}{$customQueryParams}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
+            <a href="{$thisUrl}?glm_action=list&alpha={$a.alpha}&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}" class="glm-alpha-link{if $a.default} glm-alpha-link-selected{/if}">{$a.alpha}</a>
       {/foreach}
        </div>
     {/if}
 
     {if $paging}
         <br>
-        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}{$customQueryParams}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
-        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}{$customQueryParams}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+        <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
         <br>
         showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
     {/if}
     {if $paging}
         <div class="glm-member-paging-bottom">
             <br>
-            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}{$customQueryParams}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
-            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}{$customQueryParams}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Previous&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$prevStart} style="pointer-events: none; opacity: 0.5;"{/if}>Previous page</a>
+            <a href="{$thisUrl}?glm_action=list&textSearch={$textSearch}&categorySearch={$catSearchSelected}&regionSearch={$regionSearchSelected}&pageSelect=Next&prevStart={$prevStart}&nextStart={$nextStart}&limit={$limit}&alpha={$alphaSelected}" class="glm-alpha-link" {if !$nextStart} style="pointer-events: none; opacity: 0.5;"{/if}>Next page</a>
             <br>
             showing {$start} through {$lastDisplayed} of {$filteredMembersFound}
         </div>
         $('.glm-member-list-record').each(function(){
            if( $(this).find('.slash-price').length != 0 ){
                $(this).find('.msrp-value').addClass('sale');
-//               $(this).find( $('.sale-price-value') ).insertAfter( $(this).find('.sale') ).css('display', 'block').css('float', 'right').addClass('sale-text');
-           }
-        });
-
-        $('.glm-member-list-record').each(function(){
-           if( $(this).find('.slash-price').length != 0 ){
-               $(this).find('.msrp-value').css('color','black').css('text-decoration','none').removeClass('glm-columns').wrap('<div class="mrsp-sale-wrapper" style="text-decoration: line-through; color: red;"></div>');
+               $(this).find( $('.sale-price-value') ).insertAfter( $(this).find('.sale') ).css('display', 'block').css('float', 'right').addClass('sale-text');
            }
         });
 
             $(this).css("display", "block");
 
         });
+        //         var cat_ids     = [];
+//        $.fn.manufacturer_brand = function(){
+//
+//            $(this).on("change", function(){
+//                var _ = $(this);
+//
+//                var cat_names   = [];
+//                var cat_id      = _.val();
+//                var el_id       = _.attr('id');
+//                var cats        = _.prev().find('span');
+//
+//                cat_ids.push(cat_id);
+//
+//                cats.each(function(){
+//                    cat_names.push(_.text());
+//                });
+//
+        var cat_ids     = [];
+        var selected_brands = [];
+        var all_brands  = '{$brands|@json_encode}';
+        all_brands = JSON.parse(all_brands);
+        var categories = '{$categories|@json_encode}';
+        categories = JSON.parse(categories);
+      
+        $('#rvManufacturers').on("change", function(){
+                
+            var _ = $(this);
+            var brands      = [];
+            var cat_names   = [];
+            var cat_id      = _.val();
+            var el_id       = _.attr('id');
+            var cats        = _.prev().find('span');
+            $('#brands option').remove();    
+    
+            if( cat_id ){
+                
+            } else {
+                $.each(all_brands, function(index, item){
+                    {literal} var option = $('<option>', {value: item.id, text: item.name}); {/literal}
+                    $('#brands').append(option);                             
+                });
+            }
+            $.each(cat_id, function(index, item){
+                var select_id = item;
+                $.each(categories , function(index, item){
+                   if( parseInt(select_id) === item.parent_id ){                  
+                       brands.push(item);
+                   }
+                });
+            });
+
+        
+            $.each(brands, function(index, item){
+                {literal} var option = $('<option>', {value: item.id, text: item.name}); {/literal}
+                $('#brands').append(option);
+                                                    
+            });
+                
+            $('#brands').prev().prev().remove();
+            $('#brands').prev().remove();
+            jQuery('#brands').asmSelect();
+                
+            if( $('#brands').prev().children('li').length <= 0 ){
+                $("#rvManufacturers").prev().prev().prop('disabled', false);
+            }
+        });
+            
+        $('#brands').on("change", function(){
+           
+                var _ = $(this);
+                selected_brands = [];
+                var cat_names   = [];
+                var cat_id      = _.val();
+                var el_id       = _.attr('id');
+                var cats        = _.prev().find('span');
+
+                $.each(cat_id, function(index, item){
+                   selected_brands.push(item); 
+                });
+      
+                if(selected_brands.length > 0){
+                    $("#rvManufacturers").prev().prev().prop("disabled","disabled");
+                } else {
+                    $("#rvManufacturers").prev().prev().prop("disabled",false);
+                }
+ //                var data = {
+ //                  action: 'glm_members_admin_ajax',
+ //                  glm_action: 'filterSearch',
+
+ //                      console.log(response);
+ //                  }
+ //                });
+//
+//            });
+//        }
+//        $('#rvManufacturers').manufacturer_brand();
+//        $('#brands').manufacturer_brand();
+            });
+            $('#manufacturer-form').submit(function(e){
+                if( $('#brands').prev().children('li').length > 0 ){
+                    $('#rvManufacturers option').remove();
+                }
+       
+            });
 //         var cat_ids     = [];
 //        $.fn.manufacturer_brand = function(){
 //