Attach the 'add' action to the tagger input box. Adding tags now
authorMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jan 2009 15:28:26 +0000 (10:28 -0500)
committerMichael J. Rubinsky <mrubinsk@horde.org>
Sat, 31 Jan 2009 15:28:26 +0000 (10:28 -0500)
work from the calendar panel.

Obviously the CSS needs some work, UI suggestions welcome.

kronolith/js/tagactions.js
kronolith/lib/Imple/TagActions.php
kronolith/templates/panel.inc

index 84c85bc..f9fc362 100755 (executable)
@@ -1,14 +1,14 @@
-function addTag()
+function addTag(resource, type, endpoint)
 {
-    if (!$('addtag').value.blank()) {
+    if (!$('newtags-input_' + resource).value.blank()) {
         var params = new Object();
-        params.requestType="TagActions/action=add/gallery=" + tagActions.gallery + "/tags=" + $('addtag').value;
-        new Ajax.Updater({success:'tags'},
-                         tagActions.url,
+        params.imple="TagActions/action=add/resource=" + resource + "/type=" + type + "/tags=" + $('newtags-input_' + resource).value;
+        new Ajax.Updater({success:'tags_' + resource},
+                         endpoint,
                          {
                              method: 'post',
                              parameters: params,
-                             onComplete: function() {$('addtag').value = "";}
+                             onComplete: function() {$('newtags-input_' + resource).value = "";}
                          }
         );
     }
@@ -27,6 +27,7 @@ function removeTag(resource, type, tagid, endpoint)
                          parameters: params
                      }
     );
+    
     return true;
 }
 
index 619a49a..c0df540 100644 (file)
@@ -23,11 +23,11 @@ class Kronolith_Imple_TagActions extends Kronolith_Imple
         $action = $this->_params['action'];
         $content_id = $this->_params['resource'];
         $content_type = $this->_params['type'];
-        $tag_id = $this->_params['tagId'];
+        $tag_id = !empty($this->_params['tagId']) ? $this->_params['tagId'] : null;
         $endpoint = Horde::url('imple.php', true);
 
         if ($action == 'add') {
-            $js = "Event.observe('" . $dom_id . "', 'click', function(event) {addTag(); Event.stop(event)});";
+            $js = "Event.observe('" . $dom_id . "_" . $content_id . "', 'click', function(event) {addTag('" . $content_id . "', '" . $content_type . "', '" . $endpoint . "'); Event.stop(event)});";
         } elseif ($action == 'delete') {
             $js = "Event.observe('" . $dom_id . "', 'click', function(event) {removeTag('" . $content_id . "', '" . $content_type . "', " . $tag_id . ", '" . $endpoint . "'); Event.stop(event)});";
         }
@@ -61,12 +61,12 @@ class Kronolith_Imple_TagActions extends Kronolith_Imple
 
         if ($perm) {
             /* Get the resource owner */
+            $tagger = new Kronolith_Tagger();
             switch ($request) {
             case 'add':
-                //@TODO
+                $tagger->tag($args['resource'], $tags, $args['type']);
                 break;
             case 'remove':
-                $tagger = new Kronolith_Tagger();
                 $tagger->untag($args['resource'], (int)$tags, $args['type']);
                 break;
             }
index c410548..750ce80 100644 (file)
@@ -62,11 +62,15 @@ $tagger = new Kronolith_Tagger();
        <?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" />
+      <input type="text" name="newtags-input_<?php echo $id?>" id="newtags-input_<?php echo $id?>" size="10" /><input type="button" class="button" value="add" name="newtags-button_<?php echo $id?>" id="newtags-button_<?php echo $id?>" />
       <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' => $id));
+      Kronolith_Imple::factory('TagActions', array('triggerId' => 'newtags-button',
+                                                   'resource' => $id,
+                                                   'type' => 'calendar',
+                                                   'action' => 'add'));
       ?>
   </div>
   </div>