public HttpResponseMessage RenderTemplate([FromUri] int templateId) { try { var template = Sexy.TemplateContext.GetTemplate(templateId); var engine = EngineFactory.CreateEngine(template); var dataSource = (ViewDataSource)Sexy.GetViewDataSource(ActiveModule.ModuleID, SexyContent.HasEditPermission(ActiveModule), template); engine.Init(template, Sexy.App, ActiveModule, dataSource, InstancePurposes.WebView, Sexy); engine.CustomizeData(); if (template.AttributeSetID.HasValue && !template.DemoEntityID.HasValue && dataSource["Default"].List.Count == 0) { var toolbar = "<ul class='sc-menu' data-toolbar='" + Newtonsoft.Json.JsonConvert.SerializeObject(new { sortOrder = 0, useModuleList = true, action = "edit" }) + "'></ul>"; return(new HttpResponseMessage(HttpStatusCode.OK) { Content = new StringContent("<div class='dnnFormMessage dnnFormInfo'>No demo item exists for the selected template. " + toolbar + "</div>") }); } var response = new HttpResponseMessage(HttpStatusCode.OK); response.Content = new StringContent(engine.Render(), Encoding.UTF8, "text/plain"); return(response); } catch (Exception e) { DotNetNuke.Services.Exceptions.Exceptions.LogException(e); throw e; } }
public void AddItem([FromUri] int?sortOrder = null) { var contentGroupId = Sexy.GetContentGroupIdFromModule(ActiveModule.ModuleID); var templateId = Sexy.GetTemplateForModule(ActiveModule.ModuleID).TemplateID; SexyUncached.AddContentGroupItem(contentGroupId, UserInfo.UserID, templateId, null, sortOrder.HasValue ? sortOrder.Value + 1 : sortOrder, true, ContentGroupItemType.Content, false); }
protected void Page_Load(object sender, EventArgs e) { ServicesFramework.Instance.RequestAjaxAntiForgerySupport(); try { // If logged in, inject Edit JavaScript, and delete / add items if (UserMayEditThisModule) { ClientScriptManager ClientScript = Page.ClientScript; // ToDo: Move these RegisterScripts to JS to prevent including AngularJS twice (from other modules) ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/AngularJS/angular.min.js", 80); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/2sxc.TemplateSelector.js", 81); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/2sxc.ApiService.js", 82); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/ViewEdit.js", 82); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/2sxc.DnnActionMenuMapper.js", 83); var hasContent = AppId.HasValue && Template != null && Items.Any(p => p.EntityID.HasValue); var templateChooserVisible = Settings.ContainsKey(SexyContent.SettingsShowTemplateChooser) ? Boolean.Parse(Settings[SexyContent.SettingsShowTemplateChooser].ToString()) : !hasContent; ((DotNetNuke.UI.Modules.ModuleHost) this.Parent).Attributes.Add("data-2sxc", Newtonsoft.Json.JsonConvert.SerializeObject(new { moduleId = ModuleId, manage = new { isEditMode = UserMayEditThisModule, templateChooserVisible = templateChooserVisible, hasContent = hasContent, isContentApp = IsContentApp, appId = AppId, isList = AppId.HasValue && Items.Count > 1, templateId = Template != null ? Template.TemplateID : new int?(), contentTypeId = Template != null ? Template.AttributeSetID : 0, config = new { portalId = PortalId, tabId = TabId, moduleId = ModuleId, contentGroupId = AppId.HasValue ? Sexy.GetContentGroupIdFromModule(ModuleId) : 0, dialogUrl = DotNetNuke.Common.Globals.NavigateURL(this.TabId), returnUrl = Request.RawUrl, appPath = AppId.HasValue ? Sexy.App.Path : null, cultureDimension = AppId.HasValue ? Sexy.GetCurrentLanguageID() : new int?(), isList = Template != null && Template.UseForList } } })); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/2sxc.api.js", 90); ClientResourceManager.RegisterScript(this.Page, "~/DesktopModules/ToSIC_SexyContent/Js/2sxc.api.manage.js", 91); } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
protected void EavManagementEntityDeleting(EntityDeletingEventArgs e) { if (!Sexy.CanDeleteEntity(e.EntityId)) { e.Cancel = true; e.CancelMessage += " This entity cannot be deleted because it is in use (2sxc)."; } }
protected void Page_Load(object sender, EventArgs e) { if (!UserMayEdit) { btnUpdate.Visible = false; txtTemplateContent.Enabled = false; } hlkCancel.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(this.TabId); if (IsPostBack) { return; } if (Template == null) { return; } if (File.Exists(TemplatePath)) { txtTemplateContent.Text = File.ReadAllText(TemplatePath); } // Get name of the current template and write it to lblTemplate lblTemplate.Text = Template.Name; lblTemplateLocation.Text = @"/" + TemplatePath.Replace(HttpContext.Current.Request.PhysicalApplicationPath, String.Empty).Replace('\\', '/'); lblEditTemplateFileHeading.Text = String.Format(LocalizeString("lblEditTemplateFileHeading.Text"), Template.Name); var defaultLanguageID = Sexy.ContentContext.GetLanguageId(PortalSettings.DefaultLanguage); var languageList = defaultLanguageID.HasValue ? new[] { defaultLanguageID.Value } : new[] { 0 }; var templateDefaults = Sexy.GetTemplateDefaults(Template.TemplateID).Where(t => t.ContentTypeID.HasValue); string formatString; if (Template.Type == "Token") { formatString = "[{0}:{1}]"; } else { formatString = "@{0}.{1}"; } foreach (var templateDefault in templateDefaults) { var contentTypeId = templateDefault.ContentTypeID.Value; AddHelpForAContentType(contentTypeId, formatString, templateDefault, languageList); } // todo: add AppResources and AppSettings help // add standard help AddHelpFragments(); }
protected void ProcessView() { List <ContentGroupItemType> EditableItemsTypes = new List <ContentGroupItemType>(); if (CurrentlyEditedItems.Any() && CurrentlyEditedItems.Any(c => c.ItemType == ContentGroupItemType.Content)) { EditableItemsTypes.Add(ContentGroupItemType.Content); EditableItemsTypes.Add(ContentGroupItemType.Presentation); } if (SortOrder == -1 || CurrentlyEditedItems.Any(c => c.ItemType == ContentGroupItemType.ListContent)) { EditableItemsTypes.Add(ContentGroupItemType.ListContent); EditableItemsTypes.Add(ContentGroupItemType.ListPresentation); } if (Items.Any() && Items.First().TemplateID.HasValue) { foreach (var TemplateDefault in Sexy.GetTemplateDefaults(Items.First().TemplateID.Value).Where(c => EditableItemsTypes.Contains(c.ItemType))) { if (TemplateDefault.ContentTypeID.HasValue && TemplateDefault.ContentTypeID.Value > 0) { ContentGroupItem ContentGroupItem = null; if (CurrentlyEditedItems.Any() && CurrentlyEditedItems.First().ContentGroupItemID != 0) { ContentGroupItem = CurrentlyEditedItems.FirstOrDefault(p => p.ItemType == TemplateDefault.ItemType); } var editControl = (EditContentGroupItem)LoadControl(System.IO.Path.Combine(TemplateSourceDirectory, "EditContentGroupItem.ascx")); editControl.ContentGroupItemID = ContentGroupItem != null && ContentGroupItem.ContentGroupID != 0 ? ContentGroupItem.ContentGroupItemID : new int?(); editControl.ContentGroupID = ContentGroupID.Value; editControl.AppId = AppId.Value; editControl.ZoneId = ZoneId.Value; editControl.ItemType = TemplateDefault.ItemType; editControl.TemplateID = Items.First().TemplateID.Value; editControl.SortOrder = CurrentlyEditedItems.Any() || SortOrder == -1 ? SortOrder : new int?(); editControl.ModuleID = ModuleId; editControl.TabID = TabId; editControl.AttributeSetID = TemplateDefault.ContentTypeID.Value; phNewOrEditControls.Controls.Add(editControl); } } } // Directly edit entity Id if ((!SortOrder.HasValue && EntityId.HasValue) || (!SortOrder.HasValue && AttributeSetId.HasValue && NewMode)) { var editControl = (EditEntity)LoadControl(System.IO.Path.Combine(TemplateSourceDirectory, "EditEntity.ascx")); editControl.AppId = AppId.Value; editControl.ZoneId = ZoneId.Value; editControl.ModuleID = ModuleId; editControl.TabID = TabId; editControl.AttributeSetID = AttributeSetId.HasValue ? AttributeSetId.Value : Sexy.ContentContext.GetEntity(EntityId.Value).AttributeSetID; editControl.EntityId = EntityId; phNewOrEditControls.Controls.Add(editControl); } }
/// <summary> /// Gets called when doing any action in the Cultures grid (activate or deactivate) /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void grdCultures_ItemCommand(object sender, GridCommandEventArgs e) { GridEditableItem Item = e.Item as GridEditableItem; var CultureCode = Item.GetDataKeyValue("Code").ToString(); // Activate or Deactivate the Culture Sexy.SetCultureState(CultureCode, e.CommandName == "Activate", PortalId); // Re-bind the grid grdCultures.Rebind(); }
protected void Page_Load(object sender, EventArgs e) { hlkCancel.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(this.TabId, "", null); var ListContentTemplateDefault = Sexy.GetTemplateDefault(Template.TemplateID, ContentGroupItemType.ListContent); pnlEditListHeader.Visible = (ListContentTemplateDefault != null && ListContentTemplateDefault.ContentTypeID.HasValue); if (!IsPostBack) { grdEntities.DataBind(); } }
/// <summary> /// Process View if a Template has been set /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_PreRender(object sender, EventArgs e) { try { var isSharedModule = ModuleConfiguration.PortalID != ModuleConfiguration.OwnerPortalID; if (!isSharedModule) { var noTemplatesYet = !Sexy.GetVisibleTemplates(PortalId).Any(); // If there are no templates configured - show "getting started" frame if (noTemplatesYet && IsEditable && UserInfo.IsInRole(PortalSettings.AdministratorRoleName)) { pnlGetStarted.Visible = true; var gettingStartedControl = (GettingStartedFrame)LoadControl("~/DesktopModules/ToSIC_SexyContent/SexyContent/GettingStarted/GettingStartedFrame.ascx"); gettingStartedControl.ModuleID = this.ModuleId; gettingStartedControl.ModuleConfiguration = this.ModuleConfiguration; pnlGetStarted.Controls.Add(gettingStartedControl); } if (UserMayEditThisModule) { pnlTemplateChooser.Visible = true; } if (AppId.HasValue && !Sexy.PortalIsConfigured(Server, ControlPath)) { Sexy.ConfigurePortal(Server); } } if (AppId.HasValue) { if (Items.Any() && Template != null) { ProcessView(phOutput, pnlError, pnlMessage); } else if (!IsContentApp && UserMayEditThisModule) // Select first available template automatically if it's not set yet - then refresh page { var templates = Sexy.GetAvailableTemplatesForSelector(ModuleConfiguration).ToList(); if (templates.Any()) { SexyUncached.UpdateTemplateForGroup(Sexy.GetContentGroupIdFromModule(ModuleConfiguration.ModuleID), templates.First().TemplateID, UserInfo.UserID); } Response.Redirect(Request.RawUrl); } } } catch (Exception ex) { Exceptions.ProcessModuleLoadException(this, ex); } }
protected void SetTemplateDefaultSelector(int TemplateID, ContentTypeAndDemoSelector Selector) { var ItemType = Selector.ItemType; var TemplateDefault = Sexy.GetTemplateDefault(TemplateID, ItemType); if (TemplateDefault != null) { Selector.ContentTypeID = TemplateDefault.ContentTypeID; Selector.DemoEntityID = TemplateDefault.DemoEntityID; } Selector.ItemType = ItemType; Selector.Enabled = !Sexy.IsTemplateDefaultInUse(TemplateID, ItemType); }
/// <summary> /// Handles the control load /// </summary> /// <param name="sender"></param> /// <param name="e"></param> protected void Page_Load(object sender, EventArgs e) { // Add DNN Version to body Class SexyContent.AddDNNVersionToBodyClass(this); // Bind Languages Repeater var Languages = Sexy.ContentContext.GetLanguages().Where(l => l.Active).OrderByDescending(l => l.DimensionID == DefaultLanguageID).ThenBy(l => l.ExternalKey); if (Languages.Count() == 0) { pnlDimensionNav.Visible = false; } rptDimensions.DataSource = Languages; rptDimensions.DataBind(); btnDelete.OnClientClick = "return confirm('" + LocalizeString("btnDelete.Confirm") + "')"; btnDelete.Text = Items.Count(p => p.ItemType == ContentGroupItemType.Content) > 1 ? LocalizeString("btnDelete.ListText") : LocalizeString("btnDelete.Text"); btnDelete.Visible = !NewMode && ContentGroupID.HasValue; // If there is something to edit if (CurrentlyEditedItems.Any()) { // Settings link (to change content) hlkChangeContent.NavigateUrl = Sexy.GetElementSettingsLink(CurrentlyEditedItems.First().ContentGroupItemID, ModuleId, TabId, Request.RawUrl); // Show Change Content or Reference Link only if this is the default language var IsDefaultLanguage = LanguageID == DefaultLanguageID; hlkChangeContent.Visible = !NewMode && IsDefaultLanguage && (CurrentlyEditedItems.First().ItemType == ContentGroupItemType.Content || CurrentlyEditedItems.First().ItemType == ContentGroupItemType.ListContent); } // Show message if language is not active if (!Sexy.ContentContext.HasLanguages() || (LanguageID.HasValue && Sexy.ContentContext.GetDimension(LanguageID.Value).Active)) { ProcessView(); } else { pnlActions.Visible = false; pnlLanguageNotActive.Visible = true; litLanguageName.Text = LocaleController.Instance.GetLocale(System.Threading.Thread.CurrentThread.CurrentCulture.Name).Text; if (UserInfo.IsInRole(PortalSettings.AdministratorRoleName)) { btnActivateLanguage.Visible = true; } } }
protected void grdEntities_ItemCommand(object sender, Telerik.Web.UI.GridCommandEventArgs e) { int ContentGroupItemID = Convert.ToInt32(e.Item.OwnerTableView.DataKeyValues[e.Item.ItemIndex]["ID"]); var item = Items.First(p => p.ContentGroupItemID == ContentGroupItemID); switch (e.CommandName) { case "add": SexyUncached.AddContentGroupItem(ContentGroupID, UserId, item.TemplateID.Value, null, item.SortOrder + 1, true, ContentGroupItemType.Content, false); // Refresh page Response.Redirect(Request.RawUrl); break; case "addwithedit": Response.Redirect(Sexy.GetElementAddWithEditLink(ContentGroupID, item.SortOrder + 1, ModuleId, TabId, Request.RawUrl)); break; } }
/// <summary> /// DataBind the template grid view /// </summary> private void BindGrdTemplates() { var AttributeSetList = Sexy.GetAvailableAttributeSets(SexyContent.AttributeSetScope).ToList(); var TemplateList = Sexy.GetTemplates(PortalId).ToList(); var Templates = from c in TemplateList join a in AttributeSetList on c.AttributeSetID equals a.AttributeSetId into JoinedList from a in JoinedList.DefaultIfEmpty() select new { TemplateID = c.TemplateID, TemplateName = c.Name, AttributeSetID = c.AttributeSetID, AttributeSetName = a != null ? a.Name : "No Content Type", TemplatePath = c.Path, DemoEntityID = c.DemoEntityID, IsHidden = c.IsHidden }; grdTemplates.DataSource = Templates; grdTemplates.DataBind(); }
public void SetAppId(int?appId) { // Reset template to nothing (prevents errors after changing app) SexyUncached.UpdateTemplateForGroup(Sexy.GetContentGroupIdFromModule(ActiveModule.ModuleID), null, UserInfo.UserID); SexyContent.SetAppIdForModule(ActiveModule, appId); // Change to 1. template if app has been set if (appId.HasValue) { var sexyForNewApp = new SexyContent(Sexy.App.ZoneId, appId.Value, false); var templates = sexyForNewApp.GetAvailableTemplatesForSelector(ActiveModule).ToList(); if (templates.Any()) { SexyUncached.UpdateTemplateForGroup(Sexy.GetContentGroupIdFromModule(ActiveModule.ModuleID), templates.First().TemplateID, UserInfo.UserID); } else { SexyUncached.UpdateTemplateForGroup(Sexy.GetContentGroupIdFromModule(ActiveModule.ModuleID), null, UserInfo.UserID); } } }
protected void Page_Load(object sender, EventArgs e) { hlkCancel.NavigateUrl = DotNetNuke.Common.Globals.NavigateURL(this.TabId, "", null); var contentTypes = Sexy.GetAvailableAttributeSets("2SexyContent"); var templates = Sexy.GetTemplates(PortalSettings.PortalId); var entities = DataSource.GetInitialDataSource(ZoneId.Value, AppId.Value, false); var language = System.Threading.Thread.CurrentThread.CurrentCulture.Name; var data = new { contentTypes = contentTypes.Select(c => new { Id = c.AttributeSetId, Name = c.Name, StaticName = c.StaticName, Templates = templates.Where(t => t.AttributeSetID == c.AttributeSetId).Select(p => new { p.TemplateID, p.AttributeSetID, p.Name, TemplateDefaults = Sexy.GetTemplateDefaults(p.TemplateID).Select(td => new { td.ContentTypeID, td.DemoEntityID, ItemType = td.ItemType.ToString("F") }) }), Entities = entities.List.Where(en => en.Value.Type.AttributeSetId == c.AttributeSetId).Select(en => Sexy.GetDictionaryFromEntity(en.Value, language)) }), templatesWithoutContentType = templates.Where(p => !p.AttributeSetID.HasValue).Select(t => new { t.TemplateID, t.Name }) }; pnlExportView.Attributes.Add("ng-init", "init(" + Newtonsoft.Json.JsonConvert.SerializeObject(data) + ");"); }
protected void Page_Load(object sender, EventArgs e) { // Make sure the correct Resource file is loaded LocalResourceFile = LocalResourceFile.Replace(ID, "ContentTypeAndDemoSelector"); // Set localized Error Messages for validator valContentType.ErrorMessage = LocalizeString("valContentType.ErrorMessage"); valContentType.Enabled = ContentTypeRequired; ((DotNetNuke.UI.UserControls.LabelControl)lblContentType).Text = LocalizeString("lblContentType" + ItemType.ToString("F") + ".Text"); ((DotNetNuke.UI.UserControls.LabelControl)lblDemoRow).Text = LocalizeString("lblDemoRow" + ItemType.ToString("F") + ".Text"); if (!IsPostBack) { if (EnableNoContentTypeOption) { ddlContentTypes.Items.Add(new ListItem("< no ContentType >", "-1")); } // DataBind Content Types var AttributeSets = Sexy.GetAvailableAttributeSets(SexyContent.AttributeSetScope); ddlContentTypes.DataSource = AttributeSets; if (AttributeSets.Any(a => a.AttributeSetId == _ContentTypeID)) { ddlContentTypes.SelectedValue = _ContentTypeID.ToString(); } ddlContentTypes.DataBind(); BindDemoContentDropdown(Convert.ToInt32(ddlContentTypes.SelectedValue), ddlDemoRows); if (_DemoEntityID.HasValue && _DemoEntityID != 0 && ddlDemoRows.Items.FindByValue(_DemoEntityID.Value.ToString()) != null) { ddlDemoRows.SelectedValue = _DemoEntityID.Value.ToString(); } } }
/// <summary> /// Get the content data and render it with the given template to the page. /// </summary> protected void ProcessView(PlaceHolder phOutput, Panel pnlError, Panel pnlMessage) { #region Check if everything has values and return if not if (Template == null) { ShowError(LocalizeString("TemplateConfigurationMissing.Text"), pnlError); return; } if (Template.AttributeSetID.HasValue && DataSource.GetCache(ZoneId.Value, AppId.Value).GetContentType(Template.AttributeSetID.Value) == null) { ShowError("The contents of this module cannot be displayed because it's located in another VDB.", pnlError); return; } if (Template.AttributeSetID.HasValue && !Template.DemoEntityID.HasValue && Items.All(e => !e.EntityID.HasValue)) { var toolbar = IsEditable ? "<ul class='sc-menu' data-toolbar='" + Newtonsoft.Json.JsonConvert.SerializeObject(new { sortOrder = Items.First().SortOrder, useModuleList = true, action = "edit" }) + "'></ul>" : ""; ShowMessage(LocalizeString("NoDemoItem.Text") + " " + toolbar, pnlMessage); return; } #endregion try { //var renderTemplate = Template; string renderedTemplate; var engine = EngineFactory.CreateEngine(Template); var dataSource = (ViewDataSource)Sexy.GetViewDataSource(this.ModuleId, SexyContent.HasEditPermission(this.ModuleConfiguration), Template); engine.Init(Template, Sexy.App, this.ModuleConfiguration, dataSource, Request.QueryString["type"] == "data" ? InstancePurposes.PublishData : InstancePurposes.WebView, Sexy); engine.CustomizeData(); // Output JSON data if type=data in URL if (Request.QueryString["type"] == "data") { if (dataSource.Publish.Enabled) { var publishedStreams = dataSource.Publish.Streams; renderedTemplate = Sexy.GetJsonFromStreams(dataSource, publishedStreams.Split(new[] { ',' }, StringSplitOptions.RemoveEmptyEntries)); } else { Response.StatusCode = 403; var moduleTitle = new ModuleController().GetModule(ModuleId).ModuleTitle; renderedTemplate = Newtonsoft.Json.JsonConvert.SerializeObject(new { error = "2sxc Content (" + ModuleId + "): " + String.Format(LocalizeString("EnableDataPublishing.Text"), ModuleId, moduleTitle) }); Response.TrySkipIisCustomErrors = true; } Response.ContentType = "application/json"; } else { renderedTemplate = engine.Render(); } // If standalone is specified, output just the template without anything else if (StandAlone) { Response.Clear(); Response.Write(renderedTemplate); Response.Flush(); Response.SuppressContent = true; HttpContext.Current.ApplicationInstance.CompleteRequest(); } else { phOutput.Controls.Add(new LiteralControl(renderedTemplate)); } } // Catch errors; log them catch (Exception Ex) { ShowError(LocalizeString("TemplateError.Text") + ": " + HttpUtility.HtmlEncode(Ex.ToString()), pnlError, LocalizeString("TemplateError.Text"), false); Exceptions.LogException(Ex); } }
protected void btnEditListHeader_Click(object sender, EventArgs e) { Response.Redirect(Sexy.GetElementEditLink(ContentGroupID, -1, ModuleId, TabId, Request.RawUrl)); }
/// <summary> /// Returns the Settings URL /// </summary> /// <param name="ContentGroupItemID"></param> /// <returns></returns> protected string GetSettingsUrl(int ContentGroupItemID) { var item = Items.Single(p => p.ContentGroupItemID == ContentGroupItemID); return(Sexy.GetElementSettingsLink(item.ContentGroupItemID, ModuleId, TabId, Request.RawUrl)); }
/// <summary> /// Bind the template files from the given template location /// </summary> /// <param name="TemplateType">The template type</param> /// <param name="TemplateLocation">The template location</param> /// <param name="TemplateDropDown">The template dropdown to databind</param> private void BindTemplateFiles(string TemplateType, string TemplateLocation, DropDownList TemplateDropDown) { TemplateDropDown.DataSource = Sexy.GetTemplateFiles(Server, TemplateType, TemplateLocation); TemplateDropDown.DataBind(); }
protected void btnActivateLanguage_Click(object sender, EventArgs e) { Sexy.SetCultureState(System.Threading.Thread.CurrentThread.CurrentCulture.Name, true, PortalId); Response.Redirect(Sexy.GetElementEditLink(ContentGroupID.Value, SortOrder.Value, ModuleId, TabId, "")); }
private IDictionary <int, IEntity> GetStream(ContentGroupItemType itemType, ContentGroupItemType?presentationItemType) { var entitiesToDeliver = new Dictionary <int, IEntity>(); if (!ContentGroupItems.Any(c => c.TemplateID.HasValue) && !OverrideTemplateId.HasValue) { return(entitiesToDeliver); } var items = ContentGroupItems.ToList(); // Create copy of list (not in cache) because it will get modified var templateId = OverrideTemplateId.HasValue ? OverrideTemplateId.Value : items.First().TemplateID.Value; var templateDefaults = Sexy.GetTemplateDefaults(templateId); var templateDefault = templateDefaults.FirstOrDefault(t => t.ItemType == itemType); // If no Content Elements exist and type is List, add a ContentGroupItem to List (not to DB) if ((itemType == ContentGroupItemType.Content || itemType == ContentGroupItemType.ListContent) && !items.Any(p => p.ItemType == itemType)) { if (!ListId.HasValue) { throw new Exception("GetStream() failed because ListId is null. ModuleId is " + (ModuleId.HasValue ? ModuleId.ToString() : "null")); } items.Add(new ContentGroupItem { ContentGroupID = ListId.Value, ContentGroupItemID = -1, EntityID = new int?(), SortOrder = (itemType == ContentGroupItemType.ListContent ? -1 : 0), SysCreated = DateTime.Now, SysCreatedBy = -1, TemplateID = templateId, Type = itemType.ToString("F") }); } var originals = In["Default"].List; foreach (var i in items.Where(p => p.ItemType == itemType)) { // use demo-entites where available var entityId = i.EntityID.HasValue ? i.EntityID.Value : (templateDefault != null && templateDefault.DemoEntityID.HasValue ? templateDefault.DemoEntityID.Value : new int?()); // We can't deliver entities that are not delivered by base (original stream), so continue if (!entityId.HasValue || !originals.ContainsKey(entityId.Value)) { continue; } IEntity presentation = null; if (presentationItemType.HasValue) { // Try to find presentation entity var presentationEntityId = items.Where(p => p.SortOrder == i.SortOrder && p.ItemType == presentationItemType && p.EntityID.HasValue && originals.ContainsKey(p.EntityID.Value)).Select(p => p.EntityID).FirstOrDefault(); // If there is no presentation entity, take default entity if (!presentationEntityId.HasValue) { presentationEntityId = templateDefaults.Where( d => d.ItemType == presentationItemType && d.DemoEntityID.HasValue && originals.ContainsKey(d.DemoEntityID.Value)) .Select(p => p.DemoEntityID).FirstOrDefault(); } presentation = presentationEntityId.HasValue ? originals[presentationEntityId.Value] : null; } var key = entityId.Value; // This ensures that if an entity is added more than once, the dictionary doesn't complain because of duplicate keys while (entitiesToDeliver.ContainsKey(key)) { key += 1000000000; } entitiesToDeliver.Add(key, new EAVExtensions.EntityInContentGroup(originals[entityId.Value]) { SortOrder = i.SortOrder, ContentGroupItemModified = i.SysModified, Presentation = presentation, GroupId = ListId.Value }); } return(entitiesToDeliver); }
public IEnumerable <object> GetSelectableContentTypes() { return(Sexy.GetAvailableAttributeSetsForVisibleTemplates(PortalSettings.PortalId).Select(p => new { p.AttributeSetId, p.Name })); }
protected string GetEditUrl(int ContentGroupItemID) { var item = Items.Single(p => p.ContentGroupItemID == ContentGroupItemID); return(Sexy.GetElementEditLink(item.ContentGroupID, item.SortOrder, ModuleId, TabId, Request.RawUrl)); }
public void SaveTemplateId([FromUri] int?templateId) { SexyUncached.UpdateTemplateForGroup(Sexy.GetContentGroupIdFromModule(ActiveModule.ModuleID), templateId, UserInfo.UserID); }
public IEnumerable <object> GetSelectableTemplates() { var availableTemplates = Sexy.GetAvailableTemplatesForSelector(ActiveModule); return(availableTemplates.Select(t => new { t.TemplateID, t.Name, t.AttributeSetID })); }