Files
Umbraco-CMS/src/Umbraco.Web.UI/umbraco/create/PartialViewMacro.ascx.cs
Jeremy Pyne fbed14a9e0 Partial Views and Partial View Macro's should allow for folder hierarchy for organization. This changes makes them work much like the Scripts and css folders.
I didn't add a Type drop down like the scripts screen has.  This is unnecessary and cumbersome.  Instead it works like other screens and the user can generate a hierarchy in their files by adding /'s in the names.  This is how it works in Stylesheets works and its a lot cleaner.  I added a note of this to the creation dialogs as well.

For example create a view file with the name myFolder/myView and the system will take care of folder creation automatically.  There is also a delete option.

Other errors fixed:
 Selecting a folder in the scripts lists was generating an error.
 Stylesheets would not create a new folder(but they wold make nested children in existing folders.
 Partial and Macro Views would not use the proper elpers for generating syncTree code.
2014-09-04 10:17:54 -04:00

95 lines
3.6 KiB
C#

using System;
using System.Linq;
using System.Web.UI;
using System.Web.UI.WebControls;
using umbraco.BasePages;
using Umbraco.Core;
using Umbraco.Core.IO;
using umbraco.presentation.create;
namespace Umbraco.Web.UI.Umbraco.Create
{
public partial class PartialViewMacro : UserControl
{
protected override void OnLoad(EventArgs e)
{
base.OnLoad(e);
DataBind();
LoadTemplates(PartialViewTemplate);
// Enable new contect item in folders to place items in that folder.
if (Request["nodeType"] == "partialViewMacrosFolder")
FileName.Text = Request["nodeId"] + "/";
}
private static void LoadTemplates(ListControl list)
{
var path = IOHelper.MapPath(SystemDirectories.Umbraco + "/PartialViewMacros/Templates/");
list.Items.Clear();
// always add the options of empty snippets
list.Items.Add(new ListItem("Empty", "Empty.cshtml"));
list.Items.Add(new ListItem("Empty (For Use With Custom Views)", "Empty (ForUseWithCustomViews).cshtml"));
if (System.IO.Directory.Exists(path))
{
const string extension = ".cshtml";
//Already adding Empty as the first item, so don't add it again
foreach (var fileInfo in new System.IO.DirectoryInfo(path).GetFiles("*" + extension).Where(f => f.Name.StartsWith("Empty") == false))
{
var filename = System.IO.Path.GetFileName(fileInfo.FullName);
var liText = filename.Replace(extension, "").SplitPascalCasing().ToFirstUpperInvariant();
list.Items.Add(new ListItem(liText, filename));
}
}
}
protected void SubmitButton_Click(object sender, EventArgs e)
{
if (Page.IsValid)
{
//Seriously, need to overhaul create dialogs, this is rediculous:
// http://issues.umbraco.org/issue/U4-1373
var createMacroVal = 0;
if (CreateMacroCheckBox.Checked)
createMacroVal = 1;
string returnUrl = dialogHandler_temp.Create(Request.GetItemAsString("nodeType"),
createMacroVal, //apparently we need to pass this value to 'ParentID'... of course! :P then we'll extract it in PartialViewTasks to create it.
PartialViewTemplate.SelectedValue + "|||" + FileName.Text);
BasePage.Current.ClientTools
.ChangeContentFrameUrl(returnUrl)
.ChildNodeCreated()
.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;
var name = fileName.Contains(".")
? fileName.Substring(0, (fileName.LastIndexOf('.') + 1)).Trim('.')
: fileName;
name = name.SplitPascalCasing().ToFirstUpperInvariant();
var macro = ApplicationContext.Current.Services.MacroService.GetByAlias(name);
if (macro != null)
{
args.IsValid = false;
}
}
}
}
}