2013-09-03 12:27:48 +10:00
|
|
|
|
using System;
|
|
|
|
|
|
using System.Linq;
|
|
|
|
|
|
using System.Net;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using System.Net.Http.Formatting;
|
2013-09-27 15:19:39 +10:00
|
|
|
|
using System.Web;
|
2013-09-03 12:27:48 +10:00
|
|
|
|
using System.Web.Http;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using Umbraco.Core;
|
|
|
|
|
|
using Umbraco.Core.Models;
|
|
|
|
|
|
using Umbraco.Core.Services;
|
2013-10-08 12:38:27 +11:00
|
|
|
|
using Umbraco.Web.Models.Trees;
|
2013-08-16 17:25:52 +10:00
|
|
|
|
using Umbraco.Web.Mvc;
|
2013-09-04 18:10:57 +10:00
|
|
|
|
using umbraco;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
using umbraco.BusinessLogic.Actions;
|
2013-08-16 17:25:52 +10:00
|
|
|
|
using Constants = Umbraco.Core.Constants;
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
|
{
|
2013-09-04 18:10:57 +10:00
|
|
|
|
[LegacyBaseTree(typeof(loadMedia))]
|
2013-08-12 15:06:12 +02:00
|
|
|
|
[Tree(Constants.Applications.Media, Constants.Trees.Media, "Media")]
|
2013-08-16 17:25:52 +10:00
|
|
|
|
[PluginController("UmbracoTrees")]
|
2013-10-03 11:25:26 +10:00
|
|
|
|
[CoreTree]
|
2013-08-12 15:06:12 +02:00
|
|
|
|
public class MediaTreeController : ContentTreeControllerBase
|
|
|
|
|
|
{
|
2013-10-01 16:38:10 +10:00
|
|
|
|
protected override TreeNode CreateRootNode(FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var node = base.CreateRootNode(queryStrings);
|
|
|
|
|
|
//if the user's start node is not default, then ensure the root doesn't have a menu
|
|
|
|
|
|
if (Security.CurrentUser.StartMediaId != Constants.System.Root)
|
|
|
|
|
|
{
|
|
|
|
|
|
node.MenuUrl = "";
|
|
|
|
|
|
}
|
|
|
|
|
|
return node;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
protected override int RecycleBinId
|
|
|
|
|
|
{
|
2013-10-24 16:54:17 +11:00
|
|
|
|
get { return Constants.System.RecycleBinMedia; }
|
2013-08-12 15:06:12 +02:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override bool RecycleBinSmells
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Services.MediaService.RecycleBinSmells(); }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-10-01 16:38:10 +10:00
|
|
|
|
protected override int UserStartNode
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return Security.CurrentUser.StartMediaId; }
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
protected override TreeNodeCollection PerformGetTreeNodes(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var entities = GetChildEntities(id);
|
2013-10-27 14:12:27 +01:00
|
|
|
|
var nodes = new TreeNodeCollection();
|
2013-08-12 15:06:12 +02:00
|
|
|
|
|
2013-10-27 14:12:27 +01:00
|
|
|
|
foreach (var entity in entities)
|
|
|
|
|
|
{
|
|
|
|
|
|
var e = (UmbracoEntity)entity;
|
2013-11-12 13:09:24 +11:00
|
|
|
|
var node = CreateTreeNode(e.Id.ToInvariantString(), id, queryStrings, e.Name, e.ContentTypeIcon, e.HasChildren);
|
2013-10-27 14:12:27 +01:00
|
|
|
|
|
|
|
|
|
|
node.AdditionalData.Add("contentType", e.ContentTypeAlias);
|
|
|
|
|
|
nodes.Add(node);
|
|
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return nodes;
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override MenuItemCollection PerformGetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
|
{
|
|
|
|
|
|
var menu = new MenuItemCollection();
|
|
|
|
|
|
|
2013-09-26 15:55:38 +10:00
|
|
|
|
//set the default
|
|
|
|
|
|
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
|
{
|
2013-10-01 16:38:10 +10:00
|
|
|
|
//if the user's start node is not the root then ensure the root menu is empty/doesn't exist
|
|
|
|
|
|
if (Security.CurrentUser.StartMediaId != Constants.System.Root)
|
|
|
|
|
|
{
|
|
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-13 18:19:56 +10:00
|
|
|
|
// root actions
|
2013-10-03 15:05:48 +10:00
|
|
|
|
menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionSort>(ui.Text("actions", ActionSort.Instance.Alias), true).ConvertLegacyMenuItem(null, "media", "media");
|
|
|
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-09-03 12:27:48 +10:00
|
|
|
|
int iid;
|
|
|
|
|
|
if (int.TryParse(id, out iid) == false)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
|
|
|
|
|
var item = Services.EntityService.Get(iid, UmbracoObjectTypes.Media);
|
|
|
|
|
|
if (item == null)
|
|
|
|
|
|
{
|
|
|
|
|
|
throw new HttpResponseException(HttpStatusCode.NotFound);
|
|
|
|
|
|
}
|
2013-08-12 15:06:12 +02:00
|
|
|
|
//return a normal node menu:
|
2013-10-03 15:05:48 +10:00
|
|
|
|
menu.Items.Add<ActionNew>(ui.Text("actions", ActionNew.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionMove>(ui.Text("actions", ActionMove.Instance.Alias));
|
|
|
|
|
|
menu.Items.Add<ActionDelete>(ui.Text("actions", ActionDelete.Instance.Alias));
|
2013-11-14 22:25:08 +11:00
|
|
|
|
menu.Items.Add<ActionSort>(ui.Text("actions", ActionSort.Instance.Alias)).ConvertLegacyMenuItem(item, "media", "media");
|
2013-10-03 15:05:48 +10:00
|
|
|
|
menu.Items.Add<ActionRefresh>(ui.Text("actions", ActionRefresh.Instance.Alias), true);
|
2013-10-24 16:54:17 +11:00
|
|
|
|
|
|
|
|
|
|
//if the media item is in the recycle bin, don't have a default menu, just show the regular menu
|
|
|
|
|
|
if (item.Path.Split(new[] {','}, StringSplitOptions.RemoveEmptyEntries).Contains(RecycleBinId.ToInvariantString()))
|
|
|
|
|
|
{
|
|
|
|
|
|
menu.DefaultMenuAlias = null;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
2013-08-12 15:06:12 +02:00
|
|
|
|
return menu;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
protected override UmbracoObjectTypes UmbracoObjectType
|
|
|
|
|
|
{
|
|
|
|
|
|
get { return UmbracoObjectTypes.Media; }
|
|
|
|
|
|
}
|
|
|
|
|
|
}
|
2013-08-05 19:22:00 +10:00
|
|
|
|
}
|