From a6997a5cb7723d475c7569a01eabed795181b1ae Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 17 Apr 2013 07:03:18 -0200 Subject: [PATCH 1/7] Revert U4-1922 to resume expected sorting behavior. --- .../umbraco.presentation/umbraco/controls/ContentControl.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 0603bf125f..2b8df31950 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -133,7 +133,7 @@ namespace umbraco.controls // Iterate through the property types and add them to the tab // zb-00036 #29889 : fix property types getter to get the right set of properties // ge : had a bit of a corrupt db and got weird NRE errors so rewrote this to catch the error and rethrow with detail - foreach (PropertyType propertyType in tab.GetPropertyTypes(_content.ContentType.Id).OrderBy(x=>x.SortOrder)) + foreach (PropertyType propertyType in tab.GetPropertyTypes(_content.ContentType.Id)) { // table.Rows.Add(addControl(_content.getProperty(editPropertyType.Alias), tp)); var property = _content.getProperty(propertyType); From 0cf2a1fc2ab736e30029b578b43d0d3e8569e152 Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 17 Apr 2013 10:57:24 -0200 Subject: [PATCH 2/7] Possible fix for U4-2097 Package import causes template tree to break - modified closure problem --- src/Umbraco.Core/Services/PackagingService.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 037878b44f..7784e5d76f 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -596,10 +596,11 @@ namespace Umbraco.Core.Services LogHelper.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", tempElement.Element("Alias").Value, tempElement.Element("Master").Value)); } + XElement elementCopy = tempElement; var field = new TopologicalSorter.DependencyField { - Alias = tempElement.Element("Alias").Value, - Item = new Lazy(() => tempElement), + Alias = elementCopy.Element("Alias").Value, + Item = new Lazy(() => elementCopy), DependsOn = dependencies.ToArray() }; From eba7582a979ebfa0cf03c7a8ab0576880cfa51da Mon Sep 17 00:00:00 2001 From: Sebastiaan Janssen Date: Wed, 17 Apr 2013 11:16:15 -0200 Subject: [PATCH 3/7] Eh, yeah, maybe I should start with making a copy of the element first.. d'oh! --- src/Umbraco.Core/Services/PackagingService.cs | 19 ++++++++++--------- 1 file changed, 10 insertions(+), 9 deletions(-) diff --git a/src/Umbraco.Core/Services/PackagingService.cs b/src/Umbraco.Core/Services/PackagingService.cs index 7784e5d76f..ccfe885adf 100644 --- a/src/Umbraco.Core/Services/PackagingService.cs +++ b/src/Umbraco.Core/Services/PackagingService.cs @@ -582,21 +582,22 @@ namespace Umbraco.Core.Services foreach (XElement tempElement in templateElements) { var dependencies = new List(); - if (tempElement.Element("Master") != null && - string.IsNullOrEmpty(tempElement.Element("Master").Value) == false && - templateElements.Any(x => x.Element("Alias").Value == tempElement.Element("Master").Value)) + var elementCopy = tempElement; + + if (elementCopy.Element("Master") != null && + string.IsNullOrEmpty(elementCopy.Element("Master").Value) == false && + templateElements.Any(x => x.Element("Alias").Value == elementCopy.Element("Master").Value)) { - dependencies.Add(tempElement.Element("Master").Value); + dependencies.Add(elementCopy.Element("Master").Value); } - else if (tempElement.Element("Master") != null && - string.IsNullOrEmpty(tempElement.Element("Master").Value) == false && - templateElements.Any(x => x.Element("Alias").Value == tempElement.Element("Master").Value) == + else if (elementCopy.Element("Master") != null && + string.IsNullOrEmpty(elementCopy.Element("Master").Value) == false && + templateElements.Any(x => x.Element("Alias").Value == elementCopy.Element("Master").Value) == false) { - LogHelper.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", tempElement.Element("Alias").Value, tempElement.Element("Master").Value)); + LogHelper.Info(string.Format("Template '{0}' has an invalid Master '{1}', so the reference has been ignored.", elementCopy.Element("Alias").Value, elementCopy.Element("Master").Value)); } - XElement elementCopy = tempElement; var field = new TopologicalSorter.DependencyField { Alias = elementCopy.Element("Alias").Value, From 096c5ad69f42e860c06aaae68815971f52df5c37 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 17 Apr 2013 22:05:10 +0600 Subject: [PATCH 4/7] Fixes: #U4-485, changes name field from saving to the db if it is empty. cleans up some code. --- .../umbraco/controls/ContentControl.cs | 161 ++++++++++-------- .../umbraco/editContent.aspx.cs | 27 +-- src/umbraco.controls/TabPage.cs | 65 ++++--- src/umbraco.controls/TabView.cs | 161 +++++++++--------- 4 files changed, 226 insertions(+), 188 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 2b8df31950..6857daf50e 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -7,6 +7,7 @@ using System.Linq; using System.Web; using System.Web.UI; using System.Web.UI.WebControls; +using Umbraco.Core; using umbraco.BasePages; using umbraco.cms.businesslogic; using umbraco.cms.businesslogic.datatype.controls; @@ -18,30 +19,30 @@ using umbraco.interfaces; using umbraco.uicontrols; using Umbraco.Core.IO; using Content = umbraco.cms.businesslogic.Content; -using SystemDirectories = umbraco.IO.SystemDirectories; namespace umbraco.controls { - public class ContentControlLoadEventArgs : System.ComponentModel.CancelEventArgs { } + public class ContentControlLoadEventArgs : CancelEventArgs { } /// /// Summary description for ContentControl. /// public class ContentControl : TabView { - private Content _content; - private ArrayList _dataFields = new ArrayList(); - private UmbracoEnsuredPage prntpage; + private readonly Content _content; + private readonly ArrayList _dataFields = new ArrayList(); + private UmbracoEnsuredPage _prntpage; public event EventHandler SaveAndPublish; public event EventHandler SaveToPublish; public event EventHandler Save; - private publishModes CanPublish = publishModes.NoPublish; + private readonly publishModes _canPublish = publishModes.NoPublish; public TabPage tpProp; public bool DoesPublish = false; public TextBox NameTxt = new TextBox(); public PlaceHolder NameTxtHolder = new PlaceHolder(); public RequiredFieldValidator NameTxtValidator = new RequiredFieldValidator(); - private static string _UmbracoPath = SystemDirectories.Umbraco; + private readonly CustomValidator _nameTxtCustomValidator = new CustomValidator(); + private static readonly string UmbracoPath = SystemDirectories.Umbraco; public Pane PropertiesPane = new Pane(); public Content ContentObject @@ -49,20 +50,22 @@ namespace umbraco.controls get { return _content; } } - // Error messages + [Obsolete("This is no longer used and will be removed from the codebase in future versions")] private string _errorMessage = ""; + [Obsolete("This is no longer used and will be removed from the codebase in future versions")] public string ErrorMessage { set { _errorMessage = value; } } + [Obsolete("This is no longer used and will be removed from the codebase in future versions")] protected void standardSaveAndPublishHandler(object sender, EventArgs e) { } // zb-00036 #29889 : load it only once - List virtualTabs; + List _virtualTabs; /// /// Constructor to set default properties. @@ -79,24 +82,23 @@ namespace umbraco.controls public ContentControl(Content c, publishModes CanPublish, string Id) { ID = Id; - this.CanPublish = CanPublish; + this._canPublish = CanPublish; _content = c; Width = 350; Height = 350; - SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); - Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + + _prntpage = (UmbracoEnsuredPage)Page; // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + if (_virtualTabs == null) + _virtualTabs = _content.ContentType.getVirtualTabs.ToList(); - foreach (ContentType.TabI t in virtualTabs) + foreach (ContentType.TabI t in _virtualTabs) { TabPage tp = NewTabPage(t.Caption); - addSaveAndPublishButtons(ref tp); + AddSaveAndPublishButtons(ref tp); } } @@ -107,17 +109,16 @@ namespace umbraco.controls { base.CreateChildControls(); - SaveAndPublish += new EventHandler(standardSaveAndPublishHandler); - Save += new EventHandler(standardSaveAndPublishHandler); - prntpage = (UmbracoEnsuredPage)Page; + + _prntpage = (UmbracoEnsuredPage)Page; int i = 0; var inTab = new Hashtable(); // zb-00036 #29889 : load it only once - if (virtualTabs == null) - virtualTabs = _content.ContentType.getVirtualTabs.ToList(); + if (_virtualTabs == null) + _virtualTabs = _content.ContentType.getVirtualTabs.ToList(); - foreach (ContentType.TabI tab in virtualTabs) + foreach (ContentType.TabI tab in _virtualTabs) { var tabPage = this.Panels[i] as TabPage; if (tabPage == null) @@ -139,7 +140,7 @@ namespace umbraco.controls var property = _content.getProperty(propertyType); if (property != null && tabPage != null) { - addControlNew(property, tabPage, tab.Caption); + AddControlNew(property, tabPage, tab.Caption); // adding this check, as we occasionally get an already in dictionary error, though not sure why if (!inTab.ContainsKey(propertyType.Id.ToString())) @@ -156,7 +157,7 @@ namespace umbraco.controls // Add property pane tpProp = NewTabPage(ui.Text("general", "properties", null)); - addSaveAndPublishButtons(ref tpProp); + AddSaveAndPublishButtons(ref tpProp); tpProp.Controls.Add( new LiteralControl("
There were errors - data has not been saved!
")); @@ -166,7 +167,7 @@ namespace umbraco.controls foreach (Property p in props) { if (inTab[p.PropertyType.Id.ToString()] == null) - addControlNew(p, tpProp, ui.Text("general", "properties", null)); + AddControlNew(p, tpProp, ui.Text("general", "properties", null)); } } @@ -196,12 +197,19 @@ namespace umbraco.controls // Name validation NameTxtValidator.ControlToValidate = NameTxt.ID; + _nameTxtCustomValidator.ControlToValidate = NameTxt.ID; string[] errorVars = { ui.Text("name") }; NameTxtValidator.ErrorMessage = " " + ui.Text("errorHandling", "errorMandatoryWithoutTab", errorVars, null) + "
"; NameTxtValidator.EnableClientScript = false; - NameTxtValidator.Display = ValidatorDisplay.Dynamic; + NameTxtValidator.Display = ValidatorDisplay.Dynamic; + _nameTxtCustomValidator.EnableClientScript = false; + _nameTxtCustomValidator.Display = ValidatorDisplay.Dynamic; + _nameTxtCustomValidator.ServerValidate += NameTxtCustomValidatorServerValidate; + _nameTxtCustomValidator.ValidateEmptyText = false; + NameTxtHolder.Controls.Add(NameTxt); NameTxtHolder.Controls.Add(NameTxtValidator); + NameTxtHolder.Controls.Add(_nameTxtCustomValidator); PropertiesPane.addProperty(ui.Text("general", "name", null), NameTxtHolder); Literal ltt = new Literal(); @@ -226,6 +234,23 @@ namespace umbraco.controls } } + /// + /// Custom validates the content name field + /// + /// + /// + /// + /// We need to ensure people are not entering XSS attacks on this field + /// http://issues.umbraco.org/issue/U4-485 + /// + /// This doesn't actually 'validate' but changes the text field value and strips html + /// + void NameTxtCustomValidatorServerValidate(object source, ServerValidateEventArgs args) + { + NameTxt.Text = NameTxt.Text.StripHtml(); + args.IsValid = true; + } + protected override void OnLoad(EventArgs e) { base.OnLoad(e); @@ -235,8 +260,15 @@ namespace umbraco.controls } - private void saveClick(object Sender, ImageClickEventArgs e) - { + private void SaveClick(object sender, ImageClickEventArgs e) + { + ////TODO: If we are editing media/content we should not continue saving + //// if the page is invalid! + //// http://issues.umbraco.org/issue/U4-227 + //if (Page.IsValid) + //{ + //} + var doc = this._content as Document; if (doc != null) { @@ -253,56 +285,68 @@ namespace umbraco.controls df.Save(); } - if (!string.IsNullOrEmpty(NameTxt.Text)) + //don't update if the name is empty + if (!NameTxt.Text.IsNullOrWhiteSpace()) + { _content.Text = NameTxt.Text; + } - Save(this, new EventArgs()); + if (Save != null) + { + Save(this, new EventArgs()); + } } - private void savePublish(object Sender, ImageClickEventArgs e) + private void SavePublish(object sender, ImageClickEventArgs e) { DoesPublish = true; - saveClick(Sender, e); + SaveClick(sender, e); - SaveAndPublish(this, new EventArgs()); + if (SaveAndPublish != null) + { + SaveAndPublish(this, new EventArgs()); + } } - private void saveToPublish(object Sender, ImageClickEventArgs e) + private void SendToPublishEventHandler(object sender, ImageClickEventArgs e) { - saveClick(Sender, e); - SaveToPublish(this, new EventArgs()); + SaveClick(sender, e); + if (SaveToPublish != null) + { + SaveToPublish(this, new EventArgs()); + } } - private void addSaveAndPublishButtons(ref TabPage tp) + private void AddSaveAndPublishButtons(ref TabPage tp) { MenuImageButton menuSave = tp.Menu.NewImageButton(); menuSave.ID = tp.ID + "_save"; - menuSave.ImageUrl = _UmbracoPath + "/images/editor/save.gif"; - menuSave.Click += new ImageClickEventHandler(saveClick); + menuSave.ImageUrl = UmbracoPath + "/images/editor/save.gif"; + menuSave.Click += new ImageClickEventHandler(SaveClick); menuSave.OnClickCommand = "invokeSaveHandlers();"; menuSave.AltText = ui.Text("buttons", "save", null); - if (CanPublish == publishModes.Publish) + if (_canPublish == publishModes.Publish) { MenuImageButton menuPublish = tp.Menu.NewImageButton(); menuPublish.ID = tp.ID + "_publish"; - menuPublish.ImageUrl = _UmbracoPath + "/images/editor/saveAndPublish.gif"; + menuPublish.ImageUrl = UmbracoPath + "/images/editor/saveAndPublish.gif"; menuPublish.OnClickCommand = "invokeSaveHandlers();"; - menuPublish.Click += new ImageClickEventHandler(savePublish); + menuPublish.Click += new ImageClickEventHandler(SavePublish); menuPublish.AltText = ui.Text("buttons", "saveAndPublish", null); } - else if (CanPublish == publishModes.SendToPublish) + else if (_canPublish == publishModes.SendToPublish) { MenuImageButton menuToPublish = tp.Menu.NewImageButton(); menuToPublish.ID = tp.ID + "_topublish"; - menuToPublish.ImageUrl = _UmbracoPath + "/images/editor/saveToPublish.gif"; + menuToPublish.ImageUrl = UmbracoPath + "/images/editor/saveToPublish.gif"; menuToPublish.OnClickCommand = "invokeSaveHandlers();"; - menuToPublish.Click += new ImageClickEventHandler(saveToPublish); + menuToPublish.Click += new ImageClickEventHandler(SendToPublishEventHandler); menuToPublish.AltText = ui.Text("buttons", "saveToPublish", null); } } - private void addControlNew(Property p, TabPage tp, string Caption) + private void AddControlNew(Property p, TabPage tp, string cap) { IDataType dt = p.PropertyType.DataTypeDefinition.DataType; dt.DataEditor.Editor.ID = string.Format("prop_{0}", p.PropertyType.Alias); @@ -438,7 +482,7 @@ namespace umbraco.controls { rq.EnableClientScript = false; rq.Display = ValidatorDisplay.Dynamic; - string[] errorVars = { p.PropertyType.Name, Caption }; + string[] errorVars = { p.PropertyType.Name, cap }; rq.ErrorMessage = ui.Text("errorHandling", "errorMandatory", errorVars, null) + "
"; holder.Controls.AddAt(0, rq); } @@ -473,7 +517,7 @@ namespace umbraco.controls rv.ValidationExpression = p.PropertyType.ValidationRegExp; rv.EnableClientScript = false; rv.Display = ValidatorDisplay.Dynamic; - string[] errorVars = { p.PropertyType.Name, Caption }; + string[] errorVars = { p.PropertyType.Name, cap }; rv.ErrorMessage = ui.Text("errorHandling", "errorRegExp", errorVars, null) + "
"; holder.Controls.AddAt(0, rv); } @@ -508,25 +552,6 @@ namespace umbraco.controls NoPublish } - private string dictinaryItem(string alias) - { - if (alias.Substring(1, 0) == "#") - { - - if (Dictionary.DictionaryItem.hasKey(alias.Substring(1))) - { - - Dictionary.DictionaryItem di = new Dictionary.DictionaryItem(alias.Substring(1)); - - if (di != null && !string.IsNullOrEmpty(di.Value())) - return di.Value(); - } - - } - - return alias + " " + alias.Substring(1); - } - // EVENTS public delegate void BeforeContentControlLoadEventHandler(ContentControl contentControl, ContentControlLoadEventArgs e); public delegate void AfterContentControlLoadEventHandler(ContentControl contentControl, ContentControlLoadEventArgs e); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index 9b838e184a..b2a4119301 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -1,28 +1,15 @@ using System; -using System.Collections; -using System.Collections.Specialized; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Web; -using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; -using System.Web.UI.HtmlControls; -using System.Reflection; using Umbraco.Core.IO; using umbraco.BusinessLogic.Actions; -using umbraco.cms.businesslogic.language; -using umbraco.cms.helpers; using umbraco.uicontrols.DatePicker; using umbraco.BusinessLogic; -using umbraco.presentation.preview; using umbraco.cms.businesslogic.web; using umbraco.presentation; -using umbraco.cms.businesslogic.skinning; -using System.Collections.Generic; using System.Linq; using Image = System.Web.UI.WebControls.Image; +using Umbraco.Core; namespace umbraco.cms.presentation { @@ -57,7 +44,7 @@ namespace umbraco.cms.presentation //validate! int id; - if (!int.TryParse(Request.QueryString["id"], out id)) + if (int.TryParse(Request.QueryString["id"], out id) == false) { //if this is invalid show an error this.DisplayFatalError("Invalid query string"); @@ -85,7 +72,7 @@ namespace umbraco.cms.presentation _documentHasPublishedVersion = _document.HasPublishedVersion(); // Check publishing permissions - if (!base.getUser().GetPermissions(_document.Path).Contains(ActionPublish.Instance.Letter.ToString())) + if (base.getUser().GetPermissions(_document.Path).Contains(ActionPublish.Instance.Letter.ToString()) == false) _canPublish = controls.ContentControl.publishModes.SendToPublish; _cControl = new controls.ContentControl(_document, _canPublish, "TabView1"); @@ -227,7 +214,7 @@ namespace umbraco.cms.presentation protected void Save(object sender, EventArgs e) { // error handling test - if (!Page.IsValid) + if (Page.IsValid == false) { foreach (uicontrols.TabPage tp in _cControl.GetPanels()) { @@ -247,8 +234,8 @@ namespace umbraco.cms.presentation //Audit trail... Log.Add(LogTypes.Save, getUser(), _document.Id, ""); - // Update name - if (_document.Text != _cControl.NameTxt.Text) + // Update name if it has not changed and is not empty + if (_cControl.NameTxt != null && _document.Text != _cControl.NameTxt.Text && !_cControl.NameTxt.Text.IsNullOrWhiteSpace()) { //_refreshTree = true; _document.Text = _cControl.NameTxt.Text; @@ -288,7 +275,7 @@ namespace umbraco.cms.presentation // Update the update date _dp.Text = _document.UpdateDate.ToShortDateString() + " " + _document.UpdateDate.ToShortTimeString(); - if (!_cControl.DoesPublish) + if (_cControl.DoesPublish == false) ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editContentSavedHeader", null), ui.Text("speechBubbles", "editContentSavedText", null)); ClientTools.SyncTree(_document.Path, true); diff --git a/src/umbraco.controls/TabPage.cs b/src/umbraco.controls/TabPage.cs index ce11d37f84..3cf43b78ab 100644 --- a/src/umbraco.controls/TabPage.cs +++ b/src/umbraco.controls/TabPage.cs @@ -10,15 +10,19 @@ using System.Web.UI.WebControls; using System.Web.UI.HtmlControls; namespace umbraco.uicontrols { - public class TabPage : System.Web.UI.WebControls.WebControl { + + public class TabPage : WebControl + { // Ensure that a TabPage cannot be instatiated outside // this assembly -> New instances of a tabpage can only be retrieved through the tabview private bool _hasMenu = true; - private ScrollingMenu _Menu = new ScrollingMenu(); + private readonly ScrollingMenu _menu = new ScrollingMenu(); protected LiteralControl ErrorHeaderControl = new LiteralControl(); - private ValidationSummary _vs = new ValidationSummary(); - private Control _tempErr = new Control(); - internal TabPage() { + private readonly ValidationSummary _vs = new ValidationSummary(); + private readonly Control _tempErr = new Control(); + + internal TabPage() + { } @@ -29,13 +33,19 @@ namespace umbraco.uicontrols { public string ErrorHeader { get; set; } public string CloseCaption { get; set; } - public Control ErrorControl { get { return _tempErr; } } - protected override void OnLoad(EventArgs e) { - if (this.HasMenu) { - Menu.Width = System.Web.UI.WebControls.Unit.Pixel((int)this.Width.Value - 12); - _Menu.ID = this.ID + "_menu"; - this.Controls.Add(_Menu); + public Control ErrorControl + { + get { return _tempErr; } + } + + protected override void OnLoad(EventArgs e) + { + if (this.HasMenu) + { + Menu.Width = Unit.Pixel((int) this.Width.Value - 12); + _menu.ID = this.ID + "_menu"; + this.Controls.Add(_menu); } } @@ -61,42 +71,49 @@ namespace umbraco.uicontrols { } - public ScrollingMenu Menu { - get { return _Menu; } + public ScrollingMenu Menu + { + get { return _menu; } } - public bool HasMenu { + public bool HasMenu + { get { return _hasMenu; } set { _hasMenu = value; } } - protected override void Render(System.Web.UI.HtmlTextWriter writer) { + protected override void Render(HtmlTextWriter writer) + { ErrorHeaderControl.Text = ErrorHeader; CreateChildControls(); writer.WriteLine("
"); - if (HasMenu) { + if (HasMenu) + { writer.WriteLine(""); } - int ScrollingLayerHeight = (int)((System.Web.UI.WebControls.WebControl)this.Parent).Height.Value - 22; - int ScrollingLayerWidth = (int)((System.Web.UI.WebControls.WebControl)this.Parent).Width.Value; + var scrollingLayerHeight = (int) ((WebControl) this.Parent).Height.Value - 22; + var scrollingLayerWidth = (int) ((WebControl) this.Parent).Width.Value; if (HasMenu) - ScrollingLayerHeight = ScrollingLayerHeight - 28; - writer.WriteLine("
"); + scrollingLayerHeight = scrollingLayerHeight - 28; + writer.WriteLine("
"); string styleString = ""; - foreach (string key in this.Style.Keys) { + foreach (string key in this.Style.Keys) + { styleString += key + ":" + this.Style[key] + ";"; } writer.WriteLine("
"); _tempErr.RenderControl(writer); - - foreach (System.Web.UI.Control C in this.Controls) { - if (C.ClientID != _Menu.ClientID && C.ClientID != _tempErr.ClientID ) { + + foreach (Control C in this.Controls) + { + if (C.ClientID != _menu.ClientID && C.ClientID != _tempErr.ClientID) + { C.RenderControl(writer); } } diff --git a/src/umbraco.controls/TabView.cs b/src/umbraco.controls/TabView.cs index 20f8b17a04..dfd9b7f9a7 100644 --- a/src/umbraco.controls/TabView.cs +++ b/src/umbraco.controls/TabView.cs @@ -7,7 +7,6 @@ using System.Web; using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; -using System.Web.UI.HtmlControls; using ClientDependency.Core; namespace umbraco.uicontrols { @@ -15,92 +14,102 @@ namespace umbraco.uicontrols { [ClientDependency(ClientDependencyType.Javascript, "tabview/javascript.js", "UmbracoClient")] [ClientDependency(ClientDependencyType.Css, "tabview/style.css", "UmbracoClient")] [ClientDependency(0, ClientDependencyType.Javascript, "Application/NamespaceManager.js", "UmbracoClient")] - public class TabView : System.Web.UI.WebControls.WebControl + public class TabView : WebControl { - private HtmlInputHidden tb = new HtmlInputHidden(); - private ArrayList Tabs = new ArrayList(); + private readonly ArrayList _tabs = new ArrayList(); protected ArrayList Panels = new ArrayList(); - private string status = ""; + private string _status = ""; - public ArrayList GetPanels() { - return Panels; - } + public ArrayList GetPanels() + { + return Panels; + } - public TabPage NewTabPage(string text) { - Tabs.Add(text); - TabPage tp = new TabPage(); - tp.Width = this.Width; - tp.ID = this.ID + "_tab0" + (Panels.Count + 1) + "layer"; - Panels.Add(tp); - this.Controls.Add(tp); - return tp; - } + public TabPage NewTabPage(string text) + { + _tabs.Add(text); + var tp = new TabPage(); + tp.Width = this.Width; + tp.ID = this.ID + "_tab0" + (Panels.Count + 1) + "layer"; + Panels.Add(tp); + this.Controls.Add(tp); + return tp; + } - - public string Status { - get { return status; } - set { status = value; } - } - private bool _autoResize = true; - public bool AutoResize { - get { return _autoResize; } - set { _autoResize = value; } - } + public string Status + { + get { return _status; } + set { _status = value; } + } - private string ActiveTabId { - get { - if (this.Parent.Page.IsPostBack) { - return this.Parent.Page.Request.Form[this.ClientID + "_activetab"]; - } - return this.ClientID + "_tab01"; - } - } + private bool _autoResize = true; - protected override void OnPreRender(EventArgs e) { - base.OnPreRender(e); - SetupClientScript(); - } + public bool AutoResize + { + get { return _autoResize; } + set { _autoResize = value; } + } - private void SetupClientScript() { - + private string ActiveTabId + { + get + { + if (this.Parent.Page.IsPostBack) + { + return this.Parent.Page.Request.Form[this.ClientID + "_activetab"]; + } + return this.ClientID + "_tab01"; + } + } - string strTmp = ""; - for (int i = 1; i <= Tabs.Count; i++) { - if (i > 1) - strTmp += ","; - strTmp += "\"" + this.ClientID + "_tab0" + i + "\""; - } - this.Page.ClientScript.RegisterStartupScript( - this.GetType(), - this.ClientID + "TabCollection", ";var " + this.ClientID + "_tabs = new Array(" + strTmp + ");setActiveTab('" + this.ClientID + "','" + this.ActiveTabId + "'," + this.ClientID + "_tabs);", - true); + protected override void OnPreRender(EventArgs e) + { + base.OnPreRender(e); + SetupClientScript(); + } - if (_autoResize) - this.Page.ClientScript.RegisterStartupScript(this.GetType(), "TabviewEvents", "jQuery(document).ready(function(){resizeTabView(" + this.ClientID + "_tabs, '" + this.ClientID + "'); }); jQuery(window).resize(function(){ resizeTabView(" + this.ClientID + "_tabs, '" + this.ClientID + "'); });", true); - } + private void SetupClientScript() + { + string strTmp = ""; + for (int i = 1; i <= _tabs.Count; i++) + { + if (i > 1) + strTmp += ","; + strTmp += "\"" + this.ClientID + "_tab0" + i + "\""; + } + this.Page.ClientScript.RegisterStartupScript( + this.GetType(), + this.ClientID + "TabCollection", ";var " + this.ClientID + "_tabs = new Array(" + strTmp + ");setActiveTab('" + this.ClientID + "','" + this.ActiveTabId + "'," + this.ClientID + "_tabs);", + true); - protected override void Render(HtmlTextWriter writer) { - writer.WriteLine("
"); - writer.WriteLine("
"); - writer.WriteLine(" "); - writer.WriteLine("
"); - writer.WriteLine("
"); - this.RenderChildren(writer); - writer.WriteLine("\t
"); - writer.WriteLine("\t"); - writer.WriteLine("
"); - writer.WriteLine(""); - } + if (_autoResize) + this.Page.ClientScript.RegisterStartupScript(this.GetType(), "TabviewEvents", "jQuery(document).ready(function(){resizeTabView(" + this.ClientID + "_tabs, '" + this.ClientID + "'); }); jQuery(window).resize(function(){ resizeTabView(" + this.ClientID + "_tabs, '" + this.ClientID + "'); });", true); + } + + protected override void Render(HtmlTextWriter writer) + { + writer.WriteLine("
"); + writer.WriteLine("
"); + writer.WriteLine(" "); + writer.WriteLine("
"); + writer.WriteLine("
"); + this.RenderChildren(writer); + writer.WriteLine("\t
"); + writer.WriteLine("\t"); + writer.WriteLine("
"); + writer.WriteLine(""); + } } } \ No newline at end of file From ff5dc324fe1d2ce331672e9409a8b5e051448c29 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 17 Apr 2013 22:41:43 +0600 Subject: [PATCH 5/7] Fixes: #U4-227 - ensures data is not persisted to the db for members/media if validation fails. Fixes up (enables) validation summary for members too. --- .../umbraco/controls/ContentControl.cs | 69 +++-- .../umbraco/editContent.aspx.cs | 3 - .../umbraco/editMedia.aspx.cs | 107 ++++---- .../umbraco/members/EditMember.aspx.cs | 247 +++++++++--------- 4 files changed, 217 insertions(+), 209 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 6857daf50e..b33ae42698 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -29,6 +29,13 @@ namespace umbraco.controls ///
public class ContentControl : TabView { + + public ContentControl() + { + //by default set this to true for content + SavePropertyDataWhenInvalid = true; + } + private readonly Content _content; private readonly ArrayList _dataFields = new ArrayList(); private UmbracoEnsuredPage _prntpage; @@ -50,6 +57,19 @@ namespace umbraco.controls get { return _content; } } + /// + /// This property controls whether the content property values are persisted even if validation + /// fails. If set to false, then the values will not be persisted. + /// + /// + /// This is required because when we are editing content we should be persisting invalid values to the database + /// as this makes it easier for editors to come back and fix up their changes before they publish. Of course we + /// don't publish if the page is invalid. In the case of media and members, we don't want to persist the values + /// to the database when the page is invalid because there is no published state. + /// Relates to: http://issues.umbraco.org/issue/U4-227 + /// + public bool SavePropertyDataWhenInvalid { get; set; } + [Obsolete("This is no longer used and will be removed from the codebase in future versions")] private string _errorMessage = ""; @@ -261,34 +281,33 @@ namespace umbraco.controls private void SaveClick(object sender, ImageClickEventArgs e) - { - ////TODO: If we are editing media/content we should not continue saving - //// if the page is invalid! - //// http://issues.umbraco.org/issue/U4-227 - //if (Page.IsValid) - //{ - //} - - var doc = this._content as Document; - if (doc != null) + { + //we only continue saving anything if: + // SavePropertyDataWhenInvalid == true + // OR if the page is actually valid. + if (SavePropertyDataWhenInvalid || Page.IsValid) { - var docArgs = new SaveEventArgs(); - doc.FireBeforeSave(docArgs); - - if (docArgs.Cancel) //TODO: need to have some notification to the user here + var doc = this._content as Document; + if (doc != null) { - return; - } - } - foreach (IDataEditor df in _dataFields) - { - df.Save(); - } + var docArgs = new SaveEventArgs(); + doc.FireBeforeSave(docArgs); - //don't update if the name is empty - if (!NameTxt.Text.IsNullOrWhiteSpace()) - { - _content.Text = NameTxt.Text; + if (docArgs.Cancel) //TODO: need to have some notification to the user here + { + return; + } + } + foreach (IDataEditor df in _dataFields) + { + df.Save(); + } + + //don't update if the name is empty + if (!NameTxt.Text.IsNullOrWhiteSpace()) + { + _content.Text = NameTxt.Text; + } } if (Save != null) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index b2a4119301..73ac3f0ace 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -265,9 +265,6 @@ namespace umbraco.cms.presentation } } - - - // Run Handler BusinessLogic.Actions.Action.RunActionHandlers(_document, ActionUpdate.Instance); _document.Save(); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs index ff15d142b9..9dc9c9ef03 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs @@ -25,9 +25,9 @@ namespace umbraco.cms.presentation /// public partial class editMedia : BasePages.UmbracoEnsuredPage { - private uicontrols.Pane mediaPropertiesPane = new uicontrols.Pane(); - private LiteralControl updateDateLiteral = new LiteralControl(); - private LiteralControl mediaFileLinksLiteral = new LiteralControl(); + private readonly uicontrols.Pane _mediaPropertiesPane = new uicontrols.Pane(); + private readonly LiteralControl _updateDateLiteral = new LiteralControl(); + private readonly LiteralControl _mediaFileLinksLiteral = new LiteralControl(); public editMedia() { @@ -35,18 +35,12 @@ namespace umbraco.cms.presentation } protected uicontrols.TabView TabView1; - protected System.Web.UI.WebControls.TextBox documentName; - private cms.businesslogic.media.Media _media; - controls.ContentControl tmp; - - //protected System.Web.UI.WebControls.Literal SyncPath; - + protected TextBox documentName; + private businesslogic.media.Media _media; + controls.ContentControl _contentControl; + override protected void OnInit(EventArgs e) { - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - InitializeComponent(); base.OnInit(e); _media = new cms.businesslogic.media.Media(int.Parse(Request.QueryString["id"])); @@ -55,88 +49,83 @@ namespace umbraco.cms.presentation bool exists = SqlHelper.ExecuteScalar("SELECT COUNT(nodeId) FROM cmsContentXml WHERE nodeId = @nodeId", SqlHelper.CreateParameter("@nodeId", _media.Id)) > 0; if (!exists) + { _media.XmlGenerate(new XmlDocument()); + } + _contentControl = new controls.ContentControl(_media, controls.ContentControl.publishModes.NoPublish, "TabView1"); + _contentControl.Width = Unit.Pixel(666); + _contentControl.Height = Unit.Pixel(666); - tmp = new controls.ContentControl(_media, controls.ContentControl.publishModes.NoPublish, "TabView1"); - tmp.Width = Unit.Pixel(666); - tmp.Height = Unit.Pixel(666); - plc.Controls.Add(tmp); + //this must be set to false as we don't want to proceed to save anything if the page is invalid + _contentControl.SavePropertyDataWhenInvalid = false; - tmp.Save += new System.EventHandler(Save); + plc.Controls.Add(_contentControl); - this.updateDateLiteral.ID = "updateDate"; - this.updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString(); + _contentControl.Save += new System.EventHandler(Save); - this.mediaFileLinksLiteral.ID = "mediaFileLinks"; - mediaPropertiesPane.addProperty(ui.Text("content", "updateDate", base.getUser()), this.updateDateLiteral); + this._updateDateLiteral.ID = "updateDate"; + this._updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString(); + + this._mediaFileLinksLiteral.ID = "mediaFileLinks"; + _mediaPropertiesPane.addProperty(ui.Text("content", "updateDate", base.getUser()), this._updateDateLiteral); this.UpdateMediaFileLinksLiteral(); - mediaPropertiesPane.addProperty(ui.Text("content", "mediaLinks"), this.mediaFileLinksLiteral); + _mediaPropertiesPane.addProperty(ui.Text("content", "mediaLinks"), this._mediaFileLinksLiteral); // add the property pane to the page rendering - tmp.tpProp.Controls.AddAt(1, mediaPropertiesPane); + _contentControl.tpProp.Controls.AddAt(1, _mediaPropertiesPane); } - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - - } - - protected void Page_Load(object sender, System.EventArgs e) + protected void Page_Load(object sender, EventArgs e) { - //if (!IsPostBack) - //{ - // SyncPath.Text = _media.Path; - // newName.Text = _media.Text.Replace("'", "\\'"); - //} if (!IsPostBack) { ClientTools.SyncTree(_media.Path, false); } } - protected void Save(object sender, System.EventArgs e) + protected void Save(object sender, EventArgs e) { - // error handling test + // do not continue saving anything if the page is invalid! + // http://issues.umbraco.org/issue/U4-227 if (!Page.IsValid) { - foreach (uicontrols.TabPage tp in tmp.GetPanels()) + foreach (uicontrols.TabPage tp in _contentControl.GetPanels()) { tp.ErrorControl.Visible = true; tp.ErrorHeader = ui.Text("errorHandling", "errorHeader"); tp.CloseCaption = ui.Text("close"); } } - else if (Page.IsPostBack) + else { - // hide validation summaries - foreach (uicontrols.TabPage tp in tmp.GetPanels()) + if (Page.IsPostBack) { - tp.ErrorControl.Visible = false; - } - } - _media.Save(); + // hide validation summaries + foreach (uicontrols.TabPage tp in _contentControl.GetPanels()) + { + tp.ErrorControl.Visible = false; + } + } - this.updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString(); - this.UpdateMediaFileLinksLiteral(); + _media.Save(); - _media.XmlGenerate(new XmlDocument()); - ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editMediaSaved"), ui.Text("editMediaSavedText")); - ClientTools.SyncTree(_media.Path, true); + this._updateDateLiteral.Text = _media.VersionDate.ToShortDateString() + " " + _media.VersionDate.ToShortTimeString(); + this.UpdateMediaFileLinksLiteral(); + + _media.XmlGenerate(new XmlDocument()); + ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editMediaSaved"), ui.Text("editMediaSavedText")); + ClientTools.SyncTree(_media.Path, true); + } } - private void UpdateMediaFileLinksLiteral() { var uploadField = new Factory().GetNewObject(new Guid("5032a6e6-69e3-491d-bb28-cd31cd11086c")); // always clear, incase the upload file was removed - this.mediaFileLinksLiteral.Text = string.Empty; + this._mediaFileLinksLiteral.Text = string.Empty; try { @@ -149,14 +138,14 @@ namespace umbraco.cms.presentation if (properties.Any()) { - this.mediaFileLinksLiteral.Text += ""; + this._mediaFileLinksLiteral.Text += "
"; foreach (var property in properties) { - this.mediaFileLinksLiteral.Text += string.Format("", property.PropertyType.Name, property.Value); + this._mediaFileLinksLiteral.Text += string.Format("", property.PropertyType.Name, property.Value); } - this.mediaFileLinksLiteral.Text += "
{0} {1}
{0} {1}
"; + this._mediaFileLinksLiteral.Text += ""; } } catch diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs index af928011d7..64275a3fe7 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs @@ -1,17 +1,9 @@ using System; -using System.Collections; -using System.ComponentModel; -using System.Data; -using System.Drawing; -using System.Web; -using System.Web.SessionState; using System.Web.UI; using System.Web.UI.WebControls; -using System.Web.UI.HtmlControls; - +using Umbraco.Core.IO; using umbraco.cms.businesslogic.member; using System.Web.Security; -using umbraco.IO; namespace umbraco.cms.presentation.members { @@ -25,11 +17,11 @@ namespace umbraco.cms.presentation.members CurrentApp = BusinessLogic.DefaultApps.member.ToString(); } protected uicontrols.TabView TabView1; - protected System.Web.UI.WebControls.TextBox documentName; - private cms.businesslogic.member.Member _document; - private MembershipUser m_Member; - controls.ContentControl tmp; - protected umbraco.uicontrols.UmbracoPanel m_MemberShipPanel = new umbraco.uicontrols.UmbracoPanel(); + protected TextBox documentName; + private Member _document; + private MembershipUser _member; + controls.ContentControl _contentControl; + protected uicontrols.UmbracoPanel m_MemberShipPanel = new uicontrols.UmbracoPanel(); protected TextBox MemberLoginNameTxt = new TextBox(); protected RequiredFieldValidator MemberLoginNameVal = new RequiredFieldValidator(); @@ -39,7 +31,7 @@ namespace umbraco.cms.presentation.members protected controls.DualSelectbox _memberGroups = new controls.DualSelectbox(); - protected void Page_Load(object sender, System.EventArgs e) + protected void Page_Load(object sender, EventArgs e) { // Add password changer @@ -47,19 +39,23 @@ namespace umbraco.cms.presentation.members if (Member.InUmbracoMemberMode()) { - _document = new cms.businesslogic.member.Member(int.Parse(Request.QueryString["id"])); - m_Member = Membership.GetUser(_document.Id); - tmp = new controls.ContentControl(_document, controls.ContentControl.publishModes.NoPublish, "TabView1"); - tmp.Width = Unit.Pixel(666); - tmp.Height = Unit.Pixel(666); - plc.Controls.Add(tmp); + _document = new Member(int.Parse(Request.QueryString["id"])); + _member = Membership.GetUser(_document.Id); + _contentControl = new controls.ContentControl(_document, controls.ContentControl.publishModes.NoPublish, "TabView1"); + _contentControl.Width = Unit.Pixel(666); + _contentControl.Height = Unit.Pixel(666); + + //this must be set to false as we don't want to proceed to save anything if the page is invalid + _contentControl.SavePropertyDataWhenInvalid = false; + + plc.Controls.Add(_contentControl); if (!IsPostBack) { MemberLoginNameTxt.Text = _document.LoginName; MemberEmail.Text = _document.Email; } - PlaceHolder ph = new PlaceHolder(); + var ph = new PlaceHolder(); MemberLoginNameTxt.ID = "loginname"; ph.Controls.Add(MemberLoginNameTxt); ph.Controls.Add(MemberLoginNameVal); @@ -69,26 +65,27 @@ namespace umbraco.cms.presentation.members MemberLoginNameVal.EnableClientScript = false; MemberLoginNameVal.Display = ValidatorDisplay.Dynamic; - tmp.PropertiesPane.addProperty(ui.Text("login"), ph); - tmp.PropertiesPane.addProperty(ui.Text("password"), MemberPasswordTxt); - tmp.PropertiesPane.addProperty("Email", MemberEmail); + _contentControl.PropertiesPane.addProperty(ui.Text("login"), ph); + _contentControl.PropertiesPane.addProperty(ui.Text("password"), MemberPasswordTxt); + _contentControl.PropertiesPane.addProperty("Email", MemberEmail); } else { - m_Member = Membership.GetUser(Request.QueryString["id"]); - MemberLoginNameTxt.Text = m_Member.UserName; + _member = Membership.GetUser(Request.QueryString["id"]); + MemberLoginNameTxt.Text = _member.UserName; if (!IsPostBack) { - MemberEmail.Text = m_Member.Email; + MemberEmail.Text = _member.Email; } m_MemberShipPanel.Width = 300; - m_MemberShipPanel.Text = ui.Text("edit") + " " + m_Member.UserName; - umbraco.uicontrols.Pane props = new umbraco.uicontrols.Pane(); + m_MemberShipPanel.Text = ui.Text("edit") + " " + _member.UserName; + var props = new uicontrols.Pane(); MemberLoginNameTxt.Enabled = false; // check for pw support - if (!Membership.Provider.EnablePasswordRetrieval) { + if (!Membership.Provider.EnablePasswordRetrieval) + { MemberPasswordTxt.Controls.Clear(); MemberPasswordTxt.Controls.Add( new LiteralControl("" + ui.Text("errorHandling", "errorChangingProviderPassword") + "")); @@ -102,20 +99,20 @@ namespace umbraco.cms.presentation.members } // Groups - umbraco.uicontrols.Pane p = new umbraco.uicontrols.Pane(); + var p = new uicontrols.Pane(); _memberGroups.ID = "Membergroups"; _memberGroups.Width = 175; - string selectedMembers = ""; - foreach(string role in Roles.GetAllRoles()) + var selectedMembers = ""; + foreach(var role in Roles.GetAllRoles()) { // if a role starts with __umbracoRole we won't show it as it's an internal role used for public access if (!role.StartsWith("__umbracoRole")) { - ListItem li = new ListItem(role); + var li = new ListItem(role); if (!IsPostBack) { - if (Roles.IsUserInRole(m_Member.UserName, role)) + if (Roles.IsUserInRole(_member.UserName, role)) selectedMembers += role + ","; } _memberGroups.Items.Add(li); @@ -127,113 +124,119 @@ namespace umbraco.cms.presentation.members if (Member.InUmbracoMemberMode()) { - tmp.tpProp.Controls.Add(p); - tmp.Save += new System.EventHandler(tmp_save); + _contentControl.tpProp.Controls.Add(p); + _contentControl.Save += new System.EventHandler(tmp_save); } else m_MemberShipPanel.Controls.Add(p); } - void menuSave_Click(object sender, ImageClickEventArgs e) + void MenuSaveClick(object sender, ImageClickEventArgs e) { tmp_save(sender, e); } - protected void tmp_save(object sender, System.EventArgs e) { - Page.Validate(); - if (Page.IsValid) - { - if (Member.InUmbracoMemberMode()) + + protected void tmp_save(object sender, EventArgs e) + { + Page.Validate(); + if (!Page.IsValid) + { + foreach (uicontrols.TabPage tp in _contentControl.GetPanels()) { - _document.LoginName = MemberLoginNameTxt.Text; - _document.Email = MemberEmail.Text; - - // Check if password should be changed - string tempPassword = ((controls.passwordChanger) MemberPasswordTxt.Controls[0]).Password; - if (tempPassword.Trim() != "") - _document.Password = tempPassword; - - // Groups - foreach (ListItem li in _memberGroups.Items) - if (("," + _memberGroups.Value + ",").IndexOf("," + li.Value + ",") > -1) - { - if (!Roles.IsUserInRole(_document.LoginName, li.Value)) - Roles.AddUserToRole(_document.LoginName, li.Value); - } - else if (Roles.IsUserInRole(_document.LoginName, li.Value)) - { - Roles.RemoveUserFromRole(_document.LoginName, li.Value); - } - // refresh cache - _document.XmlGenerate(new System.Xml.XmlDocument()); - _document.Save(); + tp.ErrorControl.Visible = true; + tp.ErrorHeader = ui.Text("errorHandling", "errorHeader"); + tp.CloseCaption = ui.Text("close"); } - else + } + else + { + + if (Page.IsPostBack) { - m_Member.Email = MemberEmail.Text; - if (Membership.Provider.EnablePasswordRetrieval) + // hide validation summaries + foreach (uicontrols.TabPage tp in _contentControl.GetPanels()) { - string tempPassword = ((controls.passwordChanger) MemberPasswordTxt.Controls[0]).Password; - if (tempPassword.Trim() != "") - m_Member.ChangePassword(m_Member.GetPassword(), tempPassword); + tp.ErrorControl.Visible = false; } - Membership.UpdateUser(m_Member); - // Groups - foreach (ListItem li in _memberGroups.Items) - if (("," + _memberGroups.Value + ",").IndexOf("," + li.Value + ",") > -1) - { - if (!Roles.IsUserInRole(m_Member.UserName, li.Value)) - Roles.AddUserToRole(m_Member.UserName, li.Value); - } - else if (Roles.IsUserInRole(m_Member.UserName, li.Value)) - { - Roles.RemoveUserFromRole(m_Member.UserName, li.Value); - } + } - } + if (Member.InUmbracoMemberMode()) + { + _document.LoginName = MemberLoginNameTxt.Text; + _document.Email = MemberEmail.Text; - this.speechBubble(BasePages.BasePage.speechBubbleIcon.save, - ui.Text("speechBubbles", "editMemberSaved", base.getUser()), ""); - } - } + // Check if password should be changed + string tempPassword = ((controls.passwordChanger) MemberPasswordTxt.Controls[0]).Password; + if (tempPassword.Trim() != "") + _document.Password = tempPassword; - private umbraco.uicontrols.PropertyPanel AddProperty(string Caption, Control C) { - umbraco.uicontrols.PropertyPanel pp = new umbraco.uicontrols.PropertyPanel(); - pp.Controls.Add(C); - pp.Text = Caption; - return pp; - } - - #region Web Form Designer generated code - override protected void OnInit(EventArgs e) + // Groups + foreach (ListItem li in _memberGroups.Items) + if (("," + _memberGroups.Value + ",").IndexOf("," + li.Value + ",") > -1) + { + if (!Roles.IsUserInRole(_document.LoginName, li.Value)) + Roles.AddUserToRole(_document.LoginName, li.Value); + } + else if (Roles.IsUserInRole(_document.LoginName, li.Value)) + { + Roles.RemoveUserFromRole(_document.LoginName, li.Value); + } + // refresh cache + _document.XmlGenerate(new System.Xml.XmlDocument()); + _document.Save(); + } + else + { + _member.Email = MemberEmail.Text; + if (Membership.Provider.EnablePasswordRetrieval) + { + string tempPassword = ((controls.passwordChanger) MemberPasswordTxt.Controls[0]).Password; + if (tempPassword.Trim() != "") + _member.ChangePassword(_member.GetPassword(), tempPassword); + } + Membership.UpdateUser(_member); + // Groups + foreach (ListItem li in _memberGroups.Items) + if (("," + _memberGroups.Value + ",").IndexOf("," + li.Value + ",") > -1) + { + if (!Roles.IsUserInRole(_member.UserName, li.Value)) + Roles.AddUserToRole(_member.UserName, li.Value); + } + else if (Roles.IsUserInRole(_member.UserName, li.Value)) + { + Roles.RemoveUserFromRole(_member.UserName, li.Value); + } + + } + + this.speechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editMemberSaved", base.getUser()), ""); + } + } + + private uicontrols.PropertyPanel AddProperty(string caption, Control c) + { + var pp = new uicontrols.PropertyPanel(); + pp.Controls.Add(c); + pp.Text = caption; + return pp; + } + + override protected void OnInit(EventArgs e) { - // - // CODEGEN: This call is required by the ASP.NET Web Form Designer. - // - - if (!Member.InUmbracoMemberMode()) { - m_MemberShipPanel.hasMenu = true; - umbraco.uicontrols.MenuImageButton menuSave = m_MemberShipPanel.Menu.NewImageButton(); - menuSave.ID = m_MemberShipPanel.ID + "_save"; - menuSave.ImageUrl = SystemDirectories.Umbraco + "/images/editor/save.gif"; - menuSave.Click += new ImageClickEventHandler(menuSave_Click); - menuSave.AltText = ui.Text("buttons", "save", null); - - } - InitializeComponent(); - base.OnInit(e); + if (!Member.InUmbracoMemberMode()) + { + m_MemberShipPanel.hasMenu = true; + umbraco.uicontrols.MenuImageButton menuSave = m_MemberShipPanel.Menu.NewImageButton(); + menuSave.ID = m_MemberShipPanel.ID + "_save"; + menuSave.ImageUrl = SystemDirectories.Umbraco + "/images/editor/save.gif"; + menuSave.Click += new ImageClickEventHandler(MenuSaveClick); + menuSave.AltText = ui.Text("buttons", "save", null); + } + base.OnInit(e); } - /// - /// Required method for Designer support - do not modify - /// the contents of this method with the code editor. - /// - private void InitializeComponent() - { - - } - #endregion } } From 580123cb87ccca79e667dd98a409445041cc8657 Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 17 Apr 2013 23:03:51 +0600 Subject: [PATCH 6/7] fixed merge issues --- .../umbraco/controls/ContentControl.cs | 24 +++++++++---------- .../umbraco/editContent.aspx.cs | 5 ++-- .../umbraco/editMedia.aspx.cs | 2 +- .../umbraco/members/EditMember.aspx.cs | 5 ++-- 4 files changed, 16 insertions(+), 20 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index 051baea3eb..6ae751de14 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -18,6 +18,7 @@ using umbraco.cms.businesslogic.web; using umbraco.interfaces; using umbraco.uicontrols; using Content = umbraco.cms.businesslogic.Content; +using ContentType = umbraco.cms.businesslogic.ContentType; using Media = umbraco.cms.businesslogic.media.Media; using Property = umbraco.cms.businesslogic.property.Property; using StylesheetProperty = umbraco.cms.businesslogic.web.StylesheetProperty; @@ -31,18 +32,15 @@ namespace umbraco.controls /// public class ContentControl : TabView { - private readonly Content _content; - internal Dictionary DataTypes = new Dictionary(); - private UmbracoEnsuredPage _prntpage; public ContentControl() { //by default set this to true for content SavePropertyDataWhenInvalid = true; } - + + internal Dictionary DataTypes = new Dictionary(); private readonly Content _content; - private readonly ArrayList _dataFields = new ArrayList(); private UmbracoEnsuredPage _prntpage; public event EventHandler SaveAndPublish; public event EventHandler SaveToPublish; @@ -360,16 +358,16 @@ namespace umbraco.controls } } - foreach (var property in DataTypes) - { - var defaultData = property.Value.Data as DefaultData; - if (defaultData != null) + foreach (var property in DataTypes) { - defaultData.PropertyTypeAlias = property.Key; - defaultData.NodeId = _content.Id; + var defaultData = property.Value.Data as DefaultData; + if (defaultData != null) + { + defaultData.PropertyTypeAlias = property.Key; + defaultData.NodeId = _content.Id; + } + property.Value.DataEditor.Save(); } - property.Value.DataEditor.Save(); - } //don't update if the name is empty if (!NameTxt.Text.IsNullOrWhiteSpace()) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs index adbe86d761..9b30dcdbb1 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editContent.aspx.cs @@ -2,6 +2,7 @@ using System; using System.Web.UI; using System.Web.UI.WebControls; using Umbraco.Core.IO; +using Umbraco.Core.Services; using umbraco.BusinessLogic.Actions; using umbraco.uicontrols.DatePicker; using umbraco.BusinessLogic; @@ -313,9 +314,7 @@ namespace umbraco.cms.presentation if (_document.Level == 1 || _document.PathPublished) { var previouslyPublished = _document.HasPublishedVersion(); - - Trace.Warn("before d.publish"); - + if (_document.PublishWithResult(base.getUser(), false)) { ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editContentPublishedHeader", null), ui.Text("speechBubbles", "editContentPublishedText", null)); diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs index 9dfa662532..a3f14fa9e4 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/editMedia.aspx.cs @@ -109,7 +109,7 @@ namespace umbraco.cms.presentation //so we need to 'retrieve' that value and set it on the property of the new IContent object. //NOTE This is a workaround for the legacy approach to saving values through the DataType instead of the Property //- (The DataType shouldn't be responsible for saving the value - especically directly to the db). - foreach (var item in tmp.DataTypes) + foreach (var item in _contentControl.DataTypes) { _media.getProperty(item.Key).Value = item.Value.Data.Value; } diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs index 27897c3e25..8eb6d893ef 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/members/EditMember.aspx.cs @@ -191,7 +191,7 @@ namespace umbraco.cms.presentation.members //so we need to 'retrieve' that value and set it on the property of the new IContent object. //NOTE This is a workaround for the legacy approach to saving values through the DataType instead of the Property //- (The DataType shouldn't be responsible for saving the value - especically directly to the db). - foreach (var item in tmp.DataTypes) + foreach (var item in _contentControl.DataTypes) { _document.getProperty(item.Key).Value = item.Value.Data.Value; } @@ -224,8 +224,7 @@ namespace umbraco.cms.presentation.members } - ClientTools.ShowSpeechBubble(BasePages.BasePage.speechBubbleIcon.save, - ui.Text("speechBubbles", "editMemberSaved", base.getUser()), ""); + ClientTools.ShowSpeechBubble(speechBubbleIcon.save, ui.Text("speechBubbles", "editMemberSaved", base.getUser()), ""); } } From 2f6dada4817878bea5f410593b58a49d0fa8bf5f Mon Sep 17 00:00:00 2001 From: Shannon Deminick Date: Wed, 17 Apr 2013 23:20:20 +0600 Subject: [PATCH 7/7] Fixes issue with ctor not setting default property --- .../umbraco/controls/ContentControl.cs | 21 +++++++++---------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs index b33ae42698..11e788d695 100644 --- a/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs +++ b/src/Umbraco.Web/umbraco.presentation/umbraco/controls/ContentControl.cs @@ -30,12 +30,6 @@ namespace umbraco.controls public class ContentControl : TabView { - public ContentControl() - { - //by default set this to true for content - SavePropertyDataWhenInvalid = true; - } - private readonly Content _content; private readonly ArrayList _dataFields = new ArrayList(); private UmbracoEnsuredPage _prntpage; @@ -51,7 +45,11 @@ namespace umbraco.controls private readonly CustomValidator _nameTxtCustomValidator = new CustomValidator(); private static readonly string UmbracoPath = SystemDirectories.Umbraco; public Pane PropertiesPane = new Pane(); - + // zb-00036 #29889 : load it only once + List _virtualTabs; + //default to true! + private bool _savePropertyDataWhenInvalid = true; + public Content ContentObject { get { return _content; } @@ -68,7 +66,11 @@ namespace umbraco.controls /// to the database when the page is invalid because there is no published state. /// Relates to: http://issues.umbraco.org/issue/U4-227 /// - public bool SavePropertyDataWhenInvalid { get; set; } + public bool SavePropertyDataWhenInvalid + { + get { return _savePropertyDataWhenInvalid; } + set { _savePropertyDataWhenInvalid = value; } + } [Obsolete("This is no longer used and will be removed from the codebase in future versions")] private string _errorMessage = ""; @@ -84,9 +86,6 @@ namespace umbraco.controls { } - // zb-00036 #29889 : load it only once - List _virtualTabs; - /// /// Constructor to set default properties. ///