auto-fill of default tags & contexts from project

This commit is contained in:
Eric Allen 2009-10-02 15:48:24 -04:00
parent 48f7f25702
commit 195a58174b
8 changed files with 41 additions and 26 deletions

View file

@ -130,14 +130,6 @@ class ApplicationController < ActionController::Base
RedCloth.new(text).to_html RedCloth.new(text).to_html
end end
def build_default_project_context_name_map(projects)
Hash[*projects.reject{ |p| p.default_context.nil? }.map{ |p| [p.name, p.default_context.name] }.flatten].to_json
end
def build_default_project_tags_map(projects)
Hash[*projects.reject{ |p| p.default_tags.nil? }.map{ |p| [p.name, p.default_tags] }.flatten].to_json
end
# Here's the concept behind this "mobile content negotiation" hack: In # Here's the concept behind this "mobile content negotiation" hack: In
# addition to the main, AJAXy Web UI, Tracks has a lightweight low-feature # addition to the main, AJAXy Web UI, Tracks has a lightweight low-feature
# 'mobile' version designed to be suitablef or use from a phone or PDA. It # 'mobile' version designed to be suitablef or use from a phone or PDA. It

View file

@ -218,8 +218,6 @@ class ContextsController < ApplicationController
@projects = current_user.projects @projects = current_user.projects
@count = @not_done_todos.size @count = @not_done_todos.size
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
end end
end end

View file

@ -53,8 +53,6 @@ class ProjectsController < ApplicationController
@down_count = @count + @deferred.size @down_count = @count + @deferred.size
@next_project = current_user.projects.next_from(@project) @next_project = current_user.projects.next_from(@project)
@previous_project = current_user.projects.previous_from(@project) @previous_project = current_user.projects.previous_from(@project)
@default_project_context_name_map = build_default_project_context_name_map(current_user.projects).to_json
@default_project_tags_map = build_default_project_tags_map(current_user.projects).to_json
respond_to do |format| respond_to do |format|
format.html format.html
format.m &render_project_mobile format.m &render_project_mobile

View file

@ -251,8 +251,6 @@ class RecurringTodosController < ApplicationController
@xth_day = [['first',1],['second',2],['third',3],['fourth',4],['last',5]] @xth_day = [['first',1],['second',2],['third',3],['fourth',4],['last',5]]
@projects = current_user.projects.find(:all, :include => [:default_context]) @projects = current_user.projects.find(:all, :include => [:default_context])
@contexts = current_user.contexts.find(:all) @contexts = current_user.contexts.find(:all)
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
end end
def get_recurring_todo_from_param def get_recurring_todo_from_param

View file

@ -358,8 +358,6 @@ class TodosController < ApplicationController
@not_done_todos = current_user.deferred_todos @not_done_todos = current_user.deferred_todos
@count = @not_done_todos.size @count = @not_done_todos.size
@down_count = @count @down_count = @count
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
respond_to do |format| respond_to do |format|
format.html format.html
@ -428,10 +426,7 @@ class TodosController < ApplicationController
@down_count = @count @down_count = @count
respond_to do |format| respond_to do |format|
format.html { format.html
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
}
format.m { format.m {
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']} cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
render :action => "mobile_tag" render :action => "mobile_tag"
@ -465,8 +460,6 @@ class TodosController < ApplicationController
@page_title = "TRACKS::Calendar" @page_title = "TRACKS::Calendar"
@projects = current_user.projects.find(:all) @projects = current_user.projects.find(:all)
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
due_today_date = Time.zone.now due_today_date = Time.zone.now
due_this_week_date = Time.zone.now.end_of_week due_this_week_date = Time.zone.now.end_of_week
@ -751,9 +744,6 @@ class TodosController < ApplicationController
end end
end end
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json
@default_project_tags_map = build_default_project_tags_map(@projects).to_json
render render
end end
end end

View file

@ -245,6 +245,16 @@ module TodosHelper
array_or_string_for_javascript( current_user.contexts.collect{|c| escape_javascript(c.name) } ) array_or_string_for_javascript( current_user.contexts.collect{|c| escape_javascript(c.name) } )
end end
def default_contexts_for_autocomplete
projects = current_user.projects.find(:all, :conditions => ['default_context_id is not null'])
Hash[*projects.map{ |p| [p.name, p.default_context.name] }.flatten].to_json
end
def default_tags_for_autocomplete
projects = current_user.projects.find(:all, :conditions => ['default_tags != ""'])
Hash[*projects.map{ |p| [p.name, p.default_tags] }.flatten].to_json
end
def format_ical_notes(notes) def format_ical_notes(notes)
split_notes = notes.split(/\n/) split_notes = notes.split(/\n/)
joined_notes = split_notes.join("\\n") joined_notes = split_notes.join("\\n")

View file

@ -28,6 +28,8 @@
<script type="text/javascript"> <script type="text/javascript">
var contextNames = <%= context_names_for_autocomplete %>; var contextNames = <%= context_names_for_autocomplete %>;
var projectNames = <%= project_names_for_autocomplete %>; var projectNames = <%= project_names_for_autocomplete %>;
var defaultContexts = <%= default_contexts_for_autocomplete %>;
var defaultTags = <%= default_tags_for_autocomplete %>;
</script> </script>
<link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" /> <link rel="shortcut icon" href="<%= url_for(:controller => 'favicon.ico') %>" />
<%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %> <%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %>

View file

@ -240,11 +240,38 @@ function update_project_order(event, ui){
/* Unobtrusive jQuery behavior */ /* Unobtrusive jQuery behavior */
function project_defaults(){
if(defaultContexts[$(this).val()] !== undefined) {
context_name = $(this).parents('form').find('input[name=context_name]');
if(context_name.attr('edited') === undefined){
context_name.val(defaultContexts[$(this).val()]);
}
}
if(defaultTags[$(this).val()] !== undefined) {
tag_list = $(this).parents('form').find('input[name=tag_list]');
if(tag_list.attr('edited') === undefined){
tag_list.val(defaultTags[$(this).val()]);
}
}
}
function enable_rich_interaction(){ function enable_rich_interaction(){
$('input.Date').datepicker(); $('input.Date').datepicker();
/* Autocomplete */ /* Autocomplete */
$('input[name=context_name]').autocomplete(contextNames); $('input[name=context_name]').autocomplete(contextNames);
$('input[name=project_name]').autocomplete(projectNames); $('input[name=project_name]').autocomplete(projectNames);
/* have to bind on keypress because of limitataions of live() */
$('input[name=project_name]').live('keypress', function(){
$(this).bind('blur', project_defaults);
});
$('input[name=context_name]').live('keypress', function(){
$(this).attr('edited', 'true');
});
$('input[name=tag_list]').live('keypress', function(){
$(this).attr('edited', 'true');
});
} }
$(document).ready(function() { $(document).ready(function() {