Skip to content

Commit

Permalink
new tagging-workflow when creating new project
Browse files Browse the repository at this point in the history
  • Loading branch information
bakkdoor committed Sep 7, 2008
1 parent 3927467 commit 1f8bd3f
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 33 deletions.
11 changes: 9 additions & 2 deletions src/app/controllers/projects_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,8 @@ def create
@project = Project.new(params[:project])

# add tags, only if there are any specified
@project.tag_list = session[:project_tags]
#@project.tag_list += session[:project_tags]
#params[:project][]

respond_to do |format|
if @project.save
Expand Down Expand Up @@ -162,9 +163,15 @@ def auto_complete_for_project_name
end

def auto_complete_for_tag_name
input_tags = params[:project][:tag_list].split(" ")
tag_name = input_tags.last
used_tags = input_tags - [input_tags.last]
session[:project_tags] = used_tags

#session[:project_tags] = used_tags
@tags = Tag.find(:all,
:conditions => [ 'LOWER(name) LIKE ?',
'%' + params[:tag][:name].downcase + '%' ],
'%' + tag_name.downcase + '%' ],
:order => 'name ASC')

# only return tags, that aren't used yet...
Expand Down
46 changes: 15 additions & 31 deletions src/app/views/projects/new.rhtml
Original file line number Diff line number Diff line change
Expand Up @@ -15,19 +15,24 @@
<td><%= f.label :website, (l :website) %></td>
<td><%= f.text_field :website %></td>
</tr>
<tr>
<td><%= f.label :tag_list, (l :tags) %></td>
<td>
<div id="project_tags" style="padding-bottom:1em">
<%= render :partial => "tag_list_item", :collection => @project.tag_list %>
</div>
</td>
</tr>
<tr>
<td><%= f.label :tag_name, (l :tag_search)%></td>
<td>
<%= text_field_with_auto_complete :tag, :name, {}, {:method => :get, :skip_style => true} %>
<button id="add_tag_button" type="button" onclick="remote_add_tag($('tag_name').value)"><%= l :add %></button>
<% text_field_with_auto_complete :tag, :name, {}, {:method => :get, :skip_style => true} %>
<input id="tag_list" name="project[tag_list]" size="30" type="text" />
<div class="auto_complete" id="tag_name_auto_complete"></div>
<script type="text/javascript">
var tag_name_auto_completer = new Ajax.Autocompleter('tag_list', 'tag_name_auto_complete',
'/projects/auto_complete_for_tag_name',
{
method:'get',
updateElement: function(item){
var tags = $('tag_list').value.split(" ");
tags.pop();
tags.push(item.innerText)
$('tag_list').value = tags.join(" ") + " "}}
)
</script>
</td>
</tr>
<tr>
Expand All @@ -44,26 +49,5 @@
</table>
<% end %>
<script type="text/javascript" charset="utf-8">
/*
this code is responsible for adding the tags in the background
when you click on the 'add'-button
*/
function remote_add_tag(tagname)
{
new Ajax.Updater('project_tags', '/projects/add_tag',
{
asynchronous:true,
evalScripts:true,
onComplete:function(request){new Effect.Highlight("project_tags",{duration:0.5})},
onSuccess:function(request){$('tag_name').value=""; $('tag_name').focus()},
parameters:'tag=' + escape($('tag_name').value) + '&authenticity_token=' + encodeURIComponent('<%= form_authenticity_token %>')
}
)
}
</script>



<%= link_to 'Back', projects_path %>
</div>

0 comments on commit 1f8bd3f

Please sign in to comment.