Author: wjohnald
Date: 2010-09-02 19:40:12 +0200 (Thu, 02 Sep 2010)
New Revision: 30810

Modified:
   
plugins/sfDoctrineActAsTaggablePlugin/trunk/modules/taggableComplete/actions/actions.class.php
   plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js
Log:
New inline taggable widget.  This script needs some style!  Resolves ticket 
#534.

Modified: 
plugins/sfDoctrineActAsTaggablePlugin/trunk/modules/taggableComplete/actions/actions.class.php
===================================================================
--- 
plugins/sfDoctrineActAsTaggablePlugin/trunk/modules/taggableComplete/actions/actions.class.php
      2010-09-02 16:25:03 UTC (rev 30809)
+++ 
plugins/sfDoctrineActAsTaggablePlugin/trunk/modules/taggableComplete/actions/actions.class.php
      2010-09-02 17:40:12 UTC (rev 30810)
@@ -25,7 +25,15 @@
   public function executeComplete()
   {
     $this->setLayout(false);
-    $current = $this->getRequestParameter('current');
+    $current = '';
+    if ($this->getRequestParameter('q'))
+    {
+       $current = $this->getRequestParameter('q');
+    }
+    else
+    {
+       $current = $this->getRequestParameter('current');
+    }
     $tags = array();
     $tagsInfo = array();
     $tagsAll = array();
@@ -82,6 +90,11 @@
       $all .= $tagInfo['right'];
       $n++;
     }
+    
+    if ($this->hasRequestParameter('q'))
+    {
+       $this->setTemplate('jQueryAutoComplete');
+    }
   }
 
        public function executeAddTag(sfWebRequest $request)

Modified: plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js
===================================================================
--- plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js    
2010-09-02 16:25:03 UTC (rev 30809)
+++ plugins/sfDoctrineActAsTaggablePlugin/trunk/web/js/pkTagahead.js    
2010-09-02 17:40:12 UTC (rev 30810)
@@ -109,3 +109,151 @@
   });
 }
 
+
+function aInlineTaggableWidget(selector, options)
+{
+       var typeaheadUrl = options['typeahead-url'];
+       
+       
+       function makeLink(attributes, title, text)
+       {
+               var new_link = $('<a />');
+               new_link.attr(attributes);
+               new_link.attr('title', title);
+               new_link.text(text);
+               
+               return new_link;
+       }
+       
+       function trimExcessCommas(string)
+       {
+               string = string.replace(/(^,)|(, ?$)/g, '');
+               string = string.replace(/(,,)|(, ,)/, ',');
+               string = $.trim(string);
+               
+               return string;
+       }       
+
+       $(selector).each(function()
+       {       
+               var popularTags = options['popular-tags'];
+               var existingTags = options['existing-tags'];
+               var popularsAttributes = {};
+               var existingTagsAttributes = {};
+               var existingDiv = $('<div />');
+               var popularsDiv = $('<div />');
+
+               // Establish the quick enhancement
+               var tagInput = $(this);
+               var typeAheadBox = $('<input />');
+               typeAheadBox.attr('type', 'text');
+               
+               var addButton = $('<a />');
+               addButton.text('Add');
+               addButton.attr({'href' : '#', 'class' : 'add-tags-link', 
'title' : 'Add these tags'});
+
+               tagInput.hide();
+               tagInput.parent().append(typeAheadBox);
+               tagInput.parent().append(addButton);
+
+
+
+               // Add a list of popular tags to be added
+               function addTagsToForm(link)
+               {
+                       tag = link.attr('title');
+                       
+                       var value = tagInput.val() + ', ' + tag;
+                       value = trimExcessCommas(value);
+                       tagInput.val(value);
+                       
+                       link.remove();
+
+                       var new_link = makeLink(existingTagsAttributes, tag, 'x 
' + tag);
+                       new_link.bind('click', function() { 
removeTagsFromForm($(this)); return false; });
+                       existingDiv.append(new_link);
+               }
+               
+               
+               // Add a list of tags that may be removed
+               function removeTagsFromForm(link)
+               {
+                       tag = link.attr('title');
+                       var value = tagInput.val();
+                       
+                       value = value.replace(tag, '');
+                       value = trimExcessCommas(value);
+                       tagInput.val(value);
+                       
+                       link.remove();
+               }
+
+
+               // a maker function for tag containers
+               function makeTagContainer(containerLabel, tagArray, 
linkAttributes, linkLabelType)
+               {
+                       // Add a list of tags that may be removed
+                       var tagContainer = $('<div />');
+                       
tagContainer.addClass('a-inline-taggable-widget-tag-container');
+                       var header = $('<h1 />');
+                       header.text(containerLabel);
+                       tagContainer.append(header);
+               
+                       var attributes = {};
+                       for (x in tagArray)
+                       {
+                               var linkLabel = '';
+                               if (linkLabelType == 'add')
+                               {
+                                       linkLabel = x + ' - ' + tagArray[x];
+                               }
+                               else if (linkLabelType == 'remove')
+                               {
+                                       linkLabel = 'x ' + x;
+                               }
+                               
+                               var new_link = makeLink(linkAttributes, x, 
linkLabel);
+                               
+                               if (linkLabelType == 'add')
+                               {
+                                       new_link.bind('click', function() { 
addTagsToForm($(this));  return false; });
+                               }
+                               else if (linkLabelType == 'remove')
+                               {
+                                       new_link.bind('click', function() { 
removeTagsFromForm($(this));  return false; });
+                               }
+                               
+                               tagContainer.append(new_link);
+                       }
+                       return tagContainer;
+               }
+
+               // Add the new tags to the existing form input.
+               // If the user doesn't click Save changes or add... tough?
+               function commitTagsToForm()
+               {
+                       var value = tagInput.val() + ',' + typeAheadBox.val();
+                       value = trimExcessCommas(value);
+                       tagInput.val(value);
+                       typeAheadBox.val('');
+                       
+                       return false;
+               }
+               addButton.bind('click', function() { commitTagsToForm(); return 
false; });
+       
+
+               existingDiv = makeTagContainer('Existing Tags', existingTags, 
existingTagsAttributes, 'remove');
+               tagInput.parent().append(existingDiv);
+               
+               popularsDiv = makeTagContainer('Popular Tags', popularTags, 
popularsAttributes, 'add');
+               tagInput.parent().append(popularsDiv);
+
+
+               // TypeAhead
+               typeAheadBox.autocomplete(typeaheadUrl,
+                       {
+                               multiple: true
+                       });
+       });     
+       
+}

-- 
You received this message because you are subscribed to the Google Groups 
"symfony SVN" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/symfony-svn?hl=en.

Reply via email to