{"version":3,"sources":["https:\/\/www.contempora.online\/admin\/tool\/gdpr_plus\/amd\/src\/policies-consent-manager.js"],"names":["DEFAULT_SETTINGS","POLICY_CHECKBOXES_SELECTOR","PoliciesConsentManager","alloptions","containerId","otheroptions","options","Object","assign","container","document","getElementById","querySelectorAll","forEach","element","action","dataset","ACTION_DISPATCHER","__acceptSelected","__rejectNonEssential","__acceptAll","addEventListener","bind","policyAgreed","open","showpopup","querySelector","classList","add","remove","event","emit","_cookie","status","acceptedCategories","rejectNonMandatory","forceAcceptance","policyAcceptance","policyElement","policyVersionKey","id","mandatoryPolicy","mandatory","accepted","checked","acceptance","push","policiesAcceptances","__getPoliciesAcceptance","__acceptPolicies","__setRemotePolicyAcceptance","dispatchEvent","Event","__resetPolicyUI","close","Repository","acceptPolicies","catch","displayException","policyAcceptanceFound","find","elem","policyid","value"],"mappings":"meA4BA,O,mtDAMMA,CAAAA,CAAgB,CAAG,E,CAEnBC,CAA0B,CAAG,oD,CAIdC,C,YACjB,YAA6B,YAAjBC,CAAiB,wDAAJ,EAAI,cAClBC,CAAAA,CADkB,CACcD,CADd,CAClBC,WADkB,CACFC,CADE,GACcF,CADd,kBAEzB,KAAKG,OAAL,CAAeC,MAAM,CAACC,MAAP,CAAcR,CAAd,CAAgCK,CAAhC,CAAf,CACA,KAAKI,SAAL,CAAiBC,QAAQ,CAACC,cAAT,CAAwBP,CAAxB,CAAjB,CAEA,KAAKK,SAAL,CAAeG,gBAAf,CAAgC,wBAAhC,EAA0DC,OAA1D,CAAkE,SAACC,CAAD,CAAa,IACrEC,CAAAA,CAAM,CAAGD,CAAO,CAACE,OAAR,CAAgBD,MAD4C,CAErEE,CAAiB,CAAG,CACtB,kBAAmB,CAAI,CAACC,gBADF,CAEtB,sBAAuB,CAAI,CAACC,oBAFN,CAGtB,aAAc,CAAI,CAACC,WAHG,CAFiD,CAO3EN,CAAO,CAACO,gBAAR,CAAyB,OAAzB,CAAkCJ,CAAiB,CAACF,CAAD,CAAjB,CAA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CAEf,SAAYI,CAFG,CAAnB,CAIAN,CAAgB,CAACS,IAAjB,CAAsBD,CAAtB,CACH,CAdL,EAgBA,MAAOR,CAAAA,CACV,C,2DAEkB,CACf,GAAMU,CAAAA,CAAmB,CAAG,KAAKC,uBAAL,OAA5B,CACA,KAAKC,gBAAL,CAAsBF,CAAtB,CACH,C,mEAEsB,CACnB,GAAMA,CAAAA,CAAmB,CAAG,KAAKC,uBAAL,OAA5B,CACA,KAAKC,gBAAL,CAAsBF,CAAtB,CACH,C,iDAEa,CACV,GAAMA,CAAAA,CAAmB,CAAG,KAAKC,uBAAL,OAA5B,CACA,KAAKC,gBAAL,CAAsBF,CAAtB,CACH,C,0DAEgBA,C,CAAqB,CAElC,KAAKG,2BAAL,CAAiCH,CAAjC,EACArC,QAAQ,CAACyC,aAAT,CAAuB,GAAIC,CAAAA,KAAJ,0BAAvB,CAA6CL,CAA7C,EACA,KAAKM,eAAL,CAAqBN,CAArB,EAEA,KAAKO,KAAL,EACH,C,gFAE2BP,C,CAAqB,CAC7CQ,CAAU,CAACC,cAAX,CAA0BT,CAA1B,EAA+CU,KAA\/C,CAAqDC,WAArD,CACH,C,wDAEeX,C,CAAqB,CACjC,KAAKtC,SAAL,CAAeG,gBAAf,CAAgCX,CAAhC,EAA4DY,OAA5D,CACI,SAACyB,CAAD,CAAmB,CACf,GAAMqB,CAAAA,CAAqB,CAAGZ,CAAmB,EAAIA,CAAmB,CAACa,IAApB,CACjD,SAACC,CAAD,QAAUA,CAAAA,CAAI,CAACC,QAAL,EAAiBxB,CAAa,CAACtB,OAAd,CAAsBwB,EAAjD,CADiD,CAArD,CAGA,GAAImB,CAAJ,CAA2B,CACvBrB,CAAa,CAACyB,KAAd,CAAsBzB,CAAa,CAACM,OAAd,CAAwBe,CAAqB,CAAChB,QACvE,CACJ,CARL,CAUH,C","sourcesContent":["\/\/ This file is part of Moodle - http:\/\/moodle.org\/\n\/\/\n\/\/ Moodle is free software: you can redistribute it and\/or modify\n\/\/ it under the terms of the GNU General Public License as published by\n\/\/ the Free Software Foundation, either version 3 of the License, or\n\/\/ (at your option) any later version.\n\/\/\n\/\/ Moodle is distributed in the hope that it will be useful,\n\/\/ but WITHOUT ANY WARRANTY; without even the implied warranty of\n\/\/ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the\n\/\/ GNU General Public License for more details.\n\/\/\n\/\/ You should have received a copy of the GNU General Public License\n\/\/ along with Moodle. If not, see .\n\n\/**\n * Policies consent\n *\n * Derived from https:\/\/github.com\/klaxit\/cookie-consent\n * version 0.3.4\n *\n * @module tool_gdpr_plus\/src\/policies-consent-manager\n * @class PoliciesConsentManager\n * @package tool_gdpr_plus\n * @copyright 2021 - CALL Learning - Laurent David \n * @license http:\/\/www.gnu.org\/copyleft\/gpl.html GNU GPL v3 or later\n *\/\n\nimport * as Repository from '.\/repository';\nimport {exception as displayException} from 'core\/notification';\n\n\/**\n * Defaut settings for the constructor\n *\/\nconst DEFAULT_SETTINGS = {};\n\nconst POLICY_CHECKBOXES_SELECTOR = \".policies-settings-container input.policy-checkbox\";\n\/**\n * Policy Consent Manager class\n *\/\nexport default class PoliciesConsentManager {\n constructor(alloptions = {}) {\n const {containerId, ...otheroptions} = alloptions;\n this.options = Object.assign(DEFAULT_SETTINGS, otheroptions);\n this.container = document.getElementById(containerId);\n\n this.container.querySelectorAll('.tool_gdpr_plus_action').forEach((element) => {\n const action = element.dataset.action;\n const ACTION_DISPATCHER = {\n \"accept-selected\": this.__acceptSelected,\n \"reject-nonessential\": this.__rejectNonEssential,\n \"accept-all\": this.__acceptAll\n };\n element.addEventListener(\"click\", ACTION_DISPATCHER[action].bind(this));\n });\n if (!this.options.policyAgreed) {\n this.open();\n }\n const showpopup = this.container.querySelector(\".show-popup\");\n showpopup.addEventListener(\"click\", this.open.bind(this));\n }\n\n open() {\n this.container.querySelector('.policy-container').classList.add(\"displayed\");\n }\n\n close() {\n this.container.querySelector('.policy-container').classList.remove(\"displayed\");\n }\n\n emit(event) {\n super.emit(event, this);\n }\n\n emitConsentChanged() {\n this.emit(\"user_cookie_consent_changed\", {\n 'consent': this._cookie.status,\n 'acceptedCategories': this._cookie.acceptedCategories\n });\n }\n\n __getPoliciesAcceptance(rejectNonMandatory, forceAcceptance) {\n const policyAcceptance = [];\n this.container.querySelectorAll(POLICY_CHECKBOXES_SELECTOR).forEach(\n (policyElement) => {\n const policyVersionKey = policyElement.dataset.id;\n const mandatoryPolicy = (policyElement.dataset.mandatory === '1');\n let accepted = mandatoryPolicy || policyElement.checked;\n if (rejectNonMandatory && !mandatoryPolicy) {\n accepted = false;\n }\n accepted = accepted || forceAcceptance;\n const acceptance = {\n 'policyversionid': policyVersionKey,\n 'accepted': accepted\n };\n policyAcceptance.push(acceptance);\n }\n );\n return policyAcceptance;\n }\n\n __acceptSelected() {\n const policiesAcceptances = this.__getPoliciesAcceptance(false, false);\n this.__acceptPolicies(policiesAcceptances);\n }\n\n __rejectNonEssential() {\n const policiesAcceptances = this.__getPoliciesAcceptance(true, false);\n this.__acceptPolicies(policiesAcceptances);\n }\n\n __acceptAll() {\n const policiesAcceptances = this.__getPoliciesAcceptance(false, true);\n this.__acceptPolicies(policiesAcceptances);\n }\n\n __acceptPolicies(policiesAcceptances) {\n const eventname = \"grpd_policies_accepted\";\n this.__setRemotePolicyAcceptance(policiesAcceptances);\n document.dispatchEvent(new Event(eventname), policiesAcceptances);\n this.__resetPolicyUI(policiesAcceptances);\n \/\/PolicyStorage.set(POLICY_ACCEPTED_KEY, true);\n this.close();\n }\n\n __setRemotePolicyAcceptance(policiesAcceptances) {\n Repository.acceptPolicies(policiesAcceptances).catch(displayException);\n }\n\n __resetPolicyUI(policiesAcceptances) {\n this.container.querySelectorAll(POLICY_CHECKBOXES_SELECTOR).forEach(\n (policyElement) => {\n const policyAcceptanceFound = policiesAcceptances && policiesAcceptances.find(\n (elem) => elem.policyid == policyElement.dataset.id\n );\n if (policyAcceptanceFound) {\n policyElement.value = policyElement.checked = policyAcceptanceFound.accepted;\n }\n }\n );\n }\n}\n"],"file":"policies-consent-manager.min.js"}