Hi,

I'm using this module for editing and displaying node forms and it works very well. I'm having trouble getting a view with a pager working in a popup.

For example, when displaying the node, a view is incorporated via a call to views_embed_view(), this works as expected when viewing the node on its own page. However, when viewing the same node in a popup, clicking on the view's pager controls results in the pop-up closing and the underlying page updating with the selection from the pager. I spent some time experimenting with the popups.js code so that pager buttons result in the popup div being refreshed but I couldn't get it to work.

Has anybody tried using views with pagers in a popup or is this something known not to work right now?

Thanks much (and thanks for a great module!),

Regards,
gene

Comments

sirkitree’s picture

Title: Popups and views and pagers » Popups and pagers and views, Oh My!

I've not actually tried this, but couldn't resist changing the title slightly ;)

starbow’s picture

what you need to do if find out where the pager is being themes and add a class=popups.

starbow’s picture

Add the class to the links, btw.

gsally’s picture

StatusFileSize
new2.08 KB

I spent some time fiddling with this. As a total hack I added this to the code that generates the pager links (theme_pager_link) in includes/pager.inc

$attributes['class'] = 'popups';

Next, I bumped into this bit of code in the popus.js

      if ($(element).parents('#popups').length) { 
        alert("Sorry, popup chaining is not supported (yet).");
        return false;
      }

Continuing my march of irresponsible programming, I commented this out. That lead me next to this bit of code in Drupal.popus.open

 	  $('body').append( $popups ); // Add the popups to the DOM.

That was changed to the following:

  if ($('#popups').length) {
	  $('#popups-body').html(body);
	   this.refocus(); // TODO: capture the focus when it leaves the dialog.
	   Drupal.popups.removeLoading(); // Remove the loading img.
	   $('#popups-close').click( Drupal.popups.close );
	   $('a.popups-close').click( Drupal.popups.close );	   
	   return false;
  }
  else { 
	  var $popups = $(Drupal.theme('popupDialog', title, body, buttons));
	  // Start with dialog off the side. Making it invisible causes flash in FF2.
	  $popups.css('left', '-9999px');
	  if (width) {
	    $popups.css('width', width);
	  }	  
	  $('body').append( $popups ); // Add the popups to the DOM.
  }

And, mirabile dictu, the paging works. The view updates in the context of the current page. The view in question uses an ajax pager, I haven't tested with a non-ajax pager. One problem here: I can't seem to get the "close" link to work now. Not sure what I did.

The problem, which I haven't sorted out, is how to control the style of the pager elements on the view. This code works because of the hack that was made in theme_pager_link and that should be done correctly, as every pager link is set with popups, not just the ones that appear in popup-looking dialogs. I'm not sure of the right way to go about doing that, but I'll keep plugging along.

There's a patch attached with the changes so far. Sorry about this being half-baked, when I have something more done, I'll post that as well. I'm looking for "Danger Will Robinson!!" feedback with respect to the approach; if there's any, please let me know.

starbow’s picture

Category: support » feature

That is more work than I thought it would be for you.
Display popup -> display popup is a resonable feature request. Let me know how far you get.

gsally’s picture

StatusFileSize
new2.93 KB

These are the changes that I made and it works for Ajax based pagers for views. In order to get this to work, the view's pager anchor tags must have a certain class (popups-view-pagers). This diff was made against 1.9.2.18 popup.js.

starbow’s picture

Definitely some good ideas here. I agree with you that it is worth being more flexible with allowing popup chaining. I am afraid your approach is a little to specific to your exact use case. Here is what I am thinking about.

Instead of prohibiting chaining, it changes to issuing a warning, but only if the chaining is happening inside a form.

      // If element is inside of a #popup div, show alert and bail out. 
      if ($(element).parents('form').parents('#popups').length) { 
        var go = confirm("Opening a new popup here will discard your current form input.\n" +
                         "Click 'OK' to open new popup and discard current form.\n" +
                         "Click 'Cancel' to stay in current form.");
        if (!go) return false;
      }

Then, in Drupal.popups.open

  // If a popup is currently open, just stuff new content into it.
  if ($('#popups').length) {
    $('#popups-body').html(body);
    var $popups = $('#popups');
    // TODO - remove existing button functions.
  }
  else {
    var $popups = $(Drupal.theme('popupDialog', title, body, buttons));
    // Start with dialog off the side. Making it invisible causes flash in FF2.
    $popups.css('left', '-9999px');
    if (width) {
      $popups.css('width', width);
    }
    $('body').append( $popups ); // Add the popups to the DOM.
  }

This way the popup can resize and recenter itself for different content.

Then we just change the z-order in popups.css to loading=8, popups=9, and overlay=10, and bob's your uncle.

This doesn't get you your effect of having the paging popup links only pop if they are already in a popup, but act as normal links other times. I will have to chew that one over. Maybe if the class name were "popups-chain". I will sleep on it.

kscheirer’s picture

Status: Needs review » Active
StatusFileSize
new1.8 KB

I'm thinking the popup chaining would be really useful for the user login links. In fact, based on the number of posts and half-worked out modules that try to do this, I think this could be a big win for the popups module!

Let's say the user...

  1. clicks a login link, gets a popup with the user login form (works)
  2. mistypes username or password, gets a message which includes a link to Forgot Your Password? (user/password) (works)
  3. clicks "Forgot Your Password" and the form is replaced with the user/password form (doesn't work - chaining not allowed)
  4. user enters an email that doesn't exist, form error displayed via ajax (doesn't work - get taken to user/password page w/ errors)

Using the attached patch to allow chaining (basically starbow's code in #7), and by adding the class popups-form to the user/password link I can get 1, 2, and 3 to work. Not sure how to get 4 to work, any ideas?

The only changes I made to #7 were: no confirmation for chaining, and some fadeIn/fadeOut effects for replacing the popup content.

kscheirer’s picture

Status: Active » Needs review
starbow’s picture

Status: Active » Needs review

@kscheirer, I am a little confused. Think this issue predates popup chaining (or stacking as I am calling it now) being introduced into 2.x. Are you having trouble getting stacking working with latest alpha?

starbow’s picture

Status: Needs review » Postponed (maintainer needs more info)
kscheirer’s picture

sorry, I was using 6.x-1.3, will go check out alpha5 now!

edit: Stacking works great in alpha5. I did notice its a little different than chaining though. Previously the second popups would take over the body of the first, replacing it. With Stacks, the initial popup gets hidden under the new one, but once the second one is closed, the initial popup remains.

Is there a config option to destroy the first popup when link is clicked that opens the second? I'm looking at doneTest, but I'm not sure how to use it yet :)

btw, awesome work, I will be using popups on a lot of my sites in the future!

starbow’s picture

Status: Postponed (maintainer needs more info) » Fixed

Hmm, I don't think there is an option to destroy the stack. The doneTest option just helps you control when you open a new popup vs falling back to the previous one. I suggest you open a new issue with a feature request.

resynthesize’s picture

Where is the status of gsally's original request? This is a problem that I also have. It looks like popups.js has changed significantly since the diff was posted and I could not apply it. I've tried running the latest dev copy to no avail. Any help would be much appreciated in getting this working.

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for 2 weeks with no activity.

jaime.davila’s picture

Version: 6.x-2.x-dev » 6.x-1.3

Hi Guys, sorry for reopening this bug, I'm new with drupal, but I need to support chaining

I have a button which opens the popup with an url pointing to a view, but this view has pager, so it's possible to have some extra pages.

Is there a way to accomplish this?

Any help will be appreciated

jaime.davila’s picture

Hi I just want to tell you I've been testing the patches and some modifications, and thx, it was unnecessary to reopen this bug.

Thx again :)