2014-11-20 16:28:50 +11:00
|
|
|
using System;
|
|
|
|
|
using System.Globalization;
|
|
|
|
|
using System.Net.Http.Formatting;
|
|
|
|
|
using Umbraco.Core;
|
2016-03-15 16:58:13 +01:00
|
|
|
using Umbraco.Core.Services;
|
2014-11-20 17:54:30 +11:00
|
|
|
using Umbraco.Core.Models;
|
2018-01-15 11:32:30 +01:00
|
|
|
using Umbraco.Core.Models.Entities;
|
2014-11-20 16:28:50 +11:00
|
|
|
using Umbraco.Web.Models.Trees;
|
|
|
|
|
using Umbraco.Web.Mvc;
|
|
|
|
|
using Umbraco.Web.WebApi.Filters;
|
2016-03-17 15:28:46 +01:00
|
|
|
using Umbraco.Web._Legacy.Actions;
|
2014-11-20 16:28:50 +11:00
|
|
|
using Constants = Umbraco.Core.Constants;
|
|
|
|
|
|
|
|
|
|
namespace Umbraco.Web.Trees
|
|
|
|
|
{
|
|
|
|
|
[UmbracoTreeAuthorize(Constants.Trees.Languages)]
|
2015-09-28 08:54:00 +02:00
|
|
|
[Tree(Constants.Applications.Settings, Constants.Trees.Languages, null, sortOrder: 4)]
|
2014-11-20 16:28:50 +11:00
|
|
|
[PluginController("UmbracoTrees")]
|
|
|
|
|
[CoreTree]
|
|
|
|
|
public class LanguageTreeController : TreeController
|
|
|
|
|
{
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// The method called to render the contents of the tree structure
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="queryStrings">
|
|
|
|
|
/// All of the query string parameters passed from jsTree
|
|
|
|
|
/// </param>
|
|
|
|
|
/// <remarks>
|
|
|
|
|
/// We are allowing an arbitrary number of query strings to be pased in so that developers are able to persist custom data from the front-end
|
|
|
|
|
/// to the back end to be used in the query for model data.
|
|
|
|
|
/// </remarks>
|
|
|
|
|
protected override TreeNodeCollection GetTreeNodes(string id, FormDataCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
var nodes = new TreeNodeCollection();
|
|
|
|
|
|
|
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
{
|
|
|
|
|
var languages = Services.LocalizationService.GetAllLanguages();
|
|
|
|
|
foreach (var language in languages)
|
|
|
|
|
{
|
|
|
|
|
nodes.Add(
|
|
|
|
|
CreateTreeNode(
|
|
|
|
|
language.Id.ToString(CultureInfo.InvariantCulture), "-1", queryStrings, language.CultureInfo.DisplayName, "icon-flag-alt", false,
|
|
|
|
|
//TODO: Rebuild the language editor in angular, then we dont need to have this at all (which is just a path to the legacy editor)
|
|
|
|
|
"/" + queryStrings.GetValue<string>("application") + "/framed/" +
|
2015-10-29 16:26:06 +01:00
|
|
|
Uri.EscapeDataString("settings/editLanguage.aspx?id=" + language.Id)));
|
2014-11-20 16:28:50 +11:00
|
|
|
}
|
|
|
|
|
}
|
2014-11-20 17:54:30 +11:00
|
|
|
|
2014-11-20 16:28:50 +11:00
|
|
|
return nodes;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/// <summary>
|
|
|
|
|
/// Returns the menu structure for the node
|
|
|
|
|
/// </summary>
|
|
|
|
|
/// <param name="id"></param>
|
|
|
|
|
/// <param name="queryStrings"></param>
|
|
|
|
|
/// <returns></returns>
|
|
|
|
|
protected override MenuItemCollection GetMenuForNode(string id, FormDataCollection queryStrings)
|
|
|
|
|
{
|
|
|
|
|
var menu = new MenuItemCollection();
|
2016-09-01 19:06:08 +02:00
|
|
|
|
2014-11-20 16:28:50 +11:00
|
|
|
if (id == Constants.System.Root.ToInvariantString())
|
|
|
|
|
{
|
|
|
|
|
//Create the normal create action
|
2016-03-15 16:58:13 +01:00
|
|
|
menu.Items.Add<ActionNew>(Services.TextService.Localize("actions", ActionNew.Instance.Alias))
|
2016-09-01 19:06:08 +02:00
|
|
|
//Since we haven't implemented anything for languages in angular, this needs to be converted to
|
2014-11-20 17:54:30 +11:00
|
|
|
//use the legacy format
|
|
|
|
|
.ConvertLegacyMenuItem(null, "initlanguages", queryStrings.GetValue<string>("application"));
|
2016-09-01 19:06:08 +02:00
|
|
|
|
2014-11-20 16:28:50 +11:00
|
|
|
//refresh action
|
2016-03-15 16:58:13 +01:00
|
|
|
menu.Items.Add<RefreshNode, ActionRefresh>(Services.TextService.Localize("actions", ActionRefresh.Instance.Alias), true);
|
2014-11-20 16:28:50 +11:00
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
|
2014-11-20 17:54:30 +11:00
|
|
|
var lang = Services.LocalizationService.GetLanguageById(int.Parse(id));
|
2014-11-20 19:51:42 +11:00
|
|
|
if (lang == null) return new MenuItemCollection();
|
2014-11-20 17:54:30 +11:00
|
|
|
|
2014-11-20 16:28:50 +11:00
|
|
|
//add delete option for all languages
|
2016-03-15 16:58:13 +01:00
|
|
|
menu.Items.Add<ActionDelete>(Services.TextService.Localize("actions", ActionDelete.Instance.Alias))
|
2016-09-01 19:06:08 +02:00
|
|
|
//Since we haven't implemented anything for languages in angular, this needs to be converted to
|
2014-11-20 17:54:30 +11:00
|
|
|
//use the legacy format
|
2018-01-15 11:32:30 +01:00
|
|
|
.ConvertLegacyMenuItem(new EntitySlim
|
2014-11-20 17:54:30 +11:00
|
|
|
{
|
|
|
|
|
Id = lang.Id,
|
|
|
|
|
Level = 1,
|
|
|
|
|
ParentId = -1,
|
2016-09-01 19:06:08 +02:00
|
|
|
Name = lang.CultureInfo.DisplayName
|
2014-11-20 17:54:30 +11:00
|
|
|
}, "language", queryStrings.GetValue<string>("application"));
|
2014-11-20 16:28:50 +11:00
|
|
|
|
|
|
|
|
return menu;
|
|
|
|
|
}
|
|
|
|
|
}
|
2015-10-29 16:26:06 +01:00
|
|
|
}
|