What is the event available for canceling editing? - tridion

I want to do something when the author opens a page, makes some changes and closes without saving.
I am expecting an event like close or cancel, but I can't find any event like that.
Which event should I subscribe to in this scenario?

There is no close or cancel event and since the user did not perform a save there is no event called at all (unless it is an existing item, then the close would trigger an undo-checkout). Please note that the user does get a warning when he tries to close a window without saving, so it is considered a conscious decision here.
Your only way to interact with this would be through a UI extension, but it would be interesting to know a bit more about the use case to see if it actually makes sense to go down that route (a UI extension is nontrivial).

Related

FullCalendar: is there still a viewRender event hook?

I need something like the viewRender event in order to persist the user's state. I'm building a UI where users will frequently jump in and out of the calendar, so preserving their view/range is essential for a pleasant experience. Does this exist in v5? The last mention I can find of it is from v3.
The only workaround I can think of right now is a direct click handler on every view control element, or a very heavy-handed MutationObserver. This is a React app so either one is going to be super awkward.
Thank you!
Edit 2021-02-11:
I looked at the available view render hooks but none of them address my problem. What I need is an event that will fire whenever the view state changes, including clicking between weeks/months/etc., so that I can persist the date range the user most recently viewed as well as the view they had selected.
viewDidMount is the closest to what I need, but it does not fire when the date range changes.
Edit 2021-05-26:
Another problem with using viewDidMount is that using it to enact side-effects is a bit overeager. The hook gets called whether or not the user has actually done anything, and the default view always gets passed as view inside the View Object. So there's no way to tell whether this mount event contains data I should persist or not.

Can I avoid making a synchronous callback, if I want a click to only *sometimes* open a new window?

In this scenario:
User enters some information into a textbox
User clicks a button
Server-side processing of the entered information takes place
Depending on the result of that server-side processing, either a new window is to be opened, or a message is to be displayed on the current page (and no popup)
I cannot come up with an approach other than to use async: false in the jQuery ajax call, which is strongly discouraged:
Setting this option to false (and thus making the call no longer
asynchronous) is strongly discouraged, as it can cause the browser to
become unresponsive.
I've tried:
having the call be async and in the callback handler, depending on what the server said, sometimes opening a new window - this gets blocked by popup blockers
another idea, which I've not even bothered with due to its unpleasantness, is to always open a window, and it is this new window that calls the server, and sometimes closes itself (somehow updating text in the parent on its way out)
What I've settled on is what I've described above: in the click handler, do a synchronous server call, and if the server says to do so, open a new window. Popup blockers are happy with this, because the window opening is done in the click handler. But...
Similar (but not duplicate, as I don't always want to open a new window) questions that have not provided a nice solution:
How can I open a new window using a URL that is generated inside the getScript callback function, and avoid pop-up blockers?
(How) can I open the result of a form submission in a new window?
what you can do is ,
try to have a hidden field on your page which will be set by a value like true or false at server side , that you can check later on in jquery document .ready function
if the value is false just show a msg else popup a new window
as simple as that
I tried out my 'unpleasant' idea: to always open a new window, and have that new window make the server call, closing itself if the results of the server call dictated that it was not required.
But that was pretty horrible, so I stuck with the synchronous call.
So for me, the answer to this question is no, you can't avoid being synchronous in this situation.

What is the purpose of raising an event?

what is the advantage of raising and event in asp.net user controls?
To allow someone else to execute code when you do something, without having to poll your state to know what you've done.
The purpose of raising an event is typically to inform about something that has happened or is about to happen in the code, in order to allow other parts of the program to react on this. Usually the events are designed in a way so that the code that raises the event works the same way regardless of whether there are any listeners (event handlers) attached or not.
One example would be the click event of a button. When the user clicks the button, the button will raise a click event, which will allow any attached event handler to do something. But if there is not event handler attached, the button will not change its behavior (it's just that nothing will happen).
Though most events are raised to inform that something has happened, there are some events that are raised in order to inform that something is about to happen. Sometimes these event use an EventArgs class with read/write properties (as opposed to readonly properties which are more commonly found in EventArgs classes) which allows the event listener to communicate data back to the event-raising code. I can't come up with any good asp.net example from the top of my head, but in the winforms world a typical example of this would be the Form.Closing event, where the event handler can set e.Cancel = true to prevent the form from closing.
So, in a user control it would be useful to raise an event whenever it may be of interest for external code (typically the page) to react on something that happens within the control.
To add to the other answers already here, let me use an analogy to explain events.
Suppose you wish to receive newspapers each day. You telephone the newspaper company to inform them that you wish to receive any new newspapers they may print - you 'subscribe' to the newspaper. The newspaper delivery people maintain a list of people who are subscribers - people who should receive the paper. When the newspaper is printed each day, if you are on the subscriber list, you will receive a newspaper.
Now, suppose you have an object - a button, for instance. Suppose you want to know when that button is pressed. You 'subscribe' to events - specifically an 'OnClick' or 'OnPressed' or whatever it may be named in your language of use. Whenever the user clicks the button, the button goes through its list of subscribers, and calls the function supplied to each. These are the 'event handlers'. These functions are what the subscribers want to have called when the event occurs. In English, the subscriber might say "When you're pressed, call MyOnClick() function."
Events are used in many programming paradigms to cope with complexity - events do not need to know anything about event handlers, and vice versa. This allows for looser coupling, and more modular, reusable code.
I suggest you read about the Observer Pattern, as this is the foundation for events and event handlers.

Prevent a user from closing a browser window using "X"?

Can I tell, using javascript, whether a user has clicked on the "X" icon on a browser dialog, or the "OK"/"Cancel" buttons? I have code I need to run when the window closes, but it will only run when OK or Cancel are clicked.
I currently capture the onunload event of the window. How can i accomplish this?
window.onunload = function() { alert("unloading"); }
Why do you want to do this? We can probably help you come up with a different design that doesn't require this if you tell us what you're trying to do.
However, to answer your question: it's not possible to catch that event in all cases. You cannot prevent the user from closing the browser or guarantee that your code will execute when they do. You can make it slightly annoying for them, but they can disable javascript, or kill the process, or reboot the computer. Using the unload function is the closest you can come to having some code that runs when the window closes (it will run in cases of normal shutdown or when the user navigates away).
If I understood correctly, your question is about a browser dialog, not the main browser window.
To answer your question, you probably cannot distinguish between the Cancel button and the X button of a browser dialog. They'll both end up just returning a false. If you need this level of control, you should consider writing your own simulated dialog (lightbox) instead of a real JavaScript dialog. Or perhaps look at existing frameworks/plugins with modal dialogs that give you the amount of control you need.
What about if he does ALT + F4?
To the best of my knowledge, you can't detect whether the user closed the dialog by clicking the Cancel button or the [x] button, since neither are exposed to you beyond returning the result of the action (e.g., confirm() as true/false).
You can hook into the document.onbeforeunload event to perform whatever cleanup action you require; I've done so myself by sending an asynchronous XMLHTTP request to the server to make sure the user's session gets cleaned up properly.
It is impossible to catch the closing of the browser and handle every other event that also causes a post back. You can try and many people have before you and failed.
Your best bet is to use onbeforeunload and learn how to deal with session timeouts on your serverside to clean up data.

Detecting when a user leaves a page / browser in Flex

I have an HTML wrapper that contains a Flex application, is there an Event that I can listen on, that is triggered when a user leaves the HTML wrapper either by navigation arrows or closing the browser?
Thanks.
You can also listen for Event.ACTIVATE and Event.DEACTIVATE in Flash. All EventDispatchers receive these events when Flash/AIR gains or loses focus from the OS.
http://livedocs.adobe.com/flash/9.0/ActionScriptLangRefV3/flash/events/EventDispatcher.html#event:deactivate
This is very helpful for when you you provide a link that opens a new window and you want to reduce functionality and load (pause and mute a video for example) and then resume when the user comes back.
Edit: I realized this may not be what you're asking for exactly, but I'll leave it in in case it's helpful for anyone looking for it. Also note that you can perform other actions in the onbeforeunload event that will generally be reliably executed before the user accesses the confirmation dialog, unless your unload routine is overly complex (in which case you should consider altering your design anyway).
onbeforeunload lets you interrupt page unload:
window.onbeforeunload = function(e) {
// Browser will pop up a confirmation dialog, with some text before
// and after your return string; try it in different browsers to
// see how they behave.
return 'String to confirm';
}
There is Body.onUnload, but i'm not sure how reliable it actually is.
The closest thing I've found for this is the javascript window.onunload event. However, you can't really listen for this within the Flex app, as the app may not be running anymore by the time the unload method is called. We've used it to signal to other parts of the page via javascript that the app was unloaded though, so depending on what you need to do that might be enough.
The question is, what do you need to do when the user navigates away?
If you need to perform an action on your server, then the best way to handle this is to open a Socket() when your swf initializes, and then when the user navigates away, that socket will be terminated, and the server can detect that and perform additional logic.
If you need to perform a client side operation, like saving a SharedObject, then you can't rely on a "just one last thing" event to the plugin, since there are alot of avenues to closing out a plugin session. In that case, your best bet is to continually be saving SharedObjects every few seconds.

Resources