mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-03 15:58:50 +01:00
get autocomplete working for tags
This commit is contained in:
parent
5eb2d5dde1
commit
7a74025253
3 changed files with 60 additions and 13 deletions
|
|
@ -7,7 +7,7 @@ class TodosController < ApplicationController
|
|||
append_before_filter :find_and_activate_ready, :only => [:index, :list_deferred]
|
||||
|
||||
# TODO: replace :except with :only
|
||||
append_before_filter :init, :except => [ :tag, :destroy, :completed,
|
||||
append_before_filter :init, :except => [ :tag, :tags, :destroy, :completed,
|
||||
:completed_archive, :check_deferred, :toggle_check, :toggle_star,
|
||||
:edit, :update, :defer, :create, :calendar, :auto_complete_for_predecessor, :remove_predecessor, :add_predecessor]
|
||||
|
||||
|
|
@ -546,7 +546,7 @@ class TodosController < ApplicationController
|
|||
end
|
||||
|
||||
def tags
|
||||
@tags = Tag.all
|
||||
@tags = Tag.find(:all, :conditions =>['name like ?', '%'+params[:term]+'%'])
|
||||
respond_to do |format|
|
||||
format.autocomplete { render :text => for_autocomplete(@tags, params[:term]) }
|
||||
end
|
||||
|
|
|
|||
|
|
@ -2,9 +2,9 @@
|
|||
<html xmlns="http://www.w3.org/1999/xhtml">
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
|
||||
<%= stylesheet_link_tag 'standard','superfish','niftyCorners', 'jquery-ui-1.8.6.custom', :cache => true %>
|
||||
<%= stylesheet_link_tag 'standard','superfish','niftyCorners', 'jquery-ui-1.8.7.custom', :cache => true %>
|
||||
<%= stylesheet_link_tag "print", :media => "print" %>
|
||||
<%= javascript_include_tag 'jquery-1.4.4.min', 'jquery-ui-1.8.6.custom.min', 'jquery.truncator',
|
||||
<%= javascript_include_tag 'jquery-1.4.4.min', 'jquery-ui-1.8.7.custom.min', 'jquery.truncator',
|
||||
'jquery.jeditable.mini', 'jquery.cookie', 'jquery.blockUI', 'jquery.form', :cache => 'jquery-all' %>
|
||||
<%= javascript_include_tag 'hoverIntent','superfish','application',
|
||||
'accesskey-hints','niftycube','swfobject', :cache => 'tracks' %>
|
||||
|
|
@ -12,6 +12,8 @@
|
|||
<%= javascript_tag "var SOURCE_VIEW = '#{@source_view}';" %>
|
||||
<%= javascript_tag "var TAG_NAME = '#{@tag_name}';" if @tag_name %>
|
||||
<script type="text/javascript">
|
||||
var defaultContexts = <%= default_contexts_for_autocomplete rescue '{}' %>;
|
||||
var defaultTags = <%= default_tags_for_autocomplete rescue '{}' %>;
|
||||
var dateFormat = '<%= date_format_for_date_picker %>';
|
||||
var weekStart = '<%= current_user.prefs.week_starts %>';
|
||||
function relative_to_root(path) { return '<%= root_url %>'+path; };
|
||||
|
|
|
|||
|
|
@ -60,7 +60,8 @@ var TracksForm = {
|
|||
$('#todo_new_action').show();
|
||||
$('#todo_multi_add').hide();
|
||||
$('a#toggle_multi').text("Add multiple next actions");
|
||||
} else {
|
||||
}
|
||||
else {
|
||||
$('#todo_new_action').hide();
|
||||
$('#todo_multi_add').show();
|
||||
$('a#toggle_multi').text("Add single next action");
|
||||
|
|
@ -890,16 +891,60 @@ function enable_rich_interaction(){
|
|||
$('input[name=project_name]').autocomplete({
|
||||
source: relative_to_root('projects.autocomplete')
|
||||
});
|
||||
$('input[name=project[default_context_name]]').autocomplete({
|
||||
source: relative_to_root('contexts.autocomplete')
|
||||
});
|
||||
|
||||
/* $('input[name=project[default_context_name]]').autocomplete(
|
||||
relative_to_root('contexts.autocomplete'), {matchContains: true});
|
||||
$('input[name=tag_list]:not(.ac_input)').autocomplete(
|
||||
relative_to_root('tags.autocomplete'), {multiple: true,multipleSeparator:',',matchContains:true});
|
||||
$('input[name=predecessor_list]:not(.ac_input)').autocomplete(
|
||||
relative_to_root('auto_complete_for_predecessor'),
|
||||
{multiple: true,multipleSeparator:','});
|
||||
$('input[name=tag_list]:not(.ac_input)')
|
||||
.bind( "keydown", function( event ) { // don't navigate away from the field on tab when selecting an item
|
||||
if ( event.keyCode === $.ui.keyCode.TAB &&
|
||||
$( this ).data( "autocomplete" ).menu.active ) {
|
||||
event.preventDefault();
|
||||
}
|
||||
})
|
||||
.autocomplete({
|
||||
minLength: 0,
|
||||
source: function( request, response ) {
|
||||
last_term = extractLast( request.term );
|
||||
if (last_term != "" && last_term != " ")
|
||||
$.getJSON( relative_to_root('tags.autocomplete'), {
|
||||
term: last_term
|
||||
}, response );
|
||||
},
|
||||
focus: function() {
|
||||
// prevent value inserted on focus
|
||||
return false;
|
||||
},
|
||||
select: function( event, ui ) {
|
||||
var terms = split( this.value );
|
||||
// remove the current input
|
||||
terms.pop();
|
||||
// add the selected item
|
||||
terms.push( ui.item.value );
|
||||
// add placeholder to get the comma-and-space at the end
|
||||
//terms.push( "" );
|
||||
this.value = terms.join( ", " );
|
||||
return false;
|
||||
}
|
||||
});
|
||||
|
||||
/* have to bind on keypress because of limitations of live() */
|
||||
|
||||
function split( val ) {
|
||||
return val.split( /,\s*/ );
|
||||
}
|
||||
function extractLast( term ) {
|
||||
return split( term ).pop();
|
||||
}
|
||||
|
||||
|
||||
/* multiple: true,
|
||||
multipleSeparator:',' */
|
||||
|
||||
$('input[name=predecessor_list]:not(.ac_input)').autocomplete({
|
||||
source: relative_to_root('auto_complete_for_predecessor')
|
||||
});
|
||||
|
||||
/* have to bind on keypress because of limitations of live() */
|
||||
$('input[name=project_name]').live('keypress', function(){
|
||||
$(this).bind('blur', project_defaults);
|
||||
});
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue