Blocks by Ajax and Magic Data Integration

Permalink Browser Info Environment
Hello John

I have bought Blocks by Ajax, as well as Magic Data, Magic Data On Block Load, and Magic Data Forms.

I need to have a page with a combo and a gallery.
1. The combo will present a list of filesets
2. On change on the combo, I want to reload the gallery by Ajax, and to show the selected gallery.

For now, I succeed in :
- modify the fileset in the gallery, using Magic Data On Block Load
- load the gallery using Blocks by Ajax

But I have problem to :
- force the reload when my combo is modified,
- pass the selected value to my gallery block.

Can you help please ?

Thanks in advance,

tobbie

Type: Discussion
Status: Archived
tobbie
View Replies: View Best Answer
JohntheFish replied on at Permalink Reply
JohntheFish
Some general solution strategies, there are all sorts of minor alternates within these approaches.

OPTION 1. Use the BB AJAX remote control block and set it to: request the ajax reload on a form submit of the form containing your user selector; to pass the form parameters to the ajax loading gallery block.

OPTION 2. Use the BB AJAX remote control block and set it to request the ajax reload on the blocks by ajax event. Use some MD on the page to then attach a trigger for the blocks by ajax event when the selection changes. The symbols you want are in the Blocks by Ajax group and will also pass through the selection to the ajax loading gallery block.

OPTION 3. Use the BB AJAX remote control block and set it to request the ajax reload on the blocks by ajax event. Write a snippet of javascript the page to trigger the blocks by ajax event when the selection changes with the selection as an event parameter. (This was the old way of doing it and is what the specialised symbols and form watching above now do)

You can then access those form parameters in the MD that decides what gallery to load. The MD symbols with BB AJAX include symbols for retrieving form values from Get or Post data.

For the future, I have a Sorcerer's Gallery block currently in the PRB that provides a number of gallery and slider templates where the files to show are selected by Magic Data. It works exactly the same as Sorcerer's Map or Uber List, but shows a gallery. Once released, it will remove the need to use On Block Load for this sort of application.
tobbie replied on at Permalink Reply
tobbie
Ok, I understand the principle, but I do not figure how to trigger a block using javascript.
Do you know where can I find an example of a javascript code that trigger a block ?

Thanks again for your help.

tobbie
JohntheFish replied on at Permalink Reply
JohntheFish
Writing javascript is a last resort if you have no luck with either of the first 2 options. I will edit the above to 1,2,3 to help.

To get started, its probably easiest to experiment with loading an HTML block by ajax triggered from your user selector(ie use an html block in place of the gallery to practice)

For the first option, add a remote control block and set the repeat loader to 'when a form is submitted'. This will look for the html form element containing your user selector and trigger a blocks_by_ajax browser event when the form submit button is clicked (and block the normal form submission).

If there is only 1 form on the page and only one block by ajax on the page, that is all you need to do.

Then in the ajax loaded HTML block, add some magic data to display the value of the select by reading it from get or post using FROM_​POST_​DATA or FROM_​GET_​DATA.

Once you have it working with an HTML block to just echo your selected user, you can then do the same with your gallery.



Advanced - only for when the above is working:
==============================================
Again, once the basic mechanism is working you then modify the triggering using Magic Data to catch changes in the user selector rather than submissions of the form, so creating an 'submit on select' behaviour. The MD command AUTO_​TRIGGER_​BLOCKS_​BY_​AJAX can be used to connect the select change to the ajax load.
JohntheFish replied on at Permalink Reply
JohntheFish
If you want an example of javascript, see the Blocks By AJAX remote control block. Bt that is probably a last resort, you should be able to do this with option 1 or option 2.
tobbie replied on at Permalink Reply
tobbie
Thanks for your time.
I will experiment this in the next hours, and let you know.

tobbie.
tobbie replied on at Permalink Reply
tobbie
Hello again John,

I tried option 1. Seems to be close to work but :
1. I cannot unselect the "include any form inputs with the AJAX data" checkbox. It remains checked whatever I do. I do not mind, since I want my posts with the AJAX data, but I do not understand why. Is it normal ?
2. It works for the first form submission, but, even if the "Render a repeatable AJAX loader" is checked, and set with "repeat loading whenever a form is submitted", I cannot submit the a second time :
- The button is clickable when I load the page : OK
- When I click the button the block is loaded via AJAX : OK
- The button is clickable : OK
- when I click the button, nothing happens and the button remains disabled and non clickable after the click : NOT OK

I will try option 2, but do you have any idea of what I should have missed ?

I add that info :
- I run Concrete 5.6.3, BBA 2.3.0.1, MDOBL 1.0.2, MD 2.9.2
- Chache is totally disabled for now

thanks for your help

tobbie
JohntheFish replied on at Permalink Reply
JohntheFish
Thanks for reporting the bugs. I can repeat bot on my test system. I suspect I broke both when I added the new in-the-window processing with v2.3. You can expect an upgrade to be posted soon.

I also tested and can confirm that the responder for the blocks_by_ajax
browser event is still working OK, so option 2 will work.
JohntheFish replied on at Permalink Reply
JohntheFish
v2.3.0.2 fixes the issues, so the easy Option 1 should now be working OK.
tobbie replied on at Permalink Reply
tobbie
Dear John,

I confirm v3.0.2 fix this issue. Great job.

A last question, which MD symbol should I use to have a "like" operator. I want to filter the list of filesets according to their name (get all filsets which have a fileset name starting by a specific string). Is it possible ?


tobbie
JohntheFish replied on at Permalink Best Answer Reply
JohntheFish
At the moment there are symbols for lists containing, but not for string containing or like.

Another MD user has expressed an interest in such string tests, so I have marked down some ideas for the next update of the symbols addon. I have some other addon updates to do first, so if you need it urgently you could write your own symbol. It should be fairly easy to take one of the existing comparison symbols and hack it.

To start you copy and rename into
siteroot/models/magic_data/symbols/your_symbol_name.php

Make sure to prefix with your own name, so it won't clash with anything that gets added to MD later.

eg
/tobbie_begins_with.php
TOBBIE_BEGINS_WITH

The main thing users get caught on is that MD only scans for new symbols when you load the dashboard symbol tester!

There is documentation about writing a symbol on the MD symbols docs page on c5 and on c5magic.co.uk.

http://www.c5magic.co.uk/add-ons/magic-data/developing-symbols/...
JohntheFish replied on at Permalink Reply
JohntheFish
v2.7 of symbols now contains a suite of symbols for text matching - begins with, ends with, contains, case invariant versions of these and negated versions of these.

I also have some symbols for regex matching destined for the next update to Black Magic Data - its virtually impossible to fully sanitize a regex, so a faulty regex could break a site, hence they need to be in Black magic Data.
tobbie replied on at Permalink Reply
tobbie
Ok, I'll try it.
But for now, I have the behaviour I want using some specific MD symbol, that returns the fileset list I exactly want.
I think that Magic Data is not easy to set at a glance, but very powerfull as soon as you understand exactly what it does and how it works.
Good job, really.

tobbie
JohntheFish replied on at Permalink Reply 1 Attachment
JohntheFish
Thinking of the cache, when you need to enable the cache, you may find Cache Free Content useful.
http://www.concrete5.org/marketplace/addons/cache-free-content/...

At the moment it is in the PRB, so I have attached a zip (link above) you can download.
tobbie replied on at Permalink Reply
tobbie
Thanks for your ultra quick answer and fix.
I am trying it right now !

tobbie

concrete5 Environment Information

Browser User-Agent String

Hide Post Content

This will replace the post content with the message: "Content has been removed by an Administrator"

Hide Content

Request Refund

You have not specified a license for this support ticket. You must have a valid license assigned to a support ticket to request a refund.