Bugzilla – Attachment 166517 Details for
Bug 34655
system_preferences_search.t is failing randomly
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
Bug 34655: Prevent selenium/system_preferences_search.t to fail randomly
Bug-34655-Prevent-seleniumsystempreferencessearcht.patch (text/plain), 36.79 KB, created by
David Nind
on 2024-05-10 09:29:08 UTC
(
hide
)
Description:
Bug 34655: Prevent selenium/system_preferences_search.t to fail randomly
Filename:
MIME Type:
Creator:
David Nind
Created:
2024-05-10 09:29:08 UTC
Size:
36.79 KB
patch
obsolete
>From deead8900fd28f6c05cd0d26a0ab82fb633fe8cd Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Fri, 10 May 2024 10:33:26 +0200 >Subject: [PATCH] Bug 34655: Prevent selenium/system_preferences_search.t to > fail randomly > >Removing this JS code from document.ready. >The script tag is at the end of the DOM and there is no good reasons (at >least I didn't find any) to wait for the whole document to be ready >before executing the JS code. > >It made the selenium tests selenium/system_preferences_search.t to fail >randomly with: > # Failed test 'The first "Policy" section (under "Accounting") is currently expanded' > # at t/db_dependent/selenium/system_preferences_search.t line 63. > # got: undef > # expected: 'expanded' > # Looks like you failed 1 test of 6. > >Because we set the class in this JS code and selenium won't wait for it >to finish before starting running the tests. > >Signed-off-by: David Nind <david@davidnind.com> >--- > .../prog/js/pages/preferences.js | 804 +++++++++--------- > 1 file changed, 400 insertions(+), 404 deletions(-) > >diff --git a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >index 351e42fc44..9f17436a88 100644 >--- a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >+++ b/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js >@@ -169,447 +169,443 @@ function addConsentDeleteHandler() { > }) > } > >-$( document ).ready( function () { >- >- $("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, { >- "dom": 't', >- "columnDefs": [ >- { "targets": [ -1 ], "orderable": false, "searchable": false } >- ], >- "paging": false >- })); >- >- $( '.prefs-tab' ) >- .find( 'input.preference, textarea.preference' ).on('input', function () { >- if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this ); >- } ).end() >- .find( 'select.preference' ).change( mark_modified ); >- $('.preference-checkbox').change( function () { >- $('.preference-checkbox').addClass('modified'); >- mark_modified.call(this); >- } ); >- >- $(".set_syspref").click(function() { >- var s = $(this).attr('data-syspref'); >- var v = $(this).attr('data-value'); >- // populate the input with the value in data-value >- $("#pref_"+s).val(v); >- // pass the DOM element to trigger "modified" to enable submit button >- mark_modified.call($("#pref_"+s)[0]); >- return false; >- }); >+$("table.preferences").dataTable($.extend(true, {}, dataTablesDefaults, { >+ "dom": 't', >+ "columnDefs": [ >+ { "targets": [ -1 ], "orderable": false, "searchable": false } >+ ], >+ "paging": false >+})); >+ >+$( '.prefs-tab' ) >+ .find( 'input.preference, textarea.preference' ).on('input', function () { >+ if ( this.defaultValue === undefined || this.value != this.defaultValue ) mark_modified.call( this ); >+ } ).end() >+ .find( 'select.preference' ).change( mark_modified ); >+$('.preference-checkbox').change( function () { >+ $('.preference-checkbox').addClass('modified'); >+ mark_modified.call(this); >+} ); > >- $(".sortable").each( (i, e) => { >- Sortable.create(e, { >- animation: 150, >- onUpdate: function( e ){ >- $(e.target).find('input:first').change(); >- } >- }); >+$(".set_syspref").click(function() { >+ var s = $(this).attr('data-syspref'); >+ var v = $(this).attr('data-value'); >+ // populate the input with the value in data-value >+ $("#pref_"+s).val(v); >+ // pass the DOM element to trigger "modified" to enable submit button >+ mark_modified.call($("#pref_"+s)[0]); >+ return false; >+}); >+ >+$(".sortable").each( (i, e) => { >+ Sortable.create(e, { >+ animation: 150, >+ onUpdate: function( e ){ >+ $(e.target).find('input:first').change(); >+ } > }); >+}); > >- $( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } ); >+$( '.prefs-tab .action .cancel' ).click( function () { KOHA.Preferences.Modified = false } ); > >- $( '.prefs-tab .save-all' ).prop('disabled', true).click( function () { >- KOHA.Preferences.Save( this.form ); >- return false; >- }); >+$( '.prefs-tab .save-all' ).prop('disabled', true).click( function () { >+ KOHA.Preferences.Save( this.form ); >+ return false; >+}); > >- addExpandHandler(); >+addExpandHandler(); > >- addCollapseHandler(); >+addCollapseHandler(); > >- $("h3").attr("class", "expanded").attr("title", __("Collapse this section")); >- var collapsible = $(".collapsed,.expanded"); >+$("h3").attr("class", "expanded").attr("title", __("Collapse this section")); >+var collapsible = $(".collapsed,.expanded"); > >- $(collapsible).on("click",function(){ >- var h3Id = $(this).attr("id"); >- var panel = $("#collapse_" + h3Id); >- if(panel.is(":visible")){ >- $(this).addClass("collapsed").removeClass("expanded").attr("title", __("Expand this section") ); >- panel.hide(); >- } else { >- $(this).addClass("expanded").removeClass("collapsed").attr("title", __("Collapse this section") ); >- panel.show(); >- } >- }); >+$(collapsible).on("click",function(){ >+ var h3Id = $(this).attr("id"); >+ var panel = $("#collapse_" + h3Id); >+ if(panel.is(":visible")){ >+ $(this).addClass("collapsed").removeClass("expanded").attr("title", __("Expand this section") ); >+ panel.hide(); >+ } else { >+ $(this).addClass("expanded").removeClass("collapsed").attr("title", __("Collapse this section") ); >+ panel.show(); >+ } >+}); >+ >+$(".pref_sublink").on("click", function(){ >+ /* If the user clicks a sub-menu link in the sidebar, >+ check to see if it is collapsed. If so, expand it */ >+ var href = $(this).attr("href"); >+ href = href.replace("#",""); >+ var panel = $("#collapse_" + href ); >+ if( panel.is(":hidden") ){ >+ $("#" + href).addClass("expanded").removeClass("collapsed").attr("title", __("Collapse this section") ); >+ panel.show(); >+ } >+}); > >- $(".pref_sublink").on("click", function(){ >- /* If the user clicks a sub-menu link in the sidebar, >- check to see if it is collapsed. If so, expand it */ >- var href = $(this).attr("href"); >- href = href.replace("#",""); >- var panel = $("#collapse_" + href ); >- if( panel.is(":hidden") ){ >- $("#" + href).addClass("expanded").removeClass("collapsed").attr("title", __("Collapse this section") ); >- panel.show(); >- } >- }); >+if ( to_highlight ) { >+ var words = to_highlight.split( ' ' ); >+ $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) { >+ $.each( words, function ( i, word ) { $( td ).highlight( word ) } ); >+ } ).find( 'option, textarea' ).removeHighlight(); >+} > >- if ( to_highlight ) { >- var words = to_highlight.split( ' ' ); >- $( '.prefs-tab table' ).find( 'td, th' ).not( '.name-cell' ).each( function ( i, td ) { >- $.each( words, function ( i, word ) { $( td ).highlight( word ) } ); >- } ).find( 'option, textarea' ).removeHighlight(); >- } >+if ( search_jumped ) { >+ document.location.hash = "jumped"; >+} > >- if ( search_jumped ) { >- document.location.hash = "jumped"; >+$("#pref_UpdateItemLocationOnCheckin, #pref_UpdateItemLocationOnCheckout").change(function(){ >+ var the_text = $(this).val(); >+ var alert_text = ''; >+ if (the_text.indexOf('_ALL_:') != -1) alert_text = __("Note: _ALL_ value will override all other values") + '\n'; >+ var split_text =the_text.split("\n"); >+ var alert_issues = ''; >+ var issue_count = 0; >+ var reg_check = /.*:\s.*/; >+ for (var i=0; i < split_text.length; i++){ >+ if ( !split_text[i].match(reg_check) && split_text[i].length ) { >+ alert_issues+=split_text[i]+"\n"; >+ issue_count++; >+ } > } >- >- $("#pref_UpdateItemLocationOnCheckin, #pref_UpdateItemLocationOnCheckout").change(function(){ >- var the_text = $(this).val(); >- var alert_text = ''; >- if (the_text.indexOf('_ALL_:') != -1) alert_text = __("Note: _ALL_ value will override all other values") + '\n'; >- var split_text =the_text.split("\n"); >- var alert_issues = ''; >- var issue_count = 0; >- var reg_check = /.*:\s.*/; >- for (var i=0; i < split_text.length; i++){ >- if ( !split_text[i].match(reg_check) && split_text[i].length ) { >- alert_issues+=split_text[i]+"\n"; >- issue_count++; >+ if (issue_count) alert_text += "\n" + __("The following values are not formatted correctly:") + "\n" + alert_issues; >+ if ( alert_text.length ) alert(alert_text); >+}); >+ >+$(".prefs-tab form").each(function () { >+ $(this).validate({ >+ rules: { }, >+ errorPlacement: function(error, element) { >+ var placement = $(element).parent(); >+ if (placement) { >+ $(placement).append(error) >+ } else { >+ error.insertAfter(element); > } > } >- if (issue_count) alert_text += "\n" + __("The following values are not formatted correctly:") + "\n" + alert_issues; >- if ( alert_text.length ) alert(alert_text); > }); >+}); > >- $(".prefs-tab form").each(function () { >- $(this).validate({ >- rules: { }, >- errorPlacement: function(error, element) { >- var placement = $(element).parent(); >- if (placement) { >- $(placement).append(error) >- } else { >- error.insertAfter(element); >- } >- } >- }); >+$(".preference-email").each(function() { >+ $(this).rules("add", { >+ email: true > }); >+}); >+ >+ >+$(".modalselect").on("click", function(){ >+ var datasource = $(this).data("source"); >+ var exclusions = $(this).data("exclusions").split('|'); >+ var inclusions = $(this).data("inclusions").split('|'); >+ var required = $(this).data("required").split('|'); >+ var pref_name = this.id.replace(/pref_/, ''); >+ var pref_value = this.value; >+ var prefs = pref_value.split("|"); >+ >+ let data = db_columns[datasource]; >+ var items = []; >+ var checked = ""; >+ var readonly = ""; >+ var disabled = ""; >+ var style = ""; >+ $.each( Object.keys(data).sort(), function( i, key ){ >+ if( prefs.indexOf( key ) >= 0 ){ >+ checked = ' checked="checked" '; >+ } else { >+ checked = ""; >+ } >+ if( required.indexOf( key ) >= 0 ){ >+ style = "required"; >+ checked = ' checked="checked" '; >+ } else if( exclusions.indexOf( key ) >= 0 ){ >+ style = "disabled"; >+ disabled = ' disabled="disabled" '; >+ checked = ""; >+ } else if( inclusions.indexOf( key ) >= 0 ){ >+ style = "disabled"; >+ disabled = ' disabled="disabled" '; >+ checked = ' checked="checked" '; >+ } else { >+ style = ""; >+ disabled = ""; >+ } > >- $(".preference-email").each(function() { >- $(this).rules("add", { >- email: true >- }); >+ items.push('<label class="' + style +'"><input class="dbcolumn_selection" type="checkbox" id="' + key + '"' + checked + disabled + ' name="pref" value="' + key + '" /> ' + data[key]+ ' (' + key + ')</label>'); > }); >- >- >- $(".modalselect").on("click", function(){ >- var datasource = $(this).data("source"); >- var exclusions = $(this).data("exclusions").split('|'); >- var inclusions = $(this).data("inclusions").split('|'); >- var required = $(this).data("required").split('|'); >- var pref_name = this.id.replace(/pref_/, ''); >- var pref_value = this.value; >- var prefs = pref_value.split("|"); >- >- let data = db_columns[datasource]; >- var items = []; >- var checked = ""; >- var readonly = ""; >- var disabled = ""; >- var style = ""; >- $.each( Object.keys(data).sort(), function( i, key ){ >- if( prefs.indexOf( key ) >= 0 ){ >- checked = ' checked="checked" '; >- } else { >- checked = ""; >- } >- if( required.indexOf( key ) >= 0 ){ >- style = "required"; >- checked = ' checked="checked" '; >- } else if( exclusions.indexOf( key ) >= 0 ){ >- style = "disabled"; >- disabled = ' disabled="disabled" '; >- checked = ""; >- } else if( inclusions.indexOf( key ) >= 0 ){ >- style = "disabled"; >- disabled = ' disabled="disabled" '; >- checked = ' checked="checked" '; >- } else { >- style = ""; >- disabled = ""; >- } >- >- items.push('<label class="' + style +'"><input class="dbcolumn_selection" type="checkbox" id="' + key + '"' + checked + disabled + ' name="pref" value="' + key + '" /> ' + data[key]+ ' (' + key + ')</label>'); >- }); >- $("<div/>", { >- "class": "columns-2", >- html: items.join("") >- }).appendTo("#prefModalBody"); >- >- $("#saveModalPrefs").data("target", this.id ); >- $("#saveModalPrefs").data("type", "modalselect" ); >- $("#prefModalLabel").text( pref_name ); >+ $("<div/>", { >+ "class": "columns-2", >+ html: items.join("") >+ }).appendTo("#prefModalBody"); >+ >+ $("#saveModalPrefs").data("target", this.id ); >+ $("#saveModalPrefs").data("type", "modalselect" ); >+ $("#prefModalLabel").text( pref_name ); >+ $("#prefModal").modal("show"); >+}); >+ >+// Initialise the content of our modal, using the function >+// specified in the data-initiator attribute >+$('.modaljs').on('click', function () { >+ const init = $(this).data('initiator'); >+ if (init) { >+ window[init](this); > $("#prefModal").modal("show"); >- }); >- >- // Initialise the content of our modal, using the function >- // specified in the data-initiator attribute >- $('.modaljs').on('click', function () { >- const init = $(this).data('initiator'); >- if (init) { >- window[init](this); >- $("#prefModal").modal("show"); >+ } >+}); >+ >+// Initialise the content of our modal, if we are dealing >+// with a modalselect modal >+function prepareModalSelect(formfieldid) { >+ var prefs = []; >+ $("#prefModal input[type='checkbox']").each(function(){ >+ if( $(this).prop("checked") ){ >+ prefs.push( this.value ); > } > }); >+ return prefs.join("|"); >+} > >- // Initialise the content of our modal, if we are dealing >- // with a modalselect modal >- function prepareModalSelect(formfieldid) { >- var prefs = []; >- $("#prefModal input[type='checkbox']").each(function(){ >- if( $(this).prop("checked") ){ >- prefs.push( this.value ); >- } >- }); >- return prefs.join("|"); >- } >- >- // Return a checkbox with an appropriate checked state >- function checkBox(id, className, state) { >- return state ? >- '<input id="' + id + '" type="checkbox" class="' + className + '" checked>' : >- '<input id="' + id + '" type="checkbox" class="' + className + '">'; >- } >- >- // Create a cookieConsentedJS item, correctly populated >- function createCookieConsentedJSItem(item, idx) { >- const id = 'CookieConsentedJS_' + idx; >- const code = item.code && item.code.length > 0 ? atob(item.code) : ''; >- const itemId = item.id && item.id.length > 0 ? item.id : ''; >- return '<div id="' + id + '" class="cookieConsentedJSItem" data-id="' + itemId + '">' + >- ' <div class="consentRow">' + >- ' <div class="consentItem">' + >- ' <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + >- ' <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' + >- ' </div >' + >- ' <div class="consentItem">' + >- ' <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' + >- ' <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' + >- ' </div>' + >- ' <div class="consentItem">' + >- ' <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' + >- checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) + >- ' </div>' + >- ' <div class="consentItem">' + >- ' <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' + >- checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) + >- ' </div >' + >- ' <div class="consentItem">' + >- ' <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' + >- ' <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' + >- ' </div >' + >- ' <div class="consentItem">' + >- ' <label for="cookieDomain' + id + '">' + __('Cookie domain') + ':</label>' + >- ' <input id="cookieDomain' + id + '" class="metaCookieDomain" type="text" value="' + item.cookieDomain + '"><span class="required">' + __('Required') + '</span>' + >- ' </div >' + >- ' <div class="consentItem">' + >- ' <label for="cookiePath' + id + '">' + __('Cookie path') + ':</label>' + >- ' <input id="cookiePath' + id + '" class="metaCookiePath" type="text" value="' + item.cookiePath + '"><span class="required">' + __('Required') + '</span>' + >- ' </div >' + >- ' </div >' + >- ' <div class="consentRow codeRow">' + >- ' <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' + >- ' <div>' + >- ' <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Expand') + '</a>' + >- ' <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Collapse') + '</a>' + >- ' </div >' + >- ' </div>' + >- ' <a class="consentDelete" data-target="' + id + '" href="#">' + __('Delete') + '</a>' + >- '</div > '; >- } >+// Return a checkbox with an appropriate checked state >+function checkBox(id, className, state) { >+ return state ? >+ '<input id="' + id + '" type="checkbox" class="' + className + '" checked>' : >+ '<input id="' + id + '" type="checkbox" class="' + className + '">'; >+} > >- // Return the markup for all cookieConsentedJS items concatenated >- function populateConsentMarkup(items) { >- return items.reduce(function (acc, current, idx) { >- return acc + createCookieConsentedJSItem(current, idx); >- }, ''); >- } >+// Create a cookieConsentedJS item, correctly populated >+function createCookieConsentedJSItem(item, idx) { >+ const id = 'CookieConsentedJS_' + idx; >+ const code = item.code && item.code.length > 0 ? atob(item.code) : ''; >+ const itemId = item.id && item.id.length > 0 ? item.id : ''; >+ return '<div id="' + id + '" class="cookieConsentedJSItem" data-id="' + itemId + '">' + >+ ' <div class="consentRow">' + >+ ' <div class="consentItem">' + >+ ' <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' + >+ ' <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' + >+ ' <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div>' + >+ ' <div class="consentItem">' + >+ ' <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' + >+ checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) + >+ ' </div>' + >+ ' <div class="consentItem">' + >+ ' <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' + >+ checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' + >+ ' <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label for="cookieDomain' + id + '">' + __('Cookie domain') + ':</label>' + >+ ' <input id="cookieDomain' + id + '" class="metaCookieDomain" type="text" value="' + item.cookieDomain + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' <div class="consentItem">' + >+ ' <label for="cookiePath' + id + '">' + __('Cookie path') + ':</label>' + >+ ' <input id="cookiePath' + id + '" class="metaCookiePath" type="text" value="' + item.cookiePath + '"><span class="required">' + __('Required') + '</span>' + >+ ' </div >' + >+ ' </div >' + >+ ' <div class="consentRow codeRow">' + >+ ' <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' + >+ ' <div>' + >+ ' <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Expand') + '</a>' + >+ ' <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Collapse') + '</a>' + >+ ' </div >' + >+ ' </div>' + >+ ' <a class="consentDelete" data-target="' + id + '" href="#">' + __('Delete') + '</a>' + >+ '</div > '; >+} > >- // Return the markup for a validation warning >- function populateValidationWarning() { >- return '<div id="cookieConsentedJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; >- } >+// Return the markup for all cookieConsentedJS items concatenated >+function populateConsentMarkup(items) { >+ return items.reduce(function (acc, current, idx) { >+ return acc + createCookieConsentedJSItem(current, idx); >+ }, ''); >+} > >- // Return a new, empty consent item >- function emptyConsentItem() { >- return { >- name: '', >- description: '', >- matchPattern: '', >- cookieDomain: '', >- cookiePath: '', >- code: '', >- opacConsent: false, >- staffConsent: false >- }; >- } >+// Return the markup for a validation warning >+function populateValidationWarning() { >+ return '<div id="cookieConsentedJSWarning" class="error" style="display:none;">' + __('You must complete all fields') + '</div>'; >+} > >- // Add the handler for a new empty consent item >- function addNewHandler() { >- $("#cookieConsentedJSAddNew").on("click", function (e) { >- e.preventDefault(); >- const currentLen = $('.cookieConsentedJSItem').length; >- const newItem = emptyConsentItem(); >- const markup = createCookieConsentedJSItem(newItem, currentLen); >- $('#prefModal .modal-body #cookieConsentedJSItems').append($(markup)); >- addExpandHandler(); >- addCollapseHandler(); >- addConsentDeleteHandler(); >- }); >- } >+// Return a new, empty consent item >+function emptyConsentItem() { >+ return { >+ name: '', >+ description: '', >+ matchPattern: '', >+ cookieDomain: '', >+ cookiePath: '', >+ code: '', >+ opacConsent: false, >+ staffConsent: false >+ }; >+} > >- // Populate the cookieConsentedJS modal, we also initialise any >- // event handlers that are required. This function is added >- // to the window object so we can call it if we are passed it's name >- // as a data-initiator attribute >- // (e.g.) >- // const f = 'populateCookieConsentedJS'; >- // window[f](); >- window.populateCookieConsentedJS = function(el) { >- let items = []; >- let decoded = ''; >- if (el.value && el.value.length > 0) { >- try { >- decoded = atob(el.value); >- } catch (err) { >- throw (__( >- 'Unable to Base64 decode value stored in CookieConsentedJS syspref: ' + >- err.message >- )); >- } >- try { >- items = JSON.parse(decoded); >- } catch (err) { >- throw (__( >- 'Unable to JSON parse decoded value stored in CookieConsentedJS syspref: ' + >- err.message >- )); >- } >- } >- const markup = populateConsentMarkup(items); >- const validationWarning = populateValidationWarning(); >- const pref_name = el.id.replace(/pref_/, ''); >- $('#saveModalPrefs').data('target', el.id); >- $('#prefModalLabel').text( pref_name ); >- $('#prefModal .modal-body').html($('<div id="cookieConsentedJSItems">' + validationWarning + markup + '</div><div><a href="#" id="cookieConsentedJSAddNew">' + __('Add new code') + '</a></div>')); >+// Add the handler for a new empty consent item >+function addNewHandler() { >+ $("#cookieConsentedJSAddNew").on("click", function (e) { >+ e.preventDefault(); >+ const currentLen = $('.cookieConsentedJSItem').length; >+ const newItem = emptyConsentItem(); >+ const markup = createCookieConsentedJSItem(newItem, currentLen); >+ $('#prefModal .modal-body #cookieConsentedJSItems').append($(markup)); > addExpandHandler(); > addCollapseHandler(); >- addNewHandler(); > addConsentDeleteHandler(); >- } >+ }); >+} > >- // Prepare the data in the UI for sending back as a syspref. >- // We validate that everything is what we expect. This function is added >- // to the window object so we can call it if we are passed it's name >- // as a data-initiator attribute >- // e.g. >- // const f = 'prepareCookieConsentedJS'; >- // window[f](); >- window.prepareCookieConsentedJS = function () { >- const items = $('.cookieConsentedJSItem'); >- const invalid = []; >- const valid = []; >- items.each(function () { >- const id = $(this).data('id').length > 0 ? >- $(this).data('id') : >- '_' + Math.random().toString(36).substr(2, 9); >- const name = $(this).find('.metaName').val(); >- const desc = $(this).find('.metaDescription').val(); >- const matchPattern = $(this).find('.metaMatchPattern').val(); >- const cookieDomain = $(this).find('.metaCookieDomain').val(); >- const cookiePath = $(this).find('.metaCookiePath').val(); >- const opacConsent = $(this).find('.opacConsent').is(':checked') >- const staffConsent = $(this).find('.staffConsent').is(':checked'); >- const code = $(this).find('.preference-code').val(); >- // If the name, description, match pattern code are empty, then they've >- // added a new entry, but not filled it in, we can skip it >- if ( >- name.length === 0 && >- desc.length === 0 && >- matchPattern.length === 0 && >- cookieDomain.length === 0 && >- cookiePath.length === 0 && >- code.length === 0 >- ) { >- return; >- } >- // They've filled in at least some info >- if ( >- (name.length === 0) || >- (desc.length === 0) || >- (matchPattern.length === 0) || >- (cookiePath.length === 0) || >- (code.length === 0) >- ) { >- invalid.push(this); >- } else { >- const obj = { >- id: id, >- name: name, >- description: desc, >- matchPattern: matchPattern, >- cookieDomain: cookieDomain, >- cookiePath: cookiePath, >- opacConsent: opacConsent, >- staffConsent: staffConsent, >- code: btoa(code) >- } >- valid.push(obj); >- } >- }); >- // We failed validation >- if (invalid.length > 0) { >- $('#cookieConsentedJSWarning').show(); >- return false; >+// Populate the cookieConsentedJS modal, we also initialise any >+// event handlers that are required. This function is added >+// to the window object so we can call it if we are passed it's name >+// as a data-initiator attribute >+// (e.g.) >+// const f = 'populateCookieConsentedJS'; >+// window[f](); >+window.populateCookieConsentedJS = function(el) { >+ let items = []; >+ let decoded = ''; >+ if (el.value && el.value.length > 0) { >+ try { >+ decoded = atob(el.value); >+ } catch (err) { >+ throw (__( >+ 'Unable to Base64 decode value stored in CookieConsentedJS syspref: ' + >+ err.message >+ )); > } >- $('#cookieConsentedJSWarning').hide(); >- if (valid.length === 0) { >- return ''; >+ try { >+ items = JSON.parse(decoded); >+ } catch (err) { >+ throw (__( >+ 'Unable to JSON parse decoded value stored in CookieConsentedJS syspref: ' + >+ err.message >+ )); > } >- const json = JSON.stringify(valid); >- const base64 = btoa(json); >- return base64; > } >+ const markup = populateConsentMarkup(items); >+ const validationWarning = populateValidationWarning(); >+ const pref_name = el.id.replace(/pref_/, ''); >+ $('#saveModalPrefs').data('target', el.id); >+ $('#prefModalLabel').text( pref_name ); >+ $('#prefModal .modal-body').html($('<div id="cookieConsentedJSItems">' + validationWarning + markup + '</div><div><a href="#" id="cookieConsentedJSAddNew">' + __('Add new code') + '</a></div>')); >+ addExpandHandler(); >+ addCollapseHandler(); >+ addNewHandler(); >+ addConsentDeleteHandler(); >+} > >- $("#saveModalPrefs").on("click", function(){ >- var formfieldid = $("#" + $(this).data("target")); >- let finalString = ""; >- if ($(this).data("type") == "modalselect") { >- finalString = prepareModalSelect(formfieldid); >- } else { >- const processor = $(".modaljs").data("processor"); >- finalString = window[processor](); >+// Prepare the data in the UI for sending back as a syspref. >+// We validate that everything is what we expect. This function is added >+// to the window object so we can call it if we are passed it's name >+// as a data-initiator attribute >+// e.g. >+// const f = 'prepareCookieConsentedJS'; >+// window[f](); >+window.prepareCookieConsentedJS = function () { >+ const items = $('.cookieConsentedJSItem'); >+ const invalid = []; >+ const valid = []; >+ items.each(function () { >+ const id = $(this).data('id').length > 0 ? >+ $(this).data('id') : >+ '_' + Math.random().toString(36).substr(2, 9); >+ const name = $(this).find('.metaName').val(); >+ const desc = $(this).find('.metaDescription').val(); >+ const matchPattern = $(this).find('.metaMatchPattern').val(); >+ const cookieDomain = $(this).find('.metaCookieDomain').val(); >+ const cookiePath = $(this).find('.metaCookiePath').val(); >+ const opacConsent = $(this).find('.opacConsent').is(':checked') >+ const staffConsent = $(this).find('.staffConsent').is(':checked'); >+ const code = $(this).find('.preference-code').val(); >+ // If the name, description, match pattern code are empty, then they've >+ // added a new entry, but not filled it in, we can skip it >+ if ( >+ name.length === 0 && >+ desc.length === 0 && >+ matchPattern.length === 0 && >+ cookieDomain.length === 0 && >+ cookiePath.length === 0 && >+ code.length === 0 >+ ) { >+ return; > } >- // A processor can return false if any of the submitted >- // data has failed validation >- if (finalString !== false) { >- formfieldid.val(finalString).addClass("modified"); >- mark_modified.call( formfieldid ); >- KOHA.Preferences.Save( formfieldid.closest("form") ); >- $("#prefModal").modal("hide"); >+ // They've filled in at least some info >+ if ( >+ (name.length === 0) || >+ (desc.length === 0) || >+ (matchPattern.length === 0) || >+ (cookiePath.length === 0) || >+ (code.length === 0) >+ ) { >+ invalid.push(this); >+ } else { >+ const obj = { >+ id: id, >+ name: name, >+ description: desc, >+ matchPattern: matchPattern, >+ cookieDomain: cookieDomain, >+ cookiePath: cookiePath, >+ opacConsent: opacConsent, >+ staffConsent: staffConsent, >+ code: btoa(code) >+ } >+ valid.push(obj); > } > }); >+ // We failed validation >+ if (invalid.length > 0) { >+ $('#cookieConsentedJSWarning').show(); >+ return false; >+ } >+ $('#cookieConsentedJSWarning').hide(); >+ if (valid.length === 0) { >+ return ''; >+ } >+ const json = JSON.stringify(valid); >+ const base64 = btoa(json); >+ return base64; >+} > >- $("#prefModal").on("hide.bs.modal", function(){ >- $("#prefModalLabel,#prefModalBody").html(""); >- $("#saveModalPrefs").data("target", "" ); >- }); >- >- $("#select_all").on("click",function(e){ >- e.preventDefault(); >- $("label:not(.required) .dbcolumn_selection:not(:disabled)").prop("checked", true); >- }); >- $("#clear_all").on("click",function(e){ >- e.preventDefault(); >- $("label:not(.required) .dbcolumn_selection").prop("checked", false); >- }); >- >- $("body").on("click", "label.required input.dbcolumn_selection", function(e){ >- e.preventDefault(); >- }); >- >-} ); >+$("#saveModalPrefs").on("click", function(){ >+ var formfieldid = $("#" + $(this).data("target")); >+ let finalString = ""; >+ if ($(this).data("type") == "modalselect") { >+ finalString = prepareModalSelect(formfieldid); >+ } else { >+ const processor = $(".modaljs").data("processor"); >+ finalString = window[processor](); >+ } >+ // A processor can return false if any of the submitted >+ // data has failed validation >+ if (finalString !== false) { >+ formfieldid.val(finalString).addClass("modified"); >+ mark_modified.call( formfieldid ); >+ KOHA.Preferences.Save( formfieldid.closest("form") ); >+ $("#prefModal").modal("hide"); >+ } >+}); >+ >+$("#prefModal").on("hide.bs.modal", function(){ >+ $("#prefModalLabel,#prefModalBody").html(""); >+ $("#saveModalPrefs").data("target", "" ); >+}); >+ >+$("#select_all").on("click",function(e){ >+ e.preventDefault(); >+ $("label:not(.required) .dbcolumn_selection:not(:disabled)").prop("checked", true); >+}); >+$("#clear_all").on("click",function(e){ >+ e.preventDefault(); >+ $("label:not(.required) .dbcolumn_selection").prop("checked", false); >+}); >+ >+$("body").on("click", "label.required input.dbcolumn_selection", function(e){ >+ e.preventDefault(); >+}); >-- >2.39.2
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 34655
:
166509
|
166517
|
166543
|
166544