[dev] [Ajax/Imple/Autocomplete] problems creating an autocompleter

Jonah Dekeyzer jonah at menzz.be
Thu Sep 19 21:06:59 UTC 2013


I'm developing an own module for Horde (advocaat).

I would like to add an autocompleter to some of my horde forms.

I figured out that the autocompleter used in IMP, KRONOLITH, ... makes 
use of Imple.

In order to test I created a file test.php: which contains:
---------------------------------------------------------------
<?php
require_once __DIR__ . '/lib/Application.php';
Horde_Registry::appInit('advocaat');

$page_output->header(array('title' => 'test'));

$injector->getInstance('Horde_Core_Factory_Imple')->create('Advocaat_Ajax_Imple_CnAutoCompleter', 
array(
     'box' => 'cnACBox',
     'id' => 'cn',
     'pretty' => true
));

?>
<div>
<label for="cn">CN: </label>
<input id="cn" />
</div>

<?php

$page_output->footer();
------------------------------------------------------



I also created a advocaat/lib/Ajax/Imple/CnAutoCompleter.php:
------------------------------------------------------
<?php
class Advocaat_Ajax_Imple_CnAutoCompleter extends 
Horde_Core_Ajax_Imple_AutoCompleter
{
     /**
      */
     protected function _getAutoCompleter()
     {
         $opts = array();

         foreach (array('box', 'triggerContainer') as $val) {
             if (isset($this->_params[$val])) {
                 $opts[$val] = $this->_params[$val];
             }
         }

         return empty($this->_params['pretty'])
             ? new Horde_Core_Ajax_Imple_AutoCompleter_Ajax($opts)
             : new Horde_Core_Ajax_Imple_AutoCompleter_Pretty($opts);
     }

     /**
      */
     protected function _handleAutoCompleter($input)
     {
             return array($input, "other value");  // this is a simple 
array for testing.  I wil add some functions here in the future.
     }
}
--------------------------------------------------------------------------

I tried to test the CnAutoCompleter in Kronolith to make sure 
CnAutoCompleter.php was working.

So i copied the CnAutoCompleter.php to kronolith/lib/Ajax/Imple/. and 
renamed the class to Kronolith_ (and so on).
Next I changed a TagAutoCompleter to CnAutoCompleter in 
kronolith/index.php and I could see that my CnAutoCompleter.php worked 
in the Tag field of the event.


I searched further and I added in the file 
advocaat/lib/Ajax/Application.php:
-----------------------------------
<?php
class Advocaat_Ajax_Application extends Horde_Core_Ajax_Application
{
     /**
      * Application specific initialization tasks should be done in here.
      */
     protected function _init()
     {
         // This adds the 'noop' action to the current application.
         $this->addHandler('Advocaat_Ajax_Application_Handler');
         $this->addHandler('Horde_Core_Ajax_Application_Handler_Imple');
     }

}
-----------------------------------


The autocompleter stil was not working so I searched further.

Now I believe that I have to create a file advocaat/js/advocaat.js

Based on what I saw in kronolith/js/kronolith.js, I created:
------------------------------------
<?php
AdvocaatCore = {
         clickHandler: function(e, dblclick)
         {
                 if (e.isRightClick() || typeof e.element != 'function') {
                         return;
                 }

                 var elt = e.element(),
                         orig = e.element(),
                         id, tmp, calendar;

                 while (Object.isElement(elt)) {
                         id = elt.readAttribute('id');

                         switch (id) {
                         case 'cn':
                                 
HordeImple.AutoCompleter.cns.addNewItemNode(elt.getText());
                                 e.stop();
                                 break;
                         }
                 }
         }
};

/* Initialize global event handlers. */
document.observe('dom:loaded', AdvocaatCore.onDomLoad.bind(AdvocaatCore));

/* Extend AJAX exception handling. */
HordeCore.onException = 
HordeCore.onException.wrap(AdvocaatCore.onException.bind(AdvocaatCore));
------------------------------------



My autocompleter is not working.

Did I make a mistake?
Is there an extra file I need to create?




Thx,


Jonah



More information about the dev mailing list