开发者

Show alert if moving on without saving in Flex?

Functionnaly : On one of my components of my application, I have an editing/lock system. When a user starts editing, he locks the file so other users cannot edit it.

Problem scenario : When the user activates "edition mode" and leaves screen,开发者_StackOverflow中文版 I would like to show a alert with two options : save changes, or discard changes.

There are different ways to exit screen :

  • There is a List on the left side containing other possible editabel data. A click changes the data in my component.
  • There is a menubar on top leading to other screens.
  • The edition component is embedded in a Tab navigator. When changing tabs, the alert has to show.
  • Closing browser.

Do I have to catch all of these events and plug at all those places? Is there any kind of focusout mecanism?


The answer to the first question is: YES.

You need to watch all possible exit events that could harm the currently edited data.

Well, the problem is now how to manage this properly. Using an MVC framework you would trigger the appropriate commands from your components:

  • CHANGE_LIST_ITEM (new item)
  • CHANGE_TAB (new tab)
  • CHANGE_SCREEN (new screen)

Each command then checks if the currently edited tab has been saved or not. If not, it displays the Alert. Else, if there are no changes, it allows the list, the screen chooser and the tab bar to continue.

So your components (list, screens, tabs) need to implement some kind of rollback or preventDefault mechanism. Generally, changing their state must be allowed by a central validator (in MVC the command).

In the case of the list: I would suggest that the list is not selectable by mouse click but only programmatically. You set a listener on the list item click event. If the command allows setting of a new item it will notify the list. In MVC usually by sending an async message that gets received by the list's mediator. [[And even more correct: The command would set some model properties (e.g. currentListItem) and the model than sends an async message.]]

Edit: For the browser close event, you need to call a JavaScript expert.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜