PageSourceSearch

https://repero.me/assets/controllers/select2_inventory_group_controller-f6d3fd90.js

js repero.me collected 2026-09-25 20:00:49 UTC 1,721 bytes, 66 lines download raw bytes

1import { Controller } from "@hotwired/stimulus"
2
3// Connects to data-controller="select2-inventory-group"
4export default class extends Controller {
5  connect() {
6    $(this.element).select2({
7      width: '100%',
8      placeholder: 'Search Inventory',
9      allowClear: true,
10      //minimumInputLength: 2,
11      ajax: {
12        delay: 150,
13        url: '/inventories.json',
14        dataType: 'json',
15        data: function(params){
16          var query = {
17            q: {
18              name_or_description_or_sku_i_cont_all: params.term,
19            },
20            page: params.page || 1
21          }
22          return query;
23        },
24        processResults: function (data, params) {
25          //console.log(data)
26          return {
27            results: data,
28            pagination: {
29              more: (data.length > 0)
30            }
31          }
32        }
33      },
34
35      templateResult: function(item) {
36        // if Inventory
37        if (item.hasOwnProperty('vat_percentage')) {
38        } else {
39          return;
40          // Inventory groups do not have vat_percentage
41          // Do not show inventory groups on the inventory_group page
42        }
43
44        var $final = $(
45          '<div class="">' +
46          item.name +
47          '<br><small class="text-muted">' + (item?.price || ' ')  +
48          '<br> ' + (item?.description || ' ') + '</small></div>'
49        );
50        return $final;
51      },
52
53      templateSelection: function(item) {
54        return item.text || item.name || 'Search';
55      }
56    })
57
58    $(this.element).on("select2:select", () => {
59      this.element.dispatchEvent(new Event('change', { bubbles: true }))
60    })
61  }
62
63  disconnect() {
64    $(this.element).select2('destroy')
65  }
66}

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.