[Fixed] Opening a new dialog from a block edit dialog

Permalink
I'm working on my own block and as the post title suggests, I need to be able to open a dialog from within the block edit dialog. I'd like it to have the same appearance as the block edit dialog itself, and load a page from within the tools directory of the block.

Initially I copied the code from the Edit link in the pop-up that appears when you click on the block, and modified it. In this way I've got it to successfully load the page into a dialog. But now I'm experiencing some problems (i.e. it works the first time, but subsequently it redirects the entire page) so I'd welcome any alternative suggestions.

 
Filofox replied on at Permalink Reply
Well I tried creating my own <div> and calling .dialog() directly but it looks like c5 has completely co-opted the jQuery.fn.dialog() method and it just does nothing.
Filofox replied on at Permalink Reply
So this is how I got it to work in the end:

Briefly, I'm creating a list of items dynamically using JavaScript. Each of these items has an 'edit' link which is supposed to pop up a new dialog. I'm using the following code for the edit link:

<a href="/index.php/tools/blocks/my_block/edit_item.php?item_id=' + i + '" dialog-modal="false" dialog-width="550" dialog-height="300" dialog-title="Edit item" class="edit_link dialog-launch"><span><em>Edit item</em></span></a>


...and this was working the first time but not after the list was re-written.

In the end, the fix was quite simple -- add this after the list has been created:

my_block.find( 'a.edit_link' ).dialog();


(the above being javascript of course, not php -- for some reason it's adding php tags automatically)

...which tells the system to treat the new <a> elements as dialog-launching elements (my_block is the div element that the item list is written into).

Oh, and you'll probably want to add a check to make sure it doesn't run the first time the list is rendered, otherwise it opens the dialog twice (but this might depend on how/when your list is rendered).

I hope this helps someone in the future.
mario replied on at Permalink Reply
mario
thanks for the tip! very interesting :)
Fernandos replied on at Permalink Reply
Fernandos
thx from here too ;)

I was just about going to implement this in one of my packages, I knew c5 had a function, but c/p is always much more confortable than finding the function and identifiying the dependencies and parameters that are needed.