如何在 Flex 3 中取消/不接受拖放操作?

发布于 2024-07-06 21:50:05 字数 3739 浏览 4 评论 0原文

目标: 允许用户通过从 AdvancedDataGrid 中拖动一行并将其放到垃圾桶图标上来删除记录,并通过带有“确定”和“取消”按钮的弹出警报验证用户是否打算执行此操作。

什么有效:

  • 将一行拖/放到垃圾桶图标上。
  • 如果用户单击“确定”按钮,则该记录将被删除。
  • 如果用户单击“取消”按钮,则操作被取消。

问题: 用户单击“取消”按钮并且弹出警报关闭后,ADG 中的任何行都无法拖动。 我发现,对 ADG 进行排序后,通过单击列标题,用户可以再次开始拖动行。

代码:(从原始帖子更改)

<mx:Image source="{trashImage}" buttonMode="true" 
toolTip="drag a participant here to delete them from the project"
dragDrop="deleteParticipantDrop(event)" dragEnter="deleteParticipantEnter(event)" 
dragExit="deleteParticipantDragExit(event)" top="4" right="122" id="image2" />  

// trashImage Event Handlers:
private function deleteParticipantEnter(event:DragEvent):void
{
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    DragManager.showFeedback(DragManager.MOVE);
    deleteParticipantDragEvent = event;
}

private function deleteParticipantDrop(event:DragEvent):void
{
    var selectedKitNum:String = memberRpt.selectedItem.KitNum;
    var selectedName:String = memberRpt.selectedItem.ParticipantName;
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    isEditingParticipantInfo = false;
    isDeletingParticipant = true;
    deleteParticipantDropEvent = event;
    event.stopImmediatePropagation(); // Added as per mrm
    alert.confirm("Are you sure you want to delete this participant, Kit #" + memberRpt.selectedItem.KitNum + " ("  + 
        memberRpt.selectedItem.ParticipantName + ") from the project?  This cannot be reversed!!  An email will be " +
        "sent to notify this participant and you will receive a copy of it for your records.", confirmRemoveParticipant);
}

private function deleteParticipantDragExit(event:DragEvent):void
{
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    DragManager.showFeedback(DragManager.NONE);
}

private function confirmRemoveParticipant(event:CloseEvent):void
{
    if (event.detail == Alert.YES)
    {
        deleteReason = DeleteParticipantTitleWindow(PopUpManager.createPopUp( this, DeleteParticipantTitleWindow , true));
        dispatchEvent(deleteParticipantDropEvent); // Added as per mrm
        PopUpManager.centerPopUp(deleteReason);
        deleteReason.showCloseButton = true;
        deleteReason.title = "Reason for removal from project";
        deleteReason.addEventListener("close", cleanupRemoveParticipant);
        deleteReason["cancelButton"].addEventListener("click", cleanupRemoveParticipant);
        deleteReason["okButton"].addEventListener("click", finalizeDeleteParticipant);
        isDeletingParticipant = false; 
    }
    else
    {
        cleanupRemoveParticipant();
    }
}

private function cleanupRemoveParticipant(event:Event = null):void
{
    memberRpt.invalidateDisplayList();
    memberRpt.executeBindings();
    if (deleteReason != null)
    {
        PopUpManager.removePopUp(deleteReason);
        deleteReason = null;
    }
}

public function finalizeDeleteParticipant(event:Event):void
{
    if (deleteReason.reason.text != null)
    {
        selectedReportItem = memberRpt.selectedItem;
        selectedReportItemIndex = memberRpt.selectedIndex;
        memberReportData.removeItemAt(selectedReportItemIndex);
    }
    else
    {
        alert.info("You must provide a reason for removing a participant from your project!!");
    }

    cleanupRemoveParticipant();
}

提前感谢所有有用的建议。

Goal:
Allow the user to delete a record by dragging a row from an AdvancedDataGrid, dropping it onto a trash-can icon and verify the user meant to do that via a popup alert with "OK" and "Cancel" buttons.

What is working:

  • Dragging/Dropping a row onto the trash icon.
  • If the user clicks the "OK" button, the record is deleted.
  • If the user clicks the "Cancel" button, the operation is canceled.

Problem:
After the user clicks the "Cancel" button and the popup alert closes, no rows in the ADG can be dragged. I've discovered that after sorting the ADG, by clicking on a column header, the user can begin dragging rows again.

Code: (changed from original post)

<mx:Image source="{trashImage}" buttonMode="true" 
toolTip="drag a participant here to delete them from the project"
dragDrop="deleteParticipantDrop(event)" dragEnter="deleteParticipantEnter(event)" 
dragExit="deleteParticipantDragExit(event)" top="4" right="122" id="image2" />  

// trashImage Event Handlers:
private function deleteParticipantEnter(event:DragEvent):void
{
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    DragManager.showFeedback(DragManager.MOVE);
    deleteParticipantDragEvent = event;
}

private function deleteParticipantDrop(event:DragEvent):void
{
    var selectedKitNum:String = memberRpt.selectedItem.KitNum;
    var selectedName:String = memberRpt.selectedItem.ParticipantName;
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    isEditingParticipantInfo = false;
    isDeletingParticipant = true;
    deleteParticipantDropEvent = event;
    event.stopImmediatePropagation(); // Added as per mrm
    alert.confirm("Are you sure you want to delete this participant, Kit #" + memberRpt.selectedItem.KitNum + " ("  + 
        memberRpt.selectedItem.ParticipantName + ") from the project?  This cannot be reversed!!  An email will be " +
        "sent to notify this participant and you will receive a copy of it for your records.", confirmRemoveParticipant);
}

private function deleteParticipantDragExit(event:DragEvent):void
{
    var component:IUIComponent = IUIComponent(event.currentTarget);
    dragComponent = component;
    DragManager.acceptDragDrop(component);
    DragManager.showFeedback(DragManager.NONE);
}

private function confirmRemoveParticipant(event:CloseEvent):void
{
    if (event.detail == Alert.YES)
    {
        deleteReason = DeleteParticipantTitleWindow(PopUpManager.createPopUp( this, DeleteParticipantTitleWindow , true));
        dispatchEvent(deleteParticipantDropEvent); // Added as per mrm
        PopUpManager.centerPopUp(deleteReason);
        deleteReason.showCloseButton = true;
        deleteReason.title = "Reason for removal from project";
        deleteReason.addEventListener("close", cleanupRemoveParticipant);
        deleteReason["cancelButton"].addEventListener("click", cleanupRemoveParticipant);
        deleteReason["okButton"].addEventListener("click", finalizeDeleteParticipant);
        isDeletingParticipant = false; 
    }
    else
    {
        cleanupRemoveParticipant();
    }
}

private function cleanupRemoveParticipant(event:Event = null):void
{
    memberRpt.invalidateDisplayList();
    memberRpt.executeBindings();
    if (deleteReason != null)
    {
        PopUpManager.removePopUp(deleteReason);
        deleteReason = null;
    }
}

public function finalizeDeleteParticipant(event:Event):void
{
    if (deleteReason.reason.text != null)
    {
        selectedReportItem = memberRpt.selectedItem;
        selectedReportItemIndex = memberRpt.selectedIndex;
        memberReportData.removeItemAt(selectedReportItemIndex);
    }
    else
    {
        alert.info("You must provide a reason for removing a participant from your project!!");
    }

    cleanupRemoveParticipant();
}

Thanks in advance for all helpful suggestions.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(6

才能让你更想念 2024-07-13 21:50:05

您是否尝试过在取消事件后在 ADG 上运行 validateNow() 方法?

以下是有关 validateNow() 方法的更多信息。

为什么你需要了解 validateNow...

我确实认为这就是什么您正在寻找! 如果是这种情况,请告诉我们......

Have you tried running the validateNow() method on the ADG after the cancel event?

Here is some more information on the validateNow() method.

Why you need to know about validateNow...

I really do think this is what you're looking for! Please let us know if that is the case...

不乱于心 2024-07-13 21:50:05

尝试使用封闭控件中的executeBindings 和/或invalidateDisplayList 刷新数据网格上的数据绑定。

老实说,这听起来有点像一个错误。 您是否已在 flexcoders 上发布此内容? Adobe 的人在那里闲逛(可能也在这里,但肯定在那里)

Try refreshing the data bindings on the datagrid using executeBindings and/or invalidateDisplayList in the enclosing control.

To be honest this sounds a bit like a bug. Have you posted this on flexcoders? The Adobe guys hang out on there (probably here too, but definitely there)

愿与i 2024-07-13 21:50:05

等一下...刚刚发现在弹出窗口的放置事件和取消按钮之间有一个异步 Web 服务调用,该调用似乎由 GetParticipantOrderInformation 处理。 那是对的吗?

如果是,那么您在执行此操作之前是否尝试过提供一个更简单的“取消”对话框? 我想知道事件层的组合是否导致了问题。

Hang on... just spotted that between the drop event and the cancel button of the popup there is an asynchronous web service call which appears to be handled by GetParticipantOrderInformation. Is that correct?

If yes, then have you tried offering a simpler dialog for Cancel before you do that? I wonder whether the combination of layers of events is causing a problem.

半山落雨半山空 2024-07-13 21:50:05

我通过executeBindings 和invalidateDisplayList 方法刷新数据网格上的数据绑定没有取得任何成功。 在拨打网络服务电话之前我也没有显示确认警报。 事实上,我发现进行 Web 服务调用是完全没有必要的,因此将其删除。 现在代码流程如下:

  1. 将 ADG 行拖放到垃圾桶图标上。
  2. 显示确认警报框。
  3. 如果用户单击“取消”按钮,则重新显示 ADG。

但同样的问题仍然存在。 我将使用最新代码更新代码部分。

I didn't have any success with refreshing the data bindings on the datagrid via the executeBindings and invalidateDisplayList methods. I also didn't have any luck by showing the confirmation alert before making the webservice call. In fact, I discovered that making the webservice call was completely unnecessary and removed it. So now the code flows like this:

  1. Drag/drop ADG row onto trash icon.
  2. Display confirmation Alert box.
  3. If user clicked "Cancel" button, redisplay the ADG.

But the same problem persists. I'll update the Code section with the latest code.

我纯我任性 2024-07-13 21:50:05

这是一个想法:
- 在创建警报窗口之前,停止 DragEvent

event.stopImmediatePropagation();
  • 存储事件,以便我们可以在用户单击“是”按钮时恢复
queuedEvent = event as DragEvent;
  • 显示警报窗口,
  • 如果用户单击“是”按钮,则恢复排队的事件
dispatchEvent(queuedEvent);

Here's an idea:
- Just before you create the alert window, stop the DragEvent

event.stopImmediatePropagation();
  • store the event so we can resume if the user clicks the Yes button
queuedEvent = event as DragEvent;
  • show the alert window
  • if the user clicks the yes button, resume the queued event
dispatchEvent(queuedEvent);
熊抱啵儿 2024-07-13 21:50:05

DragManager.showFeedback(DragManager.NONE);

DragManager.showFeedback(DragManager.NONE);

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文