Skip to content

Instantly share code, notes, and snippets.

@enkelmedia
Created January 26, 2018 22:55
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save enkelmedia/8ba9c77b2f14ef6c29578aec6c0a7961 to your computer and use it in GitHub Desktop.
Save enkelmedia/8ba9c77b2f14ef6c29578aec6c0a7961 to your computer and use it in GitHub Desktop.
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net.Http.Formatting;
using System.Web;
using NewsletterStudio.Infrastucture;
using NewsletterStudio.Infrastucture.Services;
using Umbraco.Web.Models.ContentEditing;
using Umbraco.Web.Models.Trees;
using Umbraco.Web.Mvc;
using Umbraco.Web.Trees;
using umbraco.BusinessLogic.Actions;
using umbraco.cms.presentation.Trees;
namespace NewsletterStudio.Umbraco
{
[PluginController(NewsletterStudioApplication.Name)]
[Tree("NewsletterStudio", "MailingList", "Mailing lists", sortOrder : 10)]
public class MailingListTreeController : TreeController
{
private LocalizationService _localization;
public MailingListTreeController()
{
_localization = new LocalizationService();
}
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
{
var nodes = new TreeNodeCollection();
var repo = GlobalFactory.Current.MailingListRepository;
foreach (var mailinglist in repo.GetAll())
{
var item = this.CreateTreeNode(mailinglist.Id.ToString(), id, queryStrings, mailinglist.Name, "icon-users", false);
nodes.Add(item);
}
return nodes;
}
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
{
var menu = new MenuItemCollection();
if(id == "-1")
{
menu.DefaultMenuAlias = ActionNew.Instance.Alias;
menu.Items.Add<ActionNew>(_localization.Get("actions_create"));
menu.Items.Add<ActionRefresh>(_localization.Get("actions_refreshNode"));
}
else
{
menu.Items.Add<ActionDelete>(_localization.Get("actions_delete"));
}
return menu;
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment