From 259e17b45df5b1182c7061e9b7a8f7f59fc4ecbc Mon Sep 17 00:00:00 2001 From: Mads Rasmussen Date: Tue, 13 Nov 2018 14:25:15 +0100 Subject: [PATCH] open context menu dialog based on appState instead of dialogService --- .../umbcontextdialog.directive.js | 21 ++++++ .../src/common/services/appstate.service.js | 2 + .../src/common/services/navigation.service.js | 65 +++---------------- .../src/controllers/navigation.controller.js | 3 + .../application/umb-navigation.html | 14 ++-- .../umbcontextdialog/umb-context-dialog.html | 6 ++ 6 files changed, 46 insertions(+), 65 deletions(-) create mode 100644 src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js create mode 100644 src/Umbraco.Web.UI.Client/src/views/components/tree/umbcontextdialog/umb-context-dialog.html diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js new file mode 100644 index 0000000000..535ba2fbc8 --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/tree/umbcontextdialog/umbcontextdialog.directive.js @@ -0,0 +1,21 @@ +(function() { + 'use strict'; + + function UmbContextDialog() { + + var directive = { + restrict: 'E', + transclude: true, + templateUrl: "views/components/tree/umbcontextdialog/umb-context-dialog.html", + scope: { + title: "<", + currentNode: "<", + view: "<" + } + }; + return directive; + } + + angular.module('umbraco.directives').directive('umbContextDialog', UmbContextDialog); + +})(); diff --git a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js index d1ac3d39cf..de53f7ecea 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/appstate.service.js @@ -70,6 +70,8 @@ function appState(eventsService) { currentNode: null, //Whether the menu's dialog is being shown or not showMenuDialog: null, + // The dialogs template + dialogTemplateUrl: null, //Whether the context menu is being shown or not showMenu: null }; diff --git a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js index bda50be860..d8370e99e0 100644 --- a/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js +++ b/src/Umbraco.Web.UI.Client/src/common/services/navigation.service.js @@ -404,19 +404,13 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i //NOTE: This is assigning the current action node - this is not the same as the currently selected node! appState.setMenuState("currentNode", args.node); - //ensure the current dialog is cleared before creating another! - if (currentDialog) { - dialogService.close(currentDialog); - } - - var dialog = self.showDialog({ + self.showDialog({ node: args.node, action: found, section: appState.getSectionState("currentSection") }); - //return the dialog this is opening. - return $q.resolve(dialog); + return $q.resolve(); } } @@ -545,22 +539,6 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i throw "The args parameter must have a 'node' as the active tree node"; } - //ensure the current dialog is cleared before creating another! - if (currentDialog) { - dialogService.close(currentDialog); - currentDialog = null; - } - - setMode("dialog"); - - //NOTE: Set up the scope object and assign properties, this is legacy functionality but we have to live with it now. - // we should be passing in currentNode and currentAction using 'dialogData' for the dialog, not attaching it to a scope. - // This scope instance will be destroyed by the dialog so it cannot be a scope that exists outside of the dialog. - // If a scope instance has been passed in, we'll have to create a child scope of it, otherwise a new root scope. - var dialogScope = args.scope ? args.scope.$new() : $rootScope.$new(); - dialogScope.currentNode = args.node; - dialogScope.currentAction = args.action; - //the title might be in the meta data, check there first if (args.action.metaData["dialogTitle"]) { appState.setMenuState("dialogTitle", args.action.metaData["dialogTitle"]); @@ -570,15 +548,9 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i } var templateUrl; - var iframe; - if (args.action.metaData["actionUrl"]) { - templateUrl = args.action.metaData["actionUrl"]; - iframe = true; - } - else if (args.action.metaData["actionView"]) { + if (args.action.metaData["actionView"]) { templateUrl = args.action.metaData["actionView"]; - iframe = false; } else { @@ -604,35 +576,14 @@ function navigationService($rootScope, $routeParams, $location, $q, $timeout, $i templateUrl = "views/" + treeAlias + "/" + args.action.alias + ".html"; } - iframe = false; } - //TODO: some action's want to launch a new window like live editing, we support this in the menu item's metadata with - // a key called: "actionUrlMethod" which can be set to either: Dialog, BlankWindow. Normally this is always set to Dialog - // if a URL is specified in the "actionUrl" metadata. For now I'm not going to implement launching in a blank window, - // though would be v-easy, just not sure we want to ever support that? + setMode("dialog"); - var dialog = dialogService.open( - { - container: $("#dialog div.umb-modalcolumn-body"), - //The ONLY reason we're passing in scope to the dialogService (which is legacy functionality) is - // for backwards compatibility since many dialogs require $scope.currentNode or $scope.currentAction - // to exist - scope: dialogScope, - inline: true, - show: true, - iframe: iframe, - modalClass: "umb-dialog", - template: templateUrl, - - //These will show up on the dialog controller's $scope under dialogOptions - currentNode: args.node, - currentAction: args.action - }); - - //save the currently assigned dialog so it can be removed before a new one is created - currentDialog = dialog; - return dialog; + if(templateUrl) { + appState.setMenuState("dialogTemplateUrl", templateUrl); + } + }, /** diff --git a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js index 3161f36172..7c26317cea 100644 --- a/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js +++ b/src/Umbraco.Web.UI.Client/src/controllers/navigation.controller.js @@ -168,6 +168,9 @@ function NavigationController($scope, $rootScope, $location, $log, $q, $routePar if (args.key === "showMenuDialog") { $scope.showContextMenuDialog = args.value; } + if (args.key === "dialogTemplateUrl") { + $scope.dialogTemplateUrl = args.value; + } if (args.key === "showMenu") { $scope.showContextMenu = args.value; } diff --git a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html index ddb0396f34..8cb687daca 100644 --- a/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html +++ b/src/Umbraco.Web.UI.Client/src/views/components/application/umb-navigation.html @@ -36,15 +36,13 @@ + + - -
-
-

{{menuDialogTitle}}

-
-
-
-
diff --git a/src/Umbraco.Web.UI.Client/src/views/components/tree/umbcontextdialog/umb-context-dialog.html b/src/Umbraco.Web.UI.Client/src/views/components/tree/umbcontextdialog/umb-context-dialog.html new file mode 100644 index 0000000000..96cfc29c4f --- /dev/null +++ b/src/Umbraco.Web.UI.Client/src/views/components/tree/umbcontextdialog/umb-context-dialog.html @@ -0,0 +1,6 @@ +
+
+

{{title}}

+
+
+
\ No newline at end of file