Skip to content
Fedir Zinchuk edited this page Mar 6, 2019 · 13 revisions

Model2Blocks

FLAX.Model2Blocks - update a several blocks at once. Allows to update the couple blocks at one request.

Simple Object that contain the info about what block need to update as follows:

// Configuration
FLAX.Model2Blocks['Request-ID'] = {
 'markup-main':'Request-ID', // For update the main block
 'some-markup-one':'block-id-one', // For update the block with id="block-id-one"
 'some-markup-two':'block-id-two', // For update the block with id="block-id-two"
 // So one...
};

Answer should looks like next:

<!-- :ax:markup-main:begin: //-->
HTML code of the main block
<!-- :ax:markup-main:end: //-->
 
Everything between these blocks will be ignored.
 
<!-- :ax:some-markup-one:begin: //-->
HTML code for the some block one
<!-- :ax:some-markup-one:end: //-->

Everything between these blocks will be ignored.
 
<!-- :ax:some-markup-two:begin: //-->
HTML code for the some block two
<!-- :ax:some-markup-two:end: //-->

Everything between these blocks will be ignored.

'some-markup-one' and 'some-markup-two' - name of the blocks in the answer markup. 'block-id-one' and 'block-id-two' - the ids of the blocks in the client side code. Request-ID should be equal ID that used in FLAX.Filter, it a main block ID.

Recommended use the same name for ID and for markup.

How it works

After got answer from server FullAJAX will check whether Model2Blocks defined, if YES then will try find the all blocks that defined and put each in the block that have ID equal to ID in Model2Blocks configuration.

Example using

With the one main content request:

// Initialize filter
FLAX.Filter.add({url:'/', id:'content'});
// Model2Blocks
FLAX.Model2Blocks['content'] = {
 'content':'content',
 'menu':'menu',
 'left-block':'left-block'
}

Answer should looks like next

<!-- :ax:content:begin: //-->
HTML code of the content
<!-- :ax:content:end: //-->
 
<!-- :ax:menu:begin: //-->
HTML code of the menu
<!-- :ax:menu:end: //-->
 
<!-- :ax:left-block:begin: //-->
HTML code of the left block
<!-- :ax:left-block:end: //-->

With the several main content request:

// Initialize filter
FLAX.Filter.add({url:'/news', id:'news-container', params:'request=news'});
FLAX.Filter.add({url:'/photo', id:'photo-container', params:'request=photo'});
// Model2Blocks
FLAX.Model2Blocks['news-container'] = {
 'news-container':'news-container',
 'menu':'menu',
 'some-block-one':'some-block-one'
}
FLAX.Model2Blocks['photo-container'] = {
 'photo-container':'photo-container',
 'menu':'menu',
 'some-block-second':'some-block-second'
}

Answer similar to as above but depend from request. So when user click on link /news?id=1 will be loaded news in the news container and will updated the all blocks that defined for this request ID. And the same for /photo links.

Clone this wiki locally