diff --git a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.directives.js b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.directives.js index 212b104..4f83771 100644 --- a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.directives.js +++ b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.directives.js @@ -11,6 +11,7 @@ angular.module('umbraco.directives').directive('unContent', function ($compile) }, link: function (scope, element) { + // get template var template = scope.config && scope.config.nameTemplate ? scope.config.nameTemplate : null; @@ -33,10 +34,22 @@ angular.module('umbraco.directives').directive('unContent', function ($compile) $compile(element.contents())(scope); } - //scope.$watch('item', function (value) + //var unsubscribe = scope.$on("ncSyncVal", function (ev, args) //{ - // render(); + // if (args.key === scope.node.key) + // { + // render(); + // } //}); + var unsubscribe = scope.$watch('item', function (value) + { + render(); + }); + + scope.$on('$destroy', function () + { + unsubscribe(); + }); // first-time rendering render(); @@ -367,53 +380,67 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [ { var link = function ($scope) { - // Clone the model because some property editors - // do weird things like updating and config values - // so we want to ensure we start from a fresh every - // time, we'll just sync the value back when we need to - $scope.model = angular.copy($scope.ngModel); - $scope.nodeContext = $scope.model; - - // Find the selected tab - var selectedTab = $scope.model.variants[0].tabs[0]; - - if ($scope.tabAlias) + var createModel = function () { - angular.forEach($scope.model.variants[0].tabs, function (tab) + // Clone the model because some property editors + // do weird things like updating and config values + // so we want to ensure we start from a fresh every + // time, we'll just sync the value back when we need to + $scope.model = angular.copy($scope.ngModel); + $scope.nodeContext = $scope.model; + + // Find the selected tab + $scope.selectedTab = $scope.model.variants[0].tabs[0]; + + if ($scope.tabAlias) { - if (tab.alias.toLowerCase() === $scope.tabAlias.toLowerCase()) + angular.forEach($scope.model.variants[0].tabs, function (tab) { - selectedTab = tab; - return; - } + if (tab.alias.toLowerCase() === $scope.tabAlias.toLowerCase()) + { + $scope.selectedTab = tab; + return; + } + }); + } + + $scope.tabs = $scope.model.variants[0].tabs; + + var contentTab = _.find($scope.tabs, function (tab) + { + var alias = tab.alias.toLowerCase(); + return tab.id !== 0 && alias !== 'unestingsettings' && (!$scope.tabAlias || alias === $scope.tabAlias.toLowerCase()); }); - } - $scope.tabs = $scope.model.variants[0].tabs; + $scope.contentProperties = _.filter(contentTab.properties, function (prop) + { + return prop.propertyAlias.toLowerCase() !== 'unestinghide'; + }); - var contentTab = _.find($scope.tabs, function (tab) + //var settingsTab = _.find($scope.tabs, function (tab) + //{ + // var alias = tab.alias.toLowerCase(); + // return tab.id !== 0 && alias === 'unestingsettings'; + //}); + + //$scope.settingsProperties = settingsTab ? settingsTab.properties : []; + $scope.settingsProperties = []; + }; + + // Listen for incoming changes + var unsubscribeIn = $scope.$on("ncSyncInVal", function (ev, args) { - var alias = tab.alias.toLowerCase(); - return tab.id !== 0 && alias !== 'unestingsettings' && (!$scope.tabAlias || alias === $scope.tabAlias.toLowerCase()); + if (args.key === $scope.model.key) + { + createModel(); + } }); - $scope.contentProperties = _.filter(contentTab.properties, function (prop) - { - return prop.propertyAlias.toLowerCase() !== 'unestinghide'; - }); - - //var settingsTab = _.find($scope.tabs, function (tab) - //{ - // var alias = tab.alias.toLowerCase(); - // return tab.id !== 0 && alias === 'unestingsettings'; - //}); - - //$scope.settingsProperties = settingsTab ? settingsTab.properties : []; - $scope.settingsProperties = []; - // Listen for sync request var unsubscribe = $scope.$on("ncSyncVal", function (ev, args) { + unsubscribeIn(); + if (args.key === $scope.model.key) { // Tell inner controls we are submitting @@ -422,10 +449,10 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [ // Sync the values back angular.forEach($scope.ngModel.variants[0].tabs, function (tab) { - if (tab.alias.toLowerCase() === selectedTab.alias.toLowerCase()) + if (tab.alias.toLowerCase() === $scope.selectedTab.alias.toLowerCase()) { - var localPropsMap = selectedTab.properties.reduce(function (map, obj) + var localPropsMap = $scope.selectedTab.properties.reduce(function (map, obj) { map[obj.alias] = obj; return map; @@ -448,6 +475,8 @@ angular.module("umbraco.directives").directive('uNestingContentEditor', [ { unsubscribe(); }); + + createModel(); }; return { diff --git a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.html b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.html index b94af14..afe2845 100644 --- a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.html +++ b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.html @@ -16,7 +16,7 @@
+ ng-class="{ 'is-active' : $parent.realCurrentNode.key === node.key, 'umb-nested-content__item--single' : $parent.singleMode, 'is-hidden': isHidden(model.value[$index], node) }">
diff --git a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.js b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.js index 39bb920..23d5cf6 100644 --- a/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.js +++ b/UmbracoPackages/App_Plugins/brothers.uNesting/uNesting.js @@ -637,9 +637,6 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController unsubscribe(); }); - - - $scope.clickHide = function ($event, node, alias) { $event.preventDefault(); @@ -653,15 +650,30 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController var property = _.find(tab.properties, function (prop) { - return tab.id !== 0 && prop.propertyAlias.toLowerCase() === 'unestinghide'; + return prop.propertyAlias.toLowerCase() === 'unestinghide'; }); if (property) { property.value = property.value === '1' ? '0' : '1'; + + $scope.setDirty(); + + if ($scope.inited) + { + var newValues = []; + for (var i = 0; i < $scope.nodes.length; i++) + { + newValues.push(convertNodeIntoNCEntry($scope.nodes[i])); + } + $scope.model.value = newValues; + } } - updateModel(); + //if ($scope.realCurrentNode) + //{ + // $scope.$broadcast("ncSyncInVal", { key: $scope.realCurrentNode.key }); + //} }; $scope.canHide = function (item) @@ -669,7 +681,7 @@ angular.module("umbraco").controller("brothers.uNesting.PropertyEditorController return typeof item['uNestingHide'] !== 'undefined'; }; - $scope.isHidden = function (item) + $scope.isHidden = function (item, node) { return item['uNestingHide'] === '1'; }; diff --git a/UmbracoPackages/UnestingController.cs b/UmbracoPackages/UnestingController.cs index 047b929..a0b9249 100644 --- a/UmbracoPackages/UnestingController.cs +++ b/UmbracoPackages/UnestingController.cs @@ -42,6 +42,11 @@ namespace UmbracoPackages /// public Dictionary GetMediaByUdis([FromUri]Udi[] ids) { + if (ids == null || ids.Length == 0 || (ids.Length == 1 && ids[0] == default(Udi))) + { + return new Dictionary(); + } + var foundMedia = Services.MediaService.GetByIds(ids.Select(x => (x as GuidUdi).Guid)); return foundMedia.ToDictionary(media => (Udi)media.GetUdi(), media => {