views:

750

answers:

4

In our CMS, we have a place in which we enable users to play around with their site hierarchy - move pages around, add and remove pages, etc.

We use drag & drop to implement moving pages around.

Each move has to saved in th DB, and exported to many HTML files. If we do that in every move, it will slow down the users. Therefore we thought that it's preferable to let the users play around as much as they want, saving each change to the DB, but only when they leave the page - to export their changes to the HTML files.

We thought of making the user click a "publish" button when they're ready to commit their changes, but we're afraid users won't remember to do that, because from their stand point once they've moved a page to a new place - the action is done. Another problem with the button is that it's inconsistent with the behavior of the other parts of the site (for example, when a user moves a text inside a page, the changes are saved automatically, as there is only 1 HTML file to update)

So how can we automatically save user changes on leaving the page?

+3  A: 

You should warn the user when he leaves the page with javascript.

From http://www.siafoo.net/article/67:

Modern browsers have an event called window.beforeunload that is fired right when any event occurs that would cause the page to unload. This includes clicking on a link, submitting a form, or closing the tab or window.

Visit this page for a sample the works in most browsers:

http://www.webreference.com/dhtml/diner/beforeunload/bunload4.html

I think it's bad practice to save the page without asking the user first, thats not how normal web pages work.

Sample:

<SCRIPT LANGUAGE="JavaScript1.2" TYPE="text/javascript">
<!--
function unloadMess(){
    mess = "Wait! You haven't finished."
    return mess;
}

function setBunload(on){
    window.onbeforeunload = (on) ? unloadMess : null;
}

setBunload(true);
//-->
</SCRIPT>
Espo
I understand your comment about this not being the way web pages work. However, this is a web application, and there if you do things (eg. move things around, add or delete) you expect the changes to be saved without having to click again
Lea Cohen
+1  A: 

The easiest way I can think of is to store the page info each time the user moves items around using Ajax (e.g. with an UpdatePanel, onUpdated event, let it fire some script that updates the users page config.

Alternatively - .Net's WebParts implementation does this automatically without intervention by the programmer (unless you want to change the storage engine, it uses a local mdb in by default.

Martin
+1  A: 

Use a "Publish" checkbox/button and when the user interacts with the page in a way that causes them to navigate away ask them if they want to publish if that box is NOT checked/button not clicked. Be aware that there are actions (closing the browser, accessing their favorites menu, etc.) that you will probably not want or not be able to prompt the user.

Chuck
+1  A: 

I would force them to click a button such as publish. That is a 'training' issue.

Automatically saving changes when they leave could have other ramifications. For example if a user opens up a record and plays around with it and has no intention of changing it, they close it, like a word document, excel, etc. . . I would have your site mimic that model.

You also have to remember that the web is a disconnected environment and is not required all web applications run like a windows application.

If the user doesn't click the publish/save button then there changes are not saved and that is up to them to remember to do.

David Basarab