diff --git a/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs b/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs
index 55a712f029..8a89c5a5b7 100644
--- a/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs
+++ b/src/Umbraco.Core/Persistence/Repositories/MacroRepository.cs
@@ -172,8 +172,9 @@ namespace Umbraco.Core.Persistence.Repositories
{
if (macro.AddedProperties.Contains(propDto.Alias))
{
- //we need to insert since this was added
+ //we need to insert since this was added and re-assign the new id
Database.Insert(propDto);
+ macro.Properties[propDto.Alias].Id = propDto.Id;
}
else
{
diff --git a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs
index 31a327d24b..f318b6e723 100644
--- a/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs
+++ b/src/Umbraco.Core/PropertyEditors/ParameterValueEditor.cs
@@ -2,12 +2,6 @@
namespace Umbraco.Core.PropertyEditors
{
- [ParameterEditor("text", "Text", "textbox")]
- public class TextParameterEditor : ParameterEditor
- {
-
- }
-
///
/// Represents the value editor for the parameter editor during macro parameter editing
///
diff --git a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs
index 73ce8f0c1e..52ecf1b1e7 100644
--- a/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs
+++ b/src/Umbraco.Tests/Persistence/Repositories/MacroRepositoryTest.cs
@@ -262,14 +262,16 @@ namespace Umbraco.Tests.Persistence.Repositories
using (var repository = new MacroRepository(unitOfWork, NullCacheProvider.Current))
{
var macro = repository.Get(1);
- macro.Properties.Add(new MacroProperty("new1", "New1", 3, null));
+ macro.Properties.Add(new MacroProperty("new1", "New1", 3, "test"));
repository.AddOrUpdate(macro);
unitOfWork.Commit();
// Assert
+ Assert.Greater(macro.Properties.First().Id, 0); //ensure id is returned
var result = repository.Get(1);
+ Assert.Greater(result.Properties.First().Id, 0);
Assert.AreEqual(1, result.Properties.Count());
Assert.AreEqual("new1", result.Properties.First().Alias);
Assert.AreEqual("New1", result.Properties.First().Name);
diff --git a/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx b/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx
index 9949902022..88d079b4b9 100644
--- a/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx
+++ b/src/Umbraco.Web.UI/umbraco/developer/Macros/editMacro.aspx
@@ -25,7 +25,20 @@
$(".fileChooser input[type='text']").not(txt).val("");
//reset other drop downs
$(".fileChooser select").not($(this)).val("");
- });
+ });
+
+ //disable 'add macro property validators' when save or delete is clicked
+ $("#body_save,.delete-button").click(function (evt) {
+ $(".add-validator").each(function() {
+ ValidatorEnable($(this).get(0), false);
+ });
+ });
+ //enable the addmacro property validators when the add button is clicked
+ $(".add-button").click(function(evt) {
+ $(".add-validator").each(function () {
+ ValidatorEnable($(this).get(0), true);
+ });
+ });
});
})(jQuery);
@@ -127,15 +140,18 @@
-
+
+ Required
+ Required
+ Required
-
+
+ Required
+ Required
+ Required
-
+
diff --git a/src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs
new file mode 100644
index 0000000000..7a5475406c
--- /dev/null
+++ b/src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs
@@ -0,0 +1,54 @@
+using System.Collections.Generic;
+using System.ComponentModel.DataAnnotations;
+using System.Linq;
+using System.Text.RegularExpressions;
+using Newtonsoft.Json.Linq;
+using Umbraco.Core;
+using Umbraco.Core.Models;
+using Umbraco.Core.PropertyEditors;
+
+namespace Umbraco.Web.PropertyEditors
+{
+ internal class ColorListPreValueEditor : ValueListPreValueEditor
+ {
+ public ColorListPreValueEditor()
+ {
+ //use a custom editor too
+ Fields.First().View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html";
+ //change the description
+ Fields.First().Description = "Add and remove colors in HEX format without a prefixed '#'";
+ //need to have some custom validation happening here
+ Fields.First().Validators.Add(new ColorListValidator());
+ }
+
+ internal class ColorListValidator : IPropertyValidator
+ {
+ public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor)
+ {
+ var json = value as JArray;
+ if (json == null) yield break;
+
+ //validate each item which is a json object
+ for (var index = 0; index < json.Count; index++)
+ {
+ var i = json[index];
+ var jItem = i as JObject;
+ if (jItem == null || jItem["value"] == null) continue;
+
+ //NOTE: we will be removing empty values when persisting so no need to validate
+ var asString = jItem["value"].ToString();
+ if (asString.IsNullOrWhiteSpace()) continue;
+
+ if (Regex.IsMatch(asString, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false)
+ {
+ yield return new ValidationResult("The value " + asString + " is not a valid hex color", new[]
+ {
+ //we'll make the server field the index number of the value so it can be wired up to the view
+ "item_" + index.ToInvariantString()
+ });
+ }
+ }
+ }
+ }
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs
index 9cd5803ac7..c7b5b7ef78 100644
--- a/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs
+++ b/src/Umbraco.Web/PropertyEditors/ColorPickerPropertyEditor.cs
@@ -1,10 +1,4 @@
-using System.Collections.Generic;
-using System.ComponentModel.DataAnnotations;
-using System.Linq;
-using System.Text.RegularExpressions;
-using Newtonsoft.Json.Linq;
using Umbraco.Core;
-using Umbraco.Core.Models;
using Umbraco.Core.PropertyEditors;
namespace Umbraco.Web.PropertyEditors
@@ -25,47 +19,4 @@ namespace Umbraco.Web.PropertyEditors
}
}
-
- internal class ColorListPreValueEditor : ValueListPreValueEditor
- {
- public ColorListPreValueEditor()
- {
- //use a custom editor too
- Fields.First().View = "views/propertyeditors/colorpicker/colorpicker.prevalues.html";
- //change the description
- Fields.First().Description = "Add and remove colors in HEX format without a prefixed '#'";
- //need to have some custom validation happening here
- Fields.First().Validators.Add(new ColorListValidator());
- }
-
- internal class ColorListValidator : IPropertyValidator
- {
- public IEnumerable Validate(object value, PreValueCollection preValues, PropertyEditor editor)
- {
- var json = value as JArray;
- if (json == null) yield break;
-
- //validate each item which is a json object
- for (var index = 0; index < json.Count; index++)
- {
- var i = json[index];
- var jItem = i as JObject;
- if (jItem == null || jItem["value"] == null) continue;
-
- //NOTE: we will be removing empty values when persisting so no need to validate
- var asString = jItem["value"].ToString();
- if (asString.IsNullOrWhiteSpace()) continue;
-
- if (Regex.IsMatch(asString, "^([0-9a-f]{3}|[0-9a-f]{6})$", RegexOptions.IgnoreCase) == false)
- {
- yield return new ValidationResult("The value " + asString + " is not a valid hex color", new[]
- {
- //we'll make the server field the index number of the value so it can be wired up to the view
- "item_" + index.ToInvariantString()
- });
- }
- }
- }
- }
- }
}
\ No newline at end of file
diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextAreaParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextAreaParameterEditor.cs
new file mode 100644
index 0000000000..7b95ad6f9f
--- /dev/null
+++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextAreaParameterEditor.cs
@@ -0,0 +1,9 @@
+using Umbraco.Core.PropertyEditors;
+
+namespace Umbraco.Web.PropertyEditors.ParameterEditors
+{
+ [ParameterEditor("textMultiLine", "Textarea", "textarea")]
+ public class TextAreaParameterEditor : ParameterEditor
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextParameterEditor.cs
new file mode 100644
index 0000000000..82fab3ae41
--- /dev/null
+++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TextParameterEditor.cs
@@ -0,0 +1,9 @@
+using Umbraco.Core.PropertyEditors;
+
+namespace Umbraco.Web.PropertyEditors.ParameterEditors
+{
+ [ParameterEditor("text", "Text", "textbox")]
+ public class TextParameterEditor : ParameterEditor
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/PropertyEditors/ParameterEditors/TrueFalseParameterEditor.cs b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TrueFalseParameterEditor.cs
new file mode 100644
index 0000000000..cc02db9f8d
--- /dev/null
+++ b/src/Umbraco.Web/PropertyEditors/ParameterEditors/TrueFalseParameterEditor.cs
@@ -0,0 +1,9 @@
+using Umbraco.Core.PropertyEditors;
+
+namespace Umbraco.Web.PropertyEditors.ParameterEditors
+{
+ [ParameterEditor("bool", "True/False", "boolean")]
+ public class TrueFalseParameterEditor : ParameterEditor
+ {
+ }
+}
\ No newline at end of file
diff --git a/src/Umbraco.Web/Umbraco.Web.csproj b/src/Umbraco.Web/Umbraco.Web.csproj
index aa90c8549c..2e09ff05c7 100644
--- a/src/Umbraco.Web/Umbraco.Web.csproj
+++ b/src/Umbraco.Web/Umbraco.Web.csproj
@@ -307,6 +307,7 @@
+
@@ -341,6 +342,9 @@
+
+
+
diff --git a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs
index 311a2bdf13..408859d4cf 100644
--- a/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs
+++ b/src/Umbraco.Web/umbraco.presentation/umbraco/developer/Macros/editMacro.aspx.cs
@@ -79,6 +79,8 @@ namespace umbraco.cms.presentation.developer
}
else
{
+ Page.Validate();
+
ClientTools
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree().Tree.Alias)
.SyncTree("-1,init," + _macro.Id.ToInvariantString(), true); //true forces the reload
@@ -102,7 +104,7 @@ namespace umbraco.cms.presentation.developer
var macroElementAlias = (TextBox)item.FindControl("macroPropertyAlias");
var macroElementType = (DropDownList)item.FindControl("macroPropertyType");
- var prop = _macro.Properties[int.Parse(macroPropertyId.Value)];
+ var prop = _macro.Properties.Single(x => x.Id == int.Parse(macroPropertyId.Value));
prop.Alias = macroElementAlias.Text.Trim();
prop.Name = macroElementName.Text.Trim();
prop.EditorAlias = macroElementType.SelectedValue;
@@ -229,8 +231,12 @@ namespace umbraco.cms.presentation.developer
public void deleteMacroProperty(object sender, EventArgs e)
{
- HtmlInputHidden macroPropertyID = (HtmlInputHidden)((Control)sender).Parent.FindControl("macroPropertyID");
- SqlHelper.ExecuteNonQuery("delete from cmsMacroProperty where id = @id", SqlHelper.CreateParameter("@id", macroPropertyID.Value));
+ var macroPropertyId = (HtmlInputHidden)((Control)sender).Parent.FindControl("macroPropertyID");
+
+ var property = _macro.Properties.Single(x => x.Id == int.Parse(macroPropertyId.Value));
+ _macro.Properties.Remove(property);
+
+ Services.MacroService.Save(_macro);
macroPropertyBind();
}
@@ -261,11 +267,16 @@ namespace umbraco.cms.presentation.developer
}
public void macroPropertyCreate(object sender, EventArgs e)
- {
+ {
+ if (Page.IsValid == false)
+ {
+ return;
+ }
+
var macroPropertyAliasNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyAliasNew");
var macroPropertyNameNew = (TextBox)((Control)sender).Parent.FindControl("macroPropertyNameNew");
var macroPropertyTypeNew = (DropDownList)((Control)sender).Parent.FindControl("macroPropertyTypeNew");
- var goAhead = true;
+
if (macroPropertyAliasNew.Text != ui.Text("general", "new", UmbracoUser) + " " + ui.Text("general", "alias", UmbracoUser))
{
if (_macro.Properties.ContainsKey(macroPropertyAliasNew.Text.Trim()))