From 58741848dace8be007b88b524d34a772db5422be Mon Sep 17 00:00:00 2001 From: Robin Neal Date: Fri, 24 Mar 2017 17:01:04 +0000 Subject: [PATCH 1/3] Fix grid editors in nested content - Backup and restore grid config when closing editor containing grids. - Swap ng-if for ng-show to avoid re-initing the RTE. Not ideal, but does work. --- .../NestedContent/Js/nestedcontent.controllers.js | 15 +++++++++++++++ .../NestedContent/Views/nestedcontent.html | 2 +- 2 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js index 05a07b1..45690ac 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js @@ -378,7 +378,10 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest var updateModel = function () { if ($scope.realCurrentNode) { + var currentTabIndex = $scope.nodes.findIndex(getCurrentNodeIndex); + var gridProps = $scope.realCurrentNode.tabs[0].properties.map(backupGridConfig); $scope.$broadcast("ncSyncVal", { id: $scope.realCurrentNode.id }); + $scope.nodes[currentTabIndex].tabs[0].properties = $scope.nodes[currentTabIndex].tabs[0].properties.map(restoreGridConfig.bind(null, gridProps)); } if (inited) { var newValues = []; @@ -423,6 +426,18 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest } return _p8() + _p8(true) + _p8(true) + _p8(); }; + + var getCurrentNodeIndex = function (node) { + return node.id === $scope.realCurrentNode.id; + } + + var backupGridConfig = function (prop) { + return prop.editor == "Umbraco.Grid" ? prop : false; + } + + var restoreGridConfig = function (gridProps, prop, i) { + return gridProps[i] || prop; + } } ]); diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html index 0a98742..2072775 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html @@ -25,7 +25,7 @@ -
+
From 7f1aab55c02dab0a45545a7e3ac777a475489358 Mon Sep 17 00:00:00 2001 From: Robin Neal Date: Mon, 27 Mar 2017 15:38:50 +0100 Subject: [PATCH 2/3] Add callback service to enable extending the Nested Content plugin --- .../Js/nestedcontent.directives.js | 9 +++++-- .../Js/nestedcontent.services.js | 25 +++++++++++++++++++ .../NestedContent/package.manifest | 3 ++- 3 files changed, 34 insertions(+), 3 deletions(-) create mode 100644 src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.services.js diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.directives.js b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.directives.js index 01e3794..a2fc50c 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.directives.js +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.directives.js @@ -1,6 +1,8 @@ angular.module("umbraco.directives").directive('nestedContentEditor', [ - function () { + "Our.Umbraco.NestedContent.Services.NestedContentCallbacks", + + function (NestedContentCallbacks) { var link = function ($scope) { @@ -29,6 +31,9 @@ var unsubscribe = $scope.$on("ncSyncVal", function (ev, args) { if (args.id === $scope.model.id) { + // Run callback + NestedContentCallbacks.call("ncBeforeFormSubmitting", { scope: $scope }); + // Tell inner controls we are submitting $scope.$broadcast("formSubmitting", { scope: $scope }); @@ -94,4 +99,4 @@ // }, // link: link // } -//}); \ No newline at end of file +//}); diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.services.js b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.services.js new file mode 100644 index 0000000..cfbf763 --- /dev/null +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.services.js @@ -0,0 +1,25 @@ +angular.module('umbraco.services').factory('Our.Umbraco.NestedContent.Services.NestedContentCallbacks', + + function() { + // Define available callbacks + var callbacks = { + 'ncBeforeFormSubmitting': [] + }; + + return { + + callbacks: callbacks, + + call: function(cb, args) { + cb = this.callbacks[cb]; + if ( cb && Array.isArray(cb) && cb.length ) { + cb.forEach(function(func) { + typeof func != "function" || func(args); + }); + } + } + + }; + } + +); diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/package.manifest b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/package.manifest index 62fa763..a475a70 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/package.manifest +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/package.manifest @@ -3,7 +3,8 @@ '~/App_Plugins/NestedContent/Js/nestedcontent.filters.js', '~/App_Plugins/NestedContent/Js/nestedcontent.resources.js', '~/App_Plugins/NestedContent/Js/nestedcontent.directives.js', - '~/App_Plugins/NestedContent/Js/nestedcontent.controllers.js' + '~/App_Plugins/NestedContent/Js/nestedcontent.controllers.js', + '~/App_Plugins/NestedContent/Js/nestedcontent.services.js' ], "css" : [ "~/App_Plugins/NestedContent/Css/nestedcontent.css" From e373dfe0c9ed32b47375d5c469895be1625b66d4 Mon Sep 17 00:00:00 2001 From: Robin Neal Date: Mon, 27 Mar 2017 15:41:55 +0100 Subject: [PATCH 3/3] Remove original solution --- .../Js/nestedcontent.controllers.js | 23 ++++--------------- .../NestedContent/Views/nestedcontent.html | 2 +- 2 files changed, 5 insertions(+), 20 deletions(-) diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js index 45690ac..72d4aac 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Js/nestedcontent.controllers.js @@ -1,4 +1,4 @@ -angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.DocTypePickerController", [ +angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.DocTypePickerController", [ "$scope", "Our.Umbraco.NestedContent.Resources.NestedContentResources", @@ -8,7 +8,7 @@ $scope.add = function () { $scope.model.value.push({ // As per PR #4, all stored content type aliases must be prefixed "nc" for easier recognition. - // For good measure we'll also prefix the tab alias "nc" + // For good measure we'll also prefix the tab alias "nc" ncAlias: "", ncTabAlias: "", nameTemplate: "" @@ -305,7 +305,7 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest var initIfAllScaffoldsHaveLoaded = function () { // Initialize when all scaffolds have loaded if ($scope.model.config.contentTypes.length == scaffoldsLoaded) { - // Because we're loading the scaffolds async one at a time, we need to + // Because we're loading the scaffolds async one at a time, we need to // sort them explicitly according to the sort order defined by the data type. var contentTypeAliases = []; _.each($scope.model.config.contentTypes, function (contentType) { @@ -356,7 +356,7 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest var prop = tab.properties[p]; prop.propertyAlias = prop.alias; prop.alias = $scope.model.alias + "___" + prop.alias; - // Force validation to occur server side as this is the + // Force validation to occur server side as this is the // only way we can have consistancy between mandatory and // regex validation messages. Not ideal, but it works. prop.validation = { @@ -378,10 +378,7 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest var updateModel = function () { if ($scope.realCurrentNode) { - var currentTabIndex = $scope.nodes.findIndex(getCurrentNodeIndex); - var gridProps = $scope.realCurrentNode.tabs[0].properties.map(backupGridConfig); $scope.$broadcast("ncSyncVal", { id: $scope.realCurrentNode.id }); - $scope.nodes[currentTabIndex].tabs[0].properties = $scope.nodes[currentTabIndex].tabs[0].properties.map(restoreGridConfig.bind(null, gridProps)); } if (inited) { var newValues = []; @@ -426,18 +423,6 @@ angular.module("umbraco").controller("Our.Umbraco.NestedContent.Controllers.Nest } return _p8() + _p8(true) + _p8(true) + _p8(); }; - - var getCurrentNodeIndex = function (node) { - return node.id === $scope.realCurrentNode.id; - } - - var backupGridConfig = function (prop) { - return prop.editor == "Umbraco.Grid" ? prop : false; - } - - var restoreGridConfig = function (gridProps, prop, i) { - return gridProps[i] || prop; - } } ]); diff --git a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html index 2072775..0a98742 100644 --- a/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html +++ b/src/Our.Umbraco.NestedContent/Web/UI/App_Plugins/NestedContent/Views/nestedcontent.html @@ -25,7 +25,7 @@ -
+