Skip to content

Commit

Permalink
Revert "Fix drag&drop between flows. Handle content type restrictions. (
Browse files Browse the repository at this point in the history
#17421)" (#17504)

This reverts commit ad22778.
  • Loading branch information
MikeAlhayek authored Feb 20, 2025
1 parent c0f242c commit a266cf9
Show file tree
Hide file tree
Showing 4 changed files with 35 additions and 49 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,14 @@
@{
var widgetTemplatePlaceholderId = Html.Id("widgetTemplatePlaceholder");
var htmlFieldPrefix = ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix;
var contentTypesStringified = string.Join(";", Model.ContainedContentTypeDefinitions);
var parentContentType = Model.BagPart.ContentItem.ContentType;
string partName = ((dynamic)Model).Metadata.Name;
var totalItems = Model.ContainedContentTypeDefinitions.Count();
}
<script asp-name="jQuery-ui" at="Foot"></script>

<div>
<div id="@widgetTemplatePlaceholderId" class="widget-template-placeholder widget-template-placeholder-bagpart bagpart-@partName.HtmlClassify() row mx-0" data-buildeditorurl="@Url.Action("BuildEditor", "Admin", new { area = "OrchardCore.Flows" })" data-content-types="@contentTypesStringified">
<div id="@widgetTemplatePlaceholderId" class="widget-template-placeholder widget-template-placeholder-bagpart bagpart-@partName.HtmlClassify() row mx-0" data-buildeditorurl="@Url.Action("BuildEditor", "Admin", new { area = "OrchardCore.Flows" })">
@{
var index = 0;
foreach (var widget in Model.AccessibleWidgets)
Expand Down Expand Up @@ -146,10 +145,6 @@
});
},
stop: function (event, ui) {
if (lastContainer[0] == this && this.dataset.contentTypes.split(';').indexOf(draggedWidget[0].dataset.contentType) < 0) {
event.preventDefault();
}
lastContainer.toggleClass('widget-dropzone-hint');
widgetDragItem.find('.card').first().toggleClass('border-primary');
//clear the global variables
Expand All @@ -161,7 +156,7 @@
},
over: function (event, ui) {
var $self = $(this);
if (lastContainer[0] != this && this.dataset.contentTypes.split(';').indexOf(draggedWidget[0].dataset.contentType) >= 0) {
if (lastContainer[0] != this) {
lastContainer.toggleClass('widget-dropzone-hint');
lastContainer = $self;
$self.toggleClass('widget-dropzone-hint');
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@
}
}

<div class="widget widget-editor card@(collapsed ? " collapsed" : string.Empty)" data-content-type="@Model.ContentItem.ContentType">
<div class="widget widget-editor card@(collapsed ? " collapsed" : string.Empty)">
<div class="widget-editor-header card-header text-muted py-1 ps-2 pe-1">
@if (Model.CanMove)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
var editorId = "contentEditor_" + Model.PrefixValue;
}

<div class="widget widget-editor card my-1@(Model.Inline ? " collapsed" : string.Empty)" data-content-type="@Model.ContentItem.ContentType">
<div class="widget widget-editor card my-1@(Model.Inline ? " collapsed" : string.Empty)">
<div class="widget-editor-header card-header text-muted py-1 ps-2 pe-1">
@if (Model.CanMove != false)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,6 @@

@{
var widgetContentTypes = Model.ContainedContentTypeDefinitions;
var widgetTypesStringified = string.Join(";", widgetContentTypes);
var widgetTemplatePlaceholderId = Html.Id("widgetTemplatePlaceholder");
var htmlFieldPrefix = ViewContext.ViewData.TemplateInfo.HtmlFieldPrefix;
var parentContentType = Model.FlowPart.ContentItem.ContentType;
Expand All @@ -18,7 +17,7 @@

<script asp-name="jQuery-ui" at="Foot"></script>
<div>
<div id="@widgetTemplatePlaceholderId" class="widget-template-placeholder widget-template-placeholder-flowpart flowpart-@partName.HtmlClassify() row mx-0" data-buildeditorurl="@Url.Action("BuildEditor", "Admin", new { area = "OrchardCore.Flows" })" data-widget-types="@widgetTypesStringified">
<div id="@widgetTemplatePlaceholderId" class="widget-template-placeholder widget-template-placeholder-flowpart flowpart-@partName.HtmlClassify() row mx-0" data-buildeditorurl="@Url.Action("BuildEditor", "Admin", new { area = "OrchardCore.Flows" })">
@{
var index = 0;
foreach (var widget in Model.FlowPart.Widgets)
Expand Down Expand Up @@ -122,7 +121,7 @@
}
@*Only apply sortable if element is present in dom, do not call sortable on scripts for mock widgets *@
if ($('#@widgetTemplatePlaceholderId').length == 1) {
if ($('#@widgetTemplatePlaceholderId').length == 1) {
$("#@widgetTemplatePlaceholderId").sortable({
handle: ".widget-editor-handle",
cursor: "move",
Expand All @@ -141,12 +140,10 @@
start: function (event, ui) {
widgetDragItem = ui.item;
originalContainer = ui.item.parent();
lastContainer = ui.item.parent();
lastContainer.toggleClass('widget-dropzone-hint');
draggedWidget = widgetDragItem.find('.card').first()
draggedWidget.toggleClass('border-primary')
widgetDragItem.find('.card').first().toggleClass('border-primary')
widgetItemSourceId = widgetDragItem.parent().attr('id');
Expand All @@ -161,64 +158,58 @@
lastContainer.toggleClass('widget-dropzone-hint');
widgetDragItem.find('.card').first().toggleClass('border-primary');
if (lastContainer[0] != this && this.dataset.widgetTypes.split(';').indexOf(draggedWidget[0].dataset.contentType) >= 0) {
widgetItemDestId = widgetDragItem.parent().attr('id');
widgetItemDestId = widgetDragItem.parent().attr('id');
if (widgetItemDestId !== widgetItemSourceId) {
if (widgetItemDestId !== widgetItemSourceId) {
var inputs = widgetDragItem.children("input[name*='FlowPart']");
var inputs = widgetDragItem.children("input[name*='FlowPart']");
var destination = $('#' + widgetItemDestId);
var source = $('#' + widgetItemSourceId);
var destination = $('#' + widgetItemDestId);
var source = $('#' + widgetItemSourceId);
var sourceGuid = widgetItemSourceId.substring(0, widgetItemSourceId.lastIndexOf('_') + 1);
sourceNameGuid = sourceGuid.replaceAll('_', '.');
var sourceGuid = widgetItemSourceId.substring(0, widgetItemSourceId.lastIndexOf('_') + 1);
sourceNameGuid = sourceGuid.replaceAll('_', '.');
if (destination.length > 0) {
if (destination.length > 0) {
var destGuid = widgetItemDestId.substring(0, widgetItemDestId.lastIndexOf('_') + 1);
destNameGuid = destGuid.replaceAll('_', '.');
var destGuid = widgetItemDestId.substring(0, widgetItemDestId.lastIndexOf('_') + 1);
destNameGuid = destGuid.replaceAll('_', '.');
if (source.length > 0) {
inputs.each(function (index, item) {
$(this).attr('id', $(this).attr('id').replace(sourceGuid, destGuid));
$(this).attr('name', $(this).attr('name').replace(sourceNameGuid, destNameGuid));
});
} else {
if (source.length > 0) {
inputs.each(function (index, item) {
$(this).attr('id', $(this).attr('id').replace(sourceGuid, destGuid));
$(this).attr('name', $(this).attr('name').replace(sourceNameGuid, destNameGuid));
});
inputs.each(function (index, item) {
$(this).attr('id', destGuid + $(this).attr('id'));
$(this).attr('name', destNameGuid + $(this).attr('name'));
});
}
} else {
}
else if (source.length > 0) {
inputs.each(function (index, item) {
$(this).attr('id', $(this).attr('id').replace(sourceGuid, ''));
$(this).attr('name', $(this).attr('name').replace(sourceNameGuid, ''));
$(this).attr('id', destGuid + $(this).attr('id'));
$(this).attr('name', destNameGuid + $(this).attr('name'));
});
}
}
else if (source.length > 0) {
inputs.each(function (index, item) {
$(this).attr('id', $(this).attr('id').replace(sourceGuid, ''));
$(this).attr('name', $(this).attr('name').replace(sourceNameGuid, ''));
});
}
$(document).trigger('contentpreview:render');
widgetItemDestId = null;
}
else {
event.preventDefault();
}
$(document).trigger('contentpreview:render');
//clear the global variables
widgetDragItem = null;
lastContainer = null;
widgetItemSourceId = null;
widgetItemDestId = null;
},
over: function (event, ui) {
var $self = $(this);
if (lastContainer[0] != this && this.dataset.widgetTypes.split(';').indexOf(draggedWidget[0].dataset.contentType) >= 0) {
if (lastContainer[0] != this) {
lastContainer.toggleClass('widget-dropzone-hint');
lastContainer = $self;
$self.toggleClass('widget-dropzone-hint');
Expand Down

0 comments on commit a266cf9

Please sign in to comment.