2019-05-25 10:34:03 +02:00
|
|
|
|
using System.Linq;
|
2016-03-23 22:56:42 +01:00
|
|
|
|
using System.Net.Http.Formatting;
|
|
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Web.Models.Trees;
|
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2018-10-29 17:27:33 +11:00
|
|
|
|
using Umbraco.Web.Actions;
|
2016-03-23 22:56:42 +01:00
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
|
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
|
|
|
|
|
[UmbracoTreeAuthorize(Constants.Trees.Macros)]
|
2019-01-22 09:31:47 +01:00
|
|
|
|
[Tree(Constants.Applications.Settings, Constants.Trees.Macros, TreeTitle = "Macros", SortOrder = 4, TreeGroup = Constants.Trees.Groups.Settings)]
|
2016-03-23 22:56:42 +01:00
|
|
|
|
[PluginController("UmbracoTrees")]
|
2019-01-22 09:31:47 +01:00
|
|
|
|
[CoreTree]
|
2018-10-10 15:03:14 +01:00
|
|
|
|
public class MacrosTreeController : TreeController
|
2016-03-23 22:56:42 +01:00
|
|
|
|
{
|
2018-10-23 09:34:02 +02:00
|
|
|
|
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var root = base.CreateRootNode(queryStrings);
|
|
|
|
|
|
//check if there are any macros
|
|
|
|
|
|
root.HasChildren = Services.MacroService.GetAll().Any();
|
|
|
|
|
|
return root;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2016-03-23 22:56:42 +01:00
|
|
|
|
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
|
2019-03-29 12:06:23 +00:00
|
|
|
|
if (id == Constants.System.RootString)
|
2016-03-23 22:56:42 +01:00
|
|
|
|
{
|
2019-05-25 10:34:03 +02:00
|
|
|
|
foreach (var macro in Services.MacroService.GetAll().OrderBy(m => m.Name))
|
2016-03-23 22:56:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
nodes.Add(CreateTreeNode(
|
2016-09-01 19:06:08 +02:00
|
|
|
|
macro.Id.ToString(),
|
|
|
|
|
|
id,
|
|
|
|
|
|
queryStrings,
|
|
|
|
|
|
macro.Name,
|
2019-06-07 17:02:55 +01:00
|
|
|
|
Constants.Icons.Macro,
|
2019-01-07 08:31:06 +01:00
|
|
|
|
false));
|
2016-03-23 22:56:42 +01:00
|
|
|
|
}
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
return nodes;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
2019-03-29 12:06:23 +00:00
|
|
|
|
if (id == Constants.System.RootString)
|
2016-03-23 22:56:42 +01:00
|
|
|
|
{
|
|
|
|
|
|
//Create the normal create action
|
2018-11-15 15:28:35 +01:00
|
|
|
|
menu.Items.Add<ActionNew>(Services.TextService);
|
2019-01-21 10:44:11 +01:00
|
|
|
|
|
2016-03-23 22:56:42 +01:00
|
|
|
|
//refresh action
|
2018-10-29 17:27:33 +11:00
|
|
|
|
menu.Items.Add(new RefreshNode(Services.TextService, true));
|
2016-03-23 22:56:42 +01:00
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
var macro = Services.MacroService.GetById(int.Parse(id));
|
|
|
|
|
|
if (macro == null) return new MenuItemCollection();
|
|
|
|
|
|
|
2016-03-23 22:58:52 +01:00
|
|
|
|
//add delete option for all macros
|
2019-01-21 10:44:11 +01:00
|
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService, opensDialog: true);
|
2016-03-23 22:56:42 +01:00
|
|
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2017-07-20 11:21:28 +02:00
|
|
|
|
}
|