[commits] [Wiki] changed: Doc/Dev/HordeAjaxApplications
Ralf Lang (B1 Systems GmbH)
lang at b1-systems.de
Wed Apr 11 05:55:42 UTC 2018
rlang Wed, 11 Apr 2018 05:55:42 +0000
Modified page: https://wiki.horde.org/Doc/Dev/HordeAjaxApplications
New Revision: 11
Change log: Some more details on HordeCore.doAction workflow
@@ -40,8 +40,42 @@
?>
</code>
[http://dev.horde.org/api/master/lib/Core/classes/Horde_Core_Ajax_Application.html Horde_Core_Ajax_Application
documentation]
+
++++ Making an ajax call to Horde
+
+
+Implement $App_Ajax_Application and load at least one handler class
$App_Ajax_Application_Handler in the _init function.
+https://github.com/horde/kronolith/blob/master/lib/Ajax/Application.php
+https://github.com/horde/kronolith/blob/master/lib/Ajax/Application/Handler.php
+
+Call HordeCore.doAction(action, params, opts) from JS:
+action is corresponding to one method name in one of the loaded handlers.
+options is a json object with parameters.
+
+doAction takes care of authentication details transparently.
+
+Real Life Example:
+https://github.com/horde/kronolith/blob/master/js/kronolith.js#L296
+<code>
+ HordeCore.doAction('searchEvents', {
+ cals: Object.toJSON(cals),
+ query: query,
+ time: this.search
+}, {
+ callback: function(r) {
+
+}
+</code>
+
+The handlers have no parameters. They expect named parameters in
$this->vars->$name corresponding to the params in the doAction call's
second argument.
+
+
+Return values:
+Normally, you would return an array structure of serializable data.
It will automatically be sent to browser as a json structure. You can
also return a string (like HTML) or a Horde_Core_Ajax_Response object
for more advanced use cases.
+
+
+++ Application-specific javascript code
Most apps which sport completely distinct dynamic and traditional
views (kronolith, hermes) also have $app/js/$app.js
More information about the commits
mailing list