From 2675b5cdc4012d1d667eeedee5a7d648bfa95b3e Mon Sep 17 00:00:00 2001 From: "Michael J. Rubinsky" Date: Wed, 10 Mar 2010 11:32:47 -0500 Subject: [PATCH] Better way of loading and initializing the tag autocompleter. Avoids issues with execution timing, dom loading etc... --- kronolith/index.php | 18 +++++++++++++-- kronolith/js/kronolith.js | 33 +++++++++++++++++++-------- kronolith/lib/Ajax/Imple/TagAutoCompleter.php | 4 ++++ kronolith/templates/chunks/calendar.php | 9 -------- 4 files changed, 43 insertions(+), 21 deletions(-) diff --git a/kronolith/index.php b/kronolith/index.php index 77b7f7ca1..c17d27933 100644 --- a/kronolith/index.php +++ b/kronolith/index.php @@ -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 "\n"; diff --git a/kronolith/js/kronolith.js b/kronolith/js/kronolith.js index ba97994c0..8ddff6a38 100644 --- a/kronolith/js/kronolith.js +++ b/kronolith/js/kronolith.js @@ -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) { diff --git a/kronolith/lib/Ajax/Imple/TagAutoCompleter.php b/kronolith/lib/Ajax/Imple/TagAutoCompleter.php index ae05ada94..db30ff5fd 100644 --- a/kronolith/lib/Ajax/Imple/TagAutoCompleter.php +++ b/kronolith/lib/Ajax/Imple/TagAutoCompleter.php @@ -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; } diff --git a/kronolith/templates/chunks/calendar.php b/kronolith/templates/chunks/calendar.php index 897245394..0b2e4143c 100644 --- a/kronolith/templates/chunks/calendar.php +++ b/kronolith/templates/chunks/calendar.php @@ -215,12 +215,3 @@ asort($groups); - 'kronolithCalendarinternalTags', - 'triggerContainer' => 'kronolithACCalendarTriggerContainer', - 'box' => 'kronolithCalendarinternalACBox', - 'pretty' => true, - 'no_onload' => true)) - ->attach(); -- 2.11.0