PageSourceSearch

https://register.hbsands.org/public/js/catalog/class.DataTypeDynamic.js?1790366516

js hbsands.org collected 2026-09-30 14:56:59 UTC 3,420 bytes, 112 lines download raw bytes

1/**
2 * User Story #143638 - Equipment Rental Filters for Catalog
3 * Dynamic List DataType Class
4 * - Uses a TreeView widget like options list, eg:
5 *   - [0] => { 'label' => 'Section Label', 'items' => [ { 'id' => 123, 'label' => 'Item Label' } ] }
6 */
7
8(function($, undefined) {
9    "use strict";
10    
11    /**
12     * Dynamic List DataType Class
13     */
14    function DataTypeDynamic() {
15        window.DataType.apply(this, arguments);
16        this.defaultIcon = 'check34';
17        
18        this.widgetConfig = {
19            filter: {
20                name: 'dynamicDataFilter',
21                options: {
22                    placeholder: ''
23                },
24                polymerElement: 'rec1-filter-list'
25            }
26        };
27    }
28    window.DataTypeDynamic = DataTypeDynamic;
29
30    DataTypeDynamic.prototype = new window.DataType();
31    DataTypeDynamic.prototype.constructor = DataTypeDynamic;
32    
33    /**
34     * Static method to instantiate this datatype from a basic object
35     */
36    DataTypeDynamic.fromData = function(data) {
37        var dt = new DataTypeDynamic();
38        dt.name = data.name;
39        dt.label = data.label;
40        dt.options = data.options;
41        dt.icon = data.icon;
42        dt.dynamicOptions = data.dynamicOptions || {};
43
44        if (data.value) {
45            dt.setValue(data.value);
46        }
47
48        if(data.widgetConfig) {
49            dt.widgetConfig = $.extend(data.widgetConfig, dt.widgetConfig);
50        }
51        
52        dt.widgetConfig.filter.options.placeholder = dt.widgetConfig.filter.options.placeholder || data.placeholder;
53        return dt;
54    };
55
56    DataTypeDynamic.prototype.resetValue = function() {
57        this.value = {};
58        return this;
59    };
60
61    DataTypeDynamic.prototype.setValue = function(value) {
62        if(typeof value !== "object") {
63            throw "'value' must be an object";
64        }
65        for(var i in value) {
66            // Apply any "on" values that we have available in our options
67            if(value[i] && this.hasOption(i)) {
68                this.value[i] = value[i];
69            }
70            // Remove any "off" values that are currently populated
71            else if(!value[i] && this.value.hasOwnProperty(i)) {
72                delete this.value[i];
73            }
74        }
75    };
76    
77    /**
78     * Checks if an option (by value) is selected or not
79     */
80    DataTypeDynamic.prototype.hasValue = function(value) {
81        return (value in this.value) && this.value[value];
82    };
83
84    DataTypeDynamic.prototype.hasOption = function(id) {
85        for(var i in this.options) {
86            for (var x in this.options[i].items) {
87                if (parseInt(this.options[i].items[x].id) === parseInt(id)) {
88                    return true;
89                }
90            }
91        }
92        return false;
93    };
94
95    DataTypeDynamic.prototype.getSelectedOptions = function() {
96        var options = {selected: [], unselected: []};
97        for(var i in this.options) {
98            for (var x in this.options[i].items) {
99                var option = this.options[i].items[x];
100                option.section = this.options[i].label || null;
101                if (this.hasValue(option.id)) {
102                    options.selected.push(option);
103                }
104                else {
105                    options.unselected.push(option);
106                }
107            }
108        }
109        return options;
110    };
111
112})(jQuery);

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.