populating the brands dropdown in the search widget on page load
authorAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 13:07:24 +0000 (09:07 -0400)
committerAnthony Talarico <talarico@gaslightmedia.com>
Fri, 14 Apr 2017 13:07:24 +0000 (09:07 -0400)
if there are manufacturers retained after a search or a page refresh
the brands dropdown should also retain the list of respective brands
until a change is made

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

index 4effcbe..c14ae96 100644 (file)
         var categories = '{$categories|@json_encode}';
         categories = JSON.parse(categories);
       
+       
         $('#rvManufacturers').on("change", function(){
                 
             var _ = $(this);
                 } 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 ){
                 }
        
             });
-//         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 data = {
-//                  action: 'glm_members_admin_ajax',
-//                  glm_action: 'filterSearch',
-//                  cat_ids: cat_ids,
-//                  el_id: el_id,
-//                  cat_names: cat_names,
-//                };
-//                $.ajax({
-//                  type: 'POST',
-//                  url: '{$ajaxUrl}',
-//                  data: data,
-//                  success: function(response){
-//                      console.log(response);
-//                  }
-//                });
-//
-//            });
-//        }
-//        $('#rvManufacturers').manufacturer_brand();
-//        $('#brands').manufacturer_brand();
+
 
             jQuery('select[multiple]').asmSelect();
+                
+            if( $('#brands').prev().children('li').length > 0 ){
+               $("#rvManufacturers").prev().prev().prop("disabled","disabled");
+            }
+
+            if( $('#rvManufacturers').prev().children('li').length > 0 ){
+                
+                 $('#brands option').remove();  
+                var brands      = [];
+                var cat_id = $('#rvManufacturers').val();
+                $.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();
+                    
+            } 
+            
+            
 
             // Show search filters box
             {if $settings.list_show_search}