Allow choice between 'normal' and pretty tag UI
authorMichael J. Rubinsky <mrubinsk@horde.org>
Wed, 1 Apr 2009 21:58:10 +0000 (17:58 -0400)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Thu, 2 Apr 2009 22:01:28 +0000 (18:01 -0400)
kronolith/lib/Imple/TagAutoCompleter.php

index d35574b..09d5eb8 100644 (file)
@@ -33,30 +33,65 @@ class Kronolith_Imple_TagAutoCompleter extends Kronolith_Imple
 
     /**
      * Attach the Imple object to a javascript event.
+     * Assume that if the 'container' parameter is empty then we want a
+     * traditional autocompleter, otherwise we get a spiffy pretty one.
+     *
      */
     public function attach()
     {
+        global $registry;
         parent::attach();
         Horde::addScriptFile('autocomplete.js', 'horde', true);
 
-        $params = array(
-            '"' . $this->_params['triggerId'] . '"',
-            '"' . $this->_params['resultsId'] . '"',
-            '"' . Horde::url($GLOBALS['registry']->get('webroot', 'kronolith') . '/imple.php?imple=TagAutoCompleter/input=' . rawurlencode($this->_params['triggerId']), true) . '"'
-        );
+        if ($pretty = !empty($this->_params['container'])) {
+            Horde::addScriptFile('taggerAutoCompleter.js', 'kronolith', true);
+        }
+        $this->_params['uri'] =  Horde::url($GLOBALS['registry']->get('webroot', 'kronolith') . '/imple.php?imple=TagAutoCompleter/input=' . rawurlencode($this->_params['triggerId']), true);
+
+        if (!$pretty) {
+            $params = array(
+                '"' . $this->_params['triggerId'] . '"',
+                '"' . $this->_params['resultsId'] . '"',
+                '"' . $this->_params['uri'] . '"'
+            );
+        }
 
         $js_params = array(
             'tokens: [","]',
             'indicator: "' . $this->_params['triggerId'] . '_loading_img"'
         );
 
-        if (!empty($this->_params['updateElement'])) {
+        // The pretty version needs to set this callback itself...
+        if (!$pretty && !empty($this->_params['updateElement'])) {
             $js_params[] = 'updateElement: ' . $this->_params['updateElement'];
         }
 
         $params[] = '{' . implode(',', $js_params) . '}';
 
-        Kronolith::addInlineScript('new Ajax.Autocompleter(' . implode(',', $params) . ')', 'dom');
+        if ($pretty) {
+            $js_vars = array('resultsId' => $this->_params['resultsId'],
+                             'uri' => $this->_params['uri'],
+                             'selectedTags' => array(),
+                             'trigger' => $this->_params['triggerId'],
+                             'tags' => $this->_params['tags'],
+                             'container' => $this->_params['container'],
+                             'URI_IMG_HORDE' => $registry->getImageDir('horde'),
+                             'params' => $params);
+            // These are optional
+            if ($this->_params['debug']) {
+                $js_vars['debug'] = $this->_params['debug'];
+            }
+
+            if ($this->_params['existing']) {
+                $js_vars['existing'] = $this->_params['existing'];
+            }
+
+           $script = array('new KronolithTagger(' . Horde_Serialize::serialize($js_vars, Horde_Serialize::JSON, NLS::getCharset()) . ')');
+        } else {
+            $script = array('new Ajax.Autocompleter(' . implode(',', $params) . ')');
+        }
+
+        Kronolith::addInlineScript($script, 'dom');
     }
 
     /**