From 7bc9584940010fb6cead1cde7e67e38b7f4c4f40 Mon Sep 17 00:00:00 2001 From: kjac Date: Mon, 12 Jun 2017 22:26:03 +0200 Subject: [PATCH] Add min fieldsets handling --- .../Models/ArchetypePreValue.cs | 3 +++ app/controllers/controller.js | 16 +++++++++++++++- app/views/archetype.config.fieldset.dialog.html | 4 ++++ app/views/archetype.default.html | 4 ++++ 4 files changed, 26 insertions(+), 1 deletion(-) diff --git a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs index d670bae..6c99901 100644 --- a/app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs +++ b/app/Umbraco/Umbraco.Archetype/Models/ArchetypePreValue.cs @@ -49,6 +49,9 @@ namespace Archetype.Models [JsonProperty("hidePropertyLabel")] public bool HidePropertyLabel { get; set; } + [JsonProperty("minFieldsets", NullValueHandling = NullValueHandling.Ignore)] + public int MinFieldsets { get; set; } + [JsonProperty("maxFieldsets", NullValueHandling = NullValueHandling.Ignore)] public int MaxFieldsets { get; set; } diff --git a/app/controllers/controller.js b/app/controllers/controller.js index 34bda45..aa8b1df 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -1,5 +1,5 @@ {{VERSION}} -angular.module("umbraco").controller("Imulus.ArchetypeController", function ($scope, $http, $filter, assetsService, angularHelper, notificationsService, $timeout, fileManager, entityResource, archetypeService, archetypeLabelService, archetypeCacheService, archetypePropertyEditorResource) { +angular.module("umbraco").controller("Imulus.ArchetypeController", function ($scope, $http, $filter, $interpolate, assetsService, angularHelper, notificationsService, $timeout, fileManager, entityResource, archetypeService, archetypeLabelService, archetypeCacheService, archetypePropertyEditorResource, archetypeLocalizationService) { // Variables. var draggedParent; @@ -531,6 +531,13 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc $timeout(function () { $scope.handleMandatoryValidation(); }, 50); + + // localize the message for minimum fieldsets validation errors + archetypeLocalizationService.localize("minFieldsetsMessage").then(function (value) { + value = value || "You must add minimum {{minFieldsets}} items"; + var exp = $interpolate(value); + $scope.minFieldsetsMessage = exp({ minFieldsets: $scope.model.config.minFieldsets }); + }); } function addDefaultProperties(fieldsets) @@ -788,6 +795,13 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc } } + $scope.minFieldsetsFulfilled = function () { + if (!$scope.model.config.minFieldsets) { + return true; + } + return $scope.numberOfEnabledFieldsets() >= $scope.model.config.minFieldsets; + } + //custom js if ($scope.model.config.customJsPath) { assetsService.loadJs($scope.model.config.customJsPath); diff --git a/app/views/archetype.config.fieldset.dialog.html b/app/views/archetype.config.fieldset.dialog.html index a686220..e296528 100644 --- a/app/views/archetype.config.fieldset.dialog.html +++ b/app/views/archetype.config.fieldset.dialog.html @@ -14,6 +14,10 @@
+
+ + +
diff --git a/app/views/archetype.default.html b/app/views/archetype.default.html index d140981..8d0f650 100644 --- a/app/views/archetype.default.html +++ b/app/views/archetype.default.html @@ -14,6 +14,10 @@
Required
+ + +
{{minFieldsetsMessage}}
+