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:
Shannon
2013-10-14 18:47:34 +11:00
parent df25edfaf6
commit d9c42e2aca
7 changed files with 124 additions and 28 deletions

3
.gitignore vendored
View File

@@ -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/[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/*

View File

@@ -204,7 +204,7 @@ Umbraco.Sys.registerNamespace("Umbraco.Application");
//get our angular navigation service
var injector = getRootInjector();
var dialogService = injector.get("dialogService");
var dialogService = injector.get("dialogService");
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.
dialog.element.data("modalCb", onCloseCallback);
//add the close triggers
for (var i = 0; i < closeTriggers.length; i++) {
var e = dialog.find(closeTriggers[i]);
if (e.length > 0) {
e.click(function() {
self.closeModalWindow();
});
if (angular.isArray(closeTriggers)) {
for (var i = 0; i < closeTriggers.length; i++) {
var e = dialog.find(closeTriggers[i]);
if (e.length > 0) {
e.click(function () {
self.closeModalWindow();
});
}
}
}

View File

@@ -15,25 +15,31 @@ angular.module("umbraco.directives")
//we'll try to get the jsAction from the injector
var menuAction = action.metaData["jsAction"].split('.');
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 (!service) {
throw "The angular service " + menuAction[0] + " could not be found";
}
//if it is not two parts long then this most likely means that it's a legacy action
var js = action.metaData["jsAction"];
//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, [{
treeNode: currentNode,
action: action,
section: currentSection
}]);
var method = service[menuAction[1]];
if (!method) {
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 {
//by default we launch the dialog

View File

@@ -3,6 +3,7 @@ using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Web.Mvc;
using Umbraco.Core.Configuration;
using Umbraco.Core.IO;
@@ -197,10 +198,75 @@ namespace Umbraco.Web.Editors
var javascript = new StringBuilder();
javascript.AppendLine(LegacyTreeJavascript.GetLegacyTreeJavascript());
javascript.AppendLine(LegacyTreeJavascript.GetLegacyIActionJavascript());
//add all of the menu blocks
foreach (var file in GetLegacyActionJs(LegacyJsActionType.JsBlock))
{
javascript.AppendLine(file);
}
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
}
}
}

View File

@@ -28,6 +28,21 @@ namespace Umbraco.Web.Models.Trees
/// </summary>
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>
/// Sets the menu item to display a dialog based on an angular view path
/// </summary>
@@ -52,6 +67,11 @@ namespace Umbraco.Web.Models.Trees
menuItem.SetActionUrl(url);
}
private static void SetJsAction(this MenuItem menuItem, string jsToExecute)
{
menuItem.AdditionalData[JsActionKey] = jsToExecute;
}
/// <summary>
/// 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

View File

@@ -169,11 +169,11 @@ namespace Umbraco.Web.Models.Trees
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
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
{
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));
}
}
}

View File

@@ -157,9 +157,10 @@ namespace Umbraco.Web.Trees
.Try(GetUrlAndTitleFromLegacyAction(currentAction, xmlTreeNode.NodeID, xmlTreeNode.NodeType, xmlTreeNode.Text, currentSection),
action => menuItem.LaunchDialogUrl(action.Url, action.DialogTitle))
.OnFailure(() => GetLegacyConfirmView(currentAction, currentSection),
view => menuItem.LaunchDialogView(
view,
ui.GetText("defaultdialogs", "confirmdelete") + " '" + xmlTreeNode.Text + "' ?"));
view => menuItem.LaunchDialogView(
view,
ui.GetText("defaultdialogs", "confirmdelete") + " '" + xmlTreeNode.Text + "' ?"))
.OnFailure(() => Attempt.Succeed(true), b => menuItem.LaunchLegacyJs(menuItem.Action.JsFunctionName));
numAdded++;
}