PageSourceSearch

https://wlivestock.com/app/directives/categoryFieldSelector.js?v=buster20250808

js wlivestock.com collected 2026-10-04 06:04:20 UTC 5,778 bytes, 130 lines download raw bytes

1app.directive('categoryFieldSelector', function () {
2    return {
3        templateUrl: 'app/directives/categoryFieldSelector.html',
4        restrict: 'EA',
5        scope: {
6            categories: '=',
7            maxSelectionCount: '=',
8            categoryIdsToExclude: '=',
9            categoryFieldTypesToExclude: '=',
10            selectCategoryFieldIds: '='
11        },
12        controller: 'categoryFieldSelectorController',
13        controllerAs: 'vm',
14        bindToController: true
15    }
16});
17
18
19app.controller('categoryFieldSelectorController', ['$scope', 'lists', 'localStorageService',
20    function ($scope, lists, localStorageService) {
21
22        var vm = this;
23
24        $scope.$watch('vm.categories', function (newValue, oldValue) {
25            vm.prepCategories();
26        });
27
28        $scope.$watch('vm.categoryIdsToExclude', function (newValue, oldValue) {
29            vm.prepCategories();
30        });
31
32        $scope.$watch('vm.selectCategoryFieldIds', function (newValue, oldValue) {
33            vm.prepCategories();
34        });
35
36        vm.prepCategories = function () {
37            // Remove any excluded categories
38            $.each(vm.categoryIdsToExclude, function (index, categoryId) {
39                // Init the index of the category to be removed    
40                var indexOfItemToRemove = -1;
41                // Go find the category index of the one to be excluded
42                $.each(vm.categories, function (index, category) {
43                    if (category.categoryId == categoryId) {
44                        indexOfItemToRemove = index;
45                        // Go see if any are selected
46                        $.each(category.categoryFields, function (fieldIndex, field) {
47                            vm.removeSelectedCategoryField(field);
48                        });
49                        return false;
50                    }
51                });
52                // Remove the category
53                if (indexOfItemToRemove > -1) {
54                    vm.categories.splice(indexOfItemToRemove, 1);
55                }
56            });
57
58            // Remove any excluded category field types
59            if (vm.categoryFieldTypesToExclude.length > 0) {
60                $.each(vm.categories, function (index, category) {
61                    // Init the index of the category field to be removed    
62                    var indexOfItemsToRemove = [];
63                    // Go find the category field index of the one to be excluded
64                    $.each(category.categoryFields, function (index, categoryField) {
65                        categoryField.isSelected = 0;
66                        if (vm.categoryFieldTypesToExclude.indexOf(categoryField.categoryFieldTypeId) > -1) {
67                            indexOfItemsToRemove.push(index);
68                        }
69                    });
70                    indexOfItemsToRemove.sort(function (a, b) { return b - a });
71                    // Remove the category
72                    $.each(indexOfItemsToRemove, function (index, indexOfItemToRemove) {
73                        category.categoryFields.splice(indexOfItemToRemove, 1);
74                    });
75                });
76            }
77
78            if (vm.selectCategoryFieldIds && vm.categoryFieldTypesToExclude.length > 0) {
79                $.each(vm.selectCategoryFieldIds, function (selectedFieldIndex, selectedField) {
80                    // vm.addSelectedCategoryField(field);
81                    $.each(vm.categories, function (index, category) {
82                        // Go see if any are selected
83                        $.each(category.categoryFields, function (fieldIndex, field) {
84                            if (selectedField.categoryFieldId == field.categoryFieldId) {
85                                // Make the category field selected
86                                field.isSelected = 1;
87                                return false;
88                            }
89                        });
90                    });
91                });
92            }
93        };
94
95        vm.removeSelectedCategoryField = function (categoryField) {
96            // Init the index of the category field to be removed    
97            var indexOfItemToRemove = -1;
98            // Go find the category field index of the one to be excluded
99            $.each(vm.selectCategoryFieldIds, function (index, selectedCategoryField) {
100                if (selectedCategoryField.categoryFieldId == categoryField.categoryFieldId) {
101                    indexOfItemToRemove = index;
102                    return false;
103                }
104            });
105            // Remove the category Field
106            if (indexOfItemToRemove > -1) {
107                vm.selectCategoryFieldIds.splice(indexOfItemToRemove, 1);
108            }
109            // Make the category field not selected
110            categoryField.isSelected = 0;
111        };
112
113        vm.addSelectedCategoryField = function (categoryField) {
114
115            if (vm.selectCategoryFieldIds.length < vm.maxSelectionCount) {
116                // Add selected field to the array
117                var selectedField = {
118                    categoryFieldId: categoryField.categoryFieldId,
119                    categoryFieldName: categoryField.name
120                };
121                vm.selectCategoryFieldIds.push(selectedField);
122                // Make the category field selected
123                categoryField.isSelected = 1;
124            } else {
125                popMessage('warning', 'Max Category Fields Selected', vm.maxSelectionCount + ' category fields have already been selected. Remove one in order to add a new one.');
126            }
127            
128        };
129
130    }]);

Line numbers count LF bytes from the start of the resource, as the search results do. Vendor segments are library code the classifier recognised; they are stored but not indexed. Bytes are shown as Latin1 characters, one per byte.