Error executing template "Designs/Hewitt/QueryPublisher/ManageAccount.cshtml"
System.NullReferenceException: Object reference not set to an instance of an object.
   at CompiledRazorTemplates.Dynamic.RazorEngine_65dcd18ba42b47ba897383a887a68c3b.Execute() in c:\Domains\Sites\hewittrad.com\Files\Templates\Designs\Hewitt\QueryPublisher\ManageAccount.cshtml:line 2403
   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 System 3 @using Dynamicweb.Rendering 4 @using System.Linq 5 @using Dna.Frontend.Forms 6 @using Dna.Frontend.UI 7 @using Dna.Validation 8 @using Dynamicweb.Core 9 @using Dynamicweb.Forms 10 @using Dna.Frontend 11 @using Dynamicweb.Security.UserManagement 12 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 13 @using System 14 @using System.Linq 15 @using System.Text 16 @using System.Web 17 @using System.Collections.Generic 18 @using Dna.Frontend 19 @using Dna.Frontend.UI 20 @using Dna.Frontend.Forms 21 @using Dna.UrlServices 22 @using Dna.Validation 23 @using Dynamicweb.Core 24 @using Dynamicweb.Forms 25 @using Dynamicweb.Content 26 @using Dynamicweb.Ecommerce 27 @using Dynamicweb.Rendering 28 @using Dynamicweb.Security.UserManagement 29 @using ImageSettings = Dna.Frontend.UI.ImageSettings 30 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 31 @using System 32 @using System.IO 33 @using System.Web 34 @using System.Linq 35 @using System.Text 36 @using System.Text.RegularExpressions 37 @using System.Collections.Generic 38 @using System.Collections.Specialized 39 @using Dna.Frontend 40 @using Dna.Validation 41 @using Dna.Frontend.UI 42 @using Dna.UrlServices 43 @using Dna.Frontend.Forms 44 @using Dynamicweb.Core 45 @using Dynamicweb.Forms 46 @using Dynamicweb.Rendering 47 @functions{ 48 49 #region Url functions 50 51 public string GetCustomerCenterSortUrl(string field, string listType = "Order") 52 { 53 var paragraphId = Pageview.CurrentParagraph.ID.ToString(); 54 var sortDirectionParameter = "CCSort" + listType + paragraphId; 55 var sortFieldParameter = "CC" + listType + "ByField" + paragraphId; 56 var sortDirection = Sanitize.Parameter(sortDirectionParameter) == "Desc" || Sanitize.Parameter(sortFieldParameter) != field ? "Asc" : "Desc"; 57 58 if (field.IsNotNullOrEmpty()) 59 { 60 return "/Default.aspx?Id=" + Pageview.Page.ID + "&" + sortFieldParameter + "=" + field + "&" + sortDirectionParameter + "=" + sortDirection; 61 } 62 63 return string.Empty; 64 } 65 66 public string GetDataListSortUrl(string field) 67 { 68 var paragraphId = Pageview.CurrentParagraph.ID.ToString(); 69 var sortDirectionParameter = "sortorder"; 70 var sortFieldParameter = "sortby"; 71 var sortByParameter = Sanitize.Parameter(sortFieldParameter).IsNotNullOrEmpty() ? Sanitize.Parameter(sortFieldParameter) : string.Empty; 72 var sortOrderParameter = Sanitize.Parameter(sortDirectionParameter).IsNotNullOrEmpty() ? Sanitize.Parameter(sortDirectionParameter) : "ASC"; 73 var sortDirection = sortOrderParameter.ToUpper() == "DESC" || sortByParameter != field ? "ASC" : "DESC"; 74 75 if (field.IsNotNullOrEmpty()) 76 { 77 return "/Default.aspx?Id=" + Pageview.Page.ID + "&" + sortFieldParameter + "=" + field + "&" + sortDirectionParameter + "=" + sortDirection + "&ViewPID=" + paragraphId; 78 } 79 return string.Empty; 80 } 81 82 public string GetSortFieldParameter(string key, string field = "", string listType = "Order") 83 { 84 var paragraphId = Pageview.CurrentParagraph.ID.ToString(); 85 if (key.IsNullOrEmpty()) throw new NotSupportedException("'key' is a required field"); 86 87 switch (key) 88 { 89 case "name": 90 var parameter = "CC" + listType + "ByField" + paragraphId; 91 return Sanitize.Parameter(parameter); 92 case "value": 93 if (field.IsNullOrEmpty()) return "asc"; 94 var sortDirectionParameter = "CCSort" + listType + paragraphId; 95 var sortFieldParameter = "CC" + listType + "ByField" + paragraphId; 96 return Sanitize.Parameter(sortDirectionParameter) == "Desc" || Sanitize.Parameter(sortFieldParameter) != field ? "Asc" : "Desc"; 97 default: 98 throw new NotSupportedException(string.Format("The key '{0}' in not supported", key)); 99 } 100 } 101 102 #endregion Url functions 103 104 #region Generic functions 105 106 public static string GetAttributes(Dictionary<string, string> attributes) 107 { 108 if (attributes == null || !attributes.Any()) 109 { 110 return string.Empty; 111 } 112 113 var attributesConcat = attributes.Aggregate(string.Empty, (current, attribute) => current + GetAttribute(attribute.Key, attribute.Value)); 114 115 return attributesConcat; 116 } 117 118 public static string GetAttribute(string attributeName, string attributeValue) 119 { 120 if (attributeValue.IsNullOrEmpty() && !attributeName.Equals("value", StringComparison.InvariantCultureIgnoreCase)) return string.Empty; 121 return " " + attributeName + "=\"" + attributeValue + "\""; 122 } 123 124 #endregion Generic functions 125 126 #region Files functions 127 128 const string ImagesListTitleKey = "title"; 129 const string ImagesListImageKey = "image"; 130 131 /// <summary> 132 /// Gets the list of files from a folder. 133 /// </summary> 134 /// <return>Item1 is filename (with extension), Item2 is the title and Item3 is the FileType.</return> 135 public static IEnumerable<Tuple<string, string, FileType>> GetFilesInFolder(string defaultFile, string searchPattern, string fileTitle = "", bool addDefaultFile = true) 136 { 137 var files = new List<Tuple<string,string,FileType>>(); 138 try 139 { 140 var mapPath = HttpContext.Current.Server.MapPath(defaultFile); 141 var folderServerPath = Path.GetDirectoryName(mapPath); 142 143 if (folderServerPath == null || !Directory.Exists(folderServerPath)) return files; 144 145 // Get Images from folder 146 const string temp = @"\"; 147 const string metafield = "title"; 148 var metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(defaultFile); 149 var title = metadata != null && metadata.GetValue(metafield).IsNotNullOrEmpty() ? metadata.GetValue(metafield) : fileTitle; 150 var folderWebPath = defaultFile.Contains("/") ? defaultFile.Substring(0, defaultFile.LastIndexOf("/", StringComparison.Ordinal)) : defaultFile; 151 152 if (addDefaultFile && File.Exists(mapPath)) 153 { 154 files.Add(new Tuple<string, string, FileType>(defaultFile, title, defaultFile.GetFileType())); 155 } 156 157 foreach (var file in Directory.GetFiles(folderServerPath, searchPattern)) 158 { 159 var filePath = folderWebPath + "/" + file.Substring(file.LastIndexOf(temp, StringComparison.Ordinal) + 1, file.Length - file.LastIndexOf(temp, StringComparison.Ordinal) - 1); 160 metadata = Dynamicweb.Content.Files.Metadata.EditorFactory.GetMetadataForFile(filePath); 161 title = metadata != null && metadata.GetValue(metafield).IsNullOrEmpty() ? metadata.GetValue(metafield) : fileTitle; 162 163 files.Add(new Tuple<string, string, FileType>(filePath, title, file.GetFileType())); 164 } 165 } 166 catch (Exception ex){} 167 168 return files; 169 } 170 /// <summary> 171 /// Gets the list of image or HTML5 video files from a folder. 172 /// </summary> 173 /// <return>Item1 is filename (with extension), Item2 is the title and Item3 is the FileType (Image, Video).</return> 174 public static IEnumerable<Tuple<string,string,FileType>> GetMediaFilesInFolder(string defaulMedia, string searchPattern, string defaultName = "", bool addDefaultMedia = true) 175 { 176 return GetFilesInFolder(defaulMedia, searchPattern, defaultName, addDefaultMedia).Where(f => f.Item3 == FileType.Image || f.Item3 == FileType.Video).ToList(); 177 } 178 179 #endregion Files functions 180 181 #region Image functions 182 183 public static Dictionary<string, string> GetWidthAndHeightFromQueryString(string imageSource, bool addSource = false) 184 { 185 var widthAndHeight = new Dictionary<string, string>(); 186 187 if(imageSource.Contains("?")){ 188 var querySubstring = imageSource.Substring(imageSource.LastIndexOf('?') + 1); 189 var queryParams = HttpUtility.HtmlDecode(querySubstring).Split('&'); 190 191 if (!queryParams.Any()) 192 return widthAndHeight; 193 194 foreach (var param in queryParams.Where(k => k.StartsWith("width") || k.StartsWith("height"))) 195 { 196 var keyValuePair = param.Split('='); 197 198 if (keyValuePair[1].IsNotNullOrEmpty()) 199 { 200 widthAndHeight.Add(keyValuePair[0].ToLower(), keyValuePair[1]); 201 } 202 } 203 } 204 else if(imageSource.Contains("width") || imageSource.Contains("height")) 205 { 206 var queryParams = imageSource.Split('/'); 207 var imgParam = string.Empty; 208 209 foreach (var param in queryParams) 210 { 211 switch (imgParam) 212 { 213 case "width": 214 widthAndHeight.Add("width", param); 215 break; 216 case "height": 217 widthAndHeight.Add("height", param); 218 break; 219 } 220 221 switch (param) 222 { 223 case "width": 224 imgParam = "width"; 225 break; 226 case "height": 227 imgParam = "height"; 228 break; 229 default: 230 imgParam = string.Empty; 231 break; 232 } 233 } 234 } 235 236 if (addSource && imageSource.IsNotNullOrEmpty()) 237 { 238 widthAndHeight.Add("srcset", imageSource); 239 } 240 241 return widthAndHeight; 242 } 243 244 #endregion Image functions 245 246 #region Form Field functions 247 248 public string GetWrapperStart(bool includeWrapper, FieldType fieldType, string htmlElement, bool isRequired = false, string fieldClass = "") 249 { 250 if (!includeWrapper || htmlElement.IsNullOrEmpty()) return string.Empty; 251 var cssClass = new List<string> {fieldType.ToString().ToLower()}; 252 253 if (fieldClass.IsNotNullOrEmpty()) 254 cssClass.Add(fieldClass); 255 if (isRequired) 256 cssClass.Add("mandatory"); 257 258 var attributes = new Dictionary<string, string>() 259 { 260 {"class", string.Join(" ", cssClass)} 261 }; 262 263 return GetHtmlElement(htmlElement, attributes); 264 } 265 266 public string GetWrapperEnd(bool includeWrapper, string htmlElement) 267 { 268 return !includeWrapper ? string.Empty : GetHtmlElement(htmlElement, true); 269 } 270 271 public string GetControlWithRequiredClass(bool isRequired, string control, string fieldClass = "") 272 { 273 if (!isRequired) return control; 274 if (fieldClass.IsNotNullOrEmpty()) fieldClass += " "; 275 fieldClass += "mandatory"; 276 var regex = new Regex(Regex.Escape(" ")); 277 return regex.Replace(control, " class=\"" + fieldClass + "\" ", 1); 278 } 279 280 public static string GetAttributes(FieldSettings settings, bool returnFieldType = true) 281 { 282 var attributes = new StringBuilder(); 283 if (returnFieldType) 284 { 285 var fieldType = string.Empty; 286 switch (settings.Type) 287 { 288 case FieldType.Select: 289 break; 290 case FieldType.Checkboxlist: 291 fieldType = FieldType.Checkbox.ToString().ToLower(); 292 break; 293 case FieldType.DatetimeLocal: 294 fieldType = "datetime-local"; 295 break; 296 case FieldType.Textarea: 297 case FieldType.File: 298 case FieldType.Text: 299 case FieldType.Hidden: 300 case FieldType.Submit: 301 case FieldType.Reset: 302 case FieldType.Radio: 303 case FieldType.Checkbox: 304 case FieldType.Divider: 305 case FieldType.Image: 306 case FieldType.Password: 307 case FieldType.Textstring: 308 case FieldType.Button: 309 case FieldType.Search: 310 case FieldType.Email: 311 case FieldType.Url: 312 case FieldType.Tel: 313 case FieldType.Number: 314 case FieldType.Range: 315 case FieldType.Date: 316 case FieldType.Month: 317 case FieldType.Week: 318 case FieldType.Time: 319 case FieldType.Datetime: 320 case FieldType.Color: 321 case FieldType.Unknown: 322 default: 323 fieldType = settings.Type.ToString().ToLower(); 324 break; 325 } 326 if (!settings.Attributes.ContainsKey("type")) 327 { 328 attributes.Append(GetAttribute("type", fieldType)); 329 } 330 } 331 attributes.Append(GetAttribute("class", settings.CssClass)); 332 attributes.Append(GetAttribute("id", settings.Id)); 333 attributes.Append(GetAttribute("name", settings.SystemName)); 334 if (settings.Type != FieldType.Textarea) 335 { 336 attributes.Append(GetAttribute("value", settings.Value)); 337 } 338 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) 339 { 340 // Only works wit these types 341 attributes.Append(GetAttribute("placeholder", settings.Placeholder)); 342 } 343 if (settings.Type == FieldType.Datetime) 344 { 345 attributes.Append(GetAttribute("placeholder", "&#x1f4c5;")); 346 } 347 if (settings.Type != FieldType.Checkboxlist) 348 { 349 attributes.Append(GetAttribute("required", settings.IsRequired)); 350 } 351 attributes.Append(GetAttributes(settings.Attributes)); 352 return attributes.ToString(); 353 } 354 355 public static string GetAttributes(FieldOption optionSettings, FieldType fieldType = FieldType.Select) 356 { 357 var attributes = new StringBuilder(); 358 if (fieldType != FieldType.Select) 359 { 360 attributes.Append(GetAttribute("name", optionSettings.SystemName)); 361 } 362 attributes.Append(GetAttribute("value", optionSettings.Value)); 363 attributes.Append(GetAttributes(optionSettings.Attributes)); 364 return attributes.ToString(); 365 } 366 367 public static string GetAttribute(string attributeName, bool attributeValue) 368 { 369 if (!attributeValue) return string.Empty; 370 return " " + attributeName + "=\"" + attributeName + "\""; 371 } 372 373 public static string GetAttributeString(string string1 = "", string string2 = "") 374 { 375 var result = new List<string>(); 376 377 if (string1.IsNotNullOrEmpty()) 378 result.AddRange(string1.Split(' ').ToList()); 379 if (string2.IsNotNullOrEmpty()) 380 result.AddRange(string2.Split(' ').ToList()); 381 382 return string.Join(" ", result); 383 } 384 385 #endregion 386 387 #region Dynamicweb Template Engine Workaround 388 389 public static string GetHtmlElement(string element, bool isClosingElement = false) 390 { 391 return GetHtmlElementForDw(element, null, string.Empty, isClosingElement); 392 } 393 394 public static string GetHtmlElement(string element, Dictionary<string, string> attributes, bool isClosingElement = false) 395 { 396 return GetHtmlElementForDw(element, attributes, string.Empty, isClosingElement); 397 } 398 399 public static string GetHtmlElement(string element, string processedAttributes, bool isClosingElement = false) 400 { 401 return GetHtmlElementForDw(element, null, processedAttributes, isClosingElement); 402 } 403 404 private static string GetHtmlElementForDw(string element, Dictionary<string, string> attributes = null, string processedAttributes = "", bool isClosingElement = false) 405 { 406 var result = new StringBuilder("<"); 407 408 if (attributes != null || processedAttributes.IsNotNullOrEmpty()) 409 { 410 result.Append(element); 411 if (attributes != null) 412 { 413 result.Append(GetAttributes(attributes)); 414 } 415 else if (processedAttributes.IsNotNullOrEmpty()) 416 { 417 result.Append(processedAttributes); 418 } 419 if (isClosingElement) 420 { 421 result.Append("/"); 422 } 423 } 424 else 425 { 426 if (isClosingElement) 427 { 428 result.Append("/"); 429 } 430 result.Append(element); 431 } 432 433 result.Append(">"); 434 435 return result.ToString(); 436 } 437 438 #endregion Dynamicweb Template Engine Workaround 439 } 440 @{ 441 442 @* Tab helpers *@ 443 @helper InternalRenderTabHeader(string key, string label, string cssClass = "") 444 { 445 @SnippetStart("tabHeaders") 446 <li class="@cssClass"> 447 <a href="@key">@label</a> 448 </li> 449 @SnippetEnd("tabHeaders") 450 } 451 452 453 @* Paging helpers *@ 454 @helper InternalRenderGoToFirstPage(NameValueCollection queryParameters, string pageNumQueryParameter, int currentPage, int numOfPages, int loopPageSize, int currentPageNum = 0) 455 { 456 if (currentPageNum == 0) 457 { 458 currentPageNum = currentPage; 459 } 460 461 if (currentPage > 2 && numOfPages > loopPageSize && currentPageNum != 1) 462 { 463 queryParameters.Remove(pageNumQueryParameter); 464 @InternalRenderPageItem(queryParameters, "1") 465 @InternalRenderEllipsis() 466 } 467 } 468 469 @helper InternalRenderGoToLastPage(NameValueCollection queryParameters, string pageNumQueryParameter, int currentPage, int numOfPages, int loopPageSize, int endPage) 470 { 471 if (currentPage < numOfPages - 1 && numOfPages > loopPageSize && endPage != numOfPages) 472 { 473 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageNumQueryParameter, numOfPages.ToString()); 474 @InternalRenderEllipsis() 475 @InternalRenderPageItem(queryParameters, numOfPages.ToString()) 476 } 477 } 478 479 @helper InternalRenderPageItem(NameValueCollection queryParameters, string pageNum, string cssClass = "") 480 { 481 var url = Helpers.GetCurrentUrl(true, true); 482 var href = Helpers.BuildUri(url, queryParameters); 483 484 <li class="@cssClass"> 485 <a href="@href.PathAndQuery"> 486 @pageNum 487 </a> 488 </li> 489 } 490 491 @helper InternalRenderPageItem(string href, string label, string cssPartialClass, IconPosition position) 492 { 493 <li> 494 <a href="@href"> 495 @RenderIcon(cssPartialClass, label, position) 496 </a> 497 </li> 498 } 499 500 @helper InternalRenderEllipsis() 501 { 502 <li> 503 <span>...</span> 504 </li> 505 } 506 507 508 @* Form field helpers *@ 509 @helper InternalRenderLabel(FieldSettings settings) 510 { 511 @InternalRenderLabel(settings.Label, settings.TranslateKeyForLabel) 512 } 513 514 @helper InternalRenderLabel(string label, string translateKey = "") 515 { 516 @( translateKey.IsNotNullOrEmpty() ? Translate(translateKey) : label) 517 } 518 519 @helper InternalRenderCheckboxField(FieldSettings settings) 520 { 521 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 522 { 523 settings.Assert(FieldType.Checkbox); 524 if (settings.IsChecked && !settings.Attributes.ContainsKey("checked")) 525 { 526 settings.Attributes.Add("checked", "checked"); 527 } 528 529 @InternalRenderFieldHeader(settings, false) 530 531 if (settings.Label.IsNotNullOrEmpty() || settings.TranslateKeyForLabel.IsNotNullOrEmpty()) 532 { 533 var cssClassList = new List<string> {settings.Type.ToString().ToLower(), settings.LabelCssClass}; 534 var cssClass = string.Join(" ", cssClassList.Where(s => s.IsNotNullOrEmpty())); 535 536 if (!settings.LabelAttributes.ContainsKey("class")) 537 { 538 settings.LabelAttributes.Add("class", cssClass); 539 } 540 else 541 { 542 settings.LabelAttributes["class"] = string.Concat(cssClass, " ", settings.LabelAttributes["class"]); 543 } 544 if (!settings.LabelAttributes.ContainsKey("for")) 545 { 546 settings.LabelAttributes.Add("for", settings.Id); 547 } 548 549 @GetHtmlElement("label", settings.LabelAttributes) 550 if (settings.Control.IsNotNullOrEmpty()) 551 { 552 if (settings.Value.IsNullOrEmpty() && settings.IsRequired) 553 { 554 var checkedAttribute = "checked=\"checked\""; 555 settings.Control = settings.Control.Replace(checkedAttribute, string.Empty); 556 } 557 @settings.Control 558 } 559 else 560 { 561 @GetHtmlElement("input", GetAttributes(settings), true) 562 } 563 <span> 564 @InternalRenderLabel(settings) 565 </span> 566 @GetHtmlElement("label", true) 567 } 568 else 569 { 570 if (settings.Control.IsNotNullOrEmpty()) 571 { 572 if (settings.Value.IsNullOrEmpty() && settings.IsRequired) 573 { 574 var checkedAttribute = "checked=\"checked\""; 575 settings.Control = settings.Control.Replace(checkedAttribute, string.Empty); 576 } 577 @settings.Control 578 } 579 else 580 { 581 @GetHtmlElement("input", GetAttributes(settings), true) 582 } 583 } 584 585 @InternalRenderFieldFooter(settings) 586 } 587 } 588 589 @helper InternalRenderTextareaField(FieldSettings settings) 590 { 591 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 592 { 593 settings.Assert(FieldType.Textarea); 594 595 @InternalRenderFieldHeader(settings) 596 597 if (settings.Control.IsNotNullOrEmpty()) 598 { 599 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 600 } 601 else 602 { 603 if (!settings.Attributes.ContainsKey("rows")) 604 { 605 settings.Attributes.Add("rows", "6"); 606 } 607 if (!settings.Attributes.ContainsKey("cols")) 608 { 609 settings.Attributes.Add("cols", "50"); 610 } 611 @GetHtmlElement("textarea", GetAttributes(settings, false)) 612 @settings.Value 613 @GetHtmlElement("textarea", true) 614 } 615 616 @InternalRenderFieldFooter(settings) 617 } 618 } 619 620 @helper InternalRenderRadioOrCheckboxListField(FieldSettings settings) 621 { 622 if (settings.LoopOptions.Any() || settings.FieldOptionsList.Any() || settings.Control.IsNotNullOrEmpty()) 623 { 624 var optionCount = 0; 625 626 settings.Assert(FieldType.Radio); 627 628 @InternalRenderFieldHeader(settings) 629 630 if (settings.LoopOptions.Any()) 631 { 632 settings.CssClass = settings.Type.ToString().ToLower(); 633 foreach (var option in settings.LoopOptions) 634 { 635 optionCount++; 636 if (settings.Id.IsNullOrEmpty() || settings.Id == settings.SystemName) 637 { 638 settings.Id = settings.SystemName + optionCount; 639 } 640 641 var cssClassList = new List<string> {settings.Type.ToString().ToLower(), settings.CssClass}; 642 var cssClass = string.Join(" ", cssClassList.Where(s => s.IsNotNullOrEmpty())); 643 644 if (!settings.LabelAttributes.ContainsKey("class")) 645 { 646 settings.LabelAttributes.Add("class", cssClass); 647 } 648 else 649 { 650 settings.LabelAttributes["class"] = string.Concat(cssClass, " ", settings.LabelAttributes["class"]); 651 } 652 if (!settings.LabelAttributes.ContainsKey("for")) 653 { 654 settings.LabelAttributes.Add("for", settings.Id); 655 } 656 657 @GetHtmlElement("label", settings.LabelAttributes) 658 @GetHtmlElement("input", GetAttributes(settings), true) 659 <span>@option.GetString(settings.LabelLoopTag)</span> 660 @GetHtmlElement("label", true) 661 } 662 } 663 else if (settings.FieldOptionsList.Any()) 664 { 665 foreach (var option in settings.FieldOptionsList) 666 { 667 optionCount++; 668 669 if (option.SystemName.IsNullOrEmpty()) 670 { 671 option.SystemName = settings.SystemName; 672 } 673 if (option.Id.IsNullOrEmpty() || option.Id == option.SystemName) 674 { 675 option.Id = option.SystemName + optionCount; 676 } 677 var cssClassList = new List<string> {settings.Type.ToString().ToLower(), option.CssClass}; 678 var cssClass = string.Join(" ", cssClassList.Where(s => s.IsNotNullOrEmpty())); 679 680 if (!option.LabelAttributes.ContainsKey("class")) 681 { 682 option.LabelAttributes.Add("class", cssClass); 683 } 684 else 685 { 686 option.LabelAttributes["class"] = string.Concat(cssClass, " ", option.LabelAttributes["class"]); 687 } 688 if (!option.LabelAttributes.ContainsKey("for")) 689 { 690 option.LabelAttributes.Add("for", option.Id); 691 } 692 693 @GetHtmlElement("label", option.LabelAttributes) 694 @InternalRenderInputOptionField("input", option, settings.Type) 695 <span>@option.Label</span> 696 @GetHtmlElement("label", true) 697 } 698 } 699 else if (settings.Control.IsNotNullOrEmpty()) 700 { 701 @settings.Control 702 } 703 704 @InternalRenderFieldFooter(settings) 705 } 706 } 707 708 @helper InternalRenderInputField(FieldSettings settings) 709 { 710 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 711 { 712 settings.Assert(FieldType.Text); 713 714 @InternalRenderFieldHeader(settings) 715 716 if (settings.Control.IsNotNullOrEmpty()) 717 { 718 var type = settings.Type.ToString().ToLower(); 719 if (settings.Type == FieldType.DatetimeLocal) 720 { 721 type = "datetime-local"; 722 } 723 724 if (settings.Type == FieldType.Password) 725 { 726 settings.Control = settings.Control.Replace("input ", "input autocomplete=\"off\" "); 727 } 728 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 729 } 730 else 731 { 732 if (settings.Type == FieldType.Password && !settings.Attributes.ContainsKey("autocomplete")) 733 { 734 settings.Attributes.Add("autocomplete", "off"); 735 } 736 @GetHtmlElement("input", GetAttributes(settings), true) 737 } 738 739 @InternalRenderFieldFooter(settings) 740 } 741 } 742 743 @helper InternalRenderDateTimeField(FieldSettings settings) 744 { 745 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 746 { 747 settings.Assert(FieldType.Datetime); 748 settings.Attributes = new Dictionary<string, string> 749 { 750 {"placeholder", "&#xf073;"} 751 }; 752 753 @InternalRenderFieldHeader(settings) 754 755 if (settings.Control.IsNotNullOrEmpty()) 756 { 757 var type = settings.Type.ToString().ToLower(); 758 759 settings.Control = settings.Control.Replace("type=\"text\"", "type=\"" + type + "\""); 760 @GetControlWithRequiredClass(settings.IsRequired, settings.Control) 761 } 762 else 763 { 764 @GetHtmlElement("input", GetAttributes(settings), true) 765 } 766 767 @InternalRenderFieldFooter(settings) 768 } 769 } 770 771 @helper InternalRenderSelectField(FieldSettings settings) 772 { 773 const int limit = 10; 774 775 settings.Assert(FieldType.Select); 776 777 if (settings.CssClass.ToLower().Contains("country")) 778 { 779 @RenderCountriesDropdownField(settings, true, settings.CssClass.ToLower().Contains("highlights")) 780 } 781 else 782 { 783 if (settings.SystemName.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty() || settings.FieldOptionsList.Any() || settings.ValuesList.Any()) 784 { 785 @InternalRenderFieldHeader(settings) 786 787 int optionsCount; 788 if (settings.Control.IsNotNullOrEmpty()) 789 { 790 optionsCount = Regex.Matches(settings.Control, "option ").Count; 791 792 if (optionsCount > limit || optionsCount == 0) 793 { 794 settings.Control = settings.Control.Replace("select ", "select data-live-search=\"true\" "); 795 } 796 @GetControlWithRequiredClass(settings.IsRequired, settings.Control, settings.CssClass) 797 } 798 else 799 { 800 optionsCount = settings.FieldOptionsList.Count + settings.ValuesList.Count; 801 802 if (!settings.Attributes.ContainsKey("multiple") && !settings.Attributes.ContainsKey("data-live-search") && (optionsCount > limit || optionsCount == 0)) 803 { 804 settings.Attributes.Add("data-live-search", "true"); 805 } 806 @GetHtmlElement("select", GetAttributes(settings, false)) 807 808 if (settings.FirstHardcodedOptionLabel.IsNotNullOrEmpty()) 809 { 810 @InternalRenderOption(FieldOption.CreateOption(settings.FirstHardcodedOptionLabel, settings.FirstHardcodedOptionValue, settings.IsFirstHardcodedOptionSelected)) 811 } 812 813 foreach (var option in settings.FieldOptionsList) 814 { 815 @InternalRenderOption(option) 816 } 817 foreach (var option in settings.ValuesList) 818 { 819 @InternalRenderOption(FieldOption.CreateOption(option, option)) 820 } 821 822 @GetHtmlElement("select", true) 823 } 824 825 @InternalRenderFieldFooter(settings) 826 } 827 } 828 } 829 830 @helper InternalRenderButtonField(FieldSettings settings) 831 { 832 settings.Assert(FieldType.Button); 833 834 @InternalRenderFieldHeader(settings, false) 835 836 if (settings.Control.IsNotNullOrEmpty()) 837 { 838 var controlOutput = settings.Control; 839 switch (settings.Type) 840 { 841 case FieldType.Submit: 842 controlOutput = controlOutput.Replace("input ", "input class='btn btn-default'"); 843 break; 844 case FieldType.Reset: 845 controlOutput = controlOutput.Replace("input ", "input class='btn btn-bg2'"); 846 break; 847 case FieldType.Button: 848 case FieldType.Textarea: 849 case FieldType.File: 850 case FieldType.Text: 851 case FieldType.Hidden: 852 case FieldType.Radio: 853 case FieldType.Checkbox: 854 case FieldType.Select: 855 case FieldType.Checkboxlist: 856 case FieldType.Divider: 857 case FieldType.Image: 858 case FieldType.Password: 859 case FieldType.Textstring: 860 case FieldType.Search: 861 case FieldType.Email: 862 case FieldType.Url: 863 case FieldType.Tel: 864 case FieldType.Number: 865 case FieldType.Range: 866 case FieldType.Date: 867 case FieldType.Month: 868 case FieldType.Week: 869 case FieldType.Time: 870 case FieldType.Datetime: 871 case FieldType.DatetimeLocal: 872 case FieldType.Color: 873 case FieldType.Unknown: 874 default: 875 throw new NotSupportedException(string.Format("Unsupported Field Type: {0}.", settings.Type.ToString())); 876 } 877 @controlOutput 878 } 879 else 880 { 881 settings.CssClass = settings.CssClass.IsNullOrEmpty() ? "btn btn-default" : "btn " + settings.CssClass; 882 if (settings.Type == FieldType.Button) 883 { 884 if (settings.Label.IsNullOrEmpty()) 885 { 886 settings.Label = Translate("Button"); 887 } 888 @GetHtmlElement("button", GetAttributes(settings)) 889 @InternalRenderLabel(settings) 890 @GetHtmlElement("button", true) 891 } 892 else 893 { 894 @GetHtmlElement("input", GetAttributes(settings), true) 895 } 896 } 897 898 @InternalRenderFieldFooter(settings) 899 } 900 901 902 @* Forms for Editors field types in enum FieldType *@ 903 @helper InternalRenderTextStringField(FieldSettings settings) 904 { 905 settings.Assert(FieldType.Textstring); 906 907 if (settings.Description.IsNotNullOrEmpty() || settings.Control.IsNotNullOrEmpty()) 908 { 909 if (settings.Control.IsNotNullOrEmpty()) 910 { 911 @settings.Control 912 } 913 else 914 { 915 <p class="help-block">@settings.Description</p> 916 } 917 } 918 } 919 920 @helper InternalRenderImageField(FieldSettings settings) 921 { 922 settings.Assert(FieldType.Image); 923 924 if (settings.Control.IsNotNullOrEmpty()) 925 { 926 @settings.Control 927 } 928 } 929 930 @helper InternalRenderDividerField(FieldSettings settings) 931 { 932 settings.Assert(FieldType.Divider); 933 934 <hr class="divider" /> 935 } 936 937 @helper InternalRenderInputOptionField(string htmlElement, FieldOption optionSettings, FieldType type = FieldType.Radio) 938 { 939 var fieldType = type == FieldType.Checkboxlist ? FieldType.Checkbox.ToString().ToLower() : type.ToString().ToLower(); 940 var attributes = new StringBuilder(GetAttribute("type", fieldType)); 941 attributes.Append(GetAttribute("value", optionSettings.Value)); 942 attributes.Append(GetAttribute("name", optionSettings.SystemName)); 943 attributes.Append(optionSettings.Id.IsNotNullOrEmpty() ? GetAttribute("id", optionSettings.Id) : optionSettings.SystemName); 944 attributes.Append(GetAttributes(optionSettings.Attributes)); 945 946 if (optionSettings.IsSelected) 947 { 948 attributes.Append(GetAttribute("checked", "checked")); 949 } 950 if (optionSettings.IsDisabled) 951 { 952 attributes.Append(GetAttribute("disabled", "disabled")); 953 } 954 955 @GetHtmlElement(htmlElement, attributes.ToString()) 956 } 957 958 @helper InternalRenderOption(FieldOption optionSettings) 959 { 960 var selected = optionSettings.IsSelected ? " selected" : string.Empty; 961 var disabled = optionSettings.IsDisabled ? " disabled" : string.Empty; 962 var readOnly = optionSettings.IsReadOnly ? " readonly" : string.Empty; 963 var attributes = GetAttributes(optionSettings); 964 965 @GetHtmlElement("option", attributes + selected + disabled + readOnly) 966 @InternalRenderLabel(optionSettings.Label, optionSettings.TranslateKeyForLabel) 967 @GetHtmlElement("option", true) 968 } 969 970 @helper InternalRenderFieldHeader(FieldSettings settings, bool renderLabel = true) 971 { 972 @GetWrapperStart(settings.IncludeWrapper, settings.Type, settings.WrapperElement, settings.IsRequired, settings.WrapperCssClass) 973 if ((settings.Label.IsNotNullOrEmpty() || settings.TranslateKeyForLabel.IsNotNullOrEmpty()) && renderLabel) 974 { 975 var attributes = new Dictionary<string, string> 976 { 977 {"class", GetAttributeString("form-label", settings.LabelCssClass)} 978 }; 979 980 if (settings.Type != FieldType.Checkboxlist && settings.Type != FieldType.Radio) 981 { 982 attributes.Add("for", settings.SystemName); 983 } 984 985 @GetHtmlElement("label", attributes) 986 @InternalRenderLabel(settings) 987 @GetHtmlElement("label", true) 988 } 989 if (settings.Prepend.IsNotNullOrEmpty()) 990 { 991 var attributes = new Dictionary<string, string> 992 { 993 {"class", "fieldPrepend input-group-addon"} 994 }; 995 @GetHtmlElement("div", attributes) 996 @settings.Prepend 997 @GetHtmlElement("div", true) 998 } 999 if (settings.IncludeFieldWrapper) 1000 { 1001 @:<div class="fieldContainer hidden @settings.FieldWrapperCssClass"> 1002 } 1003 } 1004 1005 @helper InternalRenderFieldFooter(FieldSettings settings) 1006 { 1007 if (settings.Icon.IsNotNullOrEmpty()) 1008 { 1009 @RenderIcon(settings.Icon, settings.Tooltip, IconPosition.Left, true) 1010 } 1011 if (settings.Append.IsNotNullOrEmpty()) 1012 { 1013 <div class="fieldAppend input-group-addon">@settings.Append</div> 1014 } 1015 if (settings.Description.IsNotNullOrEmpty()) 1016 { 1017 <p class="help-block">@settings.Description</p> 1018 } 1019 if (settings.IncludeFieldWrapper) 1020 { 1021 @:</div> 1022 } 1023 @GetWrapperEnd(settings.IncludeWrapper, settings.WrapperElement) 1024 } 1025 1026 @helper InternalRenderQuantityField(int productStock, int productAvailableAmount, int selectedQuantity = 1, int productType = 0) 1027 { 1028 @InternalRenderQuantityField(productStock, productAvailableAmount, selectedQuantity, string.Empty, 10, false, false, productType) 1029 } 1030 1031 @helper InternalRenderQuantityField(int productStock, int productAvailableAmount, int selectedQuantity = 1, bool variantGroupsExistList = false) 1032 { 1033 @InternalRenderQuantityField(productStock, productAvailableAmount, selectedQuantity, string.Empty, 10, false, variantGroupsExistList) 1034 } 1035 1036 @helper InternalRenderQuantityField(int productStock, int productAvailableAmount, int selectedQuantity = 1, string fieldSystemName = "", int limit = 10, bool isCheckout = true, bool variantGroupsExistList = false, int productType = 0, string productId = "") 1037 { 1038 var isQuantityTextHidden = selectedQuantity < 10 && productStock > 0 || !isCheckout ? " hidden" : string.Empty; 1039 var isSelectDisabled = productStock <= 0 && !isCheckout; 1040 var quantityTextFieldSettings = new FieldSettings 1041 { 1042 Value = selectedQuantity.ToString(), 1043 SystemName = fieldSystemName.IsNullOrEmpty() ? "quantity" : fieldSystemName, 1044 Id = (fieldSystemName.IsNullOrEmpty() ? "quantity_" : fieldSystemName) + productId, 1045 Attributes = new Dictionary<string, string> 1046 { 1047 {"maxlength", "5"}, 1048 {"data-productStock", productStock.ToString()}, 1049 {"data-productAvailable", productAvailableAmount.ToString()}, 1050 {"data-outofstock", Translate("Out of stock")}, 1051 {"data-stocktranslate", Translate("The current stock is")}, 1052 {"data-currentValue", selectedQuantity.ToString()} 1053 } 1054 }; 1055 1056 if (productType != 1 && productType != 3) 1057 { 1058 quantityTextFieldSettings.Type = FieldType.Number; 1059 quantityTextFieldSettings.Label = Translate("Qty"); 1060 quantityTextFieldSettings.CssClass = "col-xs-4 col-sm-7 quantityInput" + isQuantityTextHidden; 1061 quantityTextFieldSettings.LabelCssClass = productStock > 0 ? "" : "hidden"; 1062 quantityTextFieldSettings.Attributes.Add("min", "1"); 1063 quantityTextFieldSettings.Attributes.Add("onblur", "checkMinValue(this);"); 1064 1065 <fieldset class="quantity-container pull-left"> 1066 @if (isCheckout) 1067 { 1068 <div class="@isQuantityTextHidden quantityPriceContainer"> 1069 @RenderField(quantityTextFieldSettings) 1070 @RenderBootstrapButton(new BootstrapButtonSettings {IconCssClass = "fa-refresh", CssClass = "submitQuantity btnCart-blue", ButtonType = BootstrapButtonSettings.BootstrapButtonType.Button}) 1071 </div> 1072 } 1073 else 1074 { 1075 @RenderField(quantityTextFieldSettings) 1076 } 1077 1078 @if (selectedQuantity < limit) 1079 { 1080 var quantityOptionLimit = productStock <= 0 ? 10 : productStock >= limit || variantGroupsExistList ? limit : productStock + 1; 1081 var quantityFieldSettings = new FieldSettings 1082 { 1083 Type = FieldType.Select, 1084 SystemName = "quantitySelect", 1085 Id = "quantitySelect" + productId 1086 }; 1087 if (isSelectDisabled) 1088 { 1089 quantityFieldSettings.Attributes.Add("disabled", "disabled"); 1090 } 1091 1092 for (var num = 1; num < quantityOptionLimit; num++) 1093 { 1094 var cssClass = num >= quantityOptionLimit ? "hidden" : ""; 1095 quantityFieldSettings.FieldOptionsList.Add(new FieldOption {Label = num.ToString(), Value = num.ToString(), IsSelected = selectedQuantity == num, CssClass = cssClass}); 1096 } 1097 1098 if (productStock >= limit || variantGroupsExistList) 1099 { 1100 var limitPlus = limit + "+"; 1101 var cssClass = variantGroupsExistList && productStock < limit ? "hidden" : ""; 1102 quantityFieldSettings.FieldOptionsList.Add(new FieldOption {Label = limitPlus, Value = limitPlus, CssClass = cssClass}); 1103 } 1104 @RenderField(quantityFieldSettings) 1105 } 1106 </fieldset> 1107 } 1108 else 1109 { 1110 quantityTextFieldSettings.Type = FieldType.Hidden; 1111 @RenderField(quantityTextFieldSettings) 1112 } 1113 } 1114 1115 @* Countries and Regions helpers *@ 1116 @helper InternalRenderCountryAndRegionsJsVariables(Dynamicweb.Ecommerce.International.CountryCollection countries = null) 1117 { 1118 if (countries == null) 1119 { 1120 countries = Dynamicweb.Ecommerce.Services.Countries.GetCountries(); 1121 } 1122 1123 if (countries.Any()) 1124 { 1125 @: @SnippetStart("jsVariables") var countryRegions = {}; @SnippetEnd("jsVariables") 1126 1127 foreach (var country in countries.OrderBy(s => s.Name)) 1128 { 1129 var regions = Dynamicweb.Ecommerce.Services.Countries.GetRegions(country.Code2); 1130 1131 if (regions.Any()) 1132 { 1133 @: @SnippetStart("jsVariables") countryRegions.@( country.Code2) = {}; @SnippetEnd("jsVariables") 1134 <text> 1135 @SnippetStart("jsVariables") 1136 countryRegions.@( country.Code2).code = []; 1137 countryRegions.@( country.Code2).name = []; 1138 @SnippetEnd("jsVariables") 1139 </text> 1140 foreach (var region in regions.OrderBy(s => s.Name)) 1141 { 1142 <text> 1143 @SnippetStart("jsVariables") 1144 countryRegions["@country.Code2"].code.push("@region.RegionCode"); 1145 countryRegions["@country.Code2"].name.push("@region.Name"); 1146 @SnippetEnd("jsVariables") 1147 </text> 1148 } 1149 } 1150 } 1151 } 1152 } 1153 1154 }@inherits RazorTemplateBase<RazorTemplateModel<Template>> 1155 @using Dynamicweb.Rendering 1156 @functions 1157 { 1158 public static bool IsBillingAddressReadOnly() 1159 { 1160 return Dna.Modules.Features.FeatureManager.IsEnabled("IsBillingAddressReadOnly", "Set to 'true' if the Billing Address should be read-only."); 1161 } 1162 1163 public static bool IsBillingAddressEditable() 1164 { 1165 return Dna.Modules.Features.FeatureManager.IsEnabled("IsBillingAddressEditable", "Set to 'true' if the Billing Address should be editable."); 1166 } 1167 1168 public static bool IsShippingAddressEditable() 1169 { 1170 return Dna.Modules.Features.FeatureManager.IsEnabled("IsShippingAddressEditable", "Set to 'true' if the Shipping Address should be editable."); 1171 } 1172 1173 public static bool ShowNoErpConnectionMessage() 1174 { 1175 return Dna.Modules.Features.FeatureManager.IsEnabled("showNoErpConnectionMessage", "Set to 'true' if want to show the 'No ERP Connection Message'."); 1176 } 1177 1178 public static bool ShowStateFieldAsDropdown() 1179 { 1180 return Dna.Modules.Features.FeatureManager.IsEnabled("showStateFieldAsDropdown", "Set to 'true' if the State field should be a drop-down."); 1181 } 1182 public static bool ShowVariantsAsDropdown() 1183 { 1184 return Dna.Modules.Features.FeatureManager.IsEnabled("showVariantsAsDropdown", "Set to 'true' if the Variant field should be a drop-down."); 1185 } 1186 public static bool ShowB2BLogin() 1187 { 1188 return Dna.Modules.Features.FeatureManager.IsEnabled("showB2BLogin", "Set to 'true' if it should display a login page."); 1189 } 1190 public static bool ShowRatings() 1191 { 1192 return Dna.Modules.Features.FeatureManager.IsEnabled("showRatrings", "Set to 'true' if ratings should be displayed."); 1193 } 1194 public static bool ShowReviews() 1195 { 1196 return Dna.Modules.Features.FeatureManager.IsEnabled("showReviews", "Set to 'true' if reviews should be displayed."); 1197 } 1198 1199 public static bool ShowRatingInProductList() 1200 { 1201 return Dna.Modules.Features.FeatureManager.IsEnabled("showRatingInProductList", "Set to 'true' if ratings in product list should be displayed."); 1202 } 1203 } 1204 @functions{ 1205 1206 #region Css functions 1207 1208 public static string GetPalletColorNumber(int number = 0) 1209 { 1210 switch (number) 1211 { 1212 case 1: 1213 return "#666666"; 1214 case 2: 1215 return "#092138"; 1216 default: 1217 return "#ffffff"; 1218 } 1219 } 1220 1221 public static string GetFontFamilyNumber(int number = 0) 1222 { 1223 switch (number) 1224 { 1225 case 1: 1226 return "font-family: Arial, sans-serif;"; 1227 default: 1228 return "font-family: Helvetica, Arial, sans-serif;"; 1229 } 1230 } 1231 1232 public static string GetFontSize(int fontSize = 0) 1233 { 1234 return fontSize >= 0 ? string.Concat("font-size: ", fontSize, "px;") : "font-size: 14px"; 1235 } 1236 1237 #endregion Css functions 1238 1239 #region Icon functions 1240 1241 public static string GetIcon(string cssPartialClass, string label = "", string position = "") 1242 { 1243 var icon = "<i class='fa " + cssPartialClass + "'></i>"; 1244 var spacing = string.Empty; 1245 1246 if (!label.IsNullOrEmpty()) 1247 { 1248 spacing = "&nbsp;"; 1249 } 1250 1251 if (cssPartialClass.IsNullOrEmpty()) return label; 1252 if (position == IconPosition.Left.ToString() || position.IsNullOrEmpty()) 1253 { 1254 return icon + spacing + label; 1255 } 1256 return label + spacing + icon; 1257 } 1258 1259 #endregion Icon functions 1260 1261 #region Address functions 1262 1263 public string GetAddressFormatted(User user, bool getRegionName = false, bool getCountryName = false, bool addLineBreakBetweenAddressAndCity = false, string splitBetweenRegionAndCountry = " ") 1264 { 1265 return GetAddressFormatted(user.Address, user.Address2, user.City, user.State, user.Zip, user.Country, getRegionName, getCountryName, addLineBreakBetweenAddressAndCity, splitBetweenRegionAndCountry); 1266 } 1267 1268 public string GetAddressFormatted(UserAddress userAddress, bool getRegionName = false, bool getCountryName = false, bool addLineBreakBetweenAddressAndCity = false, string splitBetweenRegionAndCountry = " ") 1269 { 1270 return GetAddressFormatted(userAddress.Address, userAddress.Address2, userAddress.City, userAddress.State, userAddress.Zip, userAddress.Country, getRegionName, getCountryName, addLineBreakBetweenAddressAndCity, splitBetweenRegionAndCountry); 1271 } 1272 1273 public string GetAddressFormatted(AddressSource addressSource, bool getRegionName = false, bool getCountryName = false, bool addLineBreakBetweenAddressAndCity = false, string splitBetweenRegionAndCountry = " ") 1274 { 1275 switch (addressSource) 1276 { 1277 case AddressSource.UserProfile: 1278 return GetAddressFormatted( 1279 GetString("UserManagement:User.Address"), 1280 GetString("UserManagement:User.Address2"), 1281 GetString("UserManagement:User.City"), 1282 GetString("UserManagement:User.State"), 1283 GetString("UserManagement:User.Zip"), 1284 GetString("UserManagement:User.Country"), 1285 getRegionName, 1286 getCountryName, 1287 addLineBreakBetweenAddressAndCity, 1288 splitBetweenRegionAndCountry 1289 ); 1290 case AddressSource.EcomCustomer: 1291 return GetAddressFormatted( 1292 GetString("Ecom:Order.Customer.Address"), 1293 GetString("Ecom:Order.Customer.Address2"), 1294 GetString("Ecom:Order.Customer.City"), 1295 GetString("Ecom:Order.Customer.Region"), 1296 GetString("Ecom:Order.Customer.Zip"), 1297 GetString("Ecom:Order.Customer.Country"), 1298 getRegionName, 1299 getCountryName, 1300 addLineBreakBetweenAddressAndCity, 1301 splitBetweenRegionAndCountry 1302 ); 1303 case AddressSource.EcomDelivery: 1304 return GetAddressFormatted( 1305 GetString("Ecom:Order.Delivery.Address"), 1306 GetString("Ecom:Order.Delivery.Address2"), 1307 GetString("Ecom:Order.Delivery.City"), 1308 GetString("Ecom:Order.Delivery.Region"), 1309 GetString("Ecom:Order.Delivery.Zip"), 1310 GetString("Ecom:Order.Delivery.Country"), 1311 getRegionName, 1312 getCountryName, 1313 addLineBreakBetweenAddressAndCity, 1314 splitBetweenRegionAndCountry 1315 ); 1316 case AddressSource.UserAddress: 1317 throw new NotImplementedException("Not applicable"); 1318 default: 1319 throw new ArgumentOutOfRangeException("addressSource property", addressSource, null); 1320 } 1321 } 1322 1323 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 = " ") 1324 { 1325 var formattedAddress = new StringBuilder(address); 1326 1327 if (address2.IsNotNullOrEmpty()) 1328 { 1329 formattedAddress.Append(string.Concat(" ",address2)); 1330 } 1331 if (addLineBreakBetweenAddressAndCity && (city + region + country).IsNotNullOrEmpty()) 1332 { 1333 formattedAddress.Append("<br/>"); 1334 } 1335 if (city.IsNotNullOrEmpty()) 1336 { 1337 formattedAddress.Append(string.Concat(" ",city)); 1338 } 1339 if (zip.IsNotNullOrEmpty()) 1340 { 1341 formattedAddress.Append(string.Concat(" ",zip)); 1342 } 1343 if (region.IsNotNullOrEmpty()) 1344 { 1345 formattedAddress.Append(zip.IsNotNullOrEmpty() ? string.Empty : ","); 1346 if (getRegionName && country.IsNotNullOrEmpty()) 1347 { 1348 var getRegions = Services.Countries.GetRegions(country); 1349 if(getRegions != null) { 1350 var regionName = getRegions.First(c => c.RegionCode == region).Name; 1351 region = regionName.IsNotNullOrEmpty() ? regionName : region; 1352 } 1353 } 1354 formattedAddress.Append(string.Concat(" ",region)); 1355 } 1356 1357 if (country.IsNullOrEmpty()) 1358 { 1359 return formattedAddress.ToString(); 1360 } 1361 1362 formattedAddress.Append(splitBetweenRegionAndCountry.IsNotNullOrEmpty() ? splitBetweenRegionAndCountry : " "); 1363 if (getCountryName) 1364 { 1365 var getCountry = Services.Countries.GetCountry(country); 1366 if(getCountry != null) 1367 { 1368 var countryName = getCountry.Name; 1369 country = countryName.IsNotNullOrEmpty() ? countryName : country; 1370 } 1371 } 1372 formattedAddress.Append(country); 1373 1374 return formattedAddress.ToString(); 1375 } 1376 1377 #endregion Address functions 1378 1379 #region Field helper functions 1380 1381 const string HighlightedCountriesSplit = "----------------"; 1382 1383 internal readonly List<string> HighlightedCountries = new List<string> 1384 { 1385 "CA", 1386 "US", 1387 HighlightedCountriesSplit 1388 }; 1389 1390 #endregion Field helper functions 1391 1392 #region Generic functions 1393 1394 private static int FormatInteger(object value) 1395 { 1396 int num; 1397 if (value == null) 1398 { 1399 value = string.Empty; 1400 } 1401 return int.TryParse(value.ToString(), out num) ? num : 0; 1402 } 1403 1404 #endregion Generic functions 1405 } 1406 @{ 1407 @* Tables and list helpers *@ 1408 @helper RenderTableHeading(string label, string sortByField = "", string listType = "Order") 1409 { 1410 if (sortByField.IsNotNullOrEmpty()) 1411 { 1412 var href = string.Empty; 1413 var icon = "fa-sort-amount-asc"; 1414 var sortOrder = "asc"; 1415 1416 if (listType == "Order" || listType == "Rma") 1417 { 1418 href = GetCustomerCenterSortUrl(sortByField, listType); 1419 if (GetSortFieldParameter("name") == sortByField) 1420 { 1421 sortOrder = GetSortFieldParameter("value", sortByField).ToLower(); 1422 icon = "fa-sort-amount-" + sortOrder; 1423 1424 } 1425 } 1426 else if (listType == "DataList") 1427 { 1428 var sortByParameter = Sanitize.Parameter("sortby").IsNotNullOrEmpty() ? Sanitize.Parameter("sortby") : string.Empty; 1429 var sortOrderParameter = Sanitize.Parameter("sortorder").IsNotNullOrEmpty() ? Sanitize.Parameter("sortorder") : "ASC"; 1430 1431 href = GetDataListSortUrl(sortByField); 1432 if (sortByParameter == sortByField) 1433 { 1434 sortOrder = sortOrderParameter.ToLower(); 1435 icon = "fa-sort-amount-" + sortOrder; 1436 sortOrder = sortOrder == "asc" ? "desc" : "asc"; 1437 } 1438 } 1439 <a href="@href" data-sortby="@sortByField" data-sortorder="@sortOrder.ToUpperInvariant()"> 1440 @RenderIcon(icon, label, IconPosition.Right) 1441 </a> 1442 } 1443 else 1444 { 1445 @label 1446 } 1447 } 1448 1449 @helper RenderDataListItem(string label, string value, string labelCss = "col-xs-4 text-right", string valueCss = "col-xs-8", string alternativeValue = "", bool isLabelBold = true) 1450 { 1451 if (value.IsNotNullOrEmpty() || alternativeValue.IsNotNullOrEmpty()) 1452 { 1453 var displayValue = alternativeValue.IsNullOrEmpty() ? value : alternativeValue; 1454 1455 <dt class="@labelCss"> 1456 @if (isLabelBold) 1457 { 1458 @: <strong> 1459 } 1460 @label 1461 @if (isLabelBold) 1462 { 1463 @: </strong> 1464 } 1465 </dt> 1466 <dd class="@valueCss"> 1467 @displayValue 1468 </dd> 1469 } 1470 } 1471 1472 @helper RenderTableRowSpacer(int height = 30, int colspan = 1) 1473 { 1474 if (height == 0) 1475 { 1476 height = 30; 1477 } 1478 1479 <tr> 1480 @if (colspan > 1) 1481 { 1482 @: <td colspan="@colspan" height="@height"></td> 1483 } 1484 else 1485 { 1486 <td height="@height"></td> 1487 } 1488 </tr> 1489 } 1490 1491 @helper RenderTableCellSpacer(int width = 10, int height = 10) 1492 { 1493 if (width == 0) 1494 { 1495 width = 10; 1496 } 1497 if (height == 0) 1498 { 1499 height = 10; 1500 } 1501 <td width="@width" height="@height">&nbsp;</td> 1502 } 1503 1504 1505 @* Tab helpers *@ 1506 @helper RenderTabContent(string tabKey, string tabLabel, string tabContent, string cssClass = "") 1507 { 1508 if (tabContent.IsNotNullOrEmpty()) 1509 { 1510 @InternalRenderTabHeader("#" + tabKey, tabLabel, cssClass) 1511 <div class="col-xs-12 @cssClass" id="@tabKey"> 1512 @tabContent 1513 </div> 1514 } 1515 } 1516 1517 1518 @* Field helpers *@ 1519 @helper RenderField(FieldSettings settings) 1520 { 1521 switch (settings.Type) 1522 { 1523 case FieldType.Button: 1524 case FieldType.Reset: 1525 case FieldType.Submit: 1526 @InternalRenderButtonField(settings) 1527 break; 1528 case FieldType.Checkbox: 1529 @InternalRenderCheckboxField(settings) 1530 break; 1531 case FieldType.Image: 1532 @InternalRenderImageField(settings) 1533 break; 1534 case FieldType.Checkboxlist: 1535 case FieldType.Radio: 1536 @InternalRenderRadioOrCheckboxListField(settings) 1537 break; 1538 case FieldType.Select: 1539 @InternalRenderSelectField(settings) 1540 break; 1541 case FieldType.Color: 1542 case FieldType.Date: 1543 case FieldType.DatetimeLocal: 1544 case FieldType.Email: 1545 case FieldType.File: 1546 case FieldType.Hidden: 1547 case FieldType.Password: 1548 case FieldType.Month: 1549 case FieldType.Number: 1550 case FieldType.Range: 1551 case FieldType.Search: 1552 case FieldType.Tel: 1553 case FieldType.Text: 1554 case FieldType.Time: 1555 case FieldType.Url: 1556 case FieldType.Week: 1557 @InternalRenderInputField(settings) 1558 break; 1559 case FieldType.Textarea: 1560 @InternalRenderTextareaField(settings) 1561 break; 1562 case FieldType.Textstring: 1563 @InternalRenderTextStringField(settings) 1564 break; 1565 case FieldType.Divider: 1566 @InternalRenderDividerField(settings) 1567 break; 1568 case FieldType.Datetime: 1569 @InternalRenderDateTimeField(settings) 1570 break; 1571 case FieldType.Unknown: 1572 @:<div style="color: #f00">Undefined FieldType: <strong>@settings.Type</strong></div> 1573 break; 1574 default: 1575 throw new NotSupportedException(string.Format("Unsupported Field Type: {0}.", settings.Type.ToString())); 1576 } 1577 } 1578 1579 @helper RenderCountriesDropdownField(List<string> countries, bool renderJsVariables = true, bool renderHighlightOptions = true, bool isFirstHardcodedOptionDisabled = true) 1580 { 1581 var settings = new FieldSettings 1582 { 1583 SystemName = "country", 1584 Id = "country", 1585 Label = Translate("Select your country:"), 1586 FirstHardcodedOptionLabel = Translate("All"), 1587 ValuesList = countries 1588 }; 1589 @RenderCountriesDropdownField(settings, renderJsVariables, renderHighlightOptions, isFirstHardcodedOptionDisabled) 1590 } 1591 1592 @helper RenderCountriesDropdownField(FieldSettings settings, bool renderJsVariables = true, bool renderHighlightOptions = true, bool isFirstHardcodedOptionDisabled = true) 1593 { 1594 1595 if (settings.SystemName.IsNotNullOrEmpty()) 1596 { 1597 const int limit = 10; 1598 const int numOfCountriesForHighlight = 10; 1599 var countries = EcommerceHelpers.GetEcomCountries(); 1600 var numOfCountries = settings.LoopOptions.Any() ? settings.LoopOptions.Count : settings.ValuesList.Any() ? settings.ValuesList.Count : countries.Count; 1601 1602 settings.Assert(FieldType.Select); 1603 if (settings.FirstHardcodedOptionLabel.IsNullOrEmpty()) 1604 { 1605 settings.FirstHardcodedOptionLabel = Translate("Select an option"); 1606 } 1607 if (!settings.Attributes.ContainsKey("multiple") && !settings.Attributes.ContainsKey("data-live-search") && numOfCountries > limit) 1608 { 1609 settings.Attributes.Add("data-live-search", "true"); 1610 } 1611 1612 if (renderJsVariables) 1613 { 1614 @InternalRenderCountryAndRegionsJsVariables(countries) 1615 } 1616 1617 @InternalRenderFieldHeader(settings) 1618 @GetHtmlElement("select", GetAttributes(settings)) 1619 @InternalRenderOption(FieldOption.CreateOption(settings.FirstHardcodedOptionLabel, settings.FirstHardcodedOptionValue, settings.IsFirstHardcodedOptionSelected, isFirstHardcodedOptionDisabled)) 1620 1621 1622 if (numOfCountries > numOfCountriesForHighlight) 1623 { 1624 @RenderSnippet("highlightedContries") 1625 } 1626 1627 if (settings.LoopOptions.Any()) 1628 { 1629 1630 foreach (var country in settings.LoopOptions) 1631 { 1632 var countryName = country.GetString("Ecom:Country.Name"); 1633 var countryCode = country.GetString("Ecom:Country.Code2"); 1634 1635 if (renderHighlightOptions && HighlightedCountries.Any(c => c.Equals(countryCode, StringComparison.CurrentCultureIgnoreCase))) 1636 { 1637 @PopulateHighlightedCountries(countryName, countryCode) 1638 } 1639 else 1640 { 1641 @InternalRenderOption(FieldOption.CreateOption(countryName, countryCode)) 1642 } 1643 1644 } 1645 } 1646 else if (settings.ValuesList.Any()) 1647 { 1648 foreach (var countryCode in settings.ValuesList.OrderBy(s => s)) 1649 { 1650 var countryName = countries.Any(c => c.Code2 == countryCode) ? countries.First(c => c.Code2 == countryCode).Name : countryCode; 1651 1652 if (renderHighlightOptions && HighlightedCountries.Any(c => c.Equals(countryCode, StringComparison.CurrentCultureIgnoreCase))) 1653 { 1654 @PopulateHighlightedCountries(countryName, countryCode) 1655 } 1656 else 1657 { 1658 @InternalRenderOption(FieldOption.CreateOption(countryName, countryCode)) 1659 } 1660 1661 } 1662 } 1663 else 1664 { 1665 foreach (var country in countries.OrderBy(s => s.Name)) 1666 { 1667 var countryCode = country.Code2; 1668 1669 if (renderHighlightOptions && HighlightedCountries.Any(c => c.Equals(countryCode, StringComparison.CurrentCultureIgnoreCase))) 1670 { 1671 @PopulateHighlightedCountries(country.Name, countryCode) 1672 } 1673 else 1674 { 1675 @InternalRenderOption(FieldOption.CreateOption(country.Name, countryCode)) 1676 } 1677 1678 } 1679 } 1680 1681 if (renderHighlightOptions && numOfCountries > numOfCountriesForHighlight && HighlightedCountries.Any(c => HighlightedCountriesSplit.Equals(c, StringComparison.CurrentCultureIgnoreCase))) 1682 { 1683 @PopulateHighlightedCountries(HighlightedCountriesSplit, string.Empty, false, true) 1684 } 1685 1686 @GetHtmlElement("select", true) 1687 1688 @InternalRenderFieldFooter(settings) 1689 } 1690 } 1691 1692 @helper PopulateHighlightedCountries(string label, string value, bool isSelected = false, bool isDisabled = false) 1693 { 1694 HighlightedCountries.Remove(value); 1695 if (value.IsNullOrEmpty()) 1696 { 1697 HighlightedCountries.Remove(label); 1698 } 1699 @SnippetStart("highlightedContries") 1700 @InternalRenderOption(FieldOption.CreateOption(label, value, isSelected, isDisabled)) 1701 @SnippetEnd("highlightedContries") 1702 } 1703 1704 1705 @* Paging helpers *@ 1706 @helper RenderPaging() 1707 { 1708 @RenderPaging( 1709 GetInteger("Ecom:CustomerCenter.Paging.NumPages"), 1710 "CCPage", 1711 GetString("Ecom:CustomerCenter.Paging.Back.URL"), 1712 GetString("Ecom:CustomerCenter.Paging.Forward.URL"), 1713 GetInteger("Ecom:CustomerCenter.Paging.CurrentPage"), 1714 GetLoop("Ecom:CustomerCenter.Paging.Pages"), 1715 "Ecom:CustomerCenter.Paging.PageIndex" 1716 ) 1717 } 1718 1719 @helper RenderPaging(int numOfPages, string pageQueryParameter, int currentPage) 1720 { 1721 var queryParameters = HttpUtility.ParseQueryString(Dynamicweb.Context.Current.Request.Url.Query); 1722 var url = Helpers.GetCurrentUrl(true, true); 1723 var previousPageUrl = string.Empty; 1724 var nextPageUrl = string.Empty; 1725 1726 if (currentPage > 1) 1727 { 1728 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageQueryParameter, (currentPage - 1).ToString()); 1729 previousPageUrl = Helpers.BuildUri(url, queryParameters).ToString(); 1730 } 1731 if (currentPage < numOfPages) 1732 { 1733 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageQueryParameter, (currentPage + 1).ToString()); 1734 nextPageUrl = Helpers.BuildUri(url, queryParameters).ToString(); 1735 } 1736 1737 @RenderPaging(numOfPages, pageQueryParameter, previousPageUrl, nextPageUrl, currentPage) 1738 } 1739 1740 @helper RenderPaging(int numOfPages, string pageQueryParameter, string previousPageUrl, string nextPageUrl, int currentPage, List<LoopItem> pagesLoop = null, string pageNumTag = "", string pageHrefTag = "", bool includeWrapper = true) 1741 { 1742 if (numOfPages > 1) 1743 { 1744 @* NOTE: pageIndex needs to be a tag name, because it will be instanciated within the loop *@ 1745 @* NOTE: 1746 queryParamenter == "PageNum" --> Product Catalog module 1747 queryParamenter == "page" --> Item Publisher module 1748 queryParamenter == "CC*" --> Customer Center module 1749 queryParamenter == "DWPagingPageNum" --> Data List module 1750 *@ 1751 1752 var loopPageSize = 3; 1753 var startPage = 1; 1754 var endPage = numOfPages; 1755 1756 var pageQueryParameter2 = pageQueryParameter == "PageNum" || pageQueryParameter == "page" || pageQueryParameter == "DWPagingPageNum" ? string.Empty : Pageview.CurrentParagraph.ID.ToString(); 1757 var pageNumQueryParameter = pageQueryParameter + pageQueryParameter2; 1758 1759 var queryParameters = HttpUtility.ParseQueryString(Dynamicweb.Context.Current.Request.Url.Query); 1760 queryParameters.Remove(pageNumQueryParameter); 1761 queryParameters.Remove("pid"); 1762 1763 if (pageQueryParameter == "page") 1764 { 1765 queryParameters.Add("pid", Pageview.CurrentParagraph.ID.ToString()); 1766 } 1767 1768 if (pagesLoop != null) 1769 { 1770 loopPageSize = pagesLoop.Count; 1771 endPage = 1; 1772 } 1773 else 1774 { 1775 var pageOffset = Math.Floor(Convert.ToDecimal(loopPageSize / 2)); 1776 var middlePage = pageOffset + 1; 1777 1778 if (numOfPages > loopPageSize) 1779 { 1780 startPage = Convert.ToInt32(currentPage - pageOffset) < 1 ? 1 : Convert.ToInt32(currentPage - pageOffset); 1781 endPage = Convert.ToInt32(currentPage + pageOffset) > numOfPages ? numOfPages : Convert.ToInt32(currentPage + pageOffset); 1782 1783 if (currentPage < middlePage) 1784 { 1785 endPage = loopPageSize; 1786 } 1787 else if (currentPage >= middlePage) 1788 { 1789 if (numOfPages < currentPage + pageOffset) 1790 { 1791 startPage = numOfPages - loopPageSize; 1792 if (loopPageSize % 2 != 0) 1793 { 1794 startPage += 1; 1795 } 1796 } 1797 1798 if (loopPageSize % 2 == 0) 1799 { 1800 startPage += 1; 1801 } 1802 } 1803 } 1804 } 1805 1806 if (includeWrapper) 1807 { 1808 @:<div class="col-xs-12 text-center paginationContainer"> 1809 } 1810 <ul class="pagination"> 1811 @if (previousPageUrl.IsNotNullOrEmpty() && previousPageUrl != "#") 1812 { 1813 @InternalRenderPageItem(previousPageUrl, Translate("Previous"), "fa-caret-left", IconPosition.Left) 1814 } 1815 @if (pagesLoop != null) 1816 { 1817 @InternalRenderGoToFirstPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, pagesLoop[0].GetInteger(pageNumTag)) 1818 foreach (var page in pagesLoop) 1819 { 1820 var pageItemHref = pageQueryParameter == "PageNum" || pageQueryParameter == "page" ? page.GetString(pageHrefTag) : string.Empty; 1821 endPage = page.GetInteger(pageNumTag); 1822 1823 queryParameters.Remove(pageNumQueryParameter); 1824 if (pageItemHref.IsNotNullOrEmpty()) 1825 { 1826 queryParameters.Add(pageNumQueryParameter, page.GetString(pageNumTag)); 1827 } 1828 @InternalRenderPageItem(queryParameters, page.GetString(pageNumTag), page.GetInteger(pageNumTag) == currentPage ? "active" : string.Empty) 1829 1830 } 1831 @InternalRenderGoToLastPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, endPage) 1832 } 1833 else 1834 { 1835 @InternalRenderGoToFirstPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize) 1836 for (var page = startPage; page <= endPage; page++) 1837 { 1838 queryParameters = Helpers.UpdateQueryStringKeyValue(queryParameters, pageNumQueryParameter, page.ToString()); 1839 @InternalRenderPageItem(queryParameters, page.ToString(), page == currentPage ? "active" : string.Empty) 1840 } 1841 @InternalRenderGoToLastPage(queryParameters, pageNumQueryParameter, currentPage, numOfPages, loopPageSize, endPage) 1842 } 1843 1844 @if (nextPageUrl.IsNotNullOrEmpty() && nextPageUrl != "#") 1845 { 1846 @InternalRenderPageItem(nextPageUrl, Translate("Next"), "fa-caret-right", IconPosition.Right) 1847 } 1848 </ul> 1849 if (includeWrapper) 1850 { 1851 @:</div> 1852 } 1853 } 1854 } 1855 1856 1857 @* Generic helpers *@ 1858 @helper RenderIcon(string cssPartialClass, string label = "", IconPosition position = IconPosition.Left, bool isLabelATooltip = false) 1859 { 1860 var icon = !isLabelATooltip ? "<i class='fa " + cssPartialClass + "'></i>" : "<i class='fa " + cssPartialClass + "' data-toggle='" + label + "'></i>"; 1861 var spacing = string.Empty; 1862 1863 if (label.IsNotNullOrEmpty()) 1864 { 1865 spacing = "&nbsp;"; 1866 } 1867 if (cssPartialClass.IsNotNullOrEmpty()) 1868 { 1869 if (isLabelATooltip) 1870 { 1871 @icon 1872 } 1873 else if (position == IconPosition.Left) 1874 { 1875 @icon 1876 @spacing 1877 @label 1878 } 1879 else 1880 { 1881 @label 1882 @spacing 1883 @icon 1884 } 1885 } 1886 else 1887 { 1888 @label 1889 } 1890 } 1891 1892 @helper RenderStackedIcons(string cssPrincipalPartialClass, string cssSecondaryPartialClass, string label = "", IconPosition position = IconPosition.Left, bool isLabelATooltip = false) 1893 { 1894 var spacing = string.Empty; 1895 var icon = new StringBuilder("<span class='fa-stack'>"); 1896 1897 icon.Append(!isLabelATooltip ? "<i class='fa " + cssPrincipalPartialClass + " fa-stack-2x'></i>" : "<i class='fa " + cssPrincipalPartialClass + " fa-stack-2x' data-toggle='" + label + "'></i>"); 1898 icon.Append("<i class='fa " + cssSecondaryPartialClass + " fa-stack-1x'></i>"); 1899 icon.Append("</span>"); 1900 1901 if (label.IsNotNullOrEmpty()) 1902 { 1903 spacing = "<text>&nbsp;</text>"; 1904 } 1905 if (cssPrincipalPartialClass.IsNotNullOrEmpty() && cssSecondaryPartialClass.IsNotNullOrEmpty()) 1906 { 1907 if (isLabelATooltip) 1908 { 1909 @icon.ToString() 1910 } 1911 else if (position == IconPosition.Left) 1912 { 1913 @icon.ToString() 1914 @spacing 1915 @label 1916 } 1917 else 1918 { 1919 @label 1920 @spacing 1921 @icon.ToString() 1922 } 1923 } 1924 else 1925 { 1926 @label 1927 } 1928 } 1929 1930 @helper RenderAction(IconAction action, string href = "", string title = "", string onClickConfirm = "") 1931 { 1932 var attributes = new Dictionary<string, string>(); 1933 1934 if (title.IsNotNullOrEmpty()) 1935 { 1936 attributes.Add("title", title); 1937 } 1938 if (onClickConfirm.IsNotNullOrEmpty()) 1939 { 1940 attributes.Add("onclick", "return confirm('" + onClickConfirm + "');"); 1941 } 1942 if (href.IsNotNullOrEmpty()) 1943 { 1944 attributes.Add("href", href); 1945 } 1946 @RenderAction(action, href, attributes) 1947 } 1948 1949 @helper RenderAction(IconAction action, string href, Dictionary<string, string> attributes) 1950 { 1951 var icon = string.Empty; 1952 var linkAttributes = string.Empty; 1953 var label = Translate(action.ToString()); 1954 1955 switch (action) 1956 { 1957 case IconAction.Add: 1958 break; 1959 case IconAction.View: 1960 icon = "fa-eye"; 1961 break; 1962 case IconAction.Edit: 1963 icon = "fa-edit"; 1964 break; 1965 case IconAction.Cancel: 1966 case IconAction.Remove: 1967 icon = "fa-times"; 1968 break; 1969 case IconAction.Delete: 1970 icon = "fa-trash"; 1971 break; 1972 case IconAction.Print: 1973 icon = "fa-print"; 1974 attributes.Add("target", "_blank"); 1975 label = string.Empty; 1976 break; 1977 case IconAction.Save: 1978 break; 1979 case IconAction.Reset: 1980 break; 1981 case IconAction.Undo: 1982 break; 1983 case IconAction.Reorder: 1984 icon = "fa-repeat"; 1985 break; 1986 case IconAction.SetDefault: 1987 icon = "fa-times"; 1988 label = string.Empty; 1989 break; 1990 case IconAction.IsDefault: 1991 icon = "fa-check"; 1992 label = string.Empty; 1993 break; 1994 default: 1995 throw new NotSupportedException("An action is needed to render this helper!"); 1996 } 1997 if (icon.IsNotNullOrEmpty()) 1998 { 1999 if (href.IsNotNullOrEmpty()) 2000 { 2001 @GetHtmlElement("a", GetAttributes(attributes)) 2002 @RenderIcon(icon, label) 2003 @GetHtmlElement("a", true) 2004 } 2005 else if (label.IsNullOrEmpty()) 2006 { 2007 @RenderIcon(icon) 2008 } 2009 } 2010 2011 } 2012 2013 @helper RenderBootstrapButton(BootstrapButtonSettings settings) 2014 { 2015 var attributes = new StringBuilder(GetAttribute("class", "btn " + (settings.CssClass.IsNotNullOrEmpty() ? settings.CssClass : "btn-default"))); 2016 attributes.Append(GetAttribute("target", settings.Target)); 2017 attributes.Append(GetAttribute("href", settings.Href)); 2018 attributes.Append(GetAttribute("name", settings.SystemName)); 2019 attributes.Append(GetAttribute("id", settings.Id)); 2020 attributes.Append(GetAttribute("value", settings.Value)); 2021 if (settings.ButtonType == BootstrapButtonSettings.BootstrapButtonType.Button && !settings.Attributes.ContainsKey("type")) 2022 { 2023 settings.Attributes.Add("type","submit"); 2024 } 2025 2026 attributes.Append(GetAttributes(settings.Attributes)); 2027 string htmlElement; 2028 2029 switch (settings.ButtonType) 2030 { 2031 case BootstrapButtonSettings.BootstrapButtonType.Button: 2032 htmlElement = "button"; 2033 break; 2034 case BootstrapButtonSettings.BootstrapButtonType.Anchor: 2035 htmlElement = "a"; 2036 break; 2037 default: 2038 throw new NotSupportedException(string.Format("Unsupported Bootstrap Button type: {0}.", settings.ButtonType.ToString())); 2039 } 2040 @GetHtmlElement(htmlElement, attributes.ToString()) 2041 @RenderIcon(settings.IconCssClass, settings.Label, settings.IconPosition) 2042 @GetHtmlElement(htmlElement, true) 2043 } 2044 2045 @helper RenderAddToCart(string productId, string productVariantId, int availableAmount = 0, bool doNotRenderHiddenFields = false) 2046 { 2047 var addToCartButtonSettings = new BootstrapButtonSettings 2048 { 2049 Label = Translate("Add to Cart"), 2050 CssClass = availableAmount <= 0 ? "btn-default addToCartSubmit disabled" : "btn-default addToCartSubmit", 2051 Href = string.Concat(Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Dynamicweb.Services.Pages.GetPageByNavigationTag(Pageview.AreaID, "MiniCart").ID),"?productid=", productId, "&amp;variantID=", productVariantId, "&amp;cartcmd=add"), 2052 IconCssClass = "fa-shopping-cart", 2053 Attributes = new Dictionary<string, string> 2054 { 2055 {"data-add", Translate("Add to Cart")}, 2056 {"data-added", Translate("Added")}, 2057 {"data-outofstock", Translate("Out of stock")}, 2058 {"data-stock", availableAmount.ToString()} 2059 } 2060 }; 2061 @RenderBootstrapButton(addToCartButtonSettings) 2062 if (!doNotRenderHiddenFields) 2063 { 2064 @RenderField(FieldSettings.CreateHiddenField("redirect", "false", "redirect" + productId)) 2065 @RenderField(FieldSettings.CreateHiddenField("cartcmd", "add", "cartcmd" + productId)) 2066 @RenderField(FieldSettings.CreateHiddenField("productid", productId, "productId" + productId)) 2067 @RenderField(FieldSettings.CreateHiddenField("variantid", productVariantId, "variantId" + productId + productVariantId)) 2068 } 2069 @RenderField(FieldSettings.CreateSubmitField(Translate("Add to Cart"), "hidden")) 2070 } 2071 2072 @helper RenderSocialMediaShare() 2073 { 2074 <div class="shareIcons"> 2075 <span>@Translate("Share")</span> 2076 @RenderSocialMedia(false, true) 2077 </div> 2078 } 2079 2080 @helper RenderOpenGraphMeta(string type, string image, string title, string teaser = "", string imageAlt = "") 2081 { 2082 var culture = Pageview.Area.Culture.Replace("-", "_"); 2083 teaser = System.Text.RegularExpressions.Regex.Replace(teaser, "<.*?>", string.Empty); 2084 if (type.IsNullOrEmpty()) 2085 { 2086 type = "article"; 2087 } 2088 if (imageAlt.IsNullOrEmpty()) 2089 { 2090 imageAlt = title; 2091 } 2092 2093 @SnippetStart("OGMeta") 2094 <meta property="og:title" content="@HttpUtility.HtmlEncode(title)"/> 2095 <meta property="og:image" content="@string.Concat(Helpers.GetCurrentUrl(true), image)"/> 2096 <meta property="og:image:width" content="600"/> 2097 <meta property="og:image:height" content="600"/> 2098 <meta property="og:image:alt" content="@HttpUtility.HtmlEncode(imageAlt)"/> 2099 <meta property="og:site_name" content="@Pageview.Area.Item["CompanyName"]"/> 2100 <meta property="og:url" content="@Helpers.GetCurrentUrl()"/> 2101 <meta property="og:description" content="@HttpUtility.HtmlEncode(teaser)"/> 2102 <meta property="og:type" content="@type"/> 2103 <meta property="og:locale" content="@culture"/> 2104 @SnippetEnd("OGMeta") 2105 } 2106 2107 @helper RenderSocialMedia(bool isEmailTemplate = false, bool isToShare = false) 2108 { 2109 var page = Dynamicweb.Extensibility.ServiceLocator.Current.GetPageService().GetPage(Dynamicweb.Services.Pages.GetPageByNavigationTag(Pageview.AreaID, "GeneralSettings").ID); 2110 var generalSettings = Dynamicweb.Content.Items.Item.GetItemById(page.ItemType, page.ItemId); 2111 2112 if(generalSettings["SocialMedia"] != null) { 2113 var socialMedia = Dynamicweb.Content.Items.ItemList.GetItemListById(int.Parse(generalSettings["SocialMedia"].ToString())); 2114 2115 if(socialMedia.Relations.Any()) 2116 { 2117 if(!isEmailTemplate) 2118 { 2119 @:<ul class="socialMedia"> 2120 } 2121 foreach (var r in socialMedia.Relations) 2122 { 2123 var socialNetwork = Dynamicweb.Content.Items.Item.GetItemById("SocialLinks", r.Id); 2124 var className = (socialNetwork["Icon"] ?? "").ToString(); 2125 var socialName = (socialNetwork["Name"] ?? "").ToString(); 2126 var socialLink = (socialNetwork["Link"] ?? "").ToString(); 2127 var shareLink = (socialNetwork["ShareURL"] ?? "").ToString(); 2128 2129 if (isEmailTemplate) 2130 { 2131 @:&nbsp; 2132 <a title="@socialName" target="_blank" href="@socialLink">@socialName</a> 2133 @:&nbsp; 2134 } 2135 else if(!isToShare || shareLink.IsNotNullOrEmpty()) 2136 { 2137 <li> 2138 <a title="@socialName" class="@className fa" target="_blank" data-sharehref="@shareLink@Helpers.GetCurrentUrl()" href="@socialLink"><span class="hidden">@socialName</span></a> 2139 </li> 2140 } 2141 } 2142 if(!isEmailTemplate) 2143 { 2144 @:</ul> 2145 } 2146 } 2147 } 2148 } 2149 2150 @helper RenderNoResults(string wording, string title = "", bool hasWrapper = false, string wrapperClass = "col-xs-12 noPadding" ) 2151 { 2152 if (hasWrapper) 2153 { 2154 @:<div class="noResultsWrapper @wrapperClass"> 2155 } 2156 if (title.IsNotNullOrEmpty()) 2157 { 2158 <h2>@title</h2> 2159 } 2160 <p>@wording</p> 2161 if (hasWrapper) 2162 { 2163 @:</div> 2164 } 2165 } 2166 2167 @helper RenderImage(ImageSettings imageSettings) 2168 { 2169 var imageMarkup = new StringBuilder(); 2170 var widthAndHeight = GetWidthAndHeightFromQueryString(imageSettings.Source); 2171 var widthAndHeightForMobile = GetWidthAndHeightFromQueryString(imageSettings.SourceForMobile, true); 2172 var widthAndHeightForTablet = GetWidthAndHeightFromQueryString(imageSettings.SourceForTablet, true); 2173 2174 if (!imageSettings.Attributes.ContainsKey("width") && widthAndHeight.ContainsKey("width") && widthAndHeight["width"].IsNotNullOrEmpty()) 2175 { 2176 imageSettings.Attributes.Add("width", widthAndHeight["width"]); 2177 } 2178 if (!imageSettings.Attributes.ContainsKey("height") && widthAndHeight.ContainsKey("height") && widthAndHeight["height"].IsNotNullOrEmpty()) 2179 { 2180 imageSettings.Attributes.Add("height", widthAndHeight["height"]); 2181 } 2182 if (!imageSettings.Attributes.ContainsKey("class")) 2183 { 2184 imageSettings.Attributes.Add("class", "img-responsive " + imageSettings.CssClass); 2185 } 2186 if (!imageSettings.Attributes.ContainsKey("src")) 2187 { 2188 imageSettings.Attributes.Add("src", imageSettings.Source); 2189 } 2190 if (!imageSettings.Attributes.ContainsKey("alt")) 2191 { 2192 imageSettings.Attributes.Add("alt", imageSettings.AltText); 2193 } 2194 if (!imageSettings.Attributes.ContainsKey("title")) 2195 { 2196 imageSettings.Attributes.Add("title", imageSettings.Title); 2197 } 2198 2199 if (imageSettings.IncludeWrapper) 2200 { 2201 var wrapperAttributes = new Dictionary<string, string>(); 2202 if (imageSettings.WrapperCssClass.IsNotNullOrEmpty()) 2203 { 2204 wrapperAttributes.Add("class", imageSettings.WrapperCssClass); 2205 } 2206 2207 imageMarkup.Append(GetHtmlElement(imageSettings.WrapperElement, wrapperAttributes)); 2208 } 2209 2210 if (imageSettings.Href.IsNotNullOrEmpty()) 2211 { 2212 var linkAttributes = new Dictionary<string, string> {{"href", imageSettings.Href}}; 2213 if (imageSettings.HrefCssClass.IsNotNullOrEmpty()) 2214 { 2215 linkAttributes.Add("class", imageSettings.HrefCssClass); 2216 } 2217 if (imageSettings.HrefTarget.IsNotNullOrEmpty()) 2218 { 2219 linkAttributes.Add("target", imageSettings.HrefTarget); 2220 } 2221 2222 imageMarkup.Append(GetHtmlElement("a", linkAttributes)); 2223 } 2224 2225 if (widthAndHeightForMobile.Any() || widthAndHeightForTablet.Any()) 2226 { 2227 imageMarkup.Append(GetHtmlElement("picture")); 2228 2229 imageMarkup.Append(GetHtmlElement("source")); 2230 2231 if (widthAndHeightForMobile.Any()) 2232 { 2233 imageMarkup.Append(GetHtmlElement("srcset", widthAndHeightForMobile)); 2234 } 2235 2236 if (widthAndHeightForTablet.Any()) 2237 { 2238 imageMarkup.Append(GetHtmlElement("srcset", widthAndHeightForTablet)); 2239 } 2240 2241 imageMarkup.Append(GetHtmlElement("source", true)); 2242 } 2243 2244 imageMarkup.Append(GetHtmlElement("img", imageSettings.Attributes, true)); 2245 2246 if (imageSettings.SourceForMobile.IsNotNullOrEmpty() || imageSettings.SourceForTablet.IsNotNullOrEmpty()) 2247 { 2248 imageMarkup.Append(GetHtmlElement("picture", true)); 2249 } 2250 2251 if (imageSettings.Href.IsNotNullOrEmpty()) 2252 { 2253 imageMarkup.Append(GetHtmlElement("a", true)); 2254 } 2255 2256 if (imageSettings.IncludeWrapper) 2257 { 2258 imageMarkup.Append(GetHtmlElement(imageSettings.WrapperElement, true)); 2259 } 2260 2261 @imageMarkup.ToString() 2262 } 2263 2264 @helper RenderHtmlElementBetweenEachString(List<string> listOfStrings, string htmlElement = "br" ) 2265 { 2266 foreach (var str in listOfStrings) 2267 { 2268 if (str.IsNullOrEmpty()){continue;} 2269 @(string.Concat(str, GetHtmlElement(htmlElement, true))) 2270 } 2271 } 2272 2273 @helper RenderProductPrice(string productPrice = "") 2274 { 2275 var showNoErpConnectionMessage = ShowNoErpConnectionMessage(); 2276 var isWebServiceConnectionAvailable = Dna.Ecommerce.LiveIntegration.TemplatesHelper.IsWebServiceConnectionAvailable(); 2277 2278 if (!isWebServiceConnectionAvailable && showNoErpConnectionMessage) 2279 { 2280 if (productPrice.IsNullOrEmpty()) 2281 { 2282 @RenderNoErpConnectionMessage() 2283 } 2284 else 2285 { 2286 <span class="noErpConnection">@Translate("Unavailable")</span> 2287 } 2288 } 2289 else 2290 { 2291 @productPrice 2292 } 2293 } 2294 2295 @helper RenderNoErpConnectionMessage() 2296 { 2297 <div class="col-xs-12 warningBox"> 2298 <p>@Translate("Pricing and inventory are currently not available. Please check back soon")</p> 2299 </div> 2300 } 2301 } 2302 2303 @inherits RazorTemplateBase<RazorTemplateModel<Template>> 2304 @using System 2305 @using Dynamicweb.Rendering 2306 @using System.Linq 2307 @using Dna.UrlServices 2308 @using Dynamicweb.Frontend 2309 2310 @functions 2311 { 2312 public int GetParagraphIdFromCc() 2313 { 2314 var sendOrderPageId = GetPageIdByNavigationTag("SendOrder"); 2315 var paragraphCollection = Dynamicweb.Services.Paragraphs.GetParagraphsByPageId(sendOrderPageId); 2316 var paragraphId = paragraphCollection != null ? paragraphCollection.Where(p => p.ModuleSystemName == "eCom_CustomerCenter" && p.ShowParagraph).Select(p => p.ID).FirstOrDefault() : 0; 2317 2318 return paragraphId; 2319 } 2320 2321 public bool IsProductOrderable(LoopItem product = null) 2322 { 2323 return IsProductStatus("Orderable", product); 2324 } 2325 2326 public bool IsProductVisible(LoopItem product = null) 2327 { 2328 return IsProductStatus("Visible", product); 2329 } 2330 2331 public bool IsProductWebAvailable(LoopItem product = null) 2332 { 2333 return IsProductOrderable(product) || IsProductVisible(product); 2334 } 2335 2336 public bool IsProductStatus(string fieldValue, LoopItem product = null) 2337 { 2338 var user = Pageview.User; 2339 var customerType = user != null ? user.CustomFieldValues.First(fv => fv.CustomField.SystemName == "AccessUser_CustomerType").Value.ToString() : ""; 2340 var defaultSettings = Pageview.Area.Item["AnonymousCustomerType"]; 2341 var anonymousUser = user == null && defaultSettings != null ? defaultSettings.ToString() : ""; 2342 2343 var productB2BStatus = product != null ? product.GetString("Ecom:Product:Field.B2BStatus.Value") : GetString("Ecom:Product:Field.B2BStatus.Value"); 2344 var productB2BEligible = product != null ? product.GetString("Ecom:Product:Field.B2BLegEligibleStatus.Value") : GetString("Ecom:Product:Field.B2BLegEligibleStatus.Value"); 2345 var productGLMPStatus = product != null ? product.GetString("Ecom:Product:Field.GLMPStatus.Value") : GetString("Ecom:Product:Field.GLMPStatus.Value"); 2346 var productB2CStatus = product != null ? product.GetString("Ecom:Product:Field.B2CStatus.Value") : GetString("Ecom:Product:Field.B2CStatus.Value"); 2347 var productB2CBoatlifter = product != null ? product.GetString("Ecom:Product:Field.B2CBoatlifterStatus.Value") : GetString("Ecom:Product:Field.B2CBoatlifterStatus.Value"); 2348 2349 var userB2B = (anonymousUser == "B2B" || customerType == "B2B") && productB2BStatus.Equals(fieldValue); 2350 var userB2BLegEligible = (anonymousUser == "B2BLegEligible" || customerType == "B2BLegEligible") && productB2BEligible.Equals(fieldValue); 2351 var userGlmp = (anonymousUser == "GLMP" || customerType == "GLMP") && productGLMPStatus.Equals(fieldValue); 2352 var userB2C = (anonymousUser == "B2C" || customerType == "B2C") && productB2CStatus.Equals(fieldValue); 2353 var userB2CBoatLifter = (anonymousUser == "B2CBoatlifter" || customerType == "B2CBoatlifter") && productB2CBoatlifter.Equals(fieldValue); 2354 2355 return userB2B || userB2BLegEligible || userB2C || userGlmp || userB2CBoatLifter; 2356 } 2357 2358 public bool IsBoatlifterSite() 2359 { 2360 var websites = Pageview.Area.Item["Websites"].ToString(); 2361 2362 return websites == "Boatlifter"; 2363 } 2364 2365 public string GetWebsiteDomain(PageView pageview) 2366 { 2367 return Dna.Hewitt.Helpers.GetWebsiteDomain(pageview); 2368 } 2369 } 2370 2371 @helper RenderIFrameContent() 2372 { 2373 @GetString("Item.IFrame") 2374 } 2375 2376 @functions{ 2377 const string PageParameter = "PageNum"; 2378 const string SearchParameter = "s"; 2379 readonly string _searchedTerms = (Sanitize.Parameter(SearchParameter, "[a-z][A-Z][0-9][.][,][-][_][&][@]") ?? "").ToLower(); 2380 } 2381 @if (!Dna.AutoImpersonate.Helpers.ImpersonateActive) 2382 { 2383 <div class="row"> 2384 <p class="col-xs-12">@Translate("AutoImpersonation is disabled for this website")</p> 2385 </div> 2386 } 2387 else 2388 { 2389 // Check if it should render the "Set default account" button 2390 var showSetDefaultAccount = false; 2391 if (Pageview.Area.Item[Dna.AutoImpersonate.Constants.AreaSettings.ShowDefaultAccount] != null) 2392 { 2393 bool.TryParse(Pageview.Area.Item[Dna.AutoImpersonate.Constants.AreaSettings.ShowDefaultAccount].ToString(), out showSetDefaultAccount); 2394 } 2395 2396 // Get Page Id to impersonate user by ajax 2397 var managePageAjax = GetPageIdByNavigationTag(Dna.AutoImpersonate.Constants.AreaSettings.ManageAccountsAjax); 2398 managePageAjax = managePageAjax != 0 ? managePageAjax : Pageview.Page.ID; 2399 2400 2401 var loginUser = Users.GetRealUser(); 2402 var currentPage = GetInteger("DwPaging.CurrentPage"); 2403 var showStopBtn = loginUser.CustomFieldValues.First(cf => cf.CustomField.SystemName.Equals(Dna.AutoImpersonate.Constants.CustomFields.ForceImpersonationSetting)).Value.Equals(Dna.AutoImpersonate.Constants.CustomFields.Options.UserNeverImpersonate); 2404 var stopBtnHref = string.Format("/Default.aspx?Id={0}&{1}=1&{2}={3}", Pageview.Page.ID, Dna.AutoImpersonate.Constants.DynamicwebParameter.StopImpersonation, PageParameter, currentPage); 2405 var usersToImpersonate = GetLoop("QueryResultItem"); 2406 var isImpersonating = Pageview.User.CurrentSecondaryUser; 2407 var userName = isImpersonating != null ? Pageview.User.Name.IsNotNullOrEmpty() ? Pageview.User.Name : string.Format("{0}{1}", Pageview.User.FirstName, Pageview.User.LastName) : ""; 2408 userName = userName.IsNotNullOrEmpty() ? userName : Pageview.User.UserName; 2409 var accessReportsGroups = (Pageview.Area.Item["AccessReportsGroups"] ?? "").ToString().Split(new char[]{','}, StringSplitOptions.RemoveEmptyEntries).Select(Int32.Parse).ToList(); 2410 2411 <div class="row"> 2412 <h1>Manage Accounts (@userName)</h1> 2413 <p class="col-xs-12 noPadding"> 2414 @Translate("Select the customer account to manage") 2415 </p> 2416 <div class="col-xs-12 searchAccountContainer generalMarginBottom"> 2417 @if (GetInteger("QueryResult.TotalCount") > 10 || _searchedTerms.IsNotNullOrEmpty()) 2418 { 2419 <form class="col-xs-12 col-md-3 DMForms" action="@Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(Pageview.Page.ID)" id="searchUsersForm" class="form-inline"> 2420 @RenderField(new FieldSettings {SystemName = SearchParameter, Type = FieldType.Search, Id = "searchSubmitList", Value = _searchedTerms, Placeholder = Translate("Search customer")}) 2421 @RenderBootstrapButton(new BootstrapButtonSettings {IconCssClass = "fa-search", ButtonType = BootstrapButtonSettings.BootstrapButtonType.Button}) 2422 </form> 2423 } 2424 </div> 2425 </div> 2426 if (Users.GetRealUser().GroupsIds.Any(g => accessReportsGroups.Contains(g)) && Pageview.User.CurrentSecondaryUser != null) 2427 { 2428 <div class="col-xs-12 noPadding-xs noPadding-sm"> 2429 @RenderBootstrapButton(new BootstrapButtonSettings 2430 { 2431 Href = stopBtnHref, 2432 CssClass = "btn-outline pull-right", 2433 Label = Translate("Stop managing") 2434 }) 2435 </div> 2436 } 2437 if (usersToImpersonate.Any()) 2438 { 2439 <table id="switchAccount" class="col-xs-12 noPadding-xs noPadding-sm dataTable" data-isImpersonating="@(Pageview.User.CurrentSecondaryUser != null)"> 2440 <tbody> 2441 @foreach (var user in usersToImpersonate) 2442 { 2443 var userId = user.GetString("UserID"); 2444 var userCurrency = user.GetString("CurrencyCharacter"); 2445 2446 var userImpersonateUrl = string.Format("/Default.aspx?Id={0}&{1}={2}&{3}={4}{5}", Pageview.Page.ID, Dna.AutoImpersonate.Constants.DynamicwebParameter.SetImpersonation, userId, PageParameter, currentPage, userCurrency.IsNotNullOrEmpty() ? string.Concat("&CurrencyCode=", userCurrency) : string.Empty); 2447 var isImpersonatedUser = userId == Pageview.User.ID.ToString(); 2448 var button = new BootstrapButtonSettings(); 2449 <tr> 2450 <td> 2451 <h3>@user.GetString("Name")</h3> 2452 <p>@user.GetString("CustomerNumber")</p> 2453 <p> 2454 @if (user.GetString("Address").IsNotNullOrEmpty()) 2455 { 2456 @GetAddressFormatted( 2457 user.GetString("Address"), 2458 user.GetString("Address2"), 2459 user.GetString("City"), 2460 user.GetString("State"), 2461 user.GetString("Zip"), 2462 user.GetString("Country"), 2463 false, 2464 false, 2465 false, 2466 ", " 2467 ) 2468 } 2469 </p> 2470 </td> 2471 <td class="text-right"> 2472 @if (isImpersonatedUser) 2473 { 2474 <p>@Translate("Currently managing")</p> 2475 } 2476 else 2477 { 2478 button.CssClass += " selectAccount"; 2479 button.Label = Translate("Manage Account"); 2480 button.Href = userImpersonateUrl; 2481 button.Attributes.Add("action", string.Format("{0}?{1}=1", Dynamicweb.Frontend.SearchEngineFriendlyURLs.GetFriendlyUrl(managePageAjax), Dna.AutoImpersonate.Constants.DynamicwebParameter.StopImpersonation)); 2482 @RenderBootstrapButton(button) 2483 } 2484 @if (showSetDefaultAccount) 2485 { 2486 var setDefaultAccountButton = new BootstrapButtonSettings(); 2487 if (Dna.AutoImpersonate.Helpers.ReadDefaultId(loginUser) == userId) 2488 { 2489 setDefaultAccountButton.CssClass = "btn-outline"; 2490 setDefaultAccountButton.Label = Translate("Default Account"); 2491 } 2492 else 2493 { 2494 setDefaultAccountButton.CssClass += " setDefaultAccount"; 2495 setDefaultAccountButton.Href = string.Format("/Default.aspx?Id={0}&DefaultAccount={1}", managePageAjax, userId); 2496 setDefaultAccountButton.Label = Translate("Set Default Account"); 2497 } 2498 @RenderBootstrapButton(setDefaultAccountButton) 2499 } 2500 </td> 2501 </tr> 2502 } 2503 </tbody> 2504 </table> 2505 @RenderPaging( 2506 GetInteger("DwPaging.PageCount"), 2507 PageParameter, 2508 GetString("DwPaging.PreviousPageLink"), 2509 GetString("DwPaging.NextPageLink"), 2510 currentPage, 2511 null, 2512 "PageGroup.PageNumber", 2513 "PageGroup.PageLink" 2514 ) 2515 } 2516 else 2517 { 2518 @RenderNoResults(Translate("You have no accounts to manage")) 2519 } 2520 @SnippetStart("jsOnLoad") 2521 var errors = Sanitize.Parameter(Dna.AutoImpersonate.Constants.Parameters.RequireManaging).IsNotNullOrEmpty() ? Translate("Please select an account to manage before continuing") : string.Empty; 2522 <text>onLoadSwitchAccount("@errors");</text> 2523 @SnippetEnd("jsOnLoad") 2524 }