SR Impact_Copy

My Downloads
addSticker

Cumulative Impact

Corrective Pairs Distributed

Corrective Pairs Distributed

5.5m

 

 Countries Reached

Countries Reached

43

 

 Increase in Productivity

Increase in Productivity

22-32%

 

 Economic Impact created

Economic Impact created

$1.2Bn

 

2018 Results

Corrective Pairs Distributed

Corrective Pairs Distributed

1.17m

 

Income Potential Released

Income Potential Released

$253Mn

 

Less than $4/day

Less than $4/day

78%

 

First Time Wearers

First Time Wearers

53%

School Children in Glasses

School Children in Glasses

176k

 People Screened Directly

People Screened Directly

291k

 

Garment Workers Screened

Garment Workers Screened

59k

 

Drivers Screened

Drivers Screened

20k

 

Partners

Partners

385

 

Error executing template "Designs/VisionSpring/Paragraph/StandardParagraphList.cshtml"
System.ArgumentOutOfRangeException: Index and length must refer to a location within the string.
Parameter name: length
   at System.String.Substring(Int32 startIndex, Int32 length)
   at CompiledRazorTemplates.Dynamic.RazorEngine_a7d3aee8ffb24dddad0a2e22ffe67382.Execute() in c:\Domains\Sites\qaredesign-drhoneydew.dw-demo.com\Files\Templates\Designs\VisionSpring\Paragraph\StandardParagraphList.cshtml:line 2144
   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.b__0(TextWriter writer)
   at RazorEngine.Templating.RazorEngineServiceExtensions.WithWriter(Action`1 withWriter)
   at Dynamicweb.Rendering.Template.RenderRazorTemplate()

1 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 2 @using Dynamicweb.Rendering 3 @using System.Web 4 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 5 @using System 6 @using Dynamicweb.Rendering 7 @using System.Collections.Generic 8 @using System.Linq 9 @using System.Runtime.InteropServices 10 @using Dna.Frontend.Forms 11 @using Dna.Frontend.UI 12 @using Dna.UrlServices 13 @using Dynamicweb.Content 14 @using Dynamicweb.Core 15 @using Lucene.Net.Util 16 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 17 @using Dynamicweb.Rendering 18 @using System 19 @using System.Collections.Generic 20 @using System.Collections.Specialized 21 @using System.IO 22 @using System.Linq 23 @using System.Web 24 @using Dna.Frontend.UI 25 @using Dna.UrlServices 26 @using Dna.Validation 27 @using Dynamicweb.Core 28 @functions{ 29 30 #region Css functions 31 32 public static string GetPalletColorNumber(int number = 0) 33 { 34 switch (number) 35 { 36 case 1: 37 return "#666666"; 38 case 2: 39 return "#333333"; 40 default: 41 return "#ffffff"; 42 } 43 } 44 45 public static string GetFontFamilyNumber(int number = 0) 46 { 47 switch (number) 48 { 49 case 1: 50 return "font-family: Arial, sans-serif;"; 51 default: 52 return "font-family: Helvetica, Arial, sans-serif;"; 53 } 54 } 55 56 public static string GetFontSize(int fontSize = 0) 57 { 58 return fontSize >= 0 ? string.Concat("font-size: ", fontSize, "px;") : "font-size: 14px"; 59 } 60 61 #endregion Css functions 62 63 #region Icon functions 64 65 public static string GetIcon(string cssPartialClass, string label = "", string position = "") 66 { 67 var icon = "<i class='fa " + cssPartialClass + "'></i>"; 68 var spacing = string.Empty; 69 70 if (!label.IsNullOrEmpty()) 71 { 72 spacing = "<text>&nbsp;</text>"; 73 } 74 75 if (cssPartialClass.IsNullOrEmpty()) return label; 76 if (position == IconPosition.Left.ToString() || position.IsNullOrEmpty()) 77 { 78 return icon + spacing + label; 79 } 80 return label + spacing + icon; 81 } 82 83 #endregion Icon functions 84 85 #region Url functions 86 87 public string GetCustomerCenterSortUrl(string field, string listType = "Order") 88 { 89 var paragraphId = Pageview.CurrentParagraph.ID.ToString(); 90 var sortDirectionParameter = "CCSort" + listType + paragraphId; 91 var sortFieldParameter = "CC" + listType + "ByField" + paragraphId; 92 var sortDirection = Sanitize.Parameter(sortDirectionParameter) == "Desc" || Sanitize.Parameter(sortFieldParameter) == field ? "Desc" : "Asc"; 93 94 if (field.IsNotNullOrEmpty()) 95 { 96 return "/Default.aspx?ID=" + Pageview.Page.ID + "&" + sortFieldParameter + "=" + field + "&" + sortDirectionParameter + "=" + sortDirection; 97 } 98 99 return string.Empty; 100 } 101 102 public string GetSortFieldParameter(string key, string field = "", string listType = "Order") 103 { 104 var paragraphId = Pageview.CurrentParagraph.ID.ToString(); 105 if (key.IsNullOrEmpty()) throw new NotSupportedException("'key' is a required field"); 106 107 switch (key) 108 { 109 case "name": 110 var parameter = "CC" + listType + "ByField" + paragraphId; 111 return Sanitize.Parameter(parameter); 112 case "value": 113 if (field.IsNullOrEmpty()) return "asc"; 114 var sortDirectionParameter = "CCSort" + listType + paragraphId; 115 var sortFieldParameter = "CC" + listType + "ByField" + paragraphId; 116 return Sanitize.Parameter(sortDirectionParameter) == "Desc" || Sanitize.Parameter(sortFieldParameter) == field ? "Desc" : "Asc"; 117 default: 118 throw new NotSupportedException(string.Format("The key '{0}' in not supported", key)); 119 } 120 } 121 122 #endregion Url functions 123 124 #region Address functions 125 126 public string GetAddressFormatted(string address, string address2, string city, string zip, string region, string country, bool getRegionName = false, bool getCountryName = false, bool addLineBreakBetweenAddressAndCity = false, string splitBetweenRegionAndCountry = " ") 127 { 128 var formattedAddress = address; 129 130 if (address2.IsNotNullOrEmpty()) 131 { 132 formattedAddress += " " + address2; 133 } 134 if (addLineBreakBetweenAddressAndCity && (city + region + country).IsNotNullOrEmpty()) 135 { 136 formattedAddress += "<br/>"; 137 } 138 if (city.IsNotNullOrEmpty()) 139 { 140 formattedAddress += " " + city + ", "; 141 } 142 if (zip.IsNotNullOrEmpty()) 143 { 144 formattedAddress += zip; 145 } 146 if (region.IsNotNullOrEmpty()) 147 { 148 int index1 = region.IndexOf(','); 149 if (index1 != -1) 150 { 151 region = region.Remove(index1, 1); 152 } 153 if (getRegionName && country.IsNotNullOrEmpty()) 154 { 155 var regionName = Dynamicweb.Ecommerce.Services.Countries.GetRegions(country).First(c => c.RegionCode == region).Name; 156 region = regionName.IsNotNullOrEmpty() ? regionName : region; 157 } 158 formattedAddress += " " + region; 159 } 160 161 if (country.IsNullOrEmpty()) 162 { 163 return formattedAddress; 164 } 165 166 formattedAddress += splitBetweenRegionAndCountry.IsNotNullOrEmpty() ? splitBetweenRegionAndCountry : " "; 167 if (getCountryName && country.IsNotNullOrEmpty()) 168 { 169 var countryName = Dynamicweb.Ecommerce.Services.Countries.GetCountry(country) != null ? Dynamicweb.Ecommerce.Services.Countries.GetCountry(country).Name : country; 170 country = countryName.IsNotNullOrEmpty() ? countryName : country; 171 } 172 formattedAddress += country; 173 174 return formattedAddress; 175 } 176 177 #endregion Address functions 178 179 #region Generic functions 180 181 private static int FormatInteger(object value) 182 { 183 int num; 184 if (value == null) 185 { 186 value = string.Empty; 187 } 188 return int.TryParse(value.ToString(), out num) ? num : 0; 189 } 190 191 public static string GetAttributes(Dictionary<string, string> attributes) 192 { 193 if (attributes == null || !attributes.Any()) 194 { 195 return string.Empty; 196 } 197 198 var attributesConcat = attributes.Aggregate(string.Empty, (current, attribute) => current + GetAttribute(attribute.Key, attribute.Value)); 199 200 return attributesConcat; 201 } 202 203 public static string GetAttribute(string attributeName, string attributeValue) 204 { 205 if (attributeValue.IsNullOrEmpty()) return string.Empty; 206 return " " + attributeName + "=\"" + attributeValue + "\""; 207 } 208 209 #endregion Generic functions 210 211 #region Files functions 212 213 const string ImagesListTitleKey = "title"; 214 const string ImagesListImageKey = "image"; 215 216 public List<Dictionary<string, string>> GetFilesInFolder(string defaultImage, string searchPattern, bool addDefaultImage = true) 217 { 218 var imagesList = new List<Dictionary<string, string>>(); 219 var mapPath = HttpContext.Current.Server.MapPath(defaultImage); 220 var folderServerPath = Path.GetDirectoryName(mapPath); 221 222 if (!Directory.Exists(folderServerPath)) return imagesList; 223 224 // Get Images from folder 225 const string temp = @"\"; 226 const string metafield = "title"; 227 var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(defaultImage); 228 var title = metadata != null && metadata.GetValue(metafield).IsNullOrEmpty() ? metadata.GetValue(metafield) : GetString("Ecom:Product.Name"); 229 var folderWebPath = defaultImage.Contains("/") ? defaultImage.Substring(0, defaultImage.LastIndexOf("/")) : defaultImage; 230 231 var dctImage = new Dictionary<string, string>(); 232 233 if (addDefaultImage && File.Exists(mapPath)) 234 { 235 dctImage.Add(ImagesListTitleKey, title); 236 dctImage.Add(ImagesListImageKey, defaultImage); 237 imagesList.Add(dctImage); 238 } 239 240 foreach (var file in Directory.GetFiles(folderServerPath, searchPattern)) 241 { 242 dctImage = new Dictionary<string, string>(); 243 var image = folderWebPath + "/" + file.Substring(file.LastIndexOf(temp, StringComparison.Ordinal) + 1, file.Length - file.LastIndexOf(temp, StringComparison.Ordinal) - 1); 244 metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(image); 245 title = metadata != null && metadata.GetValue(metafield).IsNullOrEmpty() ? metadata.GetValue(metafield) : GetString("Ecom:Product.Name"); 246 247 dctImage.Add(ImagesListTitleKey, title); 248 dctImage.Add(ImagesListImageKey, image); 249 imagesList.Add(dctImage); 250 } 251 252 return imagesList; 253 } 254 255 #endregion Files functions 256 }@inherits RazorTemplateBase<RazorTemplateModel<Template>> 257 @using System 258 @using Dynamicweb.Rendering 259 @using System.Collections.Generic 260 @using System.Linq 261 @using System.Text.RegularExpressions 262 @using Dna.Frontend 263 @using Dna.Frontend.Forms 264 @using Dna.Frontend.UI 265 @using Dynamicweb.Core 266 @using Dynamicweb.Forms 267 @functions 268 { 269 270 #region Form Field functions 271 272 public string GetWrapperStart(bool includeWrapper, FieldType fieldType, string htmlElement, bool isRequired = false, string fieldClass = "") 273 { 274 if (!includeWrapper || htmlElement.IsNullOrEmpty()) return string.Empty; 275 var cssClass = new List<string> {fieldType.ToString().ToLower(), fieldClass}; 276 if (isRequired) 277 { 278 cssClass.Add("mandatory"); 279 } 280 return "<" + htmlElement + " class='" + string.Join(" ", cssClass.ToArray()) + "'>"; 281 } 282 283 public string GetWrapperEnd(bool includeWrapper, string htmlElement) 284 { 285 return !includeWrapper ? string.Empty : "</" + htmlElement + ">"; 286 } 287 288 public string GetControlWithRequiredClass(bool isRequired, string control) 289 { 290 if (!isRequired) return control; 291 var regex = new Regex(Regex.Escape(" ")); 292 return regex.Replace(control, " required class=\"mandatory\" ", 1); 293 } 294 295 public static string GetAttributes(FieldSettings settings, bool returnFieldType = true) 296 { 297 var attributes = string.Empty; 298 if (returnFieldType) 299 { 300 var fieldType = string.Empty; 301 switch (settings.Type) 302 { 303 case FieldType.Select: 304 break; 305 case FieldType.Checkboxlist: 306 fieldType = FieldType.Checkbox.ToString().ToLower(); 307 break; 308 case FieldType.DatetimeLocal: 309 fieldType = "datetime-local"; 310 break; 311 default: 312 fieldType = settings.Type.ToString().ToLower(); 313 break; 314 } 315 if (!settings.Attributes.ContainsKey("type")) 316 { 317 attributes += GetAttribute("type", fieldType); 318 } 319 } 320 attributes += GetAttribute("class", settings.CssClass); 321 attributes += GetAttribute("id", settings.Id); 322 attributes += GetAttribute("name", settings.SystemName); 323 attributes += GetAttribute("value", settings.Value); 324 if (settings.Type == FieldType.Email || settings.Type == FieldType.Password || settings.Type == FieldType.Search || settings.Type == FieldType.Tel || settings.Type == FieldType.Text || settings.Type == FieldType.Url) 325 { 326 // Only works wit these types 327 attributes += GetAttribute("placeholder", settings.Placeholder); 328 } 329 if (settings.Type != FieldType.Checkboxlist) 330 { 331 attributes += GetAttribute("required", settings.IsRequired); 332 } 333 attributes += GetAttributes(settings.Attributes); 334 return attributes; 335 } 336 337 public static string GetAttributes(FieldOption optionSettings) 338 { 339 var attributes = string.Empty; 340 attributes += GetAttribute("name", optionSettings.SystemName); 341 attributes += GetAttribute("value", optionSettings.Value); 342 attributes += GetAttributes(optionSettings.Attributes); 343 return attributes; 344 } 345 346 public static string GetAttribute(string attributeName, bool attributeValue) 347 { 348 if (!attributeValue) return string.Empty; 349 return " " + attributeName + "=\"" + attributeName + "\""; 350 } 351 352 #endregion 353 354 const string HighlightedCountriesSplit = "----------------"; 355 356 internal readonly List<string> HighlightedCountries = new List<string> 357 { 358 "US", 359 HighlightedCountriesSplit 360 }; 361 362 } 363 @{ 364 @* Form field helpers *@ 365 @helper RenderField(FieldSettings settings) 366 { 367 switch (settings.Type) 368 { 369 case FieldType.Button: 370 case FieldType.Reset: 371 case FieldType.Submit: 372 @RenderButtonField(settings) 373 break; 374 case FieldType.Checkbox: 375 @RenderCheckboxField(settings) 376 break; 377 case FieldType.Image: 378 @RenderImageField(settings) 379 break; 380 case FieldType.Checkboxlist: 381 case FieldType.Radio: 382 @RenderRadioOrCheckboxListField(settings) 383 break; 384 case FieldType.Select: 385 @RenderSelectField(settings) 386 break; 387 case FieldType.Color: 388 case FieldType.Date: 389 case FieldType.DatetimeLocal: 390 case FieldType.Email: 391 case FieldType.File: 392 case FieldType.Hidden: 393 case FieldType.Password: 394 case FieldType.Month: 395 case FieldType.Number: 396 case FieldType.Range: 397 case FieldType.Search: 398 case FieldType.Tel: 399 case FieldType.Text: 400 case FieldType.Time: 401 case FieldType.Url: 402 case FieldType.Week: 403 @RenderInputField(settings) 404 break; 405 case FieldType.Textarea: 406 @RenderTextareaField(settings) 407 break; 408 case FieldType.Textstring: 409 @RenderTextStringField(settings) 410 break; 411 case FieldType.Divider: 412 @RenderDividerField(settings) 413 break; 414 case FieldType.Datetime: 415 @RenderDateTimeField(settings) 416 break; 417 case FieldType.Unknown: 418 @:<div style="color: #f00">Undefined FieldType: <strong>@settings.Type</strong></div> 419 break; 420 default: 421 throw new NotSupportedException(string.Format("Unsupported Field Type: {0}.", settings.Type.ToString())); 422 } 423 } 424 425 @helper RenderCheckboxField(FieldSettings settings) 426 { 427 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 428 { 429 settings.Assert(FieldType.Checkbox); 430 431 @RenderFieldHeader(settings, false) 432 433 if (settings.Label.IsNotNullOrEmpty()) 434 { 435 var possibleClasses = new List<string> {settings.Type.ToString().ToLower(), settings.LabelCssClass}; 436 var cssClass = string.Join(" ", possibleClasses.Where(s => s.IsNotNullOrEmpty())); 437 438 @( "<" + "label class=" + cssClass + " " + GetAttribute("for", settings.Id) + ">") 439 if (settings.Control.IsNotNullOrEmpty()) 440 { 441 @settings.Control 442 } 443 else 444 { 445 @RenderHtmlField("input", settings) 446 } 447 <span> 448 @settings.Label 449 </span> 450 @( "<" + "/label" + ">") 451 } 452 else 453 { 454 if (settings.Control.IsNotNullOrEmpty()) 455 { 456 @settings.Control 457 } 458 else 459 { 460 @RenderHtmlField("input", settings) 461 } 462 } 463 464 @RenderFieldFooter(settings) 465 } 466 } 467 468 @helper RenderTextareaField(FieldSettings settings) 469 { 470 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 471 { 472 settings.Assert(FieldType.Textarea); 473 474 @RenderFieldHeader(settings) 475 476 if (settings.Control.IsNotNullOrEmpty()) 477 { 478 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 479 } 480 else 481 { 482 if (!settings.Attributes.ContainsKey("rows")) 483 { 484 settings.Attributes.Add("rows", "6"); 485 } 486 if (!settings.Attributes.ContainsKey("cols")) 487 { 488 settings.Attributes.Add("cols", "50"); 489 } 490 @RenderHtmlField("textarea", settings, false) 491 } 492 493 @RenderFieldFooter(settings) 494 } 495 } 496 497 @helper RenderRadioOrCheckboxListField(FieldSettings settings) 498 { 499 if (settings.LoopOptions.Any() || settings.FieldOptionsList.Any() || settings.Control.IsNotNullOrEmpty()) 500 { 501 var optionCount = 0; 502 503 settings.Assert(FieldType.Radio); 504 505 @RenderFieldHeader(settings) 506 507 if (settings.LoopOptions.Any()) 508 { 509 settings.CssClass = settings.Type.ToString().ToLower(); 510 foreach (var option in settings.LoopOptions) 511 { 512 optionCount++; 513 settings.Id = settings.SystemName + optionCount; 514 <label class="@settings.CssClass" for="@settings.Id"> 515 @RenderHtmlField("input", settings) 516 <span>@option.GetString(settings.LabelLoopTag)</span> 517 </label> 518 } 519 } 520 else if (settings.FieldOptionsList.Any()) 521 { 522 foreach (var option in settings.FieldOptionsList) 523 { 524 optionCount++; 525 option.Id = option.SystemName + optionCount; 526 option.CssClass = settings.Type.ToString().ToLower(); 527 528 <label class="@option.CssClass" for="@option.Id"> 529 @if (settings.Type == FieldType.Checkboxlist) 530 { 531 @RenderHtmlField("input", option, FieldType.Checkbox); 532 } 533 else 534 { 535 @RenderHtmlField("input", option, settings.Type) 536 } 537 <span>@option.Label</span> 538 </label> 539 } 540 } 541 else if (settings.Control.IsNotNullOrEmpty()) 542 { 543 @settings.Control 544 } 545 546 @RenderFieldFooter(settings) 547 } 548 } 549 550 @helper RenderInputField(FieldSettings settings) 551 { 552 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 553 { 554 settings.Assert(FieldType.Text); 555 556 @RenderFieldHeader(settings) 557 558 if (settings.Control.IsNotNullOrEmpty()) 559 { 560 var type = settings.Type.ToString().ToLower(); 561 if (settings.Type == FieldType.DatetimeLocal) 562 { 563 type = "datetime-local"; 564 } 565 566 settings.Control = settings.Control.Replace("type=\"text\"", "type=\"" + type + "\""); 567 if (settings.Type == FieldType.Password) 568 { 569 settings.Control = settings.Control.Replace("input ", "input autocomplete=\"off\" "); 570 } 571 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 572 } 573 else 574 { 575 if (settings.Type == FieldType.Password && !settings.Attributes.ContainsKey("autocomplete")) 576 { 577 settings.Attributes.Add("autocomplete", "off"); 578 } 579 @RenderHtmlField("input", settings) 580 } 581 582 @RenderFieldFooter(settings) 583 } 584 } 585 586 @helper RenderDateTimeField(FieldSettings settings) 587 { 588 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 589 { 590 settings.Assert(FieldType.Datetime); 591 settings.Attributes = new Dictionary<string, string> 592 { 593 {"placeholder", "&#xf073;"} 594 }; 595 596 @RenderFieldHeader(settings) 597 598 if (settings.Control.IsNotNullOrEmpty()) 599 { 600 var type = settings.Type.ToString().ToLower(); 601 602 settings.Control = settings.Control.Replace("type=\"text\"", "type=\"" + type + "\""); 603 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 604 } 605 else 606 { 607 @RenderHtmlField("input", settings) 608 } 609 610 @RenderFieldFooter(settings) 611 } 612 } 613 614 @helper RenderSelectField(FieldSettings settings) 615 { 616 const int limit = 10; 617 618 settings.Assert(FieldType.Select); 619 620 if (settings.CssClass.ToLower().Contains("country")) 621 { 622 @RenderCountriesDropdownField(settings, true, settings.CssClass.ToLower().Contains("highlights")) 623 } 624 else 625 { 626 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty() || settings.FieldOptionsList.Any() || settings.ValuesList.Any()) 627 { 628 @RenderFieldHeader(settings) 629 630 var optionsCount = 0; 631 if (settings.Control.IsNotNullOrEmpty()) 632 { 633 optionsCount = Regex.Matches(settings.Control, "option ").Count; 634 635 if (optionsCount > limit) 636 { 637 settings.Control = settings.Control.Replace("select ", "select data-live-search=\"true\" "); 638 } 639 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 640 } 641 else 642 { 643 optionsCount = settings.FieldOptionsList.Count + settings.ValuesList.Count; 644 645 if (!settings.Attributes.ContainsKey("multiple") && !settings.Attributes.ContainsKey("data-live-search") && optionsCount > limit) 646 { 647 settings.Attributes.Add("data-live-search", "true"); 648 } 649 @RenderHtmlField("select", settings) 650 651 if (settings.FirstHardcodedOptionLabel.IsNotNullOrEmpty()) 652 { 653 @RenderOption(FieldOption.CreateOption(settings.FirstHardcodedOptionLabel, settings.FirstHardcodedOptionValue, settings.IsFirstHardcodedOptionSelected)) 654 } 655 656 foreach (var option in settings.FieldOptionsList) 657 { 658 @RenderOption(option) 659 } 660 foreach (var option in settings.ValuesList) 661 { 662 @RenderOption(FieldOption.CreateOption(option, option)) 663 } 664 665 @* The <select> is started in the RenderHtmlField *@ 666 @:</select> 667 } 668 669 @RenderFieldFooter(settings) 670 } 671 } 672 } 673 674 @helper RenderButtonField(FieldSettings settings) 675 { 676 settings.Assert(FieldType.Button); 677 678 @RenderFieldHeader(settings, false) 679 680 if (settings.Control.IsNotNullOrEmpty()) 681 { 682 var controlOutput = settings.Control; 683 switch (settings.Type) 684 { 685 case FieldType.Submit: 686 controlOutput = controlOutput.Replace("input ", "input class='btn btn-default'"); 687 break; 688 case FieldType.Reset: 689 controlOutput = controlOutput.Replace("input ", "input class='btn btn-bg2'"); 690 break; 691 default: 692 throw new NotSupportedException(string.Format("Unsupported Field Type: {0}.", settings.Type.ToString())); 693 } 694 @controlOutput 695 } 696 else 697 { 698 settings.CssClass = settings.CssClass.IsNullOrEmpty() ? "btn btn-default" : "btn " + settings.CssClass; 699 if (settings.Type == FieldType.Button) 700 { 701 @RenderHtmlField("button", settings) 702 @settings.Label 703 @:</button> 704 } 705 else 706 { 707 @RenderHtmlField("input", settings) 708 } 709 } 710 711 @RenderFieldFooter(settings) 712 } 713 714 715 @* Forms for Editors field types in enum FieldType *@ 716 @helper RenderTextStringField(FieldSettings settings) 717 { 718 settings.Assert(FieldType.Textstring); 719 720 if (settings.Description.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 721 { 722 if (settings.Control.IsNotNullOrEmpty()) 723 { 724 @settings.Control 725 } 726 else 727 { 728 <p class="help-block">@settings.Description</p> 729 } 730 } 731 } 732 733 @helper RenderImageField(FieldSettings settings) 734 { 735 settings.Assert(FieldType.Image); 736 737 if (settings.Control.IsNotNullOrEmpty()) 738 { 739 @settings.Control 740 } 741 } 742 743 @helper RenderDividerField(FieldSettings settings) 744 { 745 settings.Assert(FieldType.Divider); 746 747 <hr class="divider" /> 748 } 749 750 751 @* Form field helper extras *@ 752 @helper RenderHtmlField(string htmlElement, FieldSettings settings, bool returnFieldType = true) 753 { 754 if (settings.IsChecked && !settings.Attributes.ContainsKey("checked")) 755 { 756 settings.Attributes.Add("checked", "checked"); 757 } 758 759 // NOTE: Include files do not process html elements properly. The fix is to split '<' char from the html element 760 switch (htmlElement) 761 { 762 case "textarea": 763 @( "<" + htmlElement + GetAttributes(settings, false) + "></" + htmlElement + ">") 764 break; 765 case "select": 766 @( "<" + htmlElement + GetAttributes(settings, false) + ">") 767 break; 768 case "button": 769 @( "<" + htmlElement + GetAttributes(settings) + ">") 770 break; 771 default: 772 @( "<" + htmlElement + GetAttributes(settings, returnFieldType) + "/>") 773 break; 774 } 775 } 776 777 @helper RenderHtmlField(string htmlElement, FieldOption optionSettings, FieldType type = FieldType.Radio) 778 { 779 var attributes = GetAttribute("type", type.ToString().ToLower()); 780 attributes += GetAttribute("value", optionSettings.Value); 781 attributes += GetAttribute("name", optionSettings.SystemName); 782 attributes += optionSettings.Id.IsNotNullOrEmpty() ? GetAttribute("id", optionSettings.Id) : ""; 783 attributes += GetAttributes(optionSettings.Attributes); 784 785 if (optionSettings.IsSelected) 786 { 787 attributes += GetAttribute("checked", "checked"); 788 } 789 if (optionSettings.IsDisabled) 790 { 791 attributes += GetAttribute("disabled", "disabled"); 792 } 793 794 @( "<" + htmlElement + attributes + ">") 795 } 796 797 @helper RenderOption(FieldOption optionSettings) 798 { 799 var selected = optionSettings.IsSelected ? " selected" : string.Empty; 800 var disabled = optionSettings.IsDisabled ? " disabled" : string.Empty; 801 var readOnly = optionSettings.IsReadOnly ? " readonly" : string.Empty; 802 var attributes = GetAttributes(optionSettings); 803 804 @( string.Concat("<", "option ", attributes, selected, disabled, readOnly, ">", optionSettings.Label, "</", "option", ">")) 805 } 806 807 @helper RenderFieldHeader(FieldSettings settings, bool renderLabel = true) 808 { 809 @GetWrapperStart(settings.IncludeWrapper, settings.Type, settings.WrapperElement, settings.IsRequired, settings.WrapperCssClass) 810 if (settings.Label.IsNotNullOrEmpty() && renderLabel) 811 { 812 if (settings.Type == FieldType.Checkboxlist || settings.Type == FieldType.Radio) 813 { 814 <label class="form-label @settings.LabelCssClass">@settings.Label</label> 815 } 816 else 817 { 818 <label for="@settings.SystemName" class="form-label @settings.LabelCssClass">@settings.Label</label> 819 } 820 821 } 822 if (settings.Prepend.IsNotNullOrEmpty()) 823 { 824 <div class="fieldPrepend input-group-addon">@settings.Prepend</div> 825 } 826 if (settings.IncludeFieldWrapper) 827 { 828 @:<div class="fieldContainer hidden"> 829 } 830 } 831 832 @helper RenderFieldFooter(FieldSettings settings) 833 { 834 if (settings.Icon.IsNotNullOrEmpty()) 835 { 836 @RenderIcon(settings.Icon, settings.Tooltip, IconPosition.Left, true) 837 } 838 if (settings.Append.IsNotNullOrEmpty()) 839 { 840 <div class="fieldAppend input-group-addon">@settings.Append</div> 841 } 842 if (settings.Description.IsNotNullOrEmpty()) 843 { 844 <p class="help-block">@settings.Description</p> 845 } 846 if (settings.IncludeFieldWrapper) 847 { 848 @:</div> 849 } 850 @GetWrapperEnd(settings.IncludeWrapper, settings.WrapperElement) 851 } 852 853 @helper RenderQuantityField(int productStock, int selectedQuantity = 1, int productType = 0) 854 { 855 @RenderQuantityField(productStock, selectedQuantity, string.Empty, 10, false, false, productType) 856 } 857 858 @helper RenderQuantityField(int productStock, int selectedQuantity = 1, bool variantGroupsExistList = false) 859 { 860 @RenderQuantityField(productStock, selectedQuantity, string.Empty, 10, false, variantGroupsExistList) 861 } 862 863 @helper RenderQuantityField(int productStock, int selectedQuantity = 1, string fieldSystemName = "", int limit = 10, bool isCheckout = true, bool variantGroupsExistList = false, int productType = 0, string productId = "" , string variantText = "") 864 { 865 var isQuantityTextHidden = selectedQuantity < 10 && productStock > 0 || !isCheckout ? " hidden" : string.Empty; 866 var isSelectDisabled = productStock <= 0 && !isCheckout; 867 var quantityTextFieldSettings = new FieldSettings 868 { 869 Value = selectedQuantity.ToString(), 870 SystemName = fieldSystemName.IsNullOrEmpty() ? "quantity" : fieldSystemName, 871 Id = (fieldSystemName.IsNullOrEmpty() ? "quantity_" : fieldSystemName) + productId, 872 Attributes = new Dictionary<string, string> 873 { 874 {"maxlength", "5"}, 875 {"data-productStock", productStock.ToString()}, 876 {"data-outofstock", Translate("outOfStock", "Out of stock")}, 877 {"data-product-id" , productId}, 878 {"data-variant-text" , variantText}, 879 {"data-stocktranslate", Translate("currentStock", "The current stock is")} 880 } 881 }; 882 883 if (productType != 1 && productType != 3) 884 { 885 quantityTextFieldSettings.Type = FieldType.Number; 886 quantityTextFieldSettings.Label = Translate("qty", "Qty"); 887 quantityTextFieldSettings.CssClass = "col-xs-4 col-sm-7 quantityInput" + isQuantityTextHidden; 888 quantityTextFieldSettings.LabelCssClass = productStock > 0 ? "" : "hidden"; 889 890 <fieldset class="quantity-container pull-left"> 891 @if (isCheckout) 892 { 893 <div class="@isQuantityTextHidden quantityPriceContainer"> 894 @RenderInputField(quantityTextFieldSettings) 895 @RenderBootstrapButton(new BootstrapButtonSettings {IconCssClass = "fa-refresh", CssClass = "submitQuantity btnCart-blue", ButtonType = BootstrapButtonSettings.BootstrapButtonType.Button}) 896 </div> 897 } 898 else 899 { 900 @RenderInputField(quantityTextFieldSettings) 901 } 902 903 @if (selectedQuantity < limit) 904 { 905 var quantityOptionLimit = productStock <= 0 ? 10 : productStock < limit ? productStock : limit; 906 var quantityFieldSettings = new FieldSettings 907 { 908 Type = FieldType.Select, 909 SystemName = "quantitySelect", 910 Id = "quantitySelect" + productId 911 }; 912 if (isSelectDisabled) 913 { 914 quantityFieldSettings.Attributes.Add("disabled", "disabled"); 915 } 916 917 for (var num = 1; num < quantityOptionLimit; num++) 918 { 919 quantityFieldSettings.FieldOptionsList.Add(new FieldOption {Label = num.ToString(), Value = num.ToString(), IsSelected = selectedQuantity == num}); 920 } 921 if (productStock >= limit || variantGroupsExistList) 922 { 923 var limitPlus = limit + "+"; 924 quantityFieldSettings.FieldOptionsList.Add(new FieldOption {Label = limitPlus, Value = limitPlus}); 925 } 926 @RenderSelectField(quantityFieldSettings) 927 } 928 </fieldset> 929 } 930 else 931 { 932 quantityTextFieldSettings.Type = FieldType.Hidden; 933 @RenderInputField(quantityTextFieldSettings) 934 } 935 } 936 937 938 @* Countries and Regions helpers *@ 939 @helper RenderCountriesDropdownField(FieldSettings settings, bool renderJsVariables = true, bool renderHighlightOptions = true) 940 { 941 942 if (settings.SystemName.IsNotNullOrEmpty()) 943 { 944 const int limit = 10; 945 const int numOfCountriesForHighlight = 10; 946 var countries = EcommerceHelpers.GetEcomCountries(); 947 var numOfCountries = settings.LoopOptions.Any() ? settings.LoopOptions.Count : settings.ValuesList.Any() ? settings.ValuesList.Count : countries.Count; 948 949 settings.Assert(FieldType.Select); 950 if (settings.FirstHardcodedOptionLabel.IsNullOrEmpty()) 951 { 952 settings.FirstHardcodedOptionLabel = Translate("selectAnOption", "Select an option"); 953 } 954 if (!settings.Attributes.ContainsKey("multiple") && !settings.Attributes.ContainsKey("data-live-search") && numOfCountries > limit) 955 { 956 settings.Attributes.Add("data-live-search", "true"); 957 } 958 959 if (renderJsVariables) 960 { 961 @RenderCountryAndRegionsJsVariables(countries) 962 } 963 964 @RenderFieldHeader(settings) 965 @RenderHtmlField("select", settings) 966 @RenderOption(FieldOption.CreateOption(settings.FirstHardcodedOptionLabel, settings.FirstHardcodedOptionValue, settings.IsFirstHardcodedOptionSelected)) 967 968 if (numOfCountries > numOfCountriesForHighlight) 969 { 970 @RenderSnippet("highlightedContries") 971 } 972 973 if (settings.LoopOptions.Any()) 974 { 975 foreach (var country in settings.LoopOptions) 976 { 977 var countryName = country.GetString("Ecom:Country.Name"); 978 var countryCode = country.GetString("Ecom:Country.Code2"); 979 980 if (renderHighlightOptions && HighlightedCountries.Any(w => countryCode.Contains(w))) 981 { 982 @PopulateHighlightedCountries(countryName, countryCode) 983 } 984 985 @RenderOption(FieldOption.CreateOption(countryName, countryCode)) 986 } 987 } 988 else if (settings.ValuesList.Any()) 989 { 990 foreach (var countryCode in settings.ValuesList.OrderBy(s => s)) 991 { 992 var countryName = countries.Any(c => c.Code2 == countryCode) ? countries.First(c => c.Code2 == countryCode).Name : countryCode;; 993 994 if (renderHighlightOptions && HighlightedCountries.Any(w => countryCode.Contains(w))) 995 { 996 @PopulateHighlightedCountries(countryName, countryCode) //changed from country.Name to countryName 997 } 998 999 @RenderOption(FieldOption.CreateOption(countryName, countryCode)) //changed from country.Name to countryName 1000 } 1001 } 1002 else 1003 { 1004 foreach (var country in countries.OrderBy(s => s.Name)) 1005 { 1006 var countryCode = country.Code2; 1007 1008 if (renderHighlightOptions && HighlightedCountries.Any(w => countryCode.Contains(w))) 1009 { 1010 @PopulateHighlightedCountries(country.Name, countryCode) 1011 } 1012 @RenderOption(FieldOption.CreateOption(country.Name, countryCode)) 1013 } 1014 } 1015 1016 if (renderHighlightOptions && numOfCountries > numOfCountriesForHighlight && HighlightedCountries.Any(w => HighlightedCountriesSplit.Contains(w))) 1017 { 1018 @PopulateHighlightedCountries(HighlightedCountriesSplit, string.Empty, false, true) 1019 } 1020 1021 @* The <select> is started in the RenderHtmlField *@ 1022 @: </select> 1023 1024 @RenderFieldFooter(settings) 1025 } 1026 } 1027 1028 @helper PopulateHighlightedCountries(string label, string value, bool isSelected = false, bool isDisabled = false) 1029 { 1030 HighlightedCountries.Remove(value); 1031 if (value.IsNullOrEmpty()) 1032 { 1033 HighlightedCountries.Remove(label); 1034 } 1035 @SnippetStart("highlightedContries") 1036 @RenderOption(FieldOption.CreateOption(label, value, isSelected, isDisabled)) 1037 @SnippetEnd("highlightedContries") 1038 } 1039 1040 @helper RenderCountryAndRegionsJsVariables(Dynamicweb.Ecommerce.International.CountryCollection countries = null) 1041 { 1042 if (countries == null) 1043 { 1044 countries = Dynamicweb.Ecommerce.Services.Countries.GetCountries(); 1045 } 1046 1047 if (countries.Any()) 1048 { 1049 @: @SnippetStart("jsVariables") var countryRegions = {}; @SnippetEnd("jsVariables") 1050 1051 foreach (var country in countries.OrderBy(s => s.Name)) 1052 { 1053 var regions = Dynamicweb.Ecommerce.Services.Countries.GetRegions(country.Code2); 1054 1055 if (regions.Any()) 1056 { 1057 @: @SnippetStart("jsVariables") countryRegions.@( country.Code2) = {}; @SnippetEnd("jsVariables") 1058 <text> 1059 @SnippetStart("jsVariables") 1060 countryRegions.@( country.Code2).code = []; 1061 countryRegions.@( country.Code2).name = []; 1062 @SnippetEnd("jsVariables") 1063 </text> 1064 foreach (var region in regions.OrderBy(s => s.Name)) 1065 { 1066 <text> 1067 @SnippetStart("jsVariables") 1068 countryRegions["@country.Code2"].code.push("@region.RegionCode"); 1069 countryRegions["@country.Code2"].name.push("@region.Name"); 1070 @SnippetEnd("jsVariables") 1071 </text> 1072 } 1073 } 1074 } 1075 } 1076 } 1077 }@inherits RazorTemplateBase<RazorTemplateModel<Template>> 1078 @using System 1079 @using Dynamicweb.Rendering 1080 @using System.Collections.Generic 1081 @using System.Collections.Specialized 1082 @using System.Web 1083 @using Dna.Frontend.UI 1084 @using Dynamicweb.Core 1085 @using Dna.UrlServices 1086 1087 @helper RenderPaging() 1088 { 1089 @RenderPaging( 1090 GetInteger("Ecom:CustomerCenter.Paging.NumPages"), 1091 "CCPage", 1092 GetString("Ecom:CustomerCenter.Paging.Back.URL"), 1093 GetString("Ecom:CustomerCenter.Paging.Forward.URL"), 1094 GetInteger("Ecom:CustomerCenter.Paging.CurrentPage"), 1095 GetLoop("Ecom:CustomerCenter.Paging.Pages"), 1096 "Ecom:CustomerCenter.Paging.PageIndex" 1097 ) 1098 } 1099 1100 @helper RenderPaging(int numOfPages, string pageQueryParameter, int currentPage) 1101 { 1102 var queryParameters = HttpUtility.ParseQueryString(Dynamicweb.Context.Current.Request.Url.Query); 1103 var url = Helpers.GetCurrentUrl(true, true); 1104 var previousPageUrl = string.Empty; 1105 var nextPageUrl = string.Empty; 1106 1107 if (currentPage > 1) 1108 { 1109 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageQueryParameter, (currentPage - 1).ToString()); 1110 previousPageUrl = (string) Helpers.BuildUri(url, queryParameters).ToString(); 1111 } 1112 if (currentPage < numOfPages) 1113 { 1114 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageQueryParameter, (currentPage + 1).ToString()); 1115 nextPageUrl = (string) Helpers.BuildUri(url, queryParameters).ToString(); 1116 } 1117 1118 @RenderPaging(numOfPages, pageQueryParameter, previousPageUrl, nextPageUrl, currentPage) 1119 } 1120 1121 @helper RenderPaging(int numOfPages, string pageQueryParameter, string previousPageUrl, string nextPageUrl, int currentPage, List<LoopItem> pagesLoop = null, string pageNumTag = "", string pageHrefTag = "", bool includeWrapper = true) 1122 { 1123 if (numOfPages > 1) 1124 { 1125 @* NOTE: pageIndex needs to be a tag name, because it will be instanciated within the loop *@ 1126 @* NOTE: 1127 queryParamenter == "PageNum" --> Product Catalog module 1128 queryParamenter == "page" --> Item Publisher module 1129 queryParamenter == "CC*" --> Customer Center module 1130 queryParamenter == "DWPagingPageNum" --> Data List module 1131 *@ 1132 1133 var loopPageSize = 3; 1134 var startPage = 1; 1135 var endPage = numOfPages; 1136 1137 var pageQueryParameter2 = pageQueryParameter == "PageNum" || pageQueryParameter == "page" || pageQueryParameter == "DWPagingPageNum" ? string.Empty : Pageview.CurrentParagraph.ID.ToString(); 1138 var pageNumQueryParameter = pageQueryParameter + pageQueryParameter2; 1139 1140 var queryParameters = HttpUtility.ParseQueryString(Dynamicweb.Context.Current.Request.Url.Query); 1141 queryParameters.Remove(pageNumQueryParameter); 1142 queryParameters.Remove("pid"); 1143 1144 if (pageQueryParameter == "page") 1145 { 1146 queryParameters.Add("pid", Pageview.CurrentParagraph.ID.ToString()); 1147 } 1148 1149 if (pagesLoop != null) 1150 { 1151 loopPageSize = pagesLoop.Count; 1152 endPage = 1; 1153 } 1154 else 1155 { 1156 var pageOffset = Math.Floor(Convert.ToDecimal(loopPageSize / 2)); 1157 var middlePage = pageOffset + 1; 1158 1159 if (numOfPages > loopPageSize) 1160 { 1161 startPage = Convert.ToInt32(currentPage - pageOffset) < 1 ? 1 : Convert.ToInt32(currentPage - pageOffset); 1162 endPage = Convert.ToInt32(currentPage + pageOffset) > numOfPages ? numOfPages : Convert.ToInt32(currentPage + pageOffset); 1163 1164 if (currentPage < middlePage) 1165 { 1166 endPage = loopPageSize; 1167 } 1168 else if (currentPage >= middlePage) 1169 { 1170 if (numOfPages < currentPage + pageOffset) 1171 { 1172 startPage = numOfPages - loopPageSize; 1173 if (loopPageSize % 2 != 0) 1174 { 1175 startPage += 1; 1176 } 1177 } 1178 1179 if (loopPageSize % 2 == 0) 1180 { 1181 startPage += 1; 1182 } 1183 } 1184 } 1185 } 1186 1187 if (includeWrapper) 1188 { 1189 @:<div class="col-xs-12 text-center paginationContainer"> 1190 } 1191 <ul class="pagination"> 1192 @if (previousPageUrl.IsNotNullOrEmpty() && previousPageUrl != "#") 1193 { 1194 @RenderPageItem(previousPageUrl, Translate("Previous"), "fa-caret-left", IconPosition.Left) 1195 } 1196 @if (pagesLoop != null) 1197 { 1198 @RenderGoToFirstPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, pagesLoop[0].GetInteger(pageNumTag)) 1199 foreach (var page in pagesLoop) 1200 { 1201 var pageItemHref = pageQueryParameter == "PageNum" || pageQueryParameter == "page" ? page.GetString(pageHrefTag) : string.Empty; 1202 endPage = page.GetInteger(pageNumTag); 1203 1204 queryParameters.Remove(pageNumQueryParameter); 1205 1206 if (pageItemHref.IsNotNullOrEmpty()) 1207 { 1208 queryParameters.Add(pageNumQueryParameter, page.GetString(pageNumTag)); 1209 } 1210 @RenderPageItem(queryParameters, page.GetString(pageNumTag), page.GetInteger(pageNumTag) == currentPage ? "active" : string.Empty) 1211 1212 } 1213 @RenderGoToLastPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, endPage) 1214 } 1215 else 1216 { 1217 @RenderGoToFirstPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize) 1218 for (var page = startPage; page <= endPage; page++) 1219 { 1220 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageNumQueryParameter, page.ToString()); 1221 @RenderPageItem(queryParameters, page.ToString(), page == currentPage ? "active" : string.Empty) 1222 } 1223 @RenderGoToLastPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, endPage) 1224 } 1225 1226 @if (nextPageUrl.IsNotNullOrEmpty() && nextPageUrl != "#") 1227 { 1228 @RenderPageItem(nextPageUrl, Translate("Next"), "fa-caret-right", IconPosition.Right) 1229 } 1230 </ul> 1231 if (includeWrapper) 1232 { 1233 @:</div> 1234 } 1235 } 1236 } 1237 @helper RenderGoToFirstPage(NameValueCollection queryParameters, string pageNumQueryParameter, int currentPage, int numOfPages, int loopPageSize, int currentPageNum = 0) 1238 { 1239 if (currentPageNum == 0) 1240 { 1241 currentPageNum = currentPage; 1242 } 1243 1244 if (currentPage > 2 && numOfPages > loopPageSize && currentPageNum != 1) 1245 { 1246 queryParameters.Remove(pageNumQueryParameter); 1247 @RenderPageItem(queryParameters, "1") 1248 @RenderEllipsis() 1249 } 1250 } 1251 1252 @helper RenderGoToLastPage(NameValueCollection queryParameters, string pageNumQueryParameter, int currentPage, int numOfPages, int loopPageSize, int endPage) 1253 { 1254 if (currentPage < numOfPages - 1 && numOfPages > loopPageSize && endPage != numOfPages) 1255 { 1256 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageNumQueryParameter, numOfPages.ToString()); 1257 @RenderEllipsis() 1258 @RenderPageItem(queryParameters, numOfPages.ToString()) 1259 } 1260 } 1261 1262 @helper RenderPageItem(NameValueCollection queryParameters, string pageNum, string cssClass = "") 1263 { 1264 var url = Helpers.GetCurrentUrl(true, true); 1265 var href = Helpers.BuildUri(url, queryParameters); 1266 1267 <li class="@cssClass"> 1268 <a href="@href.PathAndQuery"> 1269 @pageNum 1270 </a> 1271 </li> 1272 } 1273 1274 @helper RenderPageItem(string href, string label, string cssPartialClass, IconPosition position) 1275 { 1276 <li> 1277 <a href="@href"> 1278 @RenderIcon(cssPartialClass, label, position) 1279 </a> 1280 </li> 1281 } 1282 1283 @helper RenderEllipsis() 1284 { 1285 <li> 1286 <span>...</span> 1287 </li> 1288 } 1289 1290 @{ 1291 @* Tables and list helpers *@ 1292 @helper RenderTableHeading(string label, string sortByField = "", string listType = "Order") 1293 { 1294 1295 if (sortByField.IsNotNullOrEmpty()) 1296 { 1297 var href = string.Empty; 1298 var icon = "fa-sort-amount-asc"; 1299 if (listType == "Order" || listType == "Rma") 1300 { 1301 href = GetCustomerCenterSortUrl(sortByField, listType); 1302 if (GetSortFieldParameter("name") == sortByField) 1303 { 1304 icon = "fa-sort-amount-" + GetSortFieldParameter("value", sortByField).ToLower(); 1305 } 1306 } 1307 <a href="@href"> 1308 @RenderIcon(icon, label, IconPosition.Right) 1309 </a> 1310 } 1311 else 1312 { 1313 @label 1314 } 1315 } 1316 1317 @helper RenderDataListItem(string label, string value, string labelCss = "col-xs-4 text-right", string valueCss = "col-xs-8", string alternativeValue = "", bool isLabelBold = true) 1318 { 1319 if (value.IsNotNullOrEmpty() || alternativeValue.IsNotNullOrEmpty()) 1320 { 1321 var displayValue = alternativeValue.IsNullOrEmpty() ? value : alternativeValue; 1322 1323 <dt class="@labelCss"> 1324 @if (isLabelBold) 1325 { 1326 @: <strong> 1327 } 1328 @label 1329 @if (isLabelBold) 1330 { 1331 @: </strong> 1332 } 1333 </dt> 1334 <dd class="@valueCss"> 1335 @displayValue 1336 </dd> 1337 } 1338 } 1339 1340 @helper RenderTableRowSpacer(int height = 30, int colspan = 1) 1341 { 1342 if (height == 0) 1343 { 1344 height = 30; 1345 } 1346 1347 <tr> 1348 @if (colspan > 1) 1349 { 1350 @: <td colspan="@colspan" height="@height"></td> 1351 } 1352 else 1353 { 1354 <td height="@height"></td> 1355 } 1356 </tr> 1357 } 1358 1359 @helper RenderTableCellSpacer(int width = 10, int height = 10) 1360 { 1361 if (width == 0) 1362 { 1363 width = 10; 1364 } 1365 if (height == 0) 1366 { 1367 height = 10; 1368 } 1369 <td width="@width" height="@height">&nbsp;</td> 1370 } 1371 1372 1373 @* Tab helpers *@ 1374 @helper RenderTabHeader(string key, string label, string cssClass = "") 1375 { 1376 @SnippetStart("tabHeaders") 1377 <li class="@cssClass"> 1378 <a href="@key">@label</a> 1379 </li> 1380 @SnippetEnd("tabHeaders") 1381 } 1382 1383 @helper RenderTabContent(string tabKey, string tabLabel, string tabContent, string cssClass = "") 1384 { 1385 if (tabContent.IsNotNullOrEmpty()) 1386 { 1387 @RenderTabHeader("#" + tabKey, tabLabel, cssClass) 1388 <div class="col-xs-12 @cssClass" id="@tabKey"> 1389 @tabContent 1390 </div> 1391 } 1392 } 1393 1394 1395 @* Generic helpers *@ 1396 @helper RenderIcon(string cssPartialClass, string label = "", IconPosition position = IconPosition.Left, bool isLabelATooltip = false) 1397 { 1398 var icon = !isLabelATooltip ? "<i class='fa " + cssPartialClass + "'></i>" : "<i class='fa " + cssPartialClass + "' data-toggle='" + label + "'></i>"; 1399 var spacing = string.Empty; 1400 1401 if (label.IsNotNullOrEmpty()) 1402 { 1403 spacing = "<text>&nbsp;</text>"; 1404 } 1405 if (cssPartialClass.IsNotNullOrEmpty()) 1406 { 1407 if (isLabelATooltip) 1408 { 1409 @icon 1410 } 1411 else if (position == IconPosition.Left) 1412 { 1413 @icon 1414 @spacing 1415 @label 1416 } 1417 else 1418 { 1419 @label 1420 @spacing 1421 @icon 1422 } 1423 } 1424 else 1425 { 1426 @label 1427 } 1428 } 1429 1430 @helper RenderStackedIcons(string cssPrincipalPartialClass, string cssSecondaryPartialClass, string label = "", IconPosition position = IconPosition.Left, bool isLabelATooltip = false) 1431 { 1432 var icon = "<span class='fa-stack'>"; 1433 icon += !isLabelATooltip ? "<i class='fa " + cssPrincipalPartialClass + " fa-stack-2x'></i>" : "<i class='fa " + cssPrincipalPartialClass + " fa-stack-2x' data-toggle='" + label + "'></i>"; 1434 icon += "<i class='fa " + cssSecondaryPartialClass + " fa-stack-1x'></i>"; 1435 icon += "</span>"; 1436 var spacing = string.Empty; 1437 1438 if (label.IsNotNullOrEmpty()) 1439 { 1440 spacing = "<text>&nbsp;</text>"; 1441 } 1442 if (cssPrincipalPartialClass.IsNotNullOrEmpty() && cssSecondaryPartialClass.IsNotNullOrEmpty()) 1443 { 1444 if (isLabelATooltip) 1445 { 1446 @icon 1447 } 1448 else if (position == IconPosition.Left) 1449 { 1450 @icon 1451 @spacing 1452 @label 1453 } 1454 else 1455 { 1456 @label 1457 @spacing 1458 @icon 1459 } 1460 } 1461 else 1462 { 1463 @label 1464 } 1465 } 1466 1467 @helper RenderAction(IconAction action, string href = "", string title = "", string onClickConfirm = "") 1468 { 1469 var attributes = new Dictionary<string, string>(); 1470 1471 if (title.IsNullOrEmpty()) 1472 { 1473 attributes.Add("title", title); 1474 } 1475 if (onClickConfirm.IsNotNullOrEmpty()) 1476 { 1477 attributes.Add("onclick", "return confirm('" + onClickConfirm + "');"); 1478 } 1479 @RenderAction(action, href, attributes) 1480 } 1481 1482 @helper RenderAction(IconAction action, string href, Dictionary<string, string> attributes) 1483 { 1484 var icon = string.Empty; 1485 var linkAttributes = string.Empty; 1486 var label = Translate(action.ToString()); 1487 1488 if (attributes != null) 1489 { 1490 linkAttributes = GetAttributes(attributes); 1491 } 1492 1493 switch (action) 1494 { 1495 case IconAction.Add: 1496 break; 1497 case IconAction.View: 1498 icon = "fa-eye"; 1499 break; 1500 case IconAction.Edit: 1501 icon = "fa-edit"; 1502 break; 1503 case IconAction.Cancel: 1504 case IconAction.Remove: 1505 icon = "fa-times"; 1506 break; 1507 case IconAction.Delete: 1508 icon = "fa-trash"; 1509 break; 1510 case IconAction.Print: 1511 icon = "fa-print"; 1512 break; 1513 case IconAction.Save: 1514 break; 1515 case IconAction.Reset: 1516 break; 1517 case IconAction.Undo: 1518 break; 1519 case IconAction.Reorder: 1520 icon = "fa-repeat"; 1521 break; 1522 case IconAction.SetDefault: 1523 icon = "fa-times"; 1524 label = string.Empty; 1525 break; 1526 case IconAction.IsDefault: 1527 icon = "fa-check"; 1528 label = string.Empty; 1529 break; 1530 default: 1531 throw new NotSupportedException("An action is needed to render this helper!"); 1532 } 1533 if (icon.IsNotNullOrEmpty()) 1534 { 1535 if (href.IsNotNullOrEmpty()) 1536 { 1537 @( "<" + "a href=\"" + href + "\" " + linkAttributes + ">") 1538 @RenderIcon(icon, label) 1539 @( "<" + "/a" + ">") 1540 } 1541 else if (label.IsNullOrEmpty()) 1542 { 1543 @RenderIcon(icon) 1544 } 1545 } 1546 1547 } 1548 1549 @helper RenderBootstrapButton(BootstrapButtonSettings settings) 1550 { 1551 var attributes = GetAttribute("class", "btn " + (settings.CssClass.IsNotNullOrEmpty() ? settings.CssClass : "btn-default")); 1552 attributes += GetAttribute("target", settings.Target); 1553 attributes += GetAttribute("href", settings.Href); 1554 attributes += GetAttribute("name", settings.SystemName); 1555 attributes += GetAttribute("id", settings.Id); 1556 attributes += GetAttribute("value", settings.Value); 1557 if (settings.ButtonType == BootstrapButtonSettings.BootstrapButtonType.Button && !settings.Attributes.ContainsKey("type")) 1558 { 1559 settings.Attributes.Add("type","submit"); 1560 } 1561 1562 attributes += GetAttributes(settings.Attributes); 1563 1564 switch (settings.ButtonType) 1565 { 1566 case BootstrapButtonSettings.BootstrapButtonType.Button: 1567 @: <button @attributes> 1568 @RenderIcon(settings.IconCssClass, settings.Label, settings.IconPosition) 1569 @: </button> 1570 break; 1571 1572 case BootstrapButtonSettings.BootstrapButtonType.Anchor: 1573 @: <a @attributes> 1574 @RenderIcon(settings.IconCssClass, settings.Label, settings.IconPosition) 1575 @: </a> 1576 break; 1577 default: 1578 throw new NotSupportedException(string.Format("Unsupported Bootstrap Button type: {0}.", settings.ButtonType.ToString())); 1579 } 1580 } 1581 1582 @helper RenderAddToCart(string productId, string productVariantId, int availableAmount = 0) 1583 { 1584 var addToCartButtonSettings = new BootstrapButtonSettings 1585 { 1586 Label = Translate("addToCart", "Add to Cart"), 1587 CssClass = "btn-default addToCartSubmit", 1588 Href = string.Concat(Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(GetPageIdByNavigationTag("MiniCart")),"?productid=", productId, "&amp;variantID=", productVariantId, "&amp;cartcmd=add"), 1589 IconCssClass = "fa-shopping-cart", 1590 Attributes = new Dictionary<string, string> 1591 { 1592 {"data-add", Translate("addToCart", "Add to Cart")}, 1593 {"data-added", Translate("added", "Added")} 1594 } 1595 }; 1596 if (availableAmount > 0) 1597 { 1598 addToCartButtonSettings.Attributes.Add("data-outofstock", Translate("outOfStock", "Out of stock")); 1599 addToCartButtonSettings.Attributes.Add("data-stock", availableAmount.ToString()); 1600 } 1601 1602 @RenderBootstrapButton(addToCartButtonSettings) 1603 @RenderButtonField(FieldSettings.CreateSubmitField(Translate("addToCart", "Add to cart"), "hidden")) 1604 } 1605 1606 @helper RenderSocialMediaShare() 1607 { 1608 <div class="shareIcons"> 1609 <span>@Translate("share", "Share")</span> 1610 @RenderSocialMedia(false, true) 1611 </div> 1612 } 1613 1614 @helper RenderOpenGraphMeta(string type, string image, string title, string teaser = "", string imageAlt = "") 1615 { 1616 var culture = Pageview.Area.Culture.Replace("-", "_"); 1617 teaser = System.Text.RegularExpressions.Regex.Replace(teaser, "<.*?>", string.Empty); 1618 if (type.IsNullOrEmpty()) 1619 { 1620 type = "article"; 1621 } 1622 if (imageAlt.IsNullOrEmpty()) 1623 { 1624 imageAlt = title; 1625 } 1626 1627 @SnippetStart("OGMeta") 1628 <meta property="og:title" content="@title"/> 1629 <meta property="og:image" content="@string.Concat(Helpers.GetCurrentUrl(true), image)"/> 1630 <meta property="og:image:alt" content="@imageAlt"/> 1631 <meta property="og:site_name" content="@Pageview.Area.Item["CompanyName"]"/> 1632 <meta property="og:url" content="@Helpers.GetCurrentUrl()"/> 1633 <meta property="og:description" content="@teaser"/> 1634 <meta property="og:type" content="@type"/> 1635 <meta property="og:locale" content="@culture"/> 1636 @SnippetEnd("OGMeta") 1637 } 1638 1639 @helper RenderSocialMedia(bool isEmailTemplate = false, bool isToShare = false) 1640 { 1641 var page = Dynamicweb.Extensibility.ServiceLocator.Current.GetPageService().GetPage(GetPageIdByNavigationTag("GeneralSettings")); 1642 var generalSettings = Dynamicweb.Content.Items.Item.GetItemById(page.ItemType, page.ItemId); 1643 1644 if(generalSettings["SocialMedia"] != null) { 1645 var socialMedia = Dynamicweb.Content.Items.ItemList.GetItemListById(int.Parse(generalSettings["SocialMedia"].ToString())); 1646 1647 if(socialMedia.Relations.Any()) 1648 { 1649 if(!isEmailTemplate) 1650 { 1651 @:<ul class="socialMedia"> 1652 } 1653 foreach (var r in socialMedia.Relations) 1654 { 1655 var socialNetwork = Dynamicweb.Content.Items.Item.GetItemById("SocialLinks", r.Id); 1656 var className = (socialNetwork["Icon"] ?? "").ToString(); 1657 var socialName = (socialNetwork["Name"] ?? "").ToString(); 1658 var socialLink = (socialNetwork["Link"] ?? "").ToString(); 1659 var shareLink = (socialNetwork["ShareURL"] ?? "").ToString(); 1660 1661 if (isEmailTemplate) 1662 { 1663 <a title="@socialName" target="_blank" href="@socialLink"> @socialName </a> 1664 } 1665 else if(!isToShare || shareLink.IsNotNullOrEmpty()) 1666 { 1667 <li> 1668 <a title="@socialName" class="@className fa" target="_blank" data-sharehref="@shareLink@Helpers.GetCurrentUrl()" href="@socialLink"><span class="hidden">@socialName</span></a> 1669 </li> 1670 } 1671 } 1672 if(!isEmailTemplate) 1673 { 1674 @:</ul> 1675 } 1676 } 1677 } 1678 } 1679 1680 @helper RenderNoResults(string wording, string title = "", bool hasWrapper = false, string wrapperClass = "col-xs-12 noPadding" ) 1681 { 1682 if (hasWrapper) 1683 { 1684 @:<div class="noResultsWrapper @wrapperClass"> 1685 } 1686 if (title.IsNotNullOrEmpty()) 1687 { 1688 <h2>@title</h2> 1689 } 1690 <p>@wording</p> 1691 if (hasWrapper) 1692 { 1693 @:</div> 1694 } 1695 } 1696 1697 @helper RenderImage(ImageSettings imageSettings) 1698 { 1699 var imageMarkup = string.Empty; 1700 1701 if (!imageSettings.Attributes.ContainsKey("class")) 1702 { 1703 imageSettings.Attributes.Add("class", "img-responsive img-fluid" + imageSettings.CssClass); 1704 } 1705 if (!imageSettings.Attributes.ContainsKey("src")) 1706 { 1707 imageSettings.Attributes.Add("src", imageSettings.Source); 1708 } 1709 if (!imageSettings.Attributes.ContainsKey("alt")) 1710 { 1711 imageSettings.Attributes.Add("alt", imageSettings.AltText); 1712 } 1713 if (!imageSettings.Attributes.ContainsKey("title")) 1714 { 1715 imageSettings.Attributes.Add("title", imageSettings.Title); 1716 } 1717 1718 if (imageSettings.IncludeWrapper) 1719 { 1720 var wrapperAttributes = new Dictionary<string, string>(); 1721 if (imageSettings.WrapperCssClass.IsNotNullOrEmpty()) 1722 { 1723 wrapperAttributes.Add("class", imageSettings.WrapperCssClass); 1724 } 1725 1726 imageMarkup += "<"; 1727 imageMarkup += imageSettings.WrapperElement + " " + GetAttributes(wrapperAttributes) + ">"; 1728 } 1729 1730 if (imageSettings.Href.IsNotNullOrEmpty()) 1731 { 1732 var linkAttributes = new Dictionary<string, string> {{"href", imageSettings.Href}}; 1733 if (imageSettings.HrefCssClass.IsNotNullOrEmpty()) 1734 { 1735 linkAttributes.Add("class", imageSettings.HrefCssClass); 1736 } 1737 if (imageSettings.HrefTarget.IsNotNullOrEmpty()) 1738 { 1739 linkAttributes.Add("target", imageSettings.HrefTarget); 1740 } 1741 1742 imageMarkup += "<"; 1743 imageMarkup += "a " + GetAttributes(linkAttributes) + ">"; 1744 } 1745 1746 imageMarkup += "<"; 1747 imageMarkup += "img " + GetAttributes(imageSettings.Attributes) + " />"; 1748 1749 if (imageSettings.Href.IsNotNullOrEmpty()) 1750 { 1751 imageMarkup += "<"; 1752 imageMarkup += "/a>"; 1753 } 1754 1755 if (imageSettings.IncludeWrapper) 1756 { 1757 imageMarkup += "<"; 1758 imageMarkup += "/" + imageSettings.WrapperElement + ">"; 1759 } 1760 1761 @imageMarkup 1762 } 1763 } 1764 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 1765 @using Dynamicweb.Rendering 1766 @using Dynamicweb.Core 1767 @using System 1768 @using System.Text.RegularExpressions 1769 @using Dna.Frontend 1770 @using Dna.Frontend.UI 1771 @using Dna.ImageProcessing 1772 @using Dynamicweb.Frontend 1773 @functions 1774 { 1775 1776 public static string StripHtml(string source) 1777 { 1778 return Regex.Replace(source, "<.*?>", string.Empty); 1779 } 1780 1781 } 1782 @{ 1783 1784 @helper RenderStandardParagraphHeading() 1785 { 1786 @RenderStandardParagraphHeading(GetBoolean("Item.ShowTitle"), GetString("Item.TitleOrder"), GetString("Item.Title"), GetString("Item.HeadingType")) 1787 } 1788 1789 1790 @helper RenderStandardParagraphHeading(bool showTitle, string titlePosition, string title, string headingTypeItem, string subtitle = "") 1791 { 1792 if (showTitle && titlePosition == "title-first") 1793 { 1794 @RenderStandardParagraphHeadingHtml(title, headingTypeItem, subtitle) 1795 } 1796 } 1797 1798 @helper RenderStandardParagraphHeadingHtml(string title, string headingTypeItem, string subtitle = "") 1799 { 1800 if (title.IsNotNullOrEmpty()) 1801 { 1802 var headingType = headingTypeItem.IsNullOrEmpty() || PageView.Current().Layout.File.Name.ToLower().Contains("standarddetail") ? "h1" : headingTypeItem; 1803 <header class="paragraphHeader"> 1804 @string.Format("<{0} class='text-center'>{1}</{0}>", headingType, title) 1805 @if (subtitle.IsNotNullOrEmpty()) 1806 { 1807 <span class="subtitle">@subtitle</span> 1808 } 1809 </header> 1810 } 1811 } 1812 1813 @helper RenderStandardParagraphText() 1814 { 1815 @RenderStandardParagraphText( 1816 GetBoolean("Item.ShowTitle"), 1817 GetString("Item.TitleOrder"), 1818 GetString("Item.Title"), 1819 GetString("Item.Order"), 1820 GetString("Item.Text"), 1821 GetString("Item.Image"), 1822 GetString("Item.Link"), 1823 GetString("Item.ImageTitle"), 1824 GetString("Item.ImageWidth"), 1825 GetString("Item.WidthMobile"), 1826 GetString("Item.Width"), 1827 GetString("Item.ImageStyle"), 1828 GetString("Item.HeadingType"), 1829 string.Empty, 1830 true) 1831 } 1832 1833 @helper RenderStandardParagraphText(bool showTitle, string titlePosition, string title, string itemLayout, string itemText, string imagePath, string link, string imageAlt, string imageWidth, string widthMobile, string itemWidth, string imageCssClass, string headingType, string subtitle = "", bool isParagraphItem = false, bool openInANewWindow = false) 1834 { 1835 if (itemLayout == "image-left" || itemLayout == "image-right") 1836 { 1837 @RenderStandardParagraphImageTag(imagePath, link, imageAlt, imageWidth, widthMobile, itemWidth, imageCssClass, itemLayout, title, openInANewWindow) 1838 } 1839 1840 if (showTitle && titlePosition == "title-with-text") 1841 { 1842 @RenderStandardParagraphHeadingHtml(title, headingType, subtitle) 1843 } 1844 1845 @RenderStandardParagraphTextHtml(itemText, isParagraphItem) 1846 } 1847 1848 @helper RenderStandardParagraphTextHtml(string itemText, bool isParagraphItem = false) 1849 { 1850 const int crop = 300; 1851 1852 if (itemText.IsNotNullOrEmpty()) 1853 { 1854 if (!isParagraphItem) 1855 { 1856 itemText = itemText.Length >= crop ? System.Net.WebUtility.HtmlDecode(StripHtml(itemText)).Substring(0, crop): itemText; 1857 if (itemText.Length >= crop) 1858 { 1859 itemText += " (...)"; 1860 } 1861 } 1862 <div class="paragraphText">@itemText</div> 1863 } 1864 } 1865 1866 @helper RenderStandardParagraphModule() 1867 { @GetString("ParagraphModule") } 1868 1869 @helper RenderStandardParagraphImage() 1870 { 1871 @RenderStandardParagraphImage( 1872 GetString("Item.Order"), 1873 GetString("Item.Image"), 1874 GetString("Item.Link"), 1875 GetString("Item.ImageTitle"), 1876 GetString("Item.ImageWidth"), 1877 GetString("Item.WidthMobile"), 1878 GetString("Item.Width"), 1879 GetString("Item.ImageStyle"), 1880 GetString("Item.Title"), 1881 GetBoolean("Item.OpenInANewWindow"), 1882 GetString("Item.Video") 1883 ) 1884 } 1885 1886 @helper RenderStandardParagraphImage(string itemLayout, string imagePath, string link, string title, string imageWidth, string widthMobile, string itemWidth, string imageCssClass, string itemTitle, bool openInANewWindow, string videoPath) 1887 { 1888 if (videoPath.IsNotNullOrEmpty()) 1889 { 1890 var videoId = videoPath.Substring(videoPath.LastIndexOf('/') + 1); 1891 imagePath = imagePath.IsNotNullOrEmpty() ? imagePath : string.Concat("https://img.youtube.com/vi/",videoId,"/0.jpg"); 1892 imageCssClass += " fancybox"; 1893 @RenderStandardParagraphImageTag(imagePath, videoPath, title, imageWidth, widthMobile, itemWidth, imageCssClass, itemLayout, itemTitle, openInANewWindow) 1894 } 1895 else if (itemLayout == "image-left-column" || itemLayout == "image-right-column" || itemLayout == "image-top" || itemLayout.IsNullOrEmpty()) 1896 { 1897 @RenderStandardParagraphImageTag(imagePath, link, title, imageWidth, widthMobile, itemWidth, imageCssClass, itemLayout, itemTitle, openInANewWindow) 1898 } 1899 } 1900 1901 @helper RenderStandardParagraphImageTag(string imageUrl, string link, string imageAlt, string imageWidth, string widthMobile, string itemWidth, string imageStyle, string itemLayout, string itemTitle, bool openInANewWindow) 1902 { 1903 if (imageUrl.IsNotNullOrEmpty()) 1904 { 1905 if (link.IsNullOrEmpty()) 1906 { 1907 @RenderStandardParagraphImageWrapper(imageUrl, imageAlt, imageWidth, widthMobile, itemWidth, imageStyle, itemLayout, itemTitle) 1908 } 1909 else 1910 { 1911 var target = openInANewWindow ? "target='_blank'" : string.Empty; 1912 <a href="@link" @target> 1913 @RenderStandardParagraphImageWrapper(imageUrl, imageAlt, imageWidth, widthMobile, itemWidth, imageStyle, itemLayout, itemTitle) 1914 </a> 1915 } 1916 } 1917 } 1918 1919 @helper RenderStandardParagraphImageWrapper(string url, string alt, string width, string widthMobile, string itemWidth, string imageCssClass, string itemLayout, string itemTitle) 1920 { 1921 var imageAlt = alt.IsNotNullOrEmpty() ? alt : itemTitle; 1922 var figureCssClass = "col-xs-" + width; 1923 var figureClass = imageCssClass; 1924 int optimizedwidth; 1925 1926 switch (itemLayout) 1927 { 1928 case "image-left": 1929 case "image-left-column": 1930 figureCssClass += " pull-left noPaddingLeft"; 1931 break; 1932 case "image-right": 1933 figureCssClass += " pull-right noPaddingRight"; 1934 break; 1935 case "image-right-column": 1936 figureCssClass += " pull-right noPaddingRight"; 1937 break; 1938 case "image-top": 1939 figureCssClass += " image-top noPadding"; 1940 if (Convert.ToInt32(width) < 12) 1941 { 1942 figureCssClass += " col-xs-offset-" + (12 - Convert.ToInt32(width)) / 2; 1943 } 1944 break; 1945 default: 1946 throw new NotSupportedException(string.Format("Unsupported item layout: {0}.", itemLayout)); 1947 1948 } 1949 figureClass = figureClass == "none" ? figureCssClass : figureClass + " " + figureCssClass; 1950 1951 if (Dynamicweb.Frontend.PageView.Current().Device == Dynamicweb.Frontend.Devices.DeviceType.Mobile) 1952 { 1953 switch (widthMobile) 1954 { 1955 case "6": 1956 optimizedwidth = 240; 1957 break; 1958 default: 1959 optimizedwidth = 480; 1960 break; 1961 } 1962 } 1963 else 1964 { 1965 switch (itemWidth) 1966 { 1967 case "3": 1968 case "4": 1969 case "6": 1970 optimizedwidth = 722; 1971 break; 1972 case "8": 1973 case "9": 1974 optimizedwidth = 960; 1975 break; 1976 default: 1977 optimizedwidth = 1280; 1978 break; 1979 } 1980 } 1981 1982 var imageUrl = Images.GetImage(new ImageProcessorSettings() {ImageUrl = url, Width = optimizedwidth}); 1983 1984 @RenderImage(new ImageSettings { WrapperCssClass = string.Concat(figureClass, " ", figureCssClass), IncludeWrapper = true, Source = imageUrl, AltText = imageAlt }) 1985 } 1986 1987 @helper RenderStandardParagraphButton() 1988 { @RenderStandardParagraphButton(GetString("Item.LinkText"), GetString("Item.Link"), GetBoolean("Item.ShowReadMoreButton"), GetBoolean("Item.OpenInANewWindow")) } 1989 1990 @helper RenderStandardParagraphButton(string label, string link, bool showReadMoreButton, bool openInANewWindow, string detailUrl = "") 1991 { 1992 var href = link.IsNotNullOrEmpty() ? link : detailUrl; 1993 1994 label = label.IsNotNullOrEmpty() ? label : Translate("Read more"); 1995 1996 if (showReadMoreButton && href.IsNotNullOrEmpty()) 1997 { 1998 <p class="paragraphButton mb-4"> 1999 @RenderBootstrapButton(new BootstrapButtonSettings {Label = label, Href = href, Target = openInANewWindow ? "_blank" : string.Empty}) 2000 </p> 2001 } 2002 } 2003 } 2004 @{ 2005 int screenWidth = (HttpContext.Current.Request.Browser.ScreenPixelsWidth) * 2 - 100; 2006 //int screenWidth = 768; 2007 var deviceType = Pageview.Device.ToString(); 2008 string displayType = GetString("Item.DisplayType"); 2009 string customClass = GetString("Item.Custom_Class_1"); 2010 List<LoopItem> standardList = GetLoop("Item.Standard_List"); 2011 var bgColor = GetValue("Item.Background_Style"); 2012 int displayDesktop = GetInteger("Item.Number_Of_Items__desktop") != 0 ? GetInteger("Item.Number_Of_Items__desktop") : 2; 2013 int displayTablet = GetInteger("Item.Number_Of_Items__tablet") != 0 ? GetInteger("Item.Number_Of_Items__tablet") : 3; 2014 int displayMobile = GetInteger("Item.Number_Of_Items__mobile") != 0 ? GetInteger("Item.Number_Of_Items__mobile") : 12; 2015 int numberOfSlider = GetInteger("Item.Number_Of_Slides") != 0 ? GetInteger("Item.Number_Of_Slides") : 3; 2016 int numberOfSlidesTablet = GetInteger("Item.Number_Of_Slides__tablet") != 0 ? GetInteger("Item.Number_Of_Slides__tablet") : 3; 2017 int numberOfSlidesMobile = GetInteger("Item.Number_Of_Slides__mobile") != 0 ? GetInteger("Item.Number_Of_Slides__mobile") : 1; 2018 int firstTabletHeight; 2019 int fistDesktopHeight; 2020 bool firstCheckParseTablet = int.TryParse(GetString("Item.Content_ContainerHeightFor_Tablets"), out firstTabletHeight); 2021 bool FirstCheckParseDesktop = int.TryParse(GetString("Item.Content_Container_Height"), out fistDesktopHeight); 2022 int deviceHeightDifference = firstTabletHeight - fistDesktopHeight + 30; 2023 int largeTabletScreenSize = firstTabletHeight - deviceHeightDifference; 2024 string landscapeTabletScreenSize = largeTabletScreenSize.ToString() + "px"; 2025 var containerHeightForDesktop = GetString("Item.Content_Container_Height") == "" ? "" : GetString("Item.Content_Container_Height")+"px"; 2026 var containerHeightForMobiles = GetString("Item.Content_Container_HeightFor_Mobiles") == "" ? "auto" : GetString("Item.Content_Container_HeightFor_Mobiles") + "px"; 2027 var containerHeightForTables = GetString("Item.Content_ContainerHeightFor_Tablets") == "" ? "auto" : screenWidth > 990 ? landscapeTabletScreenSize: GetString("Item.Content_ContainerHeightFor_Tablets") + "px"; 2028 var shotDotsTablet = standardList.Count() > numberOfSlidesTablet ? "true" : "false"; 2029 var shotDotsMobile = standardList.Count() > numberOfSlidesMobile ? "true" : "false"; 2030 var showDots = deviceType == "Mobile" ? shotDotsMobile : deviceType == "Tablet" ? shotDotsTablet : "true"; 2031 string heightForDesktop = containerHeightForDesktop != "auto" ? containerHeightForDesktop.Replace("px" , "") : string.Empty; 2032 string heightForMobile = containerHeightForMobiles != "auto" ? containerHeightForMobiles.Replace("px" , "") : string.Empty; 2033 string heightForTablet = containerHeightForTables != "auto" ? containerHeightForTables.Replace("px" , "") : string.Empty; 2034 int desktopHeight; 2035 int tabletHeight; 2036 int mobileHeight; 2037 bool checkParseDesktop = int.TryParse(heightForDesktop, out desktopHeight); 2038 bool checkParseMobile = int.TryParse(heightForMobile, out mobileHeight); 2039 bool checkParseTablet = int.TryParse(heightForTablet, out tabletHeight); 2040 double ratio = 1 + (1 / 2); 2041 int sliderWrapperDesktop = desktopHeight * 2; 2042 double sliderWrapperMobile = mobileHeight *2 - (mobileHeight*2/8); 2043 int sliderWrapperTablet = ((tabletHeight * 2) - (tabletHeight*2/10)); 2044 var containerHeight = string.Empty; 2045 2046 string sliderWrapperHeight = deviceType == "Desktop" ? sliderWrapperDesktop.ToString() : deviceType == "Mobile" ? sliderWrapperMobile.ToString() : deviceType == "Tablet" ? sliderWrapperTablet.ToString(): "auto"; 2047 string sucessStoriesHeight = customClass == "successStories" ? "min-height:" + sliderWrapperHeight + "px" : ""; 2048 2049 switch (deviceType) 2050 { 2051 case "Mobile": 2052 containerHeight = containerHeightForDesktop; 2053 break; 2054 case "Desktop": 2055 containerHeight = containerHeightForDesktop; 2056 break; 2057 case "Tablet": 2058 containerHeight = containerHeightForDesktop; 2059 break; 2060 } 2061 2062 2063 2064 bool addSticker = GetBoolean("Item.Add_Sticker"); 2065 2066 var padding = GetValue("Item.PaddingTopAndBottom") == "" ? "60" : GetValue("Item.PaddingTopAndBottom"); 2067 2068 var items = standardList.Select(i => new { 2069 image = i.GetString("Item.Standard_List.Image.Value"), 2070 title = i.GetString("Item.Standard_List.Title.Value"), 2071 content = i.GetString("Item.Standard_List.Text.Value"), 2072 imgWidth = i.GetString("Item.Standard_List.ImageWidth.Value"), 2073 buttonLink = i.GetString("Item.Standard_List.Link.Value"), 2074 buttonText = i.GetString("Item.Standard_List.LinkText.Value"), 2075 buttonShow = i.GetBoolean("Item.Standard_List.ShowReadMoreButton"), 2076 buttonNewWindow = i.GetBoolean("Item.Standard_List.OpenInANewWindow"), 2077 isCenterText = i.GetBoolean("Item.Standard_List.CenterParagraphContent") 2078 }); 2079 } 2080 2081 <article class="@customClass @bgColor p-@padding"> 2082 <div class="container"> 2083 @RenderStandardParagraphHeading()@RenderStandardParagraphImage()@RenderStandardParagraphText()@RenderStandardParagraphModule()@RenderStandardParagraphButton() 2084 2085 <div class="standard-list row"> 2086 2087 @if (displayType == "display-block") 2088 { 2089 <div class="display-block row"> 2090 @foreach (var list in items) 2091 { 2092 string centerAll = list.isCenterText ? "text-center" : ""; 2093 string openNewWindow = list.buttonNewWindow ? "target=\"_blank\"" : ""; 2094 <div class="col-xs-@displayMobile col-md-@displayTablet col-lg-@displayDesktop blockContainer noPadding" > 2095 @if (list.image.IsNotNullOrEmpty()) 2096 { 2097 @RenderImage(new ImageSettings {IncludeWrapper = true, WrapperCssClass = "col-xs-12 col-sm-" + @list.imgWidth + " noPadding", Href = list.buttonLink, Source = Images.GetImage(list.image), AltText = list.title}) 2098 } 2099 2100 <div class="contentContainer @GetString("Content_Container_HeightFor_Mobiles")" style="height: @containerHeight"> 2101 <div class="col-xs-12 col-sm-12 col-md-12 noPadding listTitle"> 2102 @if (list.buttonLink.IsNotNullOrEmpty()) 2103 {<p class="@centerAll "> 2104 <a href="@list.buttonLink" class="mainColor">@list.title</a> 2105 </p> 2106 } 2107 else 2108 { 2109 <p class="@centerAll mainColor">@list.title</p> 2110 } 2111 </div> 2112 <div class="col-xs-12 col-sm-12 col-md-12 listContent"> 2113 <p class="@centerAll">@list.content</p></div> 2114 </div> 2115 @if (list.buttonShow) 2116 { 2117 <p class="paragraphButton"> 2118 <a href="@list.buttonLink" class="btn btn-default" @openNewWindow> @list.buttonText </a> 2119 </p> 2120 2121 } 2122 2123 @if (addSticker) 2124 { 2125 <img src="/Files/Files/VisionSpring/Content%20Images/Homepage/Wonder%20of%20Clear%20Vision/category-icon%20(1).svg" class="addSticker" alt="addSticker"/> 2126 } 2127 </div> 2128 2129 } 2130 </div> 2131 } 2132 else if (displayType == "display-slider") 2133 { 2134 <div class="display-slider owl-theme" data-slides="@numberOfSlider" data-screen-width="@screenWidth"> 2135 @foreach (var list in items) 2136 { 2137 2138 string centerAll = list.isCenterText ? "text-center" : ""; 2139 string openNewWindow = list.buttonNewWindow ? "target=\"_blank\"" : ""; 2140 const int crop = 250; 2141 string paragraphText = list.content; 2142 bool isGreenArea = customClass == "successStories" ? true : false; 2143 bool requiresDots = paragraphText.Length >= crop ? true : false; 2144 string itemText = requiresDots && isGreenArea ? System.Net.WebUtility.HtmlDecode(StripHtml(paragraphText)).Substring(0, crop) : paragraphText; 2145 2146 2147 <div class="col-xs-12 col-md-12 col-lg-12 slideWrapper noPadding successStories_slideWrapper" > 2148 @if (list.image.IsNotNullOrEmpty()) 2149 { 2150 @RenderImage(new ImageSettings {IncludeWrapper = true, WrapperCssClass = "col-xs-12 col-sm-" + @list.imgWidth + " noPadding paragraphImage" , Href = list.buttonLink, Source = Images.GetImage(list.image), AltText = list.title}) 2151 } 2152 <div class="contentContainer" > 2153 <div class="col-xs-12 col-sm-12 col-md-12 noPadding listTitle successStories_ListTitle" > 2154 @if (list.buttonLink.IsNotNullOrEmpty()) 2155 { 2156 <p class="@centerAll "> 2157 <a href="@list.buttonLink" class="mainColor">@list.title</a> 2158 </p> 2159 } 2160 else 2161 { 2162 <p class="@centerAll mainColor">@list.title</p> 2163 } 2164 </div> 2165 <div class="col-xs-12 col-sm-12 col-md-12 noPadding listContent" > 2166 <p class="@centerAll"> 2167 2168 @if (requiresDots && isGreenArea) 2169 { 2170 itemText += " (...)"; 2171 @itemText 2172 } 2173 else 2174 { 2175 @paragraphText 2176 2177 } 2178 </p> 2179 </div> 2180 </div> 2181 @if (list.buttonShow) 2182 { 2183 <p class="paragraphButton"> 2184 <a href="@list.buttonLink" class="btn btn-default" @openNewWindow> @list.buttonText</a> 2185 </p> 2186 2187 } 2188 2189 @if (addSticker) 2190 { 2191 <img src="/Files/Files/VisionSpring/Content%20Images/Homepage/Wonder%20of%20Clear%20Vision/category-icon%20(1).svg" class="addSticker" alt="addSticker"/> 2192 } 2193 </div> 2194 2195 } 2196 </div> 2197 } 2198 else 2199 { 2200 <div class="display-list col-12"> 2201 @foreach (var list in items) 2202 { 2203 string centerAll = list.isCenterText ? "text-center" : ""; 2204 string openNewWindow = list.buttonNewWindow ? "target=\"_blank\"" : ""; 2205 var contentWidth = 12 - Convert.ToInt32(list.imgWidth); 2206 <div class="col-xs-@displayMobile col-md-@displayTablet col-lg-@displayDesktop noPadding row list-container"> 2207 @if (list.image.IsNotNullOrEmpty()) 2208 { 2209 @RenderImage(new ImageSettings {IncludeWrapper = true, WrapperCssClass = "col-xs-12 col-sm-" + @list.imgWidth + " noPadding", Href = list.buttonLink, Source = Images.GetImage(list.image), AltText = list.title}) 2210 } 2211 2212 <div class="contentContainer col-xs-12 col-sm-@contentWidth"> 2213 <div class="col-xs-12 col-sm-12 col-md-12 noPadding listTitle"> 2214 @if (list.buttonLink.IsNotNullOrEmpty()) 2215 {<p class="@centerAll "> 2216 <a href="@list.buttonLink" class="mainColor">@list.title</a> 2217 </p> 2218 } 2219 else 2220 { 2221 <p class="@centerAll mainColor">@list.title</p> 2222 } 2223 </div> 2224 <div class="col-xs-12 col-sm-12 col-md-12 noPadding listContent"> 2225 <p class="@centerAll ">@list.content</p></div> 2226 @if (list.buttonShow) 2227 { 2228 <p class="paragraphButton"> 2229 <a href="@list.buttonLink" class="btn btn-default" @openNewWindow> @list.buttonText</a> 2230 </p> 2231 } 2232 2233 </div> 2234 </div> 2235 if (addSticker) 2236 { 2237 <img src="/Files/Files/VisionSpring/Content%20Images/Homepage/Wonder%20of%20Clear%20Vision/category-icon%20(1).svg" class="addSticker" alt="addSticker"/> 2238 } 2239 2240 } 2241 </div> 2242 } 2243 2244 </div> 2245 </div> 2246 </article> 2247 @SnippetStart("jsOnLoad") 2248 2249 var slides = parseFloat(@numberOfSlider); 2250 var isSlider = "@displayType" == "display-slider" ? true : false; 2251 2252 2253 if(isSlider) { 2254 var customClass = "." + "@customClass"; 2255 var items = customClass + ' .display-slider'; 2256 2257 2258 $(items).owlCarousel({ 2259 loop:true, 2260 dots: @showDots, 2261 rtl: false, 2262 lazyLoad:false, 2263 margin:0, 2264 nav:true, 2265 navText: ["<i class='fa fa-chevron-left'></i>", "<i class='fa fa-chevron-right'></i>"], 2266 responsive:{ 2267 0:{ 2268 items:@numberOfSlidesMobile 2269 }, 2270 768:{ 2271 items:@numberOfSlidesTablet 2272 }, 2273 1000:{ 2274 items: @numberOfSlider 2275 } 2276 } 2277 }) 2278 } 2279 2280 @SnippetEnd("jsOnLoad") 2281 2282

Theory of Change

Our theory of change states “Eyeglasses improve daily functioning, productivity, and earning potential, creating a greater likelihood of a pathway out of poverty.”

Based on the above statement, VisionSpring's programs are designed to advance social impact along three themes: See to Earn for adults to enhance earning potential, See to Learn for school going children so that they learn better, and See to be Safe for truck drivers and allied transport workers so that all road users are safe.

Theory of Change Image