PageSourceSearch

https://www.univ-ubs.fr/plugins/odf-ubs/resources/js/search/facet-lists.js

js univ-ubs.fr collected 2026-09-24 09:14:02 UTC 7,661 bytes, 213 lines download raw bytes

1/*
2 *  Copyright 2012 Anyware Services
3 *
4 *  Licensed under the Apache License, Version 2.0 (the "License");
5 *  you may not use this file except in compliance with the License.
6 *  You may obtain a copy of the License at
7 *
8 *      http://www.apache.org/licenses/LICENSE-2.0
9 *
10 *  Unless required by applicable law or agreed to in writing, software
11 *  distributed under the License is distributed on an "AS IS" BASIS,
12 *  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 *  See the License for the specific language governing permissions and
14 *  limitations under the License.
15 */
16
17/**
18 * Update the form list according the selected criteria
19 * @param url The update url
20 * @param siteName The current site name
21 * @param lang The current language
22 * @param uniqueId A unique id
23 * @param zoneItemId The zone item id
24 */
25 function updateFormLists (url, siteName, lang, formId, uniqueId, zoneItemId)
26{
27    function updateCb(data)
28    {
29    // Iterates on facets
30    $j('> search > form > facets > facet', data).each (function() {
31        
32        // Get corresponding select field
33        var selectField = $j('#search-metadata-' + $j(this).attr('name') + '-' + uniqueId),
34            selectedValue = selectField.val();
35        
36        // Removes entries and populate the select field with entries in alphabetical order.
37        selectField.empty();
38        
39        // all option
40        selectField.append('<option value=""></option>');
41        
42        // Update list options
43        $j(this).find("item").sort(sortTextFn).each(function() {
44            var count = $j(this).attr('count');
45            var optVal = $j(this).attr('value').replace(/"/g, '&quot;');
46            
47            if (parseInt(count) != 0 || selectedValue == optVal)
48            {
49                    
50                // Update option label with new count
51                var optLabel = $j(this).text() + ' (' + count + ')';
52                
53                selectField.append('<option value="' + optVal.replace(/&quot;/g, '&amp;quot;') + '">' + optLabel + '</option>');
54            }
55        });
56                
57        // Update the "All" option
58            var totalCount = $j(this).attr('total') || 0,
59                allOption = $j('option[value=""]', selectField);
60            //allOption.text(Ext.String.format("- All () -", totalCount));
61                if (selectField[0].name == "metadata-dgesipCode")
62            {
63                allOption.text(format("- All -", totalCount));
64            }
65            else if (selectField[0].name == "metadata-siseCode")
66            {
67                allOption.text(format("- All -", totalCount));
68            }
69            else if (selectField[0].name == "metadata-distanceLearning")
70            {
71                allOption.text(format("- All -", totalCount));
72            }
73            else if (selectField[0].name == "metadata-degree")
74            {
75                allOption.text(format("Tous les diplômes ()", totalCount));
76            }
77            else if (selectField[0].name == "metadata-romeCode")
78            {
79                allOption.text(format("Tous les métiers (fiche ROME) ()", totalCount));
80            }
81            else if (selectField[0].name == "metadata-domain")
82            {
83                allOption.text(format("Tous les domaines ()", totalCount));
84            }
85            else if (selectField[0].name == "metadata-place")
86            {
87                allOption.text(format("Lieu(x) ()", totalCount));
88            }
89            else if (selectField[0].name == "metadata-internshipAbroad")
90            {
91                allOption.text(format("Avec ou sans stage à l'étranger ()", totalCount));
92            }
93            else if (selectField[0].name == "metadata-internship")
94            {
95                allOption.text(format("- All -", totalCount));
96            }
97            else if (selectField[0].name == "metadata-cite97Code")
98            {
99                allOption.text(format("Tout le référentiel CITE-97 ()", totalCount));
100            }
101            else if (selectField[0].name == "metadata-educationKind")
102            {
103                allOption.text(format("Tous les types de formation ()", totalCount));
104            }
105            else if (selectField[0].name == "metadata-catalog")
106            {
107                allOption.text(format("Tous les catalogues ()", totalCount));
108            }
109            else if (selectField[0].name == "metadata-ubsEducationLevel")
110            {
111                allOption.text(format("Tous les niveaux d'études ()", totalCount));
112            }
113            else if (selectField[0].name == "metadata-fapCode")
114            {
115                allOption.text(format("Toutes les famille professionnelle (FAP) ()", totalCount));
116            }
117            else if (selectField[0].name == "metadata-erasmusCode")
118            {
119                allOption.text(format("Tout le référentiel ERA
119SMUS ()", totalCount));
120            }
121            else if (selectField[0].name == "metadata-orgUnit")
122            {
123                allOption.text(format("Toutes les facultés, école, instituts ()", totalCount));
124            }
125            else if (selectField[0].name == "metadata-activitySector")
126            {
127                allOption.text(format("Tous les secteurs d'activités ()", totalCount));
128            }
129            else if (selectField[0].name == "metadata-formofteachingOrg")
130            {
131                allOption.text(format("Toutes les modalités de formation ()", totalCount));
132            }
133            else
134            {
135                allOption.text(format("- All () -", totalCount));
136            }
137                
138            // select the previous value
139            selectField.val(selectedValue);
140                    
141            // Send a message to notify that the select data has changed.
142            selectField.selectmenu("refresh");
143        });
144    }
145    
146    function isLocaleCompareAvailable()
147    {
148        try
149        {
150            "a".localeCompare("b");
151            return true;
152        }
153        catch (e)
154        {
155            return false;
156        }
157    }
158    
159    function localeCompareSortTextFn(a, b)
160    {
161        return $j(a).text().toLowerCase().localeCompare($j(b).text().toLowerCase());
162    }
163    
164    function basicSortTextFn(a, b)
165    {
166        return $j(a).text().toLowerCase() &lt; $j(b).text().toLowerCase() ? -1 : 1;
167    }
168    
169    // best effort alphabetical sort
170    var sortTextFn = (function ()
171    {
172        return isLocaleCompareAvailable() ? localeCompareSortTextFn : basicSortTextFn;
173    })();
174    
175    function format(text, count)
176    {
177        return text.replace("()", "(" + count + ")");
178    }
179    
180    var form = $j('#' + formId);
181    
182    var params = _getFormValues(form[0]);
183    params.siteName = siteName;
184    params.submit = 'true';
185    params.lang = lang;
186    params.zoneItemId = zoneItemId;
187    params['zone-item-id'] = zoneItemId;
188    params['facets'] = true;
189    params['content-types'] = 'org.ametys.plugins.odf.Content.program'; // For facets
190    
191    $j.post(url, params, updateCb)
192}
193
194/**
195 * Retrieves the form parameters in a Map
196 * @param form the form
197 */
198function _getFormValues (form)
199{
200    var params = {};
201    
202    for (var i = 0; i < form.elements.length; i++)
203    {
204        var elt = form.elements[i];
205        if (elt.name != '' && elt.value != '')
206        {
207            params[elt.name] = elt.value;
208        }
209    }
210    
211    return params;
212}
213

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.