[SOLVED] Figuring out which page a user came from

turnbulm

Joined: 2004-10-03
Posts: 431
Posted: Wed, 2005-07-27 21:14

I'm working on a module that has actions (in the 'item actions' section). Everything works fine at the moment - the user selects the action, it's processed, and the user is taken to another page. However...

I may not want the user to be taken away from the page they were on when they selected the action. So how do I work out (inside a GalleryController::handleRequest) exactly which view the user was on when they clicked the action link? I'd need to set the return redirect parameters appropriately to get them sent straight back to their original view.

Problems I can foresee:

  • I can't just use the ItemID I'm passed then go back to ShowItem for that ID, as this doesn't allow for the possibility of the user having clicked the action in the drop-down on an album page (the user would be sent back to the photo item rather than the album)
  • If the user comes from an album, how do I determine which page they were on so I can send them back to the same page?

Any suggestions greatly appreciated![/]

 
lvthunder

Joined: 2003-09-12
Posts: 808
Posted: Thu, 2005-07-28 01:42

I'm not that good of a programmer so I can't give you any code but can't you use the refer option that most website stat tools use to tell you where people came from.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-28 10:34

i guess what you want is that the user clicks on your link, then your controller does some work and then it should automatically redirect to the same page they were on before.

so from the user experience: they click on something, see no feedback that the click did anything and the page just refreshes.

correct? isn't that very confusing for the user? he has to see some feedback.

what you want is very easy to implement in G2:
all you have to do is add the "return" = 1 param to your link params. g2 will then automatically add return and returnName parameters to your link.
in your controller, just redirect to this url (get the url with GalleryUtilities::getRequestVariables().
See modules/core/module.inc as an example:

$links[$itemId][] =
		    array('text' => $this->translate('edit captions'),
			  'params' => array('view' => 'core.ItemAdmin',
					    'subView' => 'core.ItemEditCaptions',
					    'itemId' => $itemId,
					    'return' => 1));

what I'd recommend to not confuse the user:
do it similarely to the "edit captions" item action. when you click on it, you see a "back to ..." link in the sidebar.
just show a success message and show a back to ... link.

 
turnbulm

Joined: 2004-10-03
Posts: 431
Posted: Thu, 2005-07-28 11:01

valiant- this is for a customisation to the Checkout module that you yourself suggested ;) It's to enable the user to click 'add to cart' and carry on browsing without being dragged to the cart view. The visual indication of success will be that the 'my cart' block will show one more item, and possibly a message stating 'added xxx to cart'.

Thanks for the technical info - I'll go ahead and give that a try this week.

 
valiant

Joined: 2003-01-04
Posts: 32509
Posted: Thu, 2005-07-28 11:07

ah, sorry. for some reason i haven't looked at your username.
if you have a sidebar block showing some feedback, great.

 
turnbulm

Joined: 2004-10-03
Posts: 431
Posted: Thu, 2005-07-28 11:27

NP - I think you guys are busy enough at the moment to be allowed the odd slip ;)

 
turnbulm

Joined: 2004-10-03
Posts: 431
Posted: Thu, 2005-07-28 17:13

For anyone who's interested, I found an even easier way of achieving this based on Valiant's suggestions. First I set 'return' => 1 in module.inc as suggested. In the controller I then just removed my original $results['redirect'] variables, and put in $results['return'] = true; instead. As per the API spec for handleRequest() here this just tells G2 to go back where it came from! No need to read the URL value in and pass it back as an explicit redirect.