Fixes initial part with legacy trees and legacy actions - now a modal window can launch - but now we need to get the legacy umb client manager js tree stuff hooked in.
This commit is contained in:
3
.gitignore
vendored
3
.gitignore
vendored
@@ -104,4 +104,5 @@ src/Umbraco.Web.UI/[Uu]mbraco/[Vv]iews/**/*.html
|
|||||||
src/Umbraco.Web.UI/[Uu]mbraco/[Vv]iews/**/*.js
|
src/Umbraco.Web.UI/[Uu]mbraco/[Vv]iews/**/*.js
|
||||||
|
|
||||||
src/Umbraco.Web.UI/[Cc]onfig/appSettings.config
|
src/Umbraco.Web.UI/[Cc]onfig/appSettings.config
|
||||||
src/Umbraco.Web.UI/[Cc]onfig/connectionStrings.config
|
src/Umbraco.Web.UI/[Cc]onfig/connectionStrings.config
|
||||||
|
src/Umbraco.Web.UI/umbraco/plugins/*
|
||||||
|
|||||||
@@ -204,7 +204,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
|
|||||||
|
|
||||||
//get our angular navigation service
|
//get our angular navigation service
|
||||||
var injector = getRootInjector();
|
var injector = getRootInjector();
|
||||||
var dialogService = injector.get("dialogService");
|
var dialogService = injector.get("dialogService");
|
||||||
|
|
||||||
var self = this;
|
var self = this;
|
||||||
|
|
||||||
@@ -219,12 +219,14 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
|
|||||||
//add the callback to the jquery data for the modal so we can call it on close to support the legacy way dialogs worked.
|
//add the callback to the jquery data for the modal so we can call it on close to support the legacy way dialogs worked.
|
||||||
dialog.element.data("modalCb", onCloseCallback);
|
dialog.element.data("modalCb", onCloseCallback);
|
||||||
//add the close triggers
|
//add the close triggers
|
||||||
for (var i = 0; i < closeTriggers.length; i++) {
|
if (angular.isArray(closeTriggers)) {
|
||||||
var e = dialog.find(closeTriggers[i]);
|
for (var i = 0; i < closeTriggers.length; i++) {
|
||||||
if (e.length > 0) {
|
var e = dialog.find(closeTriggers[i]);
|
||||||
e.click(function() {
|
if (e.length > 0) {
|
||||||
self.closeModalWindow();
|
e.click(function () {
|
||||||
});
|
self.closeModalWindow();
|
||||||
|
});
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -15,25 +15,31 @@ angular.module("umbraco.directives")
|
|||||||
//we'll try to get the jsAction from the injector
|
//we'll try to get the jsAction from the injector
|
||||||
var menuAction = action.metaData["jsAction"].split('.');
|
var menuAction = action.metaData["jsAction"].split('.');
|
||||||
if (menuAction.length !== 2) {
|
if (menuAction.length !== 2) {
|
||||||
throw "The jsAction assigned to a menu action must have two parts delimited by a '.' ";
|
|
||||||
}
|
|
||||||
|
|
||||||
var service = $injector.get(menuAction[0]);
|
//if it is not two parts long then this most likely means that it's a legacy action
|
||||||
if (!service) {
|
var js = action.metaData["jsAction"];
|
||||||
throw "The angular service " + menuAction[0] + " could not be found";
|
//there's not really a different way to acheive this except for eval
|
||||||
}
|
eval(js);
|
||||||
|
|
||||||
var method = service[menuAction[1]];
|
|
||||||
|
|
||||||
if (!method) {
|
|
||||||
throw "The method " + menuAction[1] + " on the angular service " + menuAction[0] + " could not be found";
|
|
||||||
}
|
}
|
||||||
|
else {
|
||||||
|
var service = $injector.get(menuAction[0]);
|
||||||
|
if (!service) {
|
||||||
|
throw "The angular service " + menuAction[0] + " could not be found";
|
||||||
|
}
|
||||||
|
|
||||||
method.apply(this, [{
|
var method = service[menuAction[1]];
|
||||||
treeNode: currentNode,
|
|
||||||
action: action,
|
if (!method) {
|
||||||
section: currentSection
|
throw "The method " + menuAction[1] + " on the angular service " + menuAction[0] + " could not be found";
|
||||||
}]);
|
}
|
||||||
|
|
||||||
|
method.apply(this, [{
|
||||||
|
treeNode: currentNode,
|
||||||
|
action: action,
|
||||||
|
section: currentSection
|
||||||
|
}]);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
//by default we launch the dialog
|
//by default we launch the dialog
|
||||||
|
|||||||
@@ -3,6 +3,7 @@ using System.Collections.Generic;
|
|||||||
using System.IO;
|
using System.IO;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
|
using System.Text.RegularExpressions;
|
||||||
using System.Web.Mvc;
|
using System.Web.Mvc;
|
||||||
using Umbraco.Core.Configuration;
|
using Umbraco.Core.Configuration;
|
||||||
using Umbraco.Core.IO;
|
using Umbraco.Core.IO;
|
||||||
@@ -197,10 +198,75 @@ namespace Umbraco.Web.Editors
|
|||||||
var javascript = new StringBuilder();
|
var javascript = new StringBuilder();
|
||||||
javascript.AppendLine(LegacyTreeJavascript.GetLegacyTreeJavascript());
|
javascript.AppendLine(LegacyTreeJavascript.GetLegacyTreeJavascript());
|
||||||
javascript.AppendLine(LegacyTreeJavascript.GetLegacyIActionJavascript());
|
javascript.AppendLine(LegacyTreeJavascript.GetLegacyIActionJavascript());
|
||||||
|
//add all of the menu blocks
|
||||||
|
foreach (var file in GetLegacyActionJs(LegacyJsActionType.JsBlock))
|
||||||
|
{
|
||||||
|
javascript.AppendLine(file);
|
||||||
|
}
|
||||||
return JavaScript(javascript.ToString());
|
return JavaScript(javascript.ToString());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Renders out all JavaScript blocks that have bee declared in IActions
|
||||||
|
/// </summary>
|
||||||
|
private IEnumerable<string> GetLegacyActionJs(LegacyJsActionType type)
|
||||||
|
{
|
||||||
|
var blockList = new List<string>();
|
||||||
|
var urlList = new List<string>();
|
||||||
|
foreach (var jsFile in global::umbraco.BusinessLogic.Actions.Action.GetJavaScriptFileReferences())
|
||||||
|
{
|
||||||
|
//validate that this is a url, if it is not, we'll assume that it is a text block and render it as a text
|
||||||
|
//block instead.
|
||||||
|
var isValid = true;
|
||||||
|
|
||||||
|
if (Uri.IsWellFormedUriString(jsFile, UriKind.RelativeOrAbsolute))
|
||||||
|
{
|
||||||
|
//ok it validates, but so does alert('hello'); ! so we need to do more checks
|
||||||
|
|
||||||
|
//here are the valid chars in a url without escaping
|
||||||
|
if (Regex.IsMatch(jsFile, @"[^a-zA-Z0-9-._~:/?#\[\]@!$&'\(\)*\+,%;=]"))
|
||||||
|
isValid = false;
|
||||||
|
|
||||||
|
//we'll have to be smarter and just check for certain js patterns now too!
|
||||||
|
var jsPatterns = new string[] {@"\+\s*\=", @"\);", @"function\s*\(", @"!=", @"=="};
|
||||||
|
if (jsPatterns.Any(p => Regex.IsMatch(jsFile, p)))
|
||||||
|
{
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
if (isValid)
|
||||||
|
{
|
||||||
|
//it is a valid URL add to Url list
|
||||||
|
urlList.Add(jsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
isValid = false;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (isValid == false)
|
||||||
|
{
|
||||||
|
//it isn't a valid URL, must be a js block
|
||||||
|
blockList.Add(jsFile);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case LegacyJsActionType.JsBlock:
|
||||||
|
return blockList;
|
||||||
|
case LegacyJsActionType.JsUrl:
|
||||||
|
return urlList;
|
||||||
|
}
|
||||||
|
|
||||||
|
return blockList;
|
||||||
|
}
|
||||||
|
|
||||||
|
private enum LegacyJsActionType
|
||||||
|
{
|
||||||
|
JsBlock,
|
||||||
|
JsUrl
|
||||||
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -28,6 +28,21 @@ namespace Umbraco.Web.Models.Trees
|
|||||||
/// </summary>
|
/// </summary>
|
||||||
internal const string ActionViewKey = "actionView";
|
internal const string ActionViewKey = "actionView";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Used to specify the js method to execute for the menu item
|
||||||
|
/// </summary>
|
||||||
|
internal const string JsActionKey = "jsAction";
|
||||||
|
|
||||||
|
/// <summary>
|
||||||
|
/// Adds the required meta data to the menu item so that angular knows to attempt to call the Js method.
|
||||||
|
/// </summary>
|
||||||
|
/// <param name="menuItem"></param>
|
||||||
|
/// <param name="jsToExecute"></param>
|
||||||
|
public static void LaunchLegacyJs(this MenuItem menuItem, string jsToExecute)
|
||||||
|
{
|
||||||
|
menuItem.SetJsAction(jsToExecute);
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Sets the menu item to display a dialog based on an angular view path
|
/// Sets the menu item to display a dialog based on an angular view path
|
||||||
/// </summary>
|
/// </summary>
|
||||||
@@ -52,6 +67,11 @@ namespace Umbraco.Web.Models.Trees
|
|||||||
menuItem.SetActionUrl(url);
|
menuItem.SetActionUrl(url);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
private static void SetJsAction(this MenuItem menuItem, string jsToExecute)
|
||||||
|
{
|
||||||
|
menuItem.AdditionalData[JsActionKey] = jsToExecute;
|
||||||
|
}
|
||||||
|
|
||||||
/// <summary>
|
/// <summary>
|
||||||
/// Puts a dialog title into the meta data to be displayed on the dialog of the menu item (if there is one)
|
/// Puts a dialog title into the meta data to be displayed on the dialog of the menu item (if there is one)
|
||||||
/// instead of the menu name
|
/// instead of the menu name
|
||||||
|
|||||||
@@ -169,11 +169,11 @@ namespace Umbraco.Web.Models.Trees
|
|||||||
if (attribute.MethodName.IsNullOrWhiteSpace())
|
if (attribute.MethodName.IsNullOrWhiteSpace())
|
||||||
{
|
{
|
||||||
//if no method name is supplied we will assume that the menu action is the type name of the current menu class
|
//if no method name is supplied we will assume that the menu action is the type name of the current menu class
|
||||||
menuItem.AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, this.GetType().Name));
|
menuItem.AdditionalData.Add(MenuItemExtensions.JsActionKey, string.Format("{0}.{1}", attribute.ServiceName, this.GetType().Name));
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
menuItem.AdditionalData.Add("jsAction", string.Format("{0}.{1}", attribute.ServiceName, attribute.MethodName));
|
menuItem.AdditionalData.Add(MenuItemExtensions.JsActionKey, string.Format("{0}.{1}", attribute.ServiceName, attribute.MethodName));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -157,9 +157,10 @@ namespace Umbraco.Web.Trees
|
|||||||
.Try(GetUrlAndTitleFromLegacyAction(currentAction, xmlTreeNode.NodeID, xmlTreeNode.NodeType, xmlTreeNode.Text, currentSection),
|
.Try(GetUrlAndTitleFromLegacyAction(currentAction, xmlTreeNode.NodeID, xmlTreeNode.NodeType, xmlTreeNode.Text, currentSection),
|
||||||
action => menuItem.LaunchDialogUrl(action.Url, action.DialogTitle))
|
action => menuItem.LaunchDialogUrl(action.Url, action.DialogTitle))
|
||||||
.OnFailure(() => GetLegacyConfirmView(currentAction, currentSection),
|
.OnFailure(() => GetLegacyConfirmView(currentAction, currentSection),
|
||||||
view => menuItem.LaunchDialogView(
|
view => menuItem.LaunchDialogView(
|
||||||
view,
|
view,
|
||||||
ui.GetText("defaultdialogs", "confirmdelete") + " '" + xmlTreeNode.Text + "' ?"));
|
ui.GetText("defaultdialogs", "confirmdelete") + " '" + xmlTreeNode.Text + "' ?"))
|
||||||
|
.OnFailure(() => Attempt.Succeed(true), b => menuItem.LaunchLegacyJs(menuItem.Action.JsFunctionName));
|
||||||
|
|
||||||
numAdded++;
|
numAdded++;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user