Better way of loading and initializing the tag autocompleter.
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 10 Mar 2010 16:32:47 +0000 (11:32 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 10 Mar 2010 16:39:39 +0000 (11:39 -0500)
Avoids issues with execution timing, dom loading etc...

kronolith/index.php
kronolith/js/kronolith.js
kronolith/lib/Ajax/Imple/TagAutoCompleter.php
kronolith/templates/chunks/calendar.php

index 77b7f7c..c17d279 100644 (file)
@@ -80,6 +80,20 @@ Horde::outputInlineScript();
 if ($conf['maps']['driver']) {
     Kronolith::initEventMap($conf['maps']);
 }
-$tac = Horde_Ajax_Imple::factory(array('kronolith', 'TagAutoCompleter'), array('triggerId' => 'kronolithEventTags', 'box' => 'kronolithEventACBox', 'pretty' => true));
-$tac->attach();
+Horde_Ajax_Imple::factory(
+    array('kronolith', 'TagAutoCompleter'),
+    array('triggerId' => 'kronolithEventTags',
+          'box' => 'kronolithEventACBox',
+          'pretty' => true,
+          'var' => 'kronolithETagAc'))
+    ->attach();
+
+Horde_Ajax_Imple::factory(
+    array('kronolith', 'TagAutoCompleter'),
+    array('triggerId' => 'kronolithCalendarinternalTags',
+          'triggerContainer' => 'kronolithACCalendarTriggerContainer',
+          'box' => 'kronolithCalendarinternalACBox',
+          'pretty' => true,
+          'var' => 'kronolithCTagAc'))
+    ->attach();
 echo "</body>\n</html>";
index ba97994..8ddff6a 100644 (file)
@@ -2132,8 +2132,8 @@ KronolithCore = {
             RedBox.loading();
             this.doAction('chunkContent', { chunk: 'calendar' }, function(r) {
                 if (r.response.chunk) {
-                    RedBox.onDisplay = function() { this.editCalendarCallback(calendar); RedBox.onDisplay = null; }.bind(this);
                     RedBox.showHtml(r.response.chunk);
+                    this.editCalendarCallback(calendar);
                 } else {
                     this.closeRedBox();
                 }
@@ -2204,7 +2204,9 @@ KronolithCore = {
                 return;
             }
         }
-
+        if (!kronolithCTagAc.initialized) {
+            kronolithCTagAc.init()
+        }
         if (newCalendar) {
             switch (type) {
             case 'internal':
@@ -2223,6 +2225,10 @@ KronolithCore = {
             $('kronolithCalendar' + type + 'Id').clear();
             $('kronolithCalendar' + type + 'Color').setValue('#dddddd').setStyle({ backgroundColor: '#dddddd', color: '#000' });
             form.down('.kronolithCalendarDelete').hide();
+            if (calendar && type == 'remote') {
+                $('kronolithCalendarremoteUrl').setValue(calendar);
+            }
+            kronolithCTagAc.reset();
         } else {
             info = Kronolith.conf.calendars[type][calendar];
 
@@ -2232,8 +2238,11 @@ KronolithCore = {
 
             switch (type) {
             case 'internal':
-                $('kronolithCalendarinternalTags').autocompleter.init(Kronolith.conf.calendars.internal[calendar].tg);
-                // Fall through
+                $('kronolithCalendarinternalDescription').setValue(info.desc);
+                $('kronolithCalendarinternalLinkImportExport').up('span').show();
+                $('kronolithCalendarinternalExport').href = Kronolith.conf.URI_CALENDAR_EXPORT + '=' + calendar;
+                kronolithCTagAc.reset(Kronolith.conf.calendars.internal[calendar].tg);
+                break;
             case 'tasklists':
                 $('kronolithCalendar' + type + 'Description').setValue(info.desc);
                 $('kronolithCalendar' + type + 'LinkImportExport').up('span').show();
@@ -2272,6 +2281,7 @@ KronolithCore = {
             form.down('.kronolithFormActions .kronolithSeparator').show();
         } else {
             form.disable();
+            kronolithCTagAc.disable();
             form.down('.kronolithColorPicker').hide();
             form.down('.kronolithCalendarDelete').hide();
             form.down('.kronolithCalendarSave').hide();
@@ -3415,12 +3425,12 @@ KronolithCore = {
                 return;
 
             case 'kronolithEventTag':
-                $('kronolithEventTags').autocompleter.addNewItemNode(elt.getText());
+                kronolithETagAc.addNewItemNode(elt.getText());
                 e.stop();
                 return;
 
             case 'kronolithCalendarTag':
-                $('kronolithCalendarinternalTags').autocompleter.addNewItemNode(elt.getText());
+                kronolithCTagAc.addNewItemNode(elt.getText());
                 e.stop();
                 return;
 
@@ -3826,10 +3836,13 @@ KronolithCore = {
     {
         this.closeRedBox();
 
-        if (Object.isUndefined($('kronolithEventTags').autocompleter)) {
+        if (Object.isUndefined(kronolithETagAc)) {
             this.editEvent.bind(this, calendar, id, date).defer();
             return;
         }
+        if (!kronolithETagAc.initialized) {
+            kronolithETagAc.init();
+        }
 
         RedBox.onDisplay = function() {
             try {
@@ -3861,7 +3874,7 @@ KronolithCore = {
             RedBox.loading();
             this.doAction('getEvent', { cal: calendar, id: id, date: date }, this.editEventCallback.bind(this));
         } else {
-            $('kronolithEventTags').autocompleter.init();
+            kronolithETagAc.reset();
             var d;
             if (date) {
                 if (date.endsWith('all')) {
@@ -3902,7 +3915,7 @@ KronolithCore = {
             viewDates = this.viewDates(this.date, this.view),
             start = viewDates[0].dateString(),
             end = viewDates[1].dateString();
-        $('kronolithEventTags').autocompleter.shutdown();
+        kronolithETagAc.shutdown();
         this.startLoading(cal, start + end);
         this.doAction('saveEvent',
                       $H($('kronolithEventForm').serialize({ hash: true }))
@@ -4113,7 +4126,7 @@ KronolithCore = {
         }
 
         /* Tags */
-        $('kronolithEventTags').autocompleter.init(ev.tg);
+        kronolithETagAc.reset(ev.tg);
 
         /* Geo */
         if (ev.gl) {
index ae05ada..db30ff5 100644 (file)
@@ -33,6 +33,10 @@ class Kronolith_Ajax_Imple_TagAutoCompleter extends Horde_Ajax_Imple_AutoComplet
             $ret['pretty'] = 'TagAutoCompleter';
         }
 
+        if (!empty($this->_params['var'])) {
+            $ret['var'] = $this->_params['var'];
+        }
+
         return $ret;
     }
 
index 8972453..0b2e414 100644 (file)
@@ -215,12 +215,3 @@ asort($groups);
 </form>
 
 </div>
-<?php
-Horde_Ajax_Imple::factory(
-    array('kronolith', 'TagAutoCompleter'),
-    array('triggerId' => 'kronolithCalendarinternalTags',
-          'triggerContainer' => 'kronolithACCalendarTriggerContainer',
-          'box' => 'kronolithCalendarinternalACBox',
-          'pretty' => true,
-          'no_onload' => true))
-    ->attach();