Merge pull request #378 from Nicholas-Westby/fix/372-drag-drop-broken

Fix for drag & drop failing when dropping fieldset in the same Archet…
This commit is contained in:
Kenn Jacobsen
2017-02-16 12:16:44 +01:00
committed by GitHub
+16 -3
View File
@@ -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;
}