From 155355aa0058f824687c6273ca26e2e442a4d169 Mon Sep 17 00:00:00 2001 From: Nicholas-Westby Date: Wed, 14 Sep 2016 22:08:04 -0700 Subject: [PATCH] Fix for drag & drop failing when dropping fieldset in the same Archetype and the max fieldsets is reached: https://github.com/kgiszewski/Archetype/issues/372 --- app/controllers/controller.js | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/app/controllers/controller.js b/app/controllers/controller.js index ecfed46..6c274f5 100644 --- a/app/controllers/controller.js +++ b/app/controllers/controller.js @@ -211,6 +211,16 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc } + // Checks if the specified array of fieldsets contains the specified fieldset. + function arrayContainsFieldset(fieldset, fieldsets) { + for (var i = 0; i < fieldsets.length; i++) { + if (fieldsets[i] === fieldset) { + return true; + } + } + return false; + } + // Confirms that an array of properties is a subset of another array of properties. function arePropertiesSubset(subset, superset) { @@ -857,12 +867,15 @@ angular.module("umbraco").controller("Imulus.ArchetypeController", function ($sc // The source scope is the scope of the fieldset being dragged. // The target scope is the scope of the Archetype to drop into. function canMove(sourceScope, targetScope) { - var targetFieldsets = targetScope.model.config.fieldsets; + var targetFieldsetConfigs = targetScope.model.config.fieldsets; + var targetFieldsets = targetScope.model.value.fieldsets; + var sourceFieldset = sourceScope.fieldset; + var sameArchetype = arrayContainsFieldset(sourceFieldset, targetFieldsets); var model = sourceScope.fieldsetConfigModel; var canRemove = sourceScope.canRemove(); var canAdd = targetScope.canAdd(); - var valid = canRemove && canAdd; - valid = valid && modelMatchesAnyFieldset(model, targetFieldsets); + var valid = sameArchetype || (canRemove && canAdd); + valid = valid && modelMatchesAnyFieldset(model, targetFieldsetConfigs); return valid; }