/// <summary> /// Occurs when a new update is added to the Live Editing update collection. /// </summary> /// <param name="sender">The source of the event.</param> /// <param name="e">The <see cref="UpdateAddedEventArgs"/> instance containing the event data.</param> protected void Updates_UpdateAdded(object sender, UpdateAddedEventArgs e) { ItemUpdate update = e.Update as ItemUpdate; if (update != null) { List <Item> affectedItems = Utility.FindControls <Item>(item => item.GetParsedNodeId() == update.NodeId && item.Field == update.Field, Page.Master); foreach (Item affectedItem in affectedItems) { // render the item, temporarily disabling the live editing special output StringWriter itemRenderOutput = new StringWriter(); bool liveEditingWasDisabled = affectedItem.LiveEditingDisabled; affectedItem.LiveEditingDisabled = true; affectedItem.RenderControl(new HtmlTextWriter(itemRenderOutput)); affectedItem.LiveEditingDisabled = liveEditingWasDisabled; // add the item's contents to the output HtmlGenericControl itemUpdate = new HtmlGenericControl("umbraco:itemupdate"); itemUpdate.Attributes["itemId"] = affectedItem.ItemId.ToString(); itemUpdate.InnerHtml = template.ParseInternalLinks(itemRenderOutput.ToString()); itemUpdate.EnableViewState = false; m_Manager.AddClientOutput(itemUpdate); } } }
/// <summary> /// Gets the datatype for the specified item. /// </summary> /// <param name="item">The item.</param> /// <returns>The datatype.</returns> protected virtual IDataType GetDataType(Item item) { // find the property Property editProperty = null; if (item.GetParsedNodeId().HasValue) { Document document = new Document(item.GetParsedNodeId().Value); editProperty = document.getProperty(item.Field); } // find the data type IDataType editDataType = null; if (editProperty != null) { PropertyType editPropertyType = editProperty.PropertyType; editDataType = editPropertyType.DataTypeDefinition.DataType; } else { if (item.PageElements[item.Field] != null) { editDataType = new PageElementEditor(item); } } // only allow editing if we the data can be previewed IDataWithPreview data = editDataType.Data as IDataWithPreview; if (data == null) { editDataType = null; } else { if (editProperty != null) { data.PropertyId = editProperty.Id; } data.PreviewMode = true; // display the latest updated value if available ItemUpdate latestUpdate = LiveEditingContext.Updates.GetLatest <ItemUpdate>(u => u.NodeId == item.GetParsedNodeId() && u.Field == item.Field); if (latestUpdate != null) { data.Value = latestUpdate.Data; } } return(editDataType); }
/// <summary> /// Renders the field contents. /// Checks via the NodeId attribute whether to fetch data from another page than the current one. /// </summary> /// <returns> /// A string of field contents (macros not parsed) /// </returns> protected override string GetFieldContents(Item item) { // check if an update has been made to the field, and use the updated value istead IUpdateList updates = UmbracoContext.Current.LiveEditingContext.Updates; ItemUpdate latestUpdate = updates.GetLatest <ItemUpdate>(u => u.NodeId == item.GetParsedNodeId() && u.Field == item.Field); if (latestUpdate != null) { return(latestUpdate.Data as string); //can't use ToString() as a null value will throw an exception } else { return(base.GetFieldContents(item)); } }
/// <summary> /// Stops editing the current item. /// </summary> /// <remarks>Currently triggered by the client.</remarks> protected virtual void StopEditing() { if (ItemId != 0) { Debug.Assert(HasControls()); if (m_DataType != null) { // load the postback data into the data editor m_DataType.DataEditor.Save(); // store the update with the new data Item item = FindItem(ItemId); ItemUpdate update = new ItemUpdate(item.GetParsedNodeId(), item.Field, m_DataType.Data.Value); LiveEditingContext.Updates.Add(update); } ItemId = 0; } }