UNPKG

973 BJavaScriptView Raw
1
2$(function() {
3
4 if ($('#page_type').length < 1 || (typeof objectTypes === 'undefined')) {
5 return ;
6 }
7
8 // link pages types to objects types
9 const setObjectSelect = () => {
10 const option = $('#page_type').find('option:selected');
11 const objectType = objectTypes.find(function(objectType) {
12 return objectType.type === option.data('object-type');
13 });
14 if (!objectType) {
15 $('#object_id_group').hide();
16 $('#object_type').val('');
17 $('#object_id').val('');
18 return;
19 }
20
21 $('#object_id_group').show();
22 $('#object_type').val(objectType.type);
23 $('label[for="object_id"]').text(objectType.label);
24 $('#object_id').empty();
25 objectType.list.forEach(object => {
26 $('#object_id').append($('<option>', {
27 value: object.id,
28 text: object.name
29 }));
30 });
31 $('#object_id').val($('#object_id').data('value'));
32
33 }
34 setObjectSelect();
35 $('#page_type').change(setObjectSelect);
36
37
38});