From 019ac523098f79361e5ecd93d585212903912760 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 22 Mar 2019 16:06:07 +0100 Subject: [PATCH 1/4] emit "editors.dataTypeSettings.saved"-event --- .../datatypesettings.controller.js | 45 +++++++++++-------- 1 file changed, 26 insertions(+), 19 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/datatypesettings/datatypesettings.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/datatypesettings/datatypesettings.controller.js index 099439fa4b08..46a4238c0cdd 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/datatypesettings/datatypesettings.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/datatypesettings/datatypesettings.controller.js @@ -10,7 +10,8 @@ (function () { "use strict"; - function DataTypeSettingsController($scope, dataTypeResource, dataTypeHelper, localizationService, notificationsService, overlayService, formHelper) { + function DataTypeSettingsController($scope, dataTypeResource, dataTypeHelper, + localizationService, notificationsService, overlayService, formHelper, eventsService) { var vm = this; @@ -103,27 +104,33 @@ var preValues = dataTypeHelper.createPreValueProps(vm.dataType.preValues); - dataTypeResource.save(vm.dataType, preValues, $scope.model.create).then(function(newDataType) { - $scope.model.dataType = newDataType; - vm.saveButtonState = "success"; - - if ($scope.model && $scope.model.submit) { - $scope.model.submit($scope.model); - } - }, function(err) { - vm.saveButtonState = "error"; - - if(err.status === 400) { - if (err.data && (err.data.ModelState)) { - - formHelper.handleServerValidation(err.data.ModelState); - - for (var e in err.data.ModelState) { - notificationsService.error("Validation", err.data.ModelState[e][0]); + dataTypeResource.save(vm.dataType, preValues, $scope.model.create).then( + function(newDataType) { + $scope.model.dataType = newDataType; + + var args = { dataType: newDataType }; + eventsService.emit("editors.dataTypeSettings.saved", args); + + vm.saveButtonState = "success"; + + if ($scope.model && $scope.model.submit) { + $scope.model.submit($scope.model); + } + }, function(err) { + vm.saveButtonState = "error"; + + if(err.status === 400) { + if (err.data && (err.data.ModelState)) { + + formHelper.handleServerValidation(err.data.ModelState); + + for (var e in err.data.ModelState) { + notificationsService.error("Validation", err.data.ModelState[e][0]); + } } } } - }); + ); } From af4dc97b10505848e519535f32562a31de3acf23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 22 Mar 2019 16:06:39 +0100 Subject: [PATCH 2/4] changed ' to " --- .../components/content/umbcontentnodeinfo.directive.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js index d4b617f94bef..e58ff14e211e 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbcontentnodeinfo.directive.js @@ -147,7 +147,7 @@ id: documentType.id, submit: function (model) { const args = { node: scope.node }; - eventsService.emit('editors.content.reload', args); + eventsService.emit("editors.content.reload", args); editorService.close(); }, close: function () { From da503cc9b5730cb01611dbe16761956215b3bb51 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 22 Mar 2019 16:19:56 +0100 Subject: [PATCH 3/4] listen for "editors.dataTypeSettings.saved" --- .../components/umbgroupsbuilder.directive.js | 54 ++++++++++++++----- 1 file changed, 42 insertions(+), 12 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js index 15f5a1d46afa..da51528bd2f8 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/umbgroupsbuilder.directive.js @@ -1,13 +1,17 @@ (function() { 'use strict'; - function GroupsBuilderDirective(contentTypeHelper, contentTypeResource, mediaTypeResource, dataTypeHelper, dataTypeResource, $filter, iconHelper, $q, $timeout, notificationsService, localizationService, editorService) { + function GroupsBuilderDirective(contentTypeHelper, contentTypeResource, mediaTypeResource, + dataTypeHelper, dataTypeResource, $filter, iconHelper, $q, $timeout, notificationsService, + localizationService, editorService, eventsService) { function link(scope, el, attr, ctrl) { - + + var eventBindings = []; var validationTranslated = ""; var tabNoSortOrderTranslated = ""; + scope.dataTypeHasChanged = false; scope.sortingMode = false; scope.toolbar = []; scope.sortableOptionsGroup = {}; @@ -613,18 +617,44 @@ }); }); } - - - var unbindModelWatcher = scope.$watch('model', function(newValue, oldValue) { - if (newValue !== undefined && newValue.groups !== undefined) { - activate(); + + function hasPropertyOfDataTypeId(dataTypeId) { + + // look at each property + var result = _.filter(scope.model.groups, function(group) { + return _.filter(group.properties, function(property) { + return (property.dataTypeId === dataTypeId); + }); + }); + + return (result.length > 0); } - }); - // clean up - scope.$on('$destroy', function(){ - unbindModelWatcher(); - }); + + eventBindings.push(scope.$watch('model', function(newValue, oldValue) { + if (newValue !== undefined && newValue.groups !== undefined) { + activate(); + } + })); + + // clean up + eventBindings.push(eventsService.on("editors.dataTypeSettings.saved", function (name, args) { + if(hasPropertyOfDataTypeId(args.dataType.id)) { + scope.dataTypeHasChanged = true; + } + })); + + // clean up + eventBindings.push(scope.$on('$destroy', function() { + for(var e in eventBindings) { + eventBindings[e](); + } + // if a dataType has changed, we want to notify which properties that are affected by this dataTypeSettings change + if(scope.dataTypeHasChanged === true) { + var args = {documentType: scope.model}; + eventsService.emit("editors.documentType.saved", args); + } + })); } From d806855698d374378bae65878cb4c006d76eb22c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niels=20Lyngs=C3=B8?= Date: Fri, 22 Mar 2019 16:22:36 +0100 Subject: [PATCH 4/4] listen for "editors.documentType.saved" instead of "editors.content.reload" --- .../components/content/edit.controller.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js index 80b5f4ed3971..a7ce013bc359 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/edit.controller.js @@ -116,6 +116,13 @@ function isContentCultureVariant() { return $scope.content.variants.length > 1; } + + function reload() { + $scope.page.loading = true; + loadContent().then(function() { + $scope.page.loading = false; + }); + } function bindEvents() { //bindEvents can be called more than once and we don't want to have multiple bound events @@ -123,13 +130,10 @@ eventsService.unsubscribe(evts[e]); } - evts.push(eventsService.on("editors.content.reload", function (name, args) { + evts.push(eventsService.on("editors.documentType.saved", function (name, args) { // if this content item uses the updated doc type we need to reload the content item - if(args && args.node && args.node.key === $scope.content.key) { - $scope.page.loading = true; - loadContent().then(function() { - $scope.page.loading = false; - }); + if(args && args.documentType && $scope.content.documentType.id === args.documentType.id) { + reload(); } }));