public Component LoadComponent(string componentId, string content = "", string design = "", string id = "", Panel myPanel = null, string workFolder = "", int cIndex = 1, int pageid = 0, int pageType = 1, bool isDropped = false, string position = "", string customCss = "") { if (myPanel == null){return null;} //load component from class string cFolder = R.Util.Str.Capitalize(componentId.Replace("-", "/")); string className = "Rennder.Components." + cFolder.Replace("/","."); Type type = Type.GetType(className, false, true); if(type == null) { return null; } Component component = (Component)Activator.CreateInstance(type, new object[] { R }); if (component == null) { return null; } //load component content component.DataField = content; component.DesignField = design; //set up component properties component.panelName = myPanel.Name; component.index = cIndex; component.ComponentId = componentId; component.LayerId = pageid; component.pageId = pageid; component.ComponentType = "component"; if (string.IsNullOrEmpty(id)) { id = R.Util.Str.CreateID(); } component.itemId = id; //set up component properties component.isDropped = isDropped; if (isDropped == false) component.justLoaded = true; if (pageType == 1) { component.workfolder = "/content/websites/" + websiteId + "/pages/" + pageid + "/"; } else { component.workfolder = "/content/websites/" + websiteId + "/layers/" + pageid + "/"; } component.Draggable = 1; if (componentId.ToLower() == "panel") { component.ComponentType = "panel"; } else if (myPanel.isPartOfTheme == false) { component.ComponentType = "panelcomponent"; } //load position CSS properties string css = ""; if (!string.IsNullOrEmpty(position)) { string[] pos = position.Split('|'); string[] cCss = { "","","","","" }; if (!string.IsNullOrEmpty(customCss)) { cCss = customCss.Split('|'); } bool firstlvl = true; if(pos.Length == 5) { //HD screen first if(pos[4] != "" || cCss[4] != "") { if(firstlvl == true) { firstlvl = false; css += "#c" + id + ", "; } css += ".screen.hd #c" + id + ", .screen.desktop #c" + id + ", .screen.tablet #c" + id + ", .screen.mobile #c" + id + ", .screen.cell #c" + id + "{ " + GetCssForPosition(pos[4]) + "\n" + cCss[4] + "}\n"; } //Desktop screen if (pos[3] != "" || cCss[3] != "") { if (firstlvl == true) { firstlvl = false; css += "#c" + id + ", "; } css += ".screen.desktop #c" + id + ", .screen.tablet #c" + id + ", .screen.mobile #c" + id + ", .screen.cell #c" + id + "{ " + GetCssForPosition(pos[3]) + "\n" + cCss[3] + "}\n"; } //Tablet screen if (pos[2] != "" || cCss[2] != "") { if (firstlvl == true) { firstlvl = false; css += "#c" + id + ", "; } css += ".screen.tablet #c" + id + ", .screen.mobile #c" + id + ", .screen.cell #c" + id + "{ " + GetCssForPosition(pos[2]) + "\n" + cCss[2] + "}\n"; } //Mobile screen if (pos[1] != "" || cCss[1] != "") { if (firstlvl == true) { firstlvl = false; css += "#c" + id + ", "; } css += ".screen.mobile #c" + id + ", .screen.cell #c" + id + "{ " + GetCssForPosition(pos[1]) + "\n" + cCss[1] + "}\n"; } //Cell screen if (pos[0] != "" || cCss[0] != "") { if (firstlvl == true) { firstlvl = false; css += "#c" + id + ", "; } css += ".screen.cell #c" + id + "{ " + GetCssForPosition(pos[0]) + "\n" + cCss[0] + "}\n"; } } } if(css != ""){ RegisterCSS("c" + id, css); } //finish loading component component.Load(); //load component.js once if (CheckJSOnceIfLoaded("comp-" + cFolder) == false) { if (R.Server.Cache.ContainsKey("compjs-" + cFolder) == true & R.isLocal == false) //only cache if on live server { //load from cache R.Page.RegisterJSonce("comp-" + cFolder, R.Server.Cache["compjs-" + cFolder].ToString()); } else { //load from file string jsp = File.ReadAllText(R.Server.path("/app/components/" + cFolder + "/component.js")); R.Page.RegisterJSonce("comp-" + cFolder, jsp); if (R.isLocal == false) { //save to cache R.Server.Cache["compjs-" + cFolder] = jsp; } } } GetAllComponents(); Components.Add(component); ComponentViews.Add(component.GetComponentView()); return component; }
public void LoadTheme() { //load website theme into Rennder if (themeFolder == prevThemeFolder) { return; } prevThemeFolder = themeFolder; R.Elements = new Elements(R, themeFolder); if (R.isFirstLoad == true) { //load CSS for theme R.App.scaffold.Data["theme-css"] = themeFolder + "style.css?v=" + R.Version; } else { //load CSS via javascript instead RegisterJS("cssfile", "$('#themeCss').href = '" + themeFolder + "style.css?v=" + R.Version + "';"); } int[] start = new int[3]; string fileHtml = null; string fileWebsite = ""; string headWebsite = ""; string footWebsite = ""; string urlDefaultHtm = R.Server.path(themeFolder + "theme.html"); string urlWebsiteHtm = R.Server.path("/content/websites/" + websiteId + "/website.html"); //get theme HTML if (R.Server.Cache.ContainsKey(themeFolder + "theme.html") == true) { fileHtml = R.Server.Cache[themeFolder + "theme.html"].ToString(); } else { fileHtml = File.ReadAllText(urlDefaultHtm); R.Server.Cache[themeFolder + "theme.html"] = fileHtml; } //get website HTML if (R.Server.Cache.ContainsKey("/content/websites/" + websiteId + "/website.html") == true) { fileWebsite = R.Server.Cache["/content/websites/" + websiteId + "/website.html"].ToString(); } else { if (File.Exists(urlWebsiteHtm) == true) { fileWebsite = File.ReadAllText(urlWebsiteHtm); } R.Server.Cache["/content/websites/" + websiteId + "/website.html"] = fileWebsite; } if (!string.IsNullOrEmpty(fileWebsite)) { start[0] = fileWebsite.IndexOf("{{body}}"); if (start[0] >= 0) { headWebsite = fileWebsite.Substring(0, start[0]); footWebsite = fileWebsite.Substring(start[0] + 8); } fileHtml = headWebsite + fileHtml + footWebsite; } int i = -1; List<string> themeHtm = new List<string>(); start[2] = 0; do { start[0] = fileHtml.IndexOf("{{", start[2]); if (start[0] >= 0) { //found a panel start[1] = fileHtml.IndexOf("}}", start[0] + 2); if (start[1] >= 0) { i += 1; //add chunck of theme html to the page string htm = ""; htm = fileHtml.Substring(start[2], start[0] - start[2]); start[2] = start[1] + 2; //create new panel Panel newPanel = new Panel(R); string name = fileHtml.Substring(start[0] + 2, start[1] - (start[0] + 2)); newPanel.Name = name; newPanel.ID = "panel" + newPanel.Name.Replace(" ", ""); //add attributes to the panel newPanel.isPartOfTheme = true; if (newPanel.Name.ToLower() == "body") { //create loading body div htm += "<div class=\"absolute\" style=\"width:100%;\"><div class=\"relative\" id=\"divPageLoad\" style=\"width:100%;\"><div class=\"div-max-width\" style=\"width:250px; margin:0px auto; padding:100px 0px;\">"; htm += "Loading content..."; htm += "<div style=\"clear:both;\"></div></div></div></div>"; } htm += "{{panel-" + newPanel.Name.ToLower().Replace(" ", "") + "}}"; themeHtm.Add(htm); //add panel to list AddPanel(newPanel); } else { break; } } else { break; } } while (true); themeHtm.Add(fileHtml.Substring(start[2])); themeHtml = String.Join("", themeHtm.ToArray()); }
public Panel GetPanelByName(string name) { //get panel from viewstate if ((PanelViews == null) == false) { foreach (PanelView pv in PanelViews) { if (pv.Name == name | pv.ClassName == name) { Panel panel = new Panel(R); panel.LoadFromPanelView(pv); return panel; } } } //get panel on first page load if ((bodyPanels == null) == false) { for (int x = 0; x <= bodyPanels.Count - 1; x++) { if (bodyPanels[x].Name == name) return bodyPanels[x]; } } return new Panel(R); }
public void AddPanel(Panel panel) { if (bodyPanels == null) { bodyPanels = new List<Panel>(); } bodyPanels.Add(panel); if ((PanelViews == null) == true) { PanelViews = new List<PanelView>(); } }