[dev] [Ajax/Imple/Autocomplete] problems creating an autocompleter
Jonah Dekeyzer
jonah at menzz.be
Fri Sep 20 21:18:30 UTC 2013
Op 20-09-13 21:28, Jan Schneider schreef:
> Please keep discussions on the list.
>
> Zitat von Jonah Dekeyzer <jonah at menzz.be>:
>
>> Op 20-09-13 18:43, Jan Schneider schreef:
>>>
>>> Zitat von Jonah Dekeyzer <jonah at menzz.be>:
>>>
>>>> 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
>>>
>>> What exactly isn't working? And do you get any error messages?
>>
>> When I type something in the input field cn on the webpage, I do net
>> get an extra box with the choices $input and "other value" as expected.
>>
>> I did not receive any errors and the logfile (in DEBUG mode) does not
>> mention anything about the autocompleter.
>>
>>
>>
>> Jonah
>
> How about javascript errors? Do you see ajax requests at all?
I don't find any ajax requests at all in the log files of apache when I
try to use my created autocompleter.
(TagAutoCopleter in Kronolith leaves a trace).
Jonah
More information about the dev
mailing list