diff --git a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js index a188a83d83..c353d5c2fe 100644 --- a/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js +++ b/src/Umbraco.Web.UI.Client/src/common/directives/components/content/umbvariantcontenteditors.directive.js @@ -20,7 +20,7 @@ controller: umbVariantContentEditorsController }; - function umbVariantContentEditorsController($scope, $location, contentEditingHelper) { + function umbVariantContentEditorsController($scope, $location, eventsService) { var prevContentDateUpdated = null; @@ -36,6 +36,7 @@ vm.selectVariant = selectVariant; vm.selectApp = selectApp; vm.selectAppAnchor = selectAppAnchor; + vm.requestSplitView = requestSplitView; //Used to track how many content views there are (for split view there will be 2, it could support more in theory) vm.editors = []; @@ -66,7 +67,7 @@ /** Allows us to deep watch whatever we want - executes on every digest cycle */ function doCheck() { - if (!angular.equals(vm.content.updateDate, prevContentDateUpdated)) { + if (!Utilities.equals(vm.content.updateDate, prevContentDateUpdated)) { setActiveVariant(); prevContentDateUpdated = Utilities.copy(vm.content.updateDate); } @@ -84,11 +85,12 @@ function setActiveVariant() { // set the active variant var activeVariant = null; - _.each(vm.content.variants, function (v) { + vm.content.variants.forEach(v => { if ((vm.culture === "invariant" || v.language && v.language.culture === vm.culture) && v.segment === vm.segment) { activeVariant = v; } }); + if (!activeVariant) { // Set the first variant to active if we can't find it. // If the content item is invariant, then only one item exists in the array. @@ -101,13 +103,14 @@ //now re-sync any other editor content (i.e. if split view is open) for (var s = 1; s < vm.editors.length; s++) { //get the variant from the scope model - var variant = _.find(vm.content.variants, function (v) { - return (!v.language || v.language.culture === vm.editors[s].content.language.culture) && v.segment === vm.editors[s].content.segment; - }); + var variant = vm.content.variants.find(v => + (!v.language || v.language.culture === vm.editors[s].content.language.culture) && v.segment === vm.editors[s].content.segment); + vm.editors[s].content = variant; } } + eventsService.emit('editors.content.cultureChanged', activeVariant.language.culture); } /** @@ -158,32 +161,30 @@ */ function openSplitView(selectedVariant) { // enforce content contentApp in splitview. - var contentApp = vm.content.apps.find((app) => app.alias === "umbContent"); + var contentApp = vm.content.apps.find(app => app.alias === "umbContent"); if(contentApp) { selectApp(contentApp); } insertVariantEditor(vm.editors.length, selectedVariant); - splitViewChanged(); - + splitViewChanged(); } - - $scope.$on("editors.content.splitViewRequest", function(event, args) {requestSplitView(args);}); - vm.requestSplitView = requestSplitView; + function requestSplitView(args) { var culture = args.culture; var segment = args.segment; - var variant = _.find(vm.content.variants, function (v) { - return (!v.language || v.language.culture === culture) && v.segment === segment; - }); + var variant = vm.content.variants.find(v => + (!v.language || v.language.culture === culture) && v.segment === segment); if (variant != null) { openSplitView(variant); } } + eventsService.on("editors.content.splitViewRequest", (_, args) => requestSplitView(args)); + /** Closes the split view */ function closeSplitView(editorIndex) { // TODO: hacking animation states - these should hopefully be easier to do when we upgrade angular @@ -192,8 +193,9 @@ editor.content.active = false; //update the current culture to reflect the last open variant (closing the split view corresponds to selecting the other variant) - - $location.search({"cculture": vm.editors[0].content.language ? vm.editors[0].content.language.culture : null, "csegment": vm.editors[0].content.segment}); + const culture = vm.editors[0].content.language ? vm.editors[0].content.language.culture : null; + + $location.search({"cculture": culture, "csegment": vm.editors[0].content.segment}); splitViewChanged(); } @@ -220,11 +222,9 @@ $location.search("cculture", variantCulture).search("csegment", variantSegment); } else { - //update the editors collection - insertVariantEditor(editorIndex, variant); - - } + insertVariantEditor(editorIndex, variant); + } } /** @@ -242,7 +242,6 @@ vm.onSelectAppAnchor({"app": app, "anchor": anchor}); } } - } angular.module('umbraco.directives').component('umbVariantContentEditors', umbVariantContentEditors);