Some initial work on putting an autocomplete text field for adding
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jan 2009 01:57:29 +0000 (20:57 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jan 2009 14:54:39 +0000 (09:54 -0500)
tags in the calendar panel. Obviously needs work, but it's a start.
(Autocomplete works, but 'add' button does nothing yet).

kronolith/js/tagactions.js
kronolith/lib/Imple/TagActions.php
kronolith/lib/Tagger.php
kronolith/templates/panel.inc
kronolith/themes/screen.css

index 2963adc..6c5cb4c 100755 (executable)
@@ -30,9 +30,9 @@ function removeTag(resource, type, tagid, endpoint)
     return true;
 }
 
-// Since onsubmit is never called when submitting programatically we
-// can use this function to add tags when we press enter on the tag form.
-function submitcheck()
+function toggleNewTags(domid)
 {
-    return !addTag();
+       $('tag-show-' + domid).toggle();
+       $('tag-hide-' + domid).toggle();
+       $('newtags-' + domid).toggle();
 }
\ No newline at end of file
index 1c70151..ea58180 100644 (file)
@@ -90,6 +90,7 @@ class Kronolith_Imple_TagActions extends Kronolith_Imple
     {
         $tags = $tagger->getTags($id, 'calendar');
         $js = '';
+        $html = '';
 
         if ($type == 'calendar') {
             $cal = $GLOBALS['kronolith_shares']->getShare($id);
@@ -102,13 +103,11 @@ class Kronolith_Imple_TagActions extends Kronolith_Imple
             $hasEdit = $event->hasPermission(PERMS_EDIT, Auth::getAuth());
         }
 
-        $html = count($tags) ? '<h5>' . _("Tags") . '</h5>': '';
-        $html .= '<ul>';
         foreach ($tags as $tag_id => $tag) {
             $html .= '<li>' .  $tag . ($hasEdit ? '<a href="#" onclick="removeTag(\'' . $id . '\', \'' . $type . '\',' . $tag_id . ', \'' . Horde::url('imple.php', true) . '\'); Event.stop(event)" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag"), '', $GLOBALS['registry']->getImageDir('horde')) . '</a>' : '') . '</li>';
         }
 
-        return $html . '</ul><div class="clear">&nbsp;</div>';
+        return $html;
     }
 
 }
index 969a0c7..7c254cb 100644 (file)
@@ -190,4 +190,9 @@ class Kronolith_Tagger
         //TODO
     }
 
+    public function listTags($token)
+    {
+        return self::$_tagger->getTags(array('q' => $token));
+    }
+
 }
index 7a0e1cd..f5ff4c5 100644 (file)
@@ -44,22 +44,31 @@ $tagger = new Kronolith_Tagger();
  <ul id="mycalendars">
 <?php foreach ($my_calendars as $id => $cal): ?>
   <li><label><input type="checkbox" class="checkbox" name="display_cal[]" value="<?php echo htmlspecialchars($id) ?>"<?php echo (in_array($id, $display_calendars) ? ' checked="checked"' : '') . ' /> ' . htmlspecialchars($cal->get('name')) ?></label> <?php echo $info_img ?>
-   <div class="panel-tags" id="tags-<?php echo $id?>">
+   <div class="panel-tags">
    <?php $tags = $tagger->getTags($id, 'calendar'); ?>
-   <h5><?php echo (count($tags) ? _("Tags") : '');?></h5>
-   <ul style="margin-left: 10px;">
-    <?php foreach ($tags as $tag_id => $tag): ?>
-    <li><?php echo $tag . ($cal->hasPermission(Auth::getAuth(), PERMS_EDIT) ? '<a href="#" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag"), '', $registry->getImageDir('horde')) . '</a>' : '') . '</li>'?>
-    <?php
-        Kronolith_Imple::factory('TagActions', array('triggerId' => 'remove' . md5($id . $tag_id),
-                                                              'action' => 'delete',
-                                                              'resource' => $id,
-                                                              'type' => 'calendar',
-                                                              'tagId' => $tag_id));
-    ?>
-    <?php endforeach;?>
-  </ul>
-  <div class="clear">&nbsp;</div>
+    <span style="cursor:pointer;" id="tag-show-<?php echo $id?>" onclick="toggleNewTags('<?php echo $id?>');" title="<?php echo _("Add new tags")?>">+</span><span id="tag-hide-<?php echo $id?>" style="display:none;cursor:pointer;" onclick="toggleNewTags('<?php echo $id?>');">-</span>
+   <h5 style="display: inline;"><?php echo _("Tags")?></h5>
+   <div id="newtags-<?php echo $id?>" style="display:none;">
+        <ul id="tags-<?php echo $id?>">
+        <?php foreach ($tags as $tag_id => $tag): ?>
+         <li class="panel-tags"><?php echo $tag . ($cal->hasPermission(Auth::getAuth(), PERMS_EDIT) ? '<a href="#" id="remove' . md5($id . $tag_id) . '">' . Horde::img('delete-small.png', _("Remove Tag"), '', $registry->getImageDir('horde')) . '</a>' : '') . '</li>'?>
+        <?php
+         Kronolith_Imple::factory('TagActions', array('triggerId' => 'remove' . md5($id . $tag_id),
+                                                      'action' => 'delete',
+                                                      'resource' => $id,
+                                                      'type' => 'calendar',
+                                                      'tagId' => $tag_id));
+       ?>
+       <?php endforeach;?>
+      </ul>
+      <div class="clear">&nbsp;</div>
+      <input type="text" name="newtags-input-<?php echo $id?>" id="newtags-input-<?php echo $id?>" size="10" /><input type="button" class="button" value="add" id="test" />
+      <div id="newtags-input-<?php echo $id?>_results" class="autocomplete"></div>
+      <span id="newtags-input-<?php echo $id?>_loading_img" style="display:none;"><?php echo Horde::img('loading.gif', _("Loading...")) ?></span>
+     <?php
+      Kronolith_Imple::factory('TagAutoCompleter', array('triggerId' => 'newtags-input-' . $id));
+      ?>
+  </div>
   </div>
   </li>
 <?php endforeach; ?>
index bf37659..18dbdf1 100644 (file)
@@ -1118,7 +1118,7 @@ div.kronolithView .kronolithEvents .kronolithEvent .kronolithEventInfo {
     list-style-type: none;
 }
 
-.panel-tags li {
+li.panel-tags {
     float: left;
     padding: 2px;
 }