Attach Open Action

Attaching the action to open the default view

To allow the user to open the default view in the "Media" perspective, you should attach an action for this by using ActionExecutor as described in FAQ: How to attach actions to the elements in the tree using ActionExecutor?

In short, you should:

  • implement the IActionExecutor interface specifying "List.aspx" as the target URL with the node's entity token as a query parameter
  • implement the abstract class ActionToken specifying the ActionExecutor in its attribute
  • implement the IElementActionProvider where you will create an ActionElement using the ActionToken and setting visual data of the action.

MediaViewerActionProvider.cs


using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using Composite.C1Console.Elements.Plugins.ElementActionProvider;
using Composite.C1Console.Elements;
using Composite.C1Console.Security;
using Composite.C1Console.Actions;
using Composite.Data;
using Composite.C1Console.Events;
using Composite.Core.WebClient;
using Composite.Core.ResourceSystem;

namespace Composite.Backend
{
	/// <summary>
	/// Summary description for MediaViewer
	/// </summary>
	public class MediaViewerActionProvider : IElementActionProvider
	{
		private static readonly ActionGroup AppendedActionGroup = new ActionGroup("Media", ActionGroupPriority.GeneralAppendMedium);
		private ResourceHandle ReportIcon
		{
			get
			{
				return new ResourceHandle("Composite.Icons", "report");
			}
		}
		public IEnumerable<ElementAction> GetActions(EntityToken entityToken)
		{

			ElementAction elementAction = new ElementAction(new ActionHandle(new MediaViewerActionToken()))
			{
				VisualData = new ActionVisualizedData
				{
					Label = "Media Viewer",
					ToolTip = string.Empty,
					Icon = ReportIcon,
					ActionLocation = new ActionLocation
					{
						ActionType = ActionType.Edit,
						IsInToolbar = true,
						ActionGroup = AppendedActionGroup
					}
				}
			};
			yield return elementAction;
			yield break;
		}
        [ActionExecutor(typeof(MediaViewerActionExecutor))]
        public sealed class MediaViewerActionToken : ActionToken
        {
            public override IEnumerable<PermissionType> PermissionTypes
            {
                get
                {
                    yield return PermissionType.Edit;
                    yield return PermissionType.Administrate;
                }
            }

            public override bool IgnoreEntityTokenLocking
            {
                get
                {
                    return false;
                }
            }

            public override string Serialize()
            {
                return "";
            }

            public static ActionToken Deserialize(string serialiedWorkflowActionToken)
            {
                return new MediaViewerActionToken();
            }
        }

        public sealed class MediaViewerActionExecutor : IActionExecutor
        {
            public FlowToken Execute(EntityToken entityToken, ActionToken actionToken, FlowControllerServicesContainer flowControllerServicesContainer)
            {

                string currentConsoleId = flowControllerServicesContainer.GetService<IManagementConsoleMessageService>().CurrentConsoleId;

                string url = UrlUtils.ResolveAdminUrl(string.Format("InstalledPackages/Media/Default.aspx?EntityToken={0}", HttpUtility.UrlEncode(EntityTokenSerializer.Serialize(entityToken))));

                ConsoleMessageQueueFacade.Enqueue(new OpenViewMessageQueueItem
                {
                    Url = url,
                    ViewId = Guid.NewGuid().ToString(),
                    ViewType = ViewType.Main,
                    Label = "Media viewer"
                }, currentConsoleId);

                return null;
            }
        }
    }
}
Download the source

Please note that, once created, the action element provider must be registered in ~/App_Data/Composite/Composite.config.

<Composite.C1Console.Elements.Plugins.ElementActionProviderConfiguration>
  <ElementActionProviderPlugins>
    <!-- skipped for readability -->
    <add name="MediaViewerActionProvider" 
         type="Composite.Backend.MediaViewerActionProvider, App_Code" />
  </ElementActionProviderPlugins>
</Composite.C1Console.Elements.Plugins.ElementActionProviderConfiguration>