Ajax Example using the skeleton App:
This example uses the skeleton app to create an ajax function "helloAjax". This function takes a string as argument and returns a new string saying "Hello $string".
- Create the Ajax Handler Class:
- Create the Application folder:
- cd skeleton/lib/Ajax
- mkdir Application
- Create a new file named "Handler.php" inside the skeleton/lib/Ajax/Application folder.
The Handler.php will contain the Skeleton_Ajax_Application_Handler Class.
Add the following content to this file:
vars->name;
$answer = 'Hello ' . $data;
return $answer;
}
}
------
The argument of the helloAjax function is called "name".onDomLoad: function\(\)
\{
var myName = 'Foobar';
[HordeCore](HordeCore).doAction\('helloAjax', \{name: Object.toJSON\(myName\)\}, \{callback: function\(result\) \{
console.log\('Ajax answer: ' + result\);
\}\}\);
\}
}
$page_output->addScriptFile('skeleton.js');
- Test if everything works:
maintaina:/srv/git/horde5-webmail/horde # php framework/bin/horde-generate-module boneyard "Ralf Lang "
Started new Module in /srv/git/horde5-webmail/horde/boneyard!
Register the new Module with a file in the config/registry.d directory:
applications['boneyard'] = array('name' => _("Boneyard"));
We put a file with this oneliner into the directory as advised
maintaina:/srv/git/horde5-webmail/horde # vim horde/config/registry.d/boneyard.php
Now let's re-run the script generating the links for the git checkout installation
maintaina:/srv/git/horde5-webmail/horde # php framework/bin/install_dev
EMPTYING old web directory /srv/www/vhosts.d/horde.ralf-lang.de
LINKING horde
Setting static directory permissions...
LINKING applications to web directory /srv/www/vhosts.d/horde.ralf-lang.de
LINKING sam
LINKING luxor
[.. snip ..]
LINKING pastie
LINKING ingo
LINKING boneyard
LINKING hvview
LINKING sesha
LINKING passwd
LINKING operator
LINKING nag
LINKING gollem
LINKING jonah
LINKING sueporter
LINKING ulaform
LINKING framework
[ INFO ] Source directory: /srv/git/horde5-webmail/horde/framework
[ INFO ] Framework destination directory:
/srv/www/vhosts.d/horde.ralf-lang.de/libs
[ INFO ] Horde directory: /srv/www/vhosts.d/horde.ralf-lang.de
[ INFO ] Create symbolic links: Yes
[ INFO ] Package(s) to install: ALL (129 packages)
[ INFO ] Installing package ActiveSync
[.. snip ..]
[ INFO ] Installing package xxhash
Now boneyard is set up in your web-accessible dir.
chown wwwrun:www /srv/www/vhosts.d/horde.ralf-lang.de/boneyard/config
This is for SUSE - debian or redhat may have different user/group for the web server.
Next go to $yourdomain/admin/config/ the admin panel and generate the conf.php file by clicking on the "boneyard" entry and then the "create boneyard config" button.
Now "Boneyard" should appear in your horde topbar with some bogus buttons and content
Let's create the structure of a "dynamic" application
- lib/Ajax.php - The Boneyard Ajax base class to load locale- and setting-dependent content into the browser's javascript
- lib/Ajax/Application/Handler/Example.php - A handler for Ajax requests to load data from the server -- we skip that for now
- lib/View/Sidebar.php - Boneyard_View_Sidebar - a sidebar for the dynamic view
- template/dynamic/sidebar.html.php - The template used by the sidebar view
- template/dynamic/index.inc - The main template of the dynamic view
- template/dynamic/example1.inc - One of our two example views in this demo
- template/dynamic/example2.inc - One of our two example views in this demo
- js/boneyard.js - The BoneyardCore object which contains the main click handler etc
We also need to touch the index.php file to enable the dynamic view and the lib/Application.php file to advertise that dynamic view exists.
See https://github.com/ralflang/horde-boneyard to view the code in detail.