Fixes: U4-3481 Adding Scripting Files and Partial View Macro File with the same name and 'create macro' selected fails.

This commit is contained in:
Shannon
2014-03-25 12:16:27 +11:00
parent c81919e269
commit f88e60bcb5
6 changed files with 55 additions and 1 deletions

View File

@@ -24,6 +24,9 @@
<cc1:PropertyPanel runat="server">
<asp:CheckBox ID="createMacro" Runat="server" Checked="true" Text="Create Macro"></asp:CheckBox>
<asp:CustomValidator ErrorMessage="<br/>A macro already exists with the specified name" ID="MacroExistsValidator"
Display="Dynamic" ForeColor="red"
runat="server" OnServerValidate="MacroExistsValidator_OnServerValidate"/>
</cc1:PropertyPanel>
</cc1:Pane>

View File

@@ -15,6 +15,9 @@
<cc1:PropertyPanel runat="server">
<asp:CheckBox ID="CreateMacroCheckBox" runat="server" Checked="true" Text="Create Macro"></asp:CheckBox>
<asp:CustomValidator ErrorMessage="<br/>A macro already exists with the specified name" ID="MacroExistsValidator"
Display="Dynamic" ForeColor="red"
runat="server" OnServerValidate="MacroExistsValidator_OnServerValidate"/>
</cc1:PropertyPanel>
</cc1:Pane>

View File

@@ -45,7 +45,7 @@ namespace Umbraco.Web.UI.Umbraco.Create
}
}
protected void SubmitButton_Click(object sender, System.EventArgs e)
protected void SubmitButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
@@ -66,5 +66,23 @@ namespace Umbraco.Web.UI.Umbraco.Create
.CloseModalWindow();
}
}
protected void MacroExistsValidator_OnServerValidate(object source, ServerValidateEventArgs args)
{
if (CreateMacroCheckBox.Checked)
{
//TODO: Shouldn't this use our string functions to create the alias ?
var fileName = FileName.Text + ".cshtml";
var name = fileName
.Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.')
.SplitPascalCasing().ToFirstUpperInvariant();
var macro = ApplicationContext.Current.Services.MacroService.GetByAlias(name);
if (macro != null)
{
args.IsValid = false;
}
}
}
}
}

View File

@@ -48,6 +48,15 @@ namespace Umbraco.Web.UI.Umbraco.Create {
/// </remarks>
protected global::System.Web.UI.WebControls.CheckBox CreateMacroCheckBox;
/// <summary>
/// MacroExistsValidator control.
/// </summary>
/// <remarks>
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.WebControls.CustomValidator MacroExistsValidator;
/// <summary>
/// Textbox2 control.
/// </summary>