View | Details | Raw Unified | Return to bug 27378
Collapse All | Expand All

(-)a/koha-tmpl/intranet-tmpl/prog/en/includes/intranet-bottom.inc (-1 / +1 lines)
Lines 136-142 Link Here
136
    [% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %]
136
    [% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %]
137
        [% consents = JSConsents.all() %]
137
        [% consents = JSConsents.all() %]
138
        [% FOREACH consent IN consents %]
138
        [% FOREACH consent IN consents %]
139
            <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id %]" data-consent-code="[% consent.code %]" data-requires-consent="[% consent.staffConsent ? 'true' : 'false' %]"></div>
139
            <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-requires-consent="[% consent.staffConsent ? 'true' : 'false' | html %]"></div>
140
        [% END %]
140
        [% END %]
141
    [% END %]
141
    [% END %]
142
    [% IF Koha.Preference( 'CookieConsent' ) %]
142
    [% IF Koha.Preference( 'CookieConsent' ) %]
(-)a/koha-tmpl/intranet-tmpl/prog/js/cookieconsent.js (+16 lines)
Lines 102-107 Link Here
102
                const code = atob($(this).data('consent-code'));
102
                const code = atob($(this).data('consent-code'));
103
                const func = Function(code);
103
                const func = Function(code);
104
                func();
104
                func();
105
            } else {
106
                // This code doesn't have consent to run, we may need to remove
107
                // any cookies it has previously set
108
                const matchPattern = $(this).data('consent-match-pattern');
109
                if (matchPattern.length > 0) {
110
                    const regex = new RegExp(matchPattern);
111
                    const allCookies = document.cookie.split('; ');
112
                    allCookies.forEach(function (cookie) {
113
                        const name = cookie.split('=')[0];
114
                        if (regex.test(name)) {
115
                            document.cookie = name + '=; expires=Thu, 01 Jan 1970 00: 00: 01 GMT';
116
                        }
117
                    });
118
119
                }
105
            }
120
            }
106
        });
121
        });
107
    }
122
    }
Lines 125-130 Link Here
125
            e.preventDefault();
140
            e.preventDefault();
126
            localStorage.setItem('cookieConsent', []);
141
            localStorage.setItem('cookieConsent', []);
127
            hideContainer();
142
            hideContainer();
143
            runConsentedCode();
128
        });
144
        });
129
145
130
        // "Accept selected" handler
146
        // "Accept selected" handler
(-)a/koha-tmpl/intranet-tmpl/prog/js/pages/preferences.js (-3 / +43 lines)
Lines 340-346 $( document ).ready( function () { Link Here
340
        const id = 'ConsentJS_' + idx;
340
        const id = 'ConsentJS_' + idx;
341
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
341
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
342
        const itemId = item.id && item.id.length > 0 ? item.id : '';
342
        const itemId = item.id && item.id.length > 0 ? item.id : '';
343
        return '<div id="' + id + '" class="consentJSItem" 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><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="#">' + __('Click to expand') + '</a><a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a></div></div><a class="consentDelete" data-target="' + id + '" href="#">Delete</a></div>';
343
        return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' +
344
               '    <div class="consentRow">' +
345
               '        <div class="consentItem">' +
346
               '            <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' +
347
               '            <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' +
348
               '        </div >' +
349
               '        <div class="consentItem">' +
350
               '            <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' +
351
               '            <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' +
352
               '        </div>' +
353
               '        <div class="consentItem">' +
354
               '            <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' +
355
                            checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) +
356
               '        </div>' +
357
               '        <div class="consentItem">' +
358
               '            <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' +
359
                            checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) +
360
               '        </div >' +
361
               '        <div class="consentItem">' +
362
               '            <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' +
363
               '            <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' +
364
               '        </div >' +
365
               '    </div >' +
366
               '    <div class="consentRow codeRow">' +
367
               '        <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' +
368
               '        <div>' +
369
               '            <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Click to expand') + '</a>' +
370
               '            <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a>' +
371
               '        </div >' +
372
               '    </div>' +
373
               '    <a class="consentDelete" data-target="' + id + '" href="#">Delete</a>' +
374
               '</div > ';
344
    }
375
    }
345
376
346
    // Return the markup for all consentJS items concatenated
377
    // Return the markup for all consentJS items concatenated
Lines 360-365 $( document ).ready( function () { Link Here
360
        return {
391
        return {
361
            name: '',
392
            name: '',
362
            description: '',
393
            description: '',
394
            matchPattern: '',
363
            code: '',
395
            code: '',
364
            consentInOpac: false,
396
            consentInOpac: false,
365
            consentInStaff: false
397
            consentInStaff: false
Lines 437-454 $( document ).ready( function () { Link Here
437
                '_' + Math.random().toString(36).substr(2, 9);
469
                '_' + Math.random().toString(36).substr(2, 9);
438
            const name = $(this).find('.metaName').val();
470
            const name = $(this).find('.metaName').val();
439
            const desc = $(this).find('.metaDescription').val();
471
            const desc = $(this).find('.metaDescription').val();
472
            const matchPattern = $(this).find('.metaMatchPattern').val();
440
            const opacConsent = $(this).find('.opacConsent').is(':checked')
473
            const opacConsent = $(this).find('.opacConsent').is(':checked')
441
            const staffConsent = $(this).find('.staffConsent').is(':checked');
474
            const staffConsent = $(this).find('.staffConsent').is(':checked');
442
            const code = $(this).find('.preference-code').val();
475
            const code = $(this).find('.preference-code').val();
443
            // If the name, description and code are empty, then they've
476
            // If the name, description, match pattern code are empty, then they've
444
            // added a new entry, but not filled it in, we can skip it
477
            // added a new entry, but not filled it in, we can skip it
445
            if (name.length === 0 && desc.length === 0 && code.length === 0) {
478
            if (
479
                name.length === 0 &&
480
                desc.length === 0 &&
481
                matchPattern.length === 0 &&
482
                code.length === 0
483
            ) {
446
                return;
484
                return;
447
            }
485
            }
448
            // They've filled in at least some info
486
            // They've filled in at least some info
449
            if (
487
            if (
450
                (name.length === 0) ||
488
                (name.length === 0) ||
451
                (desc.length === 0) ||
489
                (desc.length === 0) ||
490
                (matchPattern.length === 0) ||
452
                (code.length === 0)
491
                (code.length === 0)
453
            ) {
492
            ) {
454
                invalid.push(this);
493
                invalid.push(this);
Lines 457-462 $( document ).ready( function () { Link Here
457
                    id: id,
496
                    id: id,
458
                    name: name,
497
                    name: name,
459
                    description: desc,
498
                    description: desc,
499
                    matchPattern: matchPattern,
460
                    opacConsent: opacConsent,
500
                    opacConsent: opacConsent,
461
                    staffConsent: staffConsent,
501
                    staffConsent: staffConsent,
462
                    code: btoa(code)
502
                    code: btoa(code)
(-)a/koha-tmpl/opac-tmpl/bootstrap/en/includes/opac-bottom.inc (-1 / +1 lines)
Lines 124-130 Link Here
124
[% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %]
124
[% IF Koha.Preference( 'CookieConsent' ) && Koha.Preference( 'ConsentJS' ).length > 0 %]
125
    [% consents = JSConsents.all() %]
125
    [% consents = JSConsents.all() %]
126
    [% FOREACH consent IN consents %]
126
    [% FOREACH consent IN consents %]
127
        <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id %]" data-consent-code="[% consent.code %]" data-requires-consent="[% consent.opacConsent ? 'true' : 'false' %]"></div>
127
        <div class="consentCode" style="display:none" aria-hidden="true" data-consent-id="[% consent.id | html %]" data-consent-code="[% consent.code | html %]" data-consent-match-pattern="[% consent.matchPattern | html %]" data-requires-consent="[% consent.opacConsent ? 'true' : 'false' | html %]"></div>
128
    [% END %]
128
    [% END %]
129
[% END %]
129
[% END %]
130
130
(-)a/koha-tmpl/opac-tmpl/bootstrap/js/cookieconsent.js (-1 / +15 lines)
Lines 116-121 Link Here
116
                const code = atob($(this).data('consent-code'));
116
                const code = atob($(this).data('consent-code'));
117
                const func = Function(code);
117
                const func = Function(code);
118
                func();
118
                func();
119
            } else {
120
                // This code doesn't have consent to run, we may need to remove
121
                // any cookies it has previously set
122
                const matchPattern = $(this).data('consent-match-pattern');
123
                if (matchPattern.length > 0) {
124
                    const regex = new RegExp(matchPattern);
125
                    const allCookies = document.cookie.split('; ');
126
                    allCookies.forEach(function (cookie) {
127
                        const name = cookie.split('=')[0];
128
                        if (regex.test(name)) {
129
                            document.cookie = name + '=; expires=Thu, 01 Jan 1970 00: 00: 01 GMT';
130
                        }
131
                    });
132
                }
119
            }
133
            }
120
        });
134
        });
121
    }
135
    }
Lines 140-145 Link Here
140
            e.preventDefault();
154
            e.preventDefault();
141
            localStorage.setItem('cookieConsent', []);
155
            localStorage.setItem('cookieConsent', []);
142
            hideContainer();
156
            hideContainer();
157
            runConsentedCode();
143
            showYourCookies();
158
            showYourCookies();
144
        });
159
        });
145
160
146
- 

Return to bug 27378