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 334-340 $( document ).ready( function () { Link Here
334
        const id = 'ConsentJS_' + idx;
334
        const id = 'ConsentJS_' + idx;
335
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
335
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
336
        const itemId = item.id && item.id.length > 0 ? item.id : '';
336
        const itemId = item.id && item.id.length > 0 ? item.id : '';
337
        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>';
337
        return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' +
338
               '    <div class="consentRow">' +
339
               '        <div class="consentItem">' +
340
               '            <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' +
341
               '            <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' +
342
               '        </div >' +
343
               '        <div class="consentItem">' +
344
               '            <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' +
345
               '            <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' +
346
               '        </div>' +
347
               '        <div class="consentItem">' +
348
               '            <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' +
349
                            checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) +
350
               '        </div>' +
351
               '        <div class="consentItem">' +
352
               '            <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' +
353
                            checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) +
354
               '        </div >' +
355
               '        <div class="consentItem">' +
356
               '            <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' +
357
               '            <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' +
358
               '        </div >' +
359
               '    </div >' +
360
               '    <div class="consentRow codeRow">' +
361
               '        <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' +
362
               '        <div>' +
363
               '            <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Click to expand') + '</a>' +
364
               '            <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a>' +
365
               '        </div >' +
366
               '    </div>' +
367
               '    <a class="consentDelete" data-target="' + id + '" href="#">Delete</a>' +
368
               '</div > ';
338
    }
369
    }
339
370
340
    // Return the markup for all consentJS items concatenated
371
    // Return the markup for all consentJS items concatenated
Lines 354-359 $( document ).ready( function () { Link Here
354
        return {
385
        return {
355
            name: '',
386
            name: '',
356
            description: '',
387
            description: '',
388
            matchPattern: '',
357
            code: '',
389
            code: '',
358
            consentInOpac: false,
390
            consentInOpac: false,
359
            consentInStaff: false
391
            consentInStaff: false
Lines 431-448 $( document ).ready( function () { Link Here
431
                '_' + Math.random().toString(36).substr(2, 9);
463
                '_' + Math.random().toString(36).substr(2, 9);
432
            const name = $(this).find('.metaName').val();
464
            const name = $(this).find('.metaName').val();
433
            const desc = $(this).find('.metaDescription').val();
465
            const desc = $(this).find('.metaDescription').val();
466
            const matchPattern = $(this).find('.metaMatchPattern').val();
434
            const opacConsent = $(this).find('.opacConsent').is(':checked')
467
            const opacConsent = $(this).find('.opacConsent').is(':checked')
435
            const staffConsent = $(this).find('.staffConsent').is(':checked');
468
            const staffConsent = $(this).find('.staffConsent').is(':checked');
436
            const code = $(this).find('.preference-code').val();
469
            const code = $(this).find('.preference-code').val();
437
            // If the name, description and code are empty, then they've
470
            // If the name, description, match pattern code are empty, then they've
438
            // added a new entry, but not filled it in, we can skip it
471
            // added a new entry, but not filled it in, we can skip it
439
            if (name.length === 0 && desc.length === 0 && code.length === 0) {
472
            if (
473
                name.length === 0 &&
474
                desc.length === 0 &&
475
                matchPattern.length === 0 &&
476
                code.length === 0
477
            ) {
440
                return;
478
                return;
441
            }
479
            }
442
            // They've filled in at least some info
480
            // They've filled in at least some info
443
            if (
481
            if (
444
                (name.length === 0) ||
482
                (name.length === 0) ||
445
                (desc.length === 0) ||
483
                (desc.length === 0) ||
484
                (matchPattern.length === 0) ||
446
                (code.length === 0)
485
                (code.length === 0)
447
            ) {
486
            ) {
448
                invalid.push(this);
487
                invalid.push(this);
Lines 451-456 $( document ).ready( function () { Link Here
451
                    id: id,
490
                    id: id,
452
                    name: name,
491
                    name: name,
453
                    description: desc,
492
                    description: desc,
493
                    matchPattern: matchPattern,
454
                    opacConsent: opacConsent,
494
                    opacConsent: opacConsent,
455
                    staffConsent: staffConsent,
495
                    staffConsent: staffConsent,
456
                    code: btoa(code)
496
                    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