evolutiontools.sk evolutiontools.cz
1 / 3
Error executing template "CookieWarning/Cookies.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_0fab1afcb5e642fe981e993a161ebcd8.Execute() in C:\inetpub\wwwroot\AllMedia\Production\Files\Templates\CookieWarning\Cookies.cshtml:line 11
   at RazorEngine.Templating.TemplateBase.RazorEngine.Templating.ITemplate.Run(ExecuteContext context, TextWriter reader)
   at RazorEngine.Templating.RazorEngineService.RunCompile(ITemplateKey key, TextWriter writer, Type modelType, Object model, DynamicViewBag viewBag)
   at RazorEngine.Templating.RazorEngineServiceExtensions.<>c__DisplayClass16_0.<RunCompile>b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.RazorTemplateRenderingProvider.Render(Template template)
   at Dynamicweb.Rendering.TemplateRenderingService.Render(Template template)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits Dynamicweb.Rendering.RazorTemplateBase<Dynamicweb.Rendering.RazorTemplateModel<Dynamicweb.Rendering.Template>> 2 @using Dynamicweb.Environment; 3 4 @{ 5 var categories = CookieManager.GetCategories(); 6 //set functional Category 7 CookieManager.AddCategory("Functional"); 8 var optInCategories = CookieManager.GetCookieOptInCategories(); 9 bool hasSelection = optInCategories.Any(); 10 11 string cookieNoticeLink = Pageview.AreaSettings.GetLink("CookiePolicyLink") != null ? Pageview.AreaSettings.GetLink("CookiePolicyLink").Url : ""; 12 string privacyPolicyLink = Pageview.AreaSettings.GetLink("PrivacyPolicyLink") != null ? Pageview.AreaSettings.GetLink("PrivacyPolicyLink").Url : ""; 13 int cookieNoticePageID = Pageview.AreaSettings.GetLink("CookiePolicyLink") != null ? Pageview.AreaSettings.GetLink("CookiePolicyLink").PageId : 0; 14 int privacyPolicyPageID = Pageview.AreaSettings.GetLink("PrivacyPolicyLink") != null ? Pageview.AreaSettings.GetLink("PrivacyPolicyLink").PageId : 0; 15 int cookieDetailsPageID = GetPageIdByNavigationTag("CookieDetails"); 16 string cookieDetailsLink = "/Default.aspx?ID=" + cookieDetailsPageID; 17 string googleTagManagerID = Pageview.AreaSettings.GetString("GoogleTagManagerID"); 18 19 string layout = Pageview.AreaSettings.GetRawValueString("CookieLayout", "modal"); 20 21 layout = Pageview.Page.ID == cookieNoticePageID || Pageview.Page.ID == privacyPolicyPageID ? "both" : layout; 22 string visibility = optInCategories.Any() ? "d-none" : ""; 23 24 var uri = Dynamicweb.Context.Current.Request.Url; 25 var hostname = uri.Scheme + Uri.SchemeDelimiter + uri.Host; 26 var cookieDetailsID = GetPageIdByNavigationTag("CookieDetails").ToString(); 27 var friendlyUrl = $"{hostname}/Default.aspx?ID={cookieDetailsID}"; 28 var cookieUrl = Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(friendlyUrl); 29 30 31 } 32 33 @if (!Pageview.IsVisualEditorMode) { 34 if (layout == "banner" || layout == "both") 35 { 36 string bannerTheme = !string.IsNullOrWhiteSpace(Pageview.AreaSettings.GetRawValueString("CookieBannerTheme")) ? " theme " + Pageview.AreaSettings.GetRawValueString("CookieBannerTheme").Replace(" ", "").Trim().ToLower() : "theme light"; 37 38 <div class="position-fixed bottom-0 w-100 shadow @bannerTheme @visibility" id="dwCookieBanner"> 39 <div class="align-items-center grid p-3"> 40 @if (layout == "banner") 41 { 42 <div class="g-col-12 g-col-md-6 g-col-lg-8"> 43 <span>@Translate("By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing")</span> 44 </div> 45 <div class="g-col-12 g-col-md-6 g-col-lg-4"> 46 <div class="grid grid-1 grid-sm-2"> 47 <button type="button" onclick="setOptInCookie(2)" class="btn btn-primary" id="CookiesAcceptAll"> 48 @Translate("Accept all") 49 </button> 50 <button type="button" onclick="setOptInCookie(1)" class="btn btn-secondary" id="CookiesDeclineAll"> 51 @Translate("Decline") 52 </button> 53 </div> 54 </div> 55 } 56 @if (layout == "both") 57 { 58 <div class="g-col-12 g-col-lg-6 g-col-xxl-8"> 59 <span>@Translate("By clicking 'Accept All' you consent that we may collect information about you for various purposes, including: Statistics and Marketing")</span> 60 </div> 61 <div class="g-col-12 g-col-lg-6 g-col-xxl-4"> 62 <div class="grid grid-1 grid-sm-3"> 63 <button type="button" class="btn btn-link" data-bs-toggle="modal" data-bs-target="#dwCookieModal"> 64 @Translate("Customize settings") 65 </button> 66 <button type="button" onclick="setOptInCookie(2)" class="btn btn-secondary" id="CookiesAcceptAll"> 67 @Translate("Accept all") 68 </button> 69 <button type="button" onclick="setOptInCookie(1)" class="btn btn-secondary" id="CookiesDeclineAll"> 70 @Translate("Decline") 71 </button> 72 </div> 73 </div> 74 } 75 </div> 76 </div> 77 } 78 79 if (layout == "modal" || layout == "both") 80 { 81 string modalTheme = !string.IsNullOrWhiteSpace(Pageview.AreaSettings.GetRawValueString("CookieModalTheme")) ? " theme " + Pageview.AreaSettings.GetRawValueString("CookieModalTheme").Replace(" ", "").Trim().ToLower() : "theme light"; 82 83 <div class="modal fade @visibility" id="dwCookieModal"> 84 <div class="modal-dialog modal-dialog-centered modal-dialog-scrollable" style="max-width:560px;"> 85 <div class="modal-content @modalTheme"> 86 <div class="modal-header"> 87 <button type="button" class="btn-close close-cookie-modal-button" data-bs-dismiss="modal" aria-label="Close">X</button> 88 </div> 89 <div style="overflow-y:auto;overflow-x:hidden"> 90 <div class="p-3 p-md-4 overflow-auto" style="max-height:50vh;"> 91 <div class="h3 mb-3">@Translate("You control your data")</div> 92 <p>@Translate("We and our partners use technologies, including cookies, to collect information about you for various purposes, including"):</p> 93 <ol> 94 <li>@Translate("Functionality")</li> 95 <li>@Translate("Statistics")</li> 96 <li>@Translate("Marketing")</li> 97 </ol> 98 <p>@Translate("By clicking 'Accept All' you consent to all these purposes. You can also choose to indicate what purposes you will consent to using the custom selections and then click 'Accept selected'").</p> 99 100 @if (!string.IsNullOrEmpty(cookieNoticeLink) || !string.IsNullOrEmpty(privacyPolicyLink)) 101 { 102 <p>@Translate("You can read more about our use of cookies and other technologies, as well as our collection and processing of personal data by clicking here"):</p> 103 } 104 105 106 <a href="@cookieUrl" class="d-block mb-3" id="CookiesReadModeAbout">@Translate("Read more about Cookies")</a> 107 108 109 @if(cookieDetailsPageID > 0) 110 { 111 <a href="@cookieDetailsLink" class="d-block mb-3" id="CookiesDetails">@Translate("Cookie details")</a> 112 } 113 114 @if (!string.IsNullOrEmpty(privacyPolicyLink)) 115 { 116 <a href="@privacyPolicyLink" class="d-block" id="CookiesPrivacyPolicy">@Translate("Our privacy policy")</a> 117 } 118 119 120 121 122 </div> 123 124 <div class="p-3 px-md-4 border-top"> 125 <div class="grid grid-1 grid-sm-2 gap-3"> 126 <button type="button" onclick="setOptInCookie(1)" class="btn btn-secondary" data-bs-dismiss="modal" id="dwCookieDeclineAll">@Translate("Decline")</button> 127 @if (categories.Any()) 128 { 129 <button type="button" onclick="acceptCustomSetup()" class="btn btn-secondary d-none" data-bs-dismiss="modal" id="dwCookieAcceptSelected">@Translate("Accept selected")</button> 130 } 131 <button type="button" onclick="setOptInCookie(2)" class="btn btn-secondary" data-bs-dismiss="modal" id="dwCookieAcceptAll">@Translate("Accept All")</button> 132 </div> 133 </div> 134 135 @if (categories.Any()) 136 { 137 int categoriesCount = 0; 138 int totalCategories = categories.Count(); 139 140 <form id="dwCookieModalCustomForm" class="12345" method="post" action="/Admin/Public/CookieOptInLevelConfig.aspx"> 141 <input type="hidden" name="cmd" value="SetCookieOptInLevel"> 142 <input type="hidden" name="OptInLevel" id="OptInLevel" value="1"> 143 <div class="grid grid-2 grid-sm-4 gap-0 px-md-3 border-top border-1"> 144 <div class="p-3"> 145 <label class="form-check-label" for="dwCookieNecessary"><span>@Translate("Necessary")</span></label> 146 <div class="form-check form-switch form-control-lg py-0"> 147 <input class="form-check-input opacity-100" type="checkbox" id="dwCookieNecessary" checked disabled style="background-color: rgba(0,0,0,0.1);"> 148 </div> 149 </div> 150 @foreach (var category in categories.Where(x => x != "Functional")) 151 { 152 string border = categoriesCount < (totalCategories - 1) ? "" : ""; 153 string optionChecked = optInCategories.Contains(category) || CookieManager.GetCookieOptInLevel() == CookieOptInLevel.All ? "checked" : ""; 154 155 <div class="p-3 @(border)"> 156 <label class="form-check-label" for="CookieCategory_@category"><span>@Translate(category)</span></label> 157 <div class="form-check form-switch form-control-lg py-0"> 158 <input class="form-check-input js-checkbox" type="checkbox" name="OptInCategory" value="@category" id="CookieCategory_@category" onchange="toggleAcceptSelected()" style="background-color: rgba(0,0,0,0.1);" @optionChecked> 159 </div> 160 </div> 161 categoriesCount++; 162 } 163 </div> 164 </form> 165 } 166 </div> 167 </div> 168 </div> 169 </div> 170 } 171 172 <script> 173 async function setOptInCookie(optInLevel) { 174 let response = await fetch("/admin/public/CookieOptInLevelConfig.aspx?cmd=SetCookieOptInLevel&OptInLevel=" + optInLevel + "&OptInCategory=Functional"); 175 @if (!string.IsNullOrWhiteSpace(googleTagManagerID)){ 176 <text> 177 if (optInLevel == '2') { 178 consentGrantedAll(); 179 window.dataLayer.push({ 180 'event': 'cookie_cat_functional', 181 'cookie_cat_functional': 'true' 182 }); 183 window.dataLayer.push({ 184 'event': 'cookie_cat_marketing', 185 'cookie_cat_marketing' : 'true' 186 }); 187 window.dataLayer.push({ 188 'event': 'cookie_cat_statistic', 189 'cookie_cat_statistic' : 'true' 190 }); 191 } else { 192 // Push a custom event to the Data Layer 193 window.dataLayer = window.dataLayer || []; 194 window.dataLayer.push({ 195 'event': 'cookie_cat_functional', 196 'cookie_cat_functional': 'true' 197 }); 198 window.dataLayer.push({ 199 'event': 'cookie_cat_marketing', 200 'cookie_cat_marketing' : 'false' 201 }); 202 window.dataLayer.push({ 203 'event': 'cookie_cat_statistic', 204 'cookie_cat_statistic' : 'false' 205 }); 206 } 207 </text> 208 } 209 210 if (response.ok) { 211 if (document.querySelector("#dwCookieBanner")) { 212 document.querySelector("#dwCookieBanner").classList.add("d-none"); 213 } 214 document.location.reload(); 215 return false; 216 } else { 217 return false; 218 } 219 } 220 221 async function acceptCustomSetup() { 222 var form = document.querySelector("#dwCookieModalCustomForm"); 223 224 let formData = new FormData(form); 225 var fetchOptions = { 226 method: 'POST', 227 body: formData 228 }; 229 230 for (const value of formData.values()) { 231 console.log(value); 232 if (value == 'Marketing') { 233 //console.log('Granting marketing cookies') 234 consentGrantedMarketing(); 235 } 236 if (value == 'Statistical') { 237 //console.log('Granting statistical cookies') 238 consentGrantedAnalyticsStorage(); 239 240 } 241 } 242 243 244 let response = await fetch(form.action, fetchOptions); 245 246 console.log('response', response); 247 248 if (response.ok) { 249 if (document.querySelector("#dwCookieBanner")) { 250 document.querySelector("#dwCookieBanner").classList.add("d-none"); 251 } 252 document.location.reload(); 253 return false; 254 } else { 255 return false; 256 } 257 } 258 259 260 function consentGrantedAll() { 261 consentGrantedMarketing(); 262 consentGrantedAnalyticsStorage(); 263 //var cookieCategoriesElement = document.querySelector("#dwCookieModalCustomForm"); 264 //cookieCategoriesElement.querySelectorAll(".js-checkbox").forEach(function (field) { 265 //field.checked == true; 266 //}); 267 } 268 269 function consentGrantedMarketing() { 270 consentGrantedAdStorage(); 271 consentGrantedAdUserData(); 272 consentGrantedAdPersonalization(); 273 // Push a custom event to the Data Layer 274 window.dataLayer = window.dataLayer || []; 275 window.dataLayer.push({ 276 'event': 'cookie_cat_marketing', 277 'ad_storage': 'granted', 278 'cookie_cat_marketing' : 'true' 279 }); 280 } 281 282 function consentGrantedAdStorage() { 283 if (!window.dataLayer) return; 284 gtag('consent', 'update', { 285 'ad_storage': 'granted' 286 }); 287 288 } 289 290 function consentGrantedAdUserData() { 291 if (!window.dataLayer) return; 292 gtag('consent', 'update', { 293 'ad_user_data': 'granted' 294 }); 295 296 } 297 298 function consentGrantedAdPersonalization() { 299 if (!window.dataLayer) return; 300 gtag('consent', 'update', { 301 'ad_personalization': 'granted' 302 }); 303 304 } 305 306 function consentGrantedAnalyticsStorage() { 307 if (!window.dataLayer) return; 308 gtag('consent', 'update', { 309 'analytics_storage': 'granted' 310 }); 311 // Push a custom event to the Data Layer 312 window.dataLayer = window.dataLayer || []; 313 window.dataLayer.push({ 314 'event': 'cookie_cat_statistic', 315 'ad_storage': 'granted', 316 'cookie_cat_statistic' : 'true' 317 }); 318 319 } 320 321 function toggleAcceptSelected() { 322 var cookieCalegoriesElement = document.querySelector("#dwCookieModalCustomForm"); 323 var enableAcceptSelected = false; 324 325 cookieCalegoriesElement.querySelectorAll(".js-checkbox").forEach(function (field) { 326 if (field.checked == true) { 327 enableAcceptSelected = true; 328 } 329 }); 330 331 if (enableAcceptSelected) { 332 document.querySelector("#dwCookieDeclineAll").classList.add("d-none"); 333 document.querySelector("#dwCookieAcceptSelected").classList.remove("d-none"); 334 } else { 335 document.querySelector("#dwCookieDeclineAll").classList.remove("d-none"); 336 document.querySelector("#dwCookieAcceptSelected").classList.add("d-none"); 337 } 338 } 339 340 function showCookieModal() { 341 var cookieModal = new bootstrap.Modal(document.querySelector('#dwCookieModal'), { 342 backdrop: 'static' 343 }); 344 345 cookieModal.show(); 346 347 } 348 349 350 function renderCookieModal() { 351 const modal = document.getElementById('dwCookieModal'); 352 if(modal !== null) { 353 const checkboxes = modal.querySelectorAll('[name="OptInCategory"]'); 354 if(checkboxes.length) { checkboxes.forEach(function(checkbox) { checkbox.dispatchEvent(new Event('change')) }) } 355 modal.classList.remove('d-none'); 356 modal.classList.add('show-close-button'); 357 new bootstrap.Modal(modal , { backdrop: 'static' }).show(); 358 } 359 } 360 361 </script> 362 363 <style> 364 .close-cookie-modal-button { display: none } 365 .show-close-button .close-cookie-modal-button { display: block !important } 366 </style> 367 368 if (layout == "modal" && !hasSelection) 369 { 370 <script type="module"> 371 showCookieModal(); 372 </script> 373 } 374 } 375