0

Using Joomla! v2.5 and modal to open a new popup

<a href="index.php?option=com_mycomponent&view=my_view" class="modal" rel="{handler: 'iframe', size: {x: 800, y: 600}}">

User will have some options (links) such as info/delete/lock.

After selecting(clicking) an option and clicking the "close" button, I need to either just close the modal or close the modal and refresh the page.

I can ALWAYS refresh the page using something like this

<a href="index.php?option=com_mycomponent&view=my_view" class="modal" rel="{handler:'iframe', size: {x: 800, y: 600},onClose:function(){var js =window.location.reload();}}">

but I need to refresh the page under conditions (eg. user clicked "delete" => refresh, user clicked "info" => do nothing)

Ideas?

Thanks

DimitrisD
  • 424
  • 3
  • 17

2 Answers2

2

So, in Joomla! 2.5 the modal popups are handled by the SqueezeBox script (version 1.3).

Set your onClose handler to call your own Javascript method, so this:

onClose:function(){var js =window.location.reload();}

Changes to:

onClose:function(){checkUserChoice();}

Or if you keep your Javascript neatly namespaced (as recommended)

onClose:function(){mycomponent.checkUserChoice();}

Have your checkUserChoice() set to make the decision:

mycomponent.checkUserChoice = function () {
    userChoice = document.id('userOption).value;
    if(userChoice == 'delete') {
        // refresh our page
    } else {
        // do something else
    }
}

Then load your custom Javascript file into the view:

// Get the document object
$document = JFactory::getDocument();
$document->addScript('path/to/myscript.js');

Or, if you only have the one small method to load:

$myscript = <<<'JS'
mycomponent.checkUserChoice = function () {
    userChoice = document.id('userOption).value;
    if(userChoice == 'delete') {
        // refresh our page
    } else {
        // do something else
    }
}
JS;

$document->addScriptDeclaration($myscript);
Craig
  • 9,335
  • 2
  • 34
  • 38
0

For the onClose handler, I'd recommend having it call your own custom JS method. In that method, handle your custom logic for determining whether to refresh the page or not.

Michael
  • 992
  • 8
  • 19