/// <summary> /// Display a page size option on the product list module. /// </summary> /// <param name="datatext"></param> /// <param name="model"></param> /// <param name="attributes"></param> /// <returns></returns> public IEncodedString PageSizeDropDownList(String datatext, NBrightRazor model, String cssclass = "") { if (datatext.StartsWith("ResourceKey:")) { datatext = ResourceKey(datatext.Replace("ResourceKey:", "")).ToString(); } var navigationdata = new NavigationData(PortalSettings.Current.PortalId, model.ModuleRef); if (navigationdata.PageSize == "") { navigationdata.PageSize = model.GetSetting("pagesize"); } var strOut = ""; var datat = datatext.Split(','); strOut = "<select class='pagesizedropdown" + model.ModuleRef + " " + cssclass + " '>"; var c = 0; var s = ""; foreach (var t in datat) { var url = ""; var param = new List <String>(); if (model.GetUrlParam("pagemid") != "") { param.Add("pagemid=" + model.ModuleId.ToString("D")); } if (model.GetUrlParam("catid") != "") { param.Add("catid=" + model.GetUrlParam("catid").Trim()); } param.Add("pagesize=" + t); var paramlist = new string[param.Count]; for (int lp = 0; lp < param.Count; lp++) { paramlist[lp] = param[lp]; } url = Globals.NavigateURL(PortalSettings.Current.ActiveTab.TabID, "", paramlist); s = ""; if (t == navigationdata.PageSize) { s = "selected"; } strOut += " <option value='" + t + "' " + s + " selectedurl='" + url + "' >" + t + "</option>"; c += 1; } strOut += "</select>"; strOut += "<script>"; strOut += "$('.pagesizedropdown" + model.ModuleRef + "').change(function () { window.location.replace($('option:selected', this).attr('selectedurl')); });"; strOut += "</script>"; return(new RawString(strOut)); }
/// <summary> /// Edit Product url /// </summary> /// <param name="info">NBrightInfo class of PRD type</param> /// <param name="model">Razor Model class (NBrightRazor)</param> /// <returns>Url to edit product</returns> public IEncodedString EditUrl(NBrightInfo info, NBrightRazor model, String ctrl = "products") { var itemid = -1; if (info != null) { itemid = info.ItemID; } return(EditUrl(itemid, model, ctrl)); }
/// <summary> /// Render a razor template with an object, this method will include the object in the List of the NBrightRazor class /// </summary> /// <param name="razorTemplName"></param> /// <param name="moduleid"></param> /// <param name="cacheKey">If empty no cache done</param> /// <param name="obj"></param> /// <param name="templateControlPath"></param> /// <param name="theme"></param> /// <param name="lang"></param> /// <param name="settings"></param> /// <returns></returns> public static string RazorTemplRender(string razorTemplName, int moduleid, string cacheKey, object obj, string templateControlPath, string theme, string lang, Dictionary<string, string> settings) { // do razor template var ckey = "NBrightBuyRazorOutput" + razorTemplName + "*" + cacheKey + PortalSettings.Current.PortalId.ToString() + "*" + lang; var razorTempl = (string)GetModCache(ckey); if (razorTempl == null) { razorTempl = GetRazorTemplateData(razorTemplName, templateControlPath, theme, lang); if (razorTempl == "") { // check for non-razor templates razorTemplName = razorTemplName.ToLower().Replace(".cshtml", ".html"); ckey = "NBrightBuyRazorOutput" + razorTemplName + "*" + cacheKey + PortalSettings.Current.PortalId.ToString() + "*" + lang; // reset cachekey razorTempl = (string)GetModCache(ckey); if (razorTempl != null) { return razorTempl; } razorTempl = GetRazorTemplateData(razorTemplName, templateControlPath, theme, lang); } if (razorTempl != "") { if (obj == null) obj = new NBrightInfo(true); var l = new List<object>(); l.Add(obj); if (settings == null) settings = new Dictionary<string, string>(); var nbRazor = new NBrightRazor(l, settings, HttpContext.Current.Request.QueryString); nbRazor.FullTemplateName = theme + "." + razorTemplName; nbRazor.TemplateName = razorTemplName; nbRazor.ThemeFolder = theme; var razorTemplateKey = "NBrightBuyRazorKey" + theme + razorTemplName + PortalSettings.Current.PortalId.ToString() + "*" + lang; razorTempl = RazorRender(nbRazor, razorTempl, razorTemplateKey, StoreSettings.Current.DebugMode); if (cacheKey != "" && !StoreSettings.Current.DebugMode) SetModCache(moduleid, ckey, razorTempl); // only save to cache if we pass in a cache key. } else { razorTempl = "ERROR - Razor Template Not Found: " + theme + "." + razorTemplName; } } return razorTempl; }
public static string RazorTemplRenderList(string razorTemplName, int moduleid, string cacheKey, List<NBrightInfo> objList, string templateControlPath, string theme, string lang, Dictionary<string, string> settings) { // do razor template var ckey = "NBrightBuyRazorOutput" + theme + razorTemplName + "*" + cacheKey + PortalSettings.Current.PortalId.ToString(); var razorTempl = (string)GetModCache(ckey); if (razorTempl == null || StoreSettings.Current.DebugMode) { razorTempl = GetRazorTemplateData(razorTemplName, templateControlPath, theme, lang); if (razorTempl != "") { var nbRazor = new NBrightRazor(objList.Cast<object>().ToList(), settings, HttpContext.Current.Request.QueryString); nbRazor.ModuleId = moduleid; var razorTemplateKey = "NBrightBuyRazorKey" + theme + razorTemplName + PortalSettings.Current.PortalId.ToString(); razorTempl = RazorRender(nbRazor, razorTempl, razorTemplateKey, StoreSettings.Current.DebugMode); if (cacheKey != "") SetModCache(moduleid, ckey, razorTempl); // only save to cache if we pass in a cache key. } } return razorTempl; }
public static Dictionary<string, string> RazorPreProcessTempl(string razorTemplName, string templateControlPath, string theme, string lang, Dictionary<string, string> settings, string moduleid = "") { var cachekey = "preprocessmetadata" + theme + "." + razorTemplName + moduleid; // get cached data if there var cachedlist = (Dictionary<string, string>)Utils.GetCache(cachekey); if (cachedlist != null) return cachedlist; // build cache data from template. cachedlist = new Dictionary<string, string>(); var razorTemplate = GetRazorTemplateData(razorTemplName, templateControlPath, theme, lang); if (razorTemplate != "" && razorTemplate.Contains("AddPreProcessMetaData")) { var obj = new NBrightInfo(true); obj.Lang = lang; obj.ModuleId = -1; var l = new List<object>(); l.Add(obj); var modRazor = new NBrightRazor(l, settings, HttpContext.Current.Request.QueryString); modRazor.FullTemplateName = theme + "." + razorTemplName; modRazor.TemplateName = razorTemplName; modRazor.ThemeFolder = theme; try { // do razor and cache preprocessmetadata razorTemplate = RazorRender(modRazor, razorTemplate, cachekey, false); } catch (Exception ex) { // Only log exception, could be a error because of missing data. The preprocessing doesn't care. } cachedlist = (Dictionary<string, string>) Utils.GetCache(cachekey); if (cachedlist == null) cachedlist = new Dictionary<string, string>(); Utils.SetCache(cachekey, cachedlist); } else { cachedlist = new Dictionary<string, string>(); Utils.SetCache(cachekey, cachedlist); } return cachedlist; }