Advertisement
Guest User

Untitled

a guest
Feb 26th, 2017
63
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.28 KB | None | 0 0
  1. private void RenderRenderings(DeviceDefinition deviceDefinition, int selectedIndex, int index)
  2. {
  3. Assert.ArgumentNotNull(deviceDefinition, "deviceDefinition");
  4. ArrayList renderings = deviceDefinition.Renderings;
  5. if (renderings == null)
  6. {
  7. return;
  8. }
  9. foreach (RenderingDefinition renderingDefinition in renderings)
  10. {
  11. if (renderingDefinition.ItemID != null)
  12. {
  13. Item item = Client.ContentDatabase.GetItem(renderingDefinition.ItemID);
  14. XmlControl xmlControl = Resource.GetWebControl("DeviceRendering") as XmlControl;
  15. Assert.IsNotNull(xmlControl, typeof(XmlControl));
  16. System.Web.UI.HtmlControls.HtmlGenericControl htmlGenericControl = new System.Web.UI.HtmlControls.HtmlGenericControl("div");
  17. htmlGenericControl.Style.Add("padding", "0");
  18. htmlGenericControl.Style.Add("margin", "0");
  19. htmlGenericControl.Style.Add("border", "0");
  20. htmlGenericControl.Style.Add("position", "relative");
  21. htmlGenericControl.Controls.Add(xmlControl);
  22. string uniqueID = Control.GetUniqueID("R");
  23. this.Renderings.Controls.Add(htmlGenericControl);
  24. htmlGenericControl.ID = Control.GetUniqueID("C");
  25. xmlControl["Click"] = "OnRenderingClick(\"" + index + "\")";
  26. xmlControl["DblClick"] = "device:edit";
  27. if (index == selectedIndex)
  28. {
  29. xmlControl["Background"] = "#D0EBF6";
  30. }
  31. this.Controls.Add(uniqueID);
  32.  
  33. //Get DataSource item path
  34. var datasource = string.Empty;
  35. Sitecore.Data.Database master = Sitecore.Configuration.Factory.GetDatabase("master");
  36. if (!string.IsNullOrEmpty(renderingDefinition.Datasource))
  37. {
  38. var dsItem = master.GetItem(renderingDefinition.Datasource);
  39. if (dsItem != null)
  40. datasource = dsItem.Paths.Path;
  41. }
  42.  
  43. if (item != null)
  44. {
  45. xmlControl["ID"] = uniqueID;
  46. xmlControl["Icon"] = item.Appearance.Icon;
  47. xmlControl["Header"] = item.DisplayName;
  48. xmlControl["Placeholder"] = WebUtil.SafeEncode(renderingDefinition.Placeholder);
  49. xmlControl["DataSource"] = datasource;
  50. }
  51. else
  52. {
  53. xmlControl["ID"] = uniqueID;
  54. xmlControl["Icon"] = "Applications/24x24/forbidden.png";
  55. xmlControl["Header"] = "Unknown rendering";
  56. xmlControl["Placeholder"] = string.Empty;
  57. xmlControl["DataSource"] = string.Empty;
  58. }
  59. if (renderingDefinition.Rules != null && !renderingDefinition.Rules.IsEmpty)
  60. {
  61. int num = renderingDefinition.Rules.Elements("rule").Count<XElement>();
  62. if (num > 1)
  63. {
  64. System.Web.UI.HtmlControls.HtmlGenericControl htmlGenericControl2 = new System.Web.UI.HtmlControls.HtmlGenericControl("span");
  65. if (num > 9)
  66. {
  67. htmlGenericControl2.Attributes["class"] = "scConditionContainer scLongConditionContainer";
  68. }
  69. else
  70. {
  71. htmlGenericControl2.Attributes["class"] = "scConditionContainer";
  72. }
  73. htmlGenericControl2.InnerText = num.ToString();
  74. htmlGenericControl.Controls.Add(htmlGenericControl2);
  75. }
  76. }
  77. RenderDeviceEditorRenderingPipeline.Run(renderingDefinition, xmlControl, htmlGenericControl);
  78. index++;
  79. }
  80. }
  81. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement