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 3f53a1e18c..4b5b3dc955 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 @@ -281,6 +281,8 @@ }, selectCompositeContentType: function (selectedContentType) { + var deferred = $q.defer(); + //first check if this is a new selection - we need to store this value here before any further digests/async // because after that the scope.model.compositeContentTypes will be populated with the selected value. var newSelection = scope.model.compositeContentTypes.indexOf(selectedContentType.alias) === -1; @@ -308,7 +310,10 @@ //based on the selection, we need to filter the available composite types list filterAvailableCompositions(selectedContentType, newSelection).then(function () { + deferred.resolve({ selectedContentType, newSelection }); // TODO: Here we could probably re-enable selection if we previously showed a throbber or something + }, function () { + deferred.reject(); }); }); } @@ -318,10 +323,14 @@ //based on the selection, we need to filter the available composite types list filterAvailableCompositions(selectedContentType, newSelection).then(function () { + deferred.resolve({ selectedContentType, newSelection }); // TODO: Here we could probably re-enable selection if we previously showed a throbber or something + }, function () { + deferred.reject(); }); } + return deferred.promise; } }; diff --git a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.controller.js b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.controller.js index aa0cd54dff..ab8c133211 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.controller.js +++ b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.controller.js @@ -1,15 +1,17 @@ (function () { "use strict"; - function CompositionsController($scope, $location, $filter, overlayService, localizationService) { + function CompositionsController($scope, $location, $filter, $timeout, overlayService, localizationService) { var vm = this; var oldModel = null; vm.showConfirmSubmit = false; + vm.loading = false; vm.isSelected = isSelected; vm.openContentType = openContentType; + vm.selectCompositeContentType = selectCompositeContentType; vm.submit = submit; vm.close = close; @@ -23,10 +25,13 @@ $scope.model.title = "Compositions"; } - // group the content types by their container paths + // Group the content types by their container paths vm.availableGroups = $filter("orderBy")( _.map( _.groupBy($scope.model.availableCompositeContentTypes, function (compositeContentType) { + + compositeContentType.selected = isSelected(compositeContentType.contentType.alias); + return compositeContentType.contentType.metaData.containerPath; }), function (group) { return { @@ -39,12 +44,12 @@ }); } - - + function isSelected(alias) { if ($scope.model.contentType.compositeContentTypes.indexOf(alias) !== -1) { return true; } + return false; } function openContentType(contentType, section) { @@ -52,6 +57,43 @@ $location.path(url); } + function selectCompositeContentType(compositeContentType) { + + vm.loading = true; + + var contentType = compositeContentType.contentType; + + $scope.model.selectCompositeContentType(contentType).then(function (response) { + + Utilities.forEach(vm.availableGroups, function (group) { + + Utilities.forEach(group.compositeContentTypes, function (obj) { + if (obj.allowed === false) { + obj.selected = false; + } + }); + }); + + $timeout(function () { + vm.loading = false; + }, 500); + + }, function () { + $timeout(function () { + vm.loading = false; + }, 500); + }); + + // Check if the template is already selected. + var index = $scope.model.contentType.compositeContentTypes.indexOf(contentType.alias); + + if (index === -1) { + $scope.model.contentType.compositeContentTypes.push(contentType.alias); + } else { + $scope.model.contentType.compositeContentTypes.splice(index, 1); + } + } + function submit() { if ($scope.model && $scope.model.submit) { diff --git a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.html b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.html index 4096192081..436c4ea30a 100644 --- a/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.html +++ b/src/Umbraco.Web.UI.Client/src/views/common/infiniteeditors/compositions/compositions.html @@ -19,38 +19,39 @@
- +
- - + + - + +
+ +
+