Adds some other macro parameters fixes up more of the macro editor, all seems to be working there now and have added validation (which never existed before :(
This commit is contained in:
@@ -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
|
||||
{
|
||||
|
||||
@@ -2,12 +2,6 @@
|
||||
|
||||
namespace Umbraco.Core.PropertyEditors
|
||||
{
|
||||
[ParameterEditor("text", "Text", "textbox")]
|
||||
public class TextParameterEditor : ParameterEditor
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// Represents the value editor for the parameter editor during macro parameter editing
|
||||
/// </summary>
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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 @@
|
||||
</HeaderTemplate>
|
||||
<ItemTemplate>
|
||||
<tr>
|
||||
<td>
|
||||
<td>
|
||||
<input type="hidden" id="macroPropertyID" runat="server" value='<%#Eval("Id")%>'
|
||||
name="macroPropertyID" />
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" runat="server" ControlToValidate="macroPropertyAlias" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:TextBox runat="server" ID="macroPropertyAlias" Text='<%#Eval("Alias")%>' />
|
||||
</td>
|
||||
<td>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator2" runat="server" ControlToValidate="macroPropertyName" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:TextBox runat="server" ID="macroPropertyName" Text='<%#Eval("Name")%>' />
|
||||
</td>
|
||||
<td>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator3" runat="server" ControlToValidate="macroPropertyType" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:DropDownList OnPreRender="AddChooseList" runat="server" ID="macroPropertyType"
|
||||
DataTextFormatString="" DataTextField='Name' DataValueField="Alias"
|
||||
DataSource='<%# GetMacroParameterEditors()%>'
|
||||
@@ -143,19 +159,22 @@
|
||||
</asp:DropDownList>
|
||||
</td>
|
||||
<td>
|
||||
<asp:Button OnClick="deleteMacroProperty" ID="delete" Text="Delete" runat="server" CssClass="btn btn-default" />
|
||||
<asp:Button OnClick="deleteMacroProperty" ID="delete" Text="Delete" runat="server" CssClass="btn btn-default delete-button" />
|
||||
</td>
|
||||
</tr>
|
||||
</ItemTemplate>
|
||||
<FooterTemplate>
|
||||
<tr>
|
||||
<td>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator1" CssClass="add-validator" runat="server" ControlToValidate="macroPropertyAliasNew" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:TextBox runat="server" ID="macroPropertyAliasNew" Text='New Alias' OnTextChanged="macroPropertyCreate" />
|
||||
</td>
|
||||
<td>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator4" CssClass="add-validator" runat="server" ControlToValidate="macroPropertyNameNew" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:TextBox runat="server" ID="macroPropertyNameNew" Text='New Name' />
|
||||
</td>
|
||||
<td>
|
||||
<asp:RequiredFieldValidator ID="RequiredFieldValidator5" CssClass="add-validator" runat="server" ControlToValidate="macroPropertyTypeNew" Display="Dynamic" ForeColor="#b94a48">Required<br/></asp:RequiredFieldValidator>
|
||||
<asp:DropDownList OnPreRender="AddChooseList" runat="server" ID="macroPropertyTypeNew"
|
||||
DataTextField="Name"
|
||||
DataValueField="Alias"
|
||||
@@ -163,7 +182,7 @@
|
||||
</asp:DropDownList>
|
||||
</td>
|
||||
<td>
|
||||
<asp:Button ID="createNew" Text="Add" runat="server" CssClass="btn btn-default" />
|
||||
<asp:Button ID="createNew" Text="Add" runat="server" CssClass="btn btn-default add-button" />
|
||||
</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
|
||||
54
src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs
Normal file
54
src/Umbraco.Web/PropertyEditors/ColorListPreValueEditor.cs
Normal file
@@ -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<ValidationResult> 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()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -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<ValidationResult> 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()
|
||||
});
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ParameterEditors
|
||||
{
|
||||
[ParameterEditor("textMultiLine", "Textarea", "textarea")]
|
||||
public class TextAreaParameterEditor : ParameterEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ParameterEditors
|
||||
{
|
||||
[ParameterEditor("text", "Text", "textbox")]
|
||||
public class TextParameterEditor : ParameterEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,9 @@
|
||||
using Umbraco.Core.PropertyEditors;
|
||||
|
||||
namespace Umbraco.Web.PropertyEditors.ParameterEditors
|
||||
{
|
||||
[ParameterEditor("bool", "True/False", "boolean")]
|
||||
public class TrueFalseParameterEditor : ParameterEditor
|
||||
{
|
||||
}
|
||||
}
|
||||
@@ -307,6 +307,7 @@
|
||||
<Compile Include="Models\ContentEditing\MacroParameter.cs" />
|
||||
<Compile Include="Models\ContentEditing\UmbracoEntityTypes.cs" />
|
||||
<Compile Include="Models\Mapping\MacroModelMapper.cs" />
|
||||
<Compile Include="PropertyEditors\ColorListPreValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\RteEmbedController.cs" />
|
||||
<Compile Include="Editors\EntityController.cs" />
|
||||
<Compile Include="Editors\MediaPostValidateAttribute.cs" />
|
||||
@@ -341,6 +342,9 @@
|
||||
<Compile Include="PropertyEditors\PublishValuesMultipleValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\DropDownMultipleWithKeysPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\RadioButtonsPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditors\TextAreaParameterEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditors\TextParameterEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ParameterEditors\TrueFalseParameterEditor.cs" />
|
||||
<Compile Include="PropertyEditors\UserPickerPropertyEditor.cs" />
|
||||
<Compile Include="PropertyEditors\ValueListPreValueEditor.cs" />
|
||||
<Compile Include="PropertyEditors\DropDownPropertyEditor.cs" />
|
||||
|
||||
@@ -79,6 +79,8 @@ namespace umbraco.cms.presentation.developer
|
||||
}
|
||||
else
|
||||
{
|
||||
Page.Validate();
|
||||
|
||||
ClientTools
|
||||
.SetActiveTreeType(TreeDefinitionCollection.Instance.FindTree<loadMacros>().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()))
|
||||
|
||||
Reference in New Issue
Block a user