add ajax functionality to user interface

Author Message

Dhaval Patel

Monday 04 February 2008 9:24:23 pm

hi all,

i have developed one site.

in that there are mainly three columns

1. left column (menu)
2. middle column (content)
3. right column(block)

now i want the paging at right column side block with ajax.

i have done this with javascript only temperarely.

but i want it using ajax only.

please any one help me.

With Best Regards,

Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
dhaval.patel@inetprocess.com
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in

André R.

Tuesday 05 February 2008 12:40:32 am

So you want to get the content asynchronous as XML?..

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Dhaval Patel

Tuesday 05 February 2008 1:00:01 am

Thank you for replying André

now i have right column (view of frontpage).

In that there is a listing of the sub items of that frontpage.

now if the list is of more then 4 articles then paging should be there.

and the data is coming from database.

With Best Regards,

Dhaval Patel
Team Leader - iNETProcess(I) Pvt. LTD.
dhaval.patel@inetprocess.com
Ph No: +91 79 65 12 35 00
http://www.inetprocess.co.in

André R.

Tuesday 05 February 2008 8:49:07 am

You have to look into a couple of things:
* creating you own module / view (in a extension) to get content from the database and display it
* alternatively you can look into using layout/set to set a different layout for the content you get with ajax and combine that with a custom view (see sitemap for example). url will look something like "domain.com/layout/set/ajax/content/view/menu/55" where 55 is the node_id
* modify you right menu to call this module or special url ( using xmlhttprequest ) when you page the menu.

eZ Online Editor 5: http://projects.ez.no/ezoe || eZJSCore (Ajax): http://projects.ez.no/ezjscore || eZ Publish EE http://ez.no/eZPublish/eZ-Publish-Enterprise-Subscription
@: http://twitter.com/andrerom

Paul Leclercq

Wednesday 06 February 2008 3:35:12 pm

Like andré said you will need to create a custom view/module for your left page.

If you use "prototype" you will be able to do something like this:

let say this will be the basic structure of your page:

<script include..... prototype.js />

<div id="leftcol"></div>
<div id="main"></div>
<div id="righcol"></div>

<script type="text/javascript">
var tmp = new Ajax.Updater('leftcol", {"/mymodule/myleftcol"|ezurl('single')});
tmp = new Ajax.Updater('main", {"/mymodule/main"|ezurl('single')});
tmp = new Ajax.Updater('rightcol", {"/mymodule/myrightcol"|ezurl('single')});
</script>

The "prototype" API will allow you to a div which has an id very simply like this:
new Ajax.Updater('leftcol", {"/mymodule/myrightcol"|ezurl('single')});

Which you can use in your links:

<a href="#" onclick="tmp = new Ajax.Updater('leftcol', {concat("mymodule/myleftcol/(option)/", $option)|ezurl('single')})">update left col</a>

or export into javascript function and then reuse in your links:

myfunction.js

function mylink(option1){
var tmp = new Ajax.Updater('leftcol", "/mymodule/myleftcol/(page)/"+ option1);
}
<a href="#" onclick="mylink(option1)">update left col</a>

More info on this fonction here:
http://www.prototypejs.org/api/ajax/updater

Download prototype here:
http://www.prototypejs.org/download

An ajax view is generaly very simple since it will just update a small part of your page:
the following lines should be all you need for your simple view files, main.php/myleftcol.php/myrightcol.php (which you would put in the "/extension/your_module_s_name/modules/"'s directory):

<?php
include_once( 'kernel/common/template.php' );
$tpl =& templateInit();

$tpl->setVariable( 'view_parameters', $Params['UserParameters'] );

$Result = array();
$Result['pagelayout'] = false;
$Result['content'] = $tpl->fetch( $template );
?>

replace $template with the url of your template and you are set.

Your module.php file can also be very basic:

<?php
$Module = array( 'name' => 'mymodule' ,
                 'variable_params' => true );

$ViewList = array();
$ViewList['myleftcol'] = array( 'script' => 'myleftcol.php');
$ViewList['main'] = array( 'script' => 'main.php');
$ViewList['myrightcol'] = array( 'script' => 'myrightcol.php');
?>

this will give you a basic pagelayour with nothing in it which is ideal for simple blocs which will be udated and will avoid you from having to create your own view.

The attentive minds will have noticed that in this exemple I have passed on the view_parameters which will allow you to keep the same functionality as with node templates. By passing on functionnality to your template using the /(param)/ methods, this will allow you to include paging on to your menu ( url/(offset)/xxx )

I recommend reading this if you get a little lost:
http://ez.no/ezpublish/documentation/development/extensions/building_an_ez_publish_module

Good luck with that,

let us know how you get on.

Xavier Dutoit

Thursday 07 February 2008 3:44:31 am

It provides a generic interface to query / fetch node and a js library to display them (have a look at the included exemples)

http://projects.ez.no/json

http://www.sydesy.com

Powered by eZ Publish™ CMS Open Source Web Content Management. Copyright © 1999-2014 eZ Systems AS (except where otherwise noted). All rights reserved.

eZ debug

Timing: Jan 18 2025 22:34:27
Script start
Timing: Jan 18 2025 22:34:27
Module start 'layout'
Timing: Jan 18 2025 22:34:27
Module start 'content'
Timing: Jan 18 2025 22:34:29
Module end 'content'
Timing: Jan 18 2025 22:34:29
Script end

Main resources:

Total runtime1.4447 sec
Peak memory usage4,096.0000 KB
Database Queries70

Timing points:

CheckpointStart (sec)Duration (sec)Memory at start (KB)Memory used (KB)
Script start 0.00000.0063 588.0469152.6406
Module start 'layout' 0.00630.0032 740.687539.4766
Module start 'content' 0.00951.4337 780.1641677.3516
Module end 'content' 1.44320.0014 1,457.515620.1250
Script end 1.4446  1,477.6406 

Time accumulators:

 Accumulator Duration (sec) Duration (%) Count Average (sec)
Ini load
Load cache0.00390.2674160.0002
Check MTime0.00170.1208160.0001
Mysql Total
Database connection0.00210.143610.0021
Mysqli_queries1.368794.7378700.0196
Looping result0.00110.0780680.0000
Template Total1.412497.820.7062
Template load0.00260.180720.0013
Template processing1.409897.585120.7049
Template load and register function0.00010.009510.0001
states
state_id_array0.00140.095210.0014
state_identifier_array0.00110.078220.0006
Override
Cache load0.00230.1601620.0000
Sytem overhead
Fetch class attribute can translate value0.00070.047440.0002
Fetch class attribute name0.00160.107890.0002
XML
Image XML parsing0.00350.242640.0009
class_abstraction
Instantiating content class attribute0.00000.0016100.0000
General
dbfile0.00280.1910280.0001
String conversion0.00000.000440.0000
Note: percentages do not add up to 100% because some accumulators overlap

Templates used to render the page:

UsageRequested templateTemplateTemplate loadedEditOverride
1node/view/full.tplfull/forum_topic.tplextension/sevenx/design/simple/override/templates/full/forum_topic.tplEdit templateOverride template
6content/datatype/view/ezxmltext.tpl<No override>extension/community_design/design/suncana/templates/content/datatype/view/ezxmltext.tplEdit templateOverride template
15content/datatype/view/ezxmltags/paragraph.tpl<No override>extension/ezwebin/design/ezwebin/templates/content/datatype/view/ezxmltags/paragraph.tplEdit templateOverride template
7content/datatype/view/ezxmltags/line.tpl<No override>design/standard/templates/content/datatype/view/ezxmltags/line.tplEdit templateOverride template
4content/datatype/view/ezimage.tpl<No override>extension/sevenx/design/simple/templates/content/datatype/view/ezimage.tplEdit templateOverride template
5content/datatype/view/ezxmltags/literal.tpl<No override>extension/community/design/standard/templates/content/datatype/view/ezxmltags/literal.tplEdit templateOverride template
1print_pagelayout.tpl<No override>extension/community/design/community/templates/print_pagelayout.tplEdit templateOverride template
 Number of times templates used: 39
 Number of unique templates used: 7

Time used to render debug report: 0.0001 secs