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 342-348 $( document ).ready( function () { Link Here
342
        const id = 'ConsentJS_' + idx;
342
        const id = 'ConsentJS_' + idx;
343
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
343
        const code = item.code && item.code.length > 0 ? atob(item.code) : '';
344
        const itemId = item.id && item.id.length > 0 ? item.id : '';
344
        const itemId = item.id && item.id.length > 0 ? item.id : '';
345
        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>';
345
        return '<div id="' + id + '" class="consentJSItem" data-id="' + itemId + '">' +
346
               '    <div class="consentRow">' +
347
               '        <div class="consentItem">' +
348
               '            <label class="required" for="name_' + id + '">' + __('Name') + ':</label>' +
349
               '            <input id="name_' + id + '" class="metaName" type="text" value="' + item.name + '"><span class="required">' + __('Required') + '</span>' +
350
               '        </div >' +
351
               '        <div class="consentItem">' +
352
               '            <label class="required" for="description_' + id + '">' + __('Description') + ':</label>' +
353
               '            <input id="description_' + id + '" class="metaDescription" type="text" value="' + item.description + '"><span class="required">' + __('Required') + '</span>' +
354
               '        </div>' +
355
               '        <div class="consentItem">' +
356
               '            <label for="opacConsent_' + id + '">' + __('Requires consent in OPAC') + ':</label>' +
357
                            checkBox('opacConsent_' + id, 'opacConsent', item.opacConsent) +
358
               '        </div>' +
359
               '        <div class="consentItem">' +
360
               '            <label for="staffConsent_' + id + '">' + __('Requires consent in staff interface') + ':</label>' +
361
                            checkBox('staffConsent_' + id, 'staffConsent', item.staffConsent) +
362
               '        </div >' +
363
               '        <div class="consentItem">' +
364
               '            <label for="matchPattern_' + id + '">' + __('String used to identify cookie name') + ':</label>' +
365
               '            <input id="matchPattern_' + id + '" class="metaMatchPattern" type="text" value="' + item.matchPattern + '"><span class="required">' + __('Required') + '</span>' +
366
               '        </div >' +
367
               '    </div >' +
368
               '    <div class="consentRow codeRow">' +
369
               '        <textarea style="display:none;" id="pref_' + id + '" class="preference preference-code codemirror" rows="10" cols="40">' + code + '</textarea>' +
370
               '        <div>' +
371
               '            <a id="expand_' + id + '" class="expand-textarea" data-target="' + id + '" data-syntax="javascript" href="#">' + __('Click to expand') + '</a>' +
372
               '            <a id="collapse_' + id + '" class="collapse-textarea" data-target="' + id + '" data-syntax="javascript" href="#" style="display:none">' + __('Click to collapse') + '</a>' +
373
               '        </div >' +
374
               '    </div>' +
375
               '    <a class="consentDelete" data-target="' + id + '" href="#">Delete</a>' +
376
               '</div > ';
346
    }
377
    }
347
378
348
    // Return the markup for all consentJS items concatenated
379
    // Return the markup for all consentJS items concatenated
Lines 362-367 $( document ).ready( function () { Link Here
362
        return {
393
        return {
363
            name: '',
394
            name: '',
364
            description: '',
395
            description: '',
396
            matchPattern: '',
365
            code: '',
397
            code: '',
366
            consentInOpac: false,
398
            consentInOpac: false,
367
            consentInStaff: false
399
            consentInStaff: false
Lines 439-456 $( document ).ready( function () { Link Here
439
                '_' + Math.random().toString(36).substr(2, 9);
471
                '_' + Math.random().toString(36).substr(2, 9);
440
            const name = $(this).find('.metaName').val();
472
            const name = $(this).find('.metaName').val();
441
            const desc = $(this).find('.metaDescription').val();
473
            const desc = $(this).find('.metaDescription').val();
474
            const matchPattern = $(this).find('.metaMatchPattern').val();
442
            const opacConsent = $(this).find('.opacConsent').is(':checked')
475
            const opacConsent = $(this).find('.opacConsent').is(':checked')
443
            const staffConsent = $(this).find('.staffConsent').is(':checked');
476
            const staffConsent = $(this).find('.staffConsent').is(':checked');
444
            const code = $(this).find('.preference-code').val();
477
            const code = $(this).find('.preference-code').val();
445
            // If the name, description and code are empty, then they've
478
            // If the name, description, match pattern code are empty, then they've
446
            // added a new entry, but not filled it in, we can skip it
479
            // added a new entry, but not filled it in, we can skip it
447
            if (name.length === 0 && desc.length === 0 && code.length === 0) {
480
            if (
481
                name.length === 0 &&
482
                desc.length === 0 &&
483
                matchPattern.length === 0 &&
484
                code.length === 0
485
            ) {
448
                return;
486
                return;
449
            }
487
            }
450
            // They've filled in at least some info
488
            // They've filled in at least some info
451
            if (
489
            if (
452
                (name.length === 0) ||
490
                (name.length === 0) ||
453
                (desc.length === 0) ||
491
                (desc.length === 0) ||
492
                (matchPattern.length === 0) ||
454
                (code.length === 0)
493
                (code.length === 0)
455
            ) {
494
            ) {
456
                invalid.push(this);
495
                invalid.push(this);
Lines 459-464 $( document ).ready( function () { Link Here
459
                    id: id,
498
                    id: id,
460
                    name: name,
499
                    name: name,
461
                    description: desc,
500
                    description: desc,
501
                    matchPattern: matchPattern,
462
                    opacConsent: opacConsent,
502
                    opacConsent: opacConsent,
463
                    staffConsent: staffConsent,
503
                    staffConsent: staffConsent,
464
                    code: btoa(code)
504
                    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