Skip to content

Commit

Permalink
Added OnConsentChanged
Browse files Browse the repository at this point in the history
- removed some console log
- added event consent changed (only for complete budle integration)
- added spaces after if operator
  • Loading branch information
giegi committed Sep 21, 2019
1 parent a058895 commit 74d3653
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 15 deletions.
1 change: 1 addition & 0 deletions src/complete.js
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@ function handleConsentResult(cmp, {vendorListVersion: listVersion} = {}, {create
cmp('showConsentTool');
} else {
log.debug('Consent found. Not showing consent tool');
cmp('setDataAlreadyStored');
}
}

Expand Down
22 changes: 15 additions & 7 deletions src/lib/cmp.js
Original file line number Diff line number Diff line change
Expand Up @@ -19,21 +19,24 @@ export default class Cmp {
this.processCommand.receiveMessage = this.receiveMessage;
this.commandQueue = [];
this.showStatus = { isBannerShowing:false, isModalShowing:false };

this.isConsentDataAlreadyStored = false;
}

commands = {
setDataAlreadyStored: () => {
this.isConsentDataAlreadyStored = true;
},
/**
* Get all publisher consent data from the data store.
*/
enablePurpose: (id, state) => {
if (id === "all") {
this.store.selectAllPurposes(state);
console.log("Set All Purposes to state " + state);
//console.log("Set All Purposes to state " + state);
} else if (id !== "" && id !== "all") {
if (typeof state === "boolean") {
this.store.selectPurpose(id, state);
console.log("Set Single Purpose (" + id + ") to state " + state);
//console.log("Set Single Purpose (" + id + ") to state " + state);
}
}
},
Expand Down Expand Up @@ -192,13 +195,13 @@ export default class Cmp {
//console.log("[CMP LOG] STORECHANGED - store passed object", _store)
//console.log("[CMP LOG] STORE VISIBILITY: " + _store.isModalShowing + " = " + _store.isBannerShowing);
//console.log("[CMP LOG] this.showStatus VISIBILITY: " + this.showStatus.isModalShowing + " = " + this.showStatus.isBannerShowing);
if(_store.isBannerShowing === false && this.showStatus.isBannerShowing === true) {
if (_store.isBannerShowing === false && this.showStatus.isBannerShowing === true) {
this.notify("isBannerHidden");
} else if(_store.isBannerShowing === true && this.showStatus.isBannerShowing === false) {
} else if (_store.isBannerShowing === true && this.showStatus.isBannerShowing === false) {
this.notify("isBannerShown");
} else if(_store.isModalShowing === true && this.showStatus.isModalShowing === false) {
} else if (_store.isModalShowing === true && this.showStatus.isModalShowing === false) {
this.notify("isModalShown");
} else if(_store.isModalShowing === false && this.showStatus.isModalShowing === true) {
} else if (_store.isModalShowing === false && this.showStatus.isModalShowing === true) {
this.notify("isModalHidden");
}
this.showStatus.isModalShowing = _store.isModalShowing;
Expand Down Expand Up @@ -308,7 +311,12 @@ export default class Cmp {

// Process any queued commands that were waiting for consent data
if (event === 'onSubmit') {
//console.log("[CMP LOG] consent already stored", this.isConsentDataAlreadyStored);
if(this.isConsentDataAlreadyStored === true) {
this.notify("onConsentChanged");
}
this.processCommandQueue();
}

};
}
16 changes: 8 additions & 8 deletions src/lib/store.js
Original file line number Diff line number Diff line change
Expand Up @@ -216,8 +216,8 @@ export default class Store {
// Update version of list to one we are using
vendorConsentData.vendorListVersion = vendorListVersion;
publisherConsentData.vendorListVersion = vendorListVersion;
console.log("Publisher Consent Data", publisherConsentData);
console.log("Custom Purposes", this.customPurposeList);
//console.log("Publisher Consent Data", publisherConsentData);
//console.log("Custom Purposes", this.customPurposeList);
publisherConsentData.created = publisherConsentData.created || now;
publisherConsentData.lastUpdated = now;

Expand Down Expand Up @@ -268,34 +268,34 @@ export default class Store {
selectAllVendors = (isSelected, purposeId) => {
const {vendors = []} = this.vendorList || {};
const operation = isSelected ? 'add' : 'delete';
console.log("VENDORS BEFORE", "PURPOSE", purposeId, "LIST", this.vendorConsentData.selectedVendorIds);
//console.log("VENDORS BEFORE", "PURPOSE", purposeId, "LIST", this.vendorConsentData.selectedVendorIds);
vendors.forEach(({id, purposeIds = []}) => {
// If a purposeId is supplied only toggle vendors that support that purpose
if (typeof purposeId !== 'number' || purposeIds.indexOf(purposeId) > -1) {
this.vendorConsentData.selectedVendorIds[operation](id);
}
});
console.log("VENDORS AFTER", "PURPOSE", purposeId, "LIST", this.vendorConsentData.selectedVendorIds);
//console.log("VENDORS AFTER", "PURPOSE", purposeId, "LIST", this.vendorConsentData.selectedVendorIds);
this.selectPurpose(purposeId, isSelected);
this.storeUpdate();
};
selectPurpose = (purposeId, isSelected) => {
const {selectedPurposeIds} = this.vendorConsentData;
console.log("BEFORE", this.vendorConsentData.selectedPurposeIds);
//console.log("BEFORE", this.vendorConsentData.selectedPurposeIds);
if (isSelected) {
selectedPurposeIds.add(purposeId);
} else {
selectedPurposeIds.delete(purposeId);
}
console.log("AFTER", this.vendorConsentData.selectedPurposeIds);
//console.log("AFTER", this.vendorConsentData.selectedPurposeIds);
this.storeUpdate();
};
selectAllPurposes = (isSelected) => {
const {purposes = []} = this.vendorList || {};
const operation = isSelected ? 'add' : 'delete';
console.log("BEFORE", this.vendorConsentData.selectedPurposeIds);
//console.log("BEFORE", this.vendorConsentData.selectedPurposeIds);
purposes.forEach(({id}) => this.vendorConsentData.selectedPurposeIds[operation](id));
console.log("AFTER", this.vendorConsentData.selectedPurposeIds);
//console.log("AFTER", this.vendorConsentData.selectedPurposeIds);
this.storeUpdate();
};
selectCustomPurpose = (purposeId, isSelected) => {
Expand Down

0 comments on commit 74d3653

Please sign in to comment.