mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-30 13:58:49 +01:00
Pre-populate default tags from project instead of adding them when a todo is created. Fixes #879.
This commit is contained in:
parent
7c1b4c0a24
commit
0fda4506eb
9 changed files with 63 additions and 14 deletions
|
|
@ -133,6 +133,10 @@ class ApplicationController < ActionController::Base
|
|||
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
|
||||
# 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
|
||||
|
|
|
|||
|
|
@ -219,6 +219,7 @@ class ContextsController < ApplicationController
|
|||
|
||||
@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
|
||||
|
||||
|
|
|
|||
|
|
@ -54,6 +54,7 @@ class ProjectsController < ApplicationController
|
|||
@next_project = current_user.projects.next_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|
|
||||
format.html
|
||||
format.m &render_project_mobile
|
||||
|
|
|
|||
|
|
@ -31,7 +31,7 @@ class RecurringTodosController < ApplicationController
|
|||
|
||||
def update
|
||||
# TODO: write tests for updating
|
||||
@recurring_todo.tag_with(params[:tag_list]) if params[:tag_list]
|
||||
@recurring_todo.tag_with(params[:edit_recurring_todo_tag_list]) if params[:edit_recurring_todo_tag_list]
|
||||
@original_item_context_id = @recurring_todo.context_id
|
||||
@original_item_project_id = @recurring_todo.project_id
|
||||
|
||||
|
|
@ -252,6 +252,7 @@ class RecurringTodosController < ApplicationController
|
|||
@projects = current_user.projects.find(:all, :include => [:default_context])
|
||||
@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
|
||||
|
||||
def get_recurring_todo_from_param
|
||||
|
|
|
|||
|
|
@ -60,11 +60,6 @@ class TodosController < ApplicationController
|
|||
project = current_user.projects.find_or_create_by_name(p.project_name)
|
||||
@new_project_created = project.new_record_before_save?
|
||||
@todo.project_id = project.id
|
||||
if tag_list.blank?
|
||||
tag_list = project.default_tags unless project.default_tags.blank?
|
||||
else
|
||||
tag_list += ','+project.default_tags unless project.default_tags.blank?
|
||||
end
|
||||
end
|
||||
|
||||
if p.context_specified_by_name?
|
||||
|
|
@ -363,7 +358,8 @@ class TodosController < ApplicationController
|
|||
@not_done_todos = current_user.deferred_todos
|
||||
@count = @not_done_todos.size
|
||||
@down_count = @count
|
||||
@default_project_context_name_map = build_default_project_context_name_map(@projects).to_json unless mobile?
|
||||
@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|
|
||||
format.html
|
||||
|
|
@ -434,6 +430,7 @@ class TodosController < ApplicationController
|
|||
respond_to do |format|
|
||||
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 {
|
||||
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
|
||||
|
|
@ -469,6 +466,7 @@ class TodosController < ApplicationController
|
|||
|
||||
@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_this_week_date = Time.zone.now.end_of_week
|
||||
|
|
@ -750,6 +748,7 @@ class TodosController < ApplicationController
|
|||
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
|
||||
end
|
||||
|
|
|
|||
|
|
@ -29,9 +29,17 @@
|
|||
todoContextNameElement.value = defaultContextName;
|
||||
}
|
||||
}
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('edit_recurring_todo_tag_list');
|
||||
defaultTagList = todoTagListElement.projectDefaultTagsMap[this.value];
|
||||
if (defaultTagList && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTagList;
|
||||
}
|
||||
}
|
||||
Event.observe($('edit_recurring_todo_project_name'), "focus", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "click", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "blur", selectDefaultContext.bind($('edit_recurring_todo_project_name')));
|
||||
Event.observe($('edit_recurring_todo_project_name'), "blur", selectDefaultTags.bind($('edit_recurring_todo_project_name')));
|
||||
</script>
|
||||
|
||||
<label for="edit_recurring_todo_context_name">Context</label>
|
||||
|
|
@ -59,9 +67,13 @@
|
|||
$('edit_recurring_todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')');
|
||||
</script>
|
||||
|
||||
<label for="tag_list">Tags (separate with commas)</label><%=
|
||||
text_field_tag "tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%>
|
||||
</div>
|
||||
<label for="edit_recurring_todo_tag_list">Tags (separate with commas)</label>
|
||||
<%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%>
|
||||
<script type="text/javascript">
|
||||
$('edit_recurring_todo_tag_list').projectDefaultTagsMap = eval('(' + <%= @default_project_tags_map %> + ')');
|
||||
Event.observe($('edit_recurring_todo_tag_list'), "focus", function(){ $('edit_recurring_todo_tag_list').editedByTracksUser = true; });
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recurring_edit_period_id">
|
||||
<div id="recurring_edit_period">
|
||||
|
|
|
|||
|
|
@ -56,9 +56,21 @@
|
|||
$('recurring_todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')');
|
||||
</script>
|
||||
|
||||
<label for="tag_list">Tags (separate with commas)</label><%=
|
||||
text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 -%>
|
||||
</div>
|
||||
<label for="tag_list">Tags ZZZZZ (separate with commas)</label>
|
||||
<%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 -%>
|
||||
<script type="text/javascript">
|
||||
$('tag_list').projectDefaultTagsMap = eval('(' + <%= @default_project_tags_map %> + ')');
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('tag_list');
|
||||
defaultTagList = todoTagListElement.projectDefaultTagsMap[this.value];
|
||||
if (defaultTagList && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTagList;
|
||||
}
|
||||
}
|
||||
Event.observe($('recurring_todo_project_name'), "blur", selectDefaultTags.bind($('recurring_todo_project_name')));
|
||||
Event.observe($('tag_list'), "focus", function(){ $('tag_list').editedByTracksUser = true; });
|
||||
</script>
|
||||
</div>
|
||||
</div>
|
||||
<div id="recurring_period_id">
|
||||
<div id="recurring_period">
|
||||
|
|
|
|||
|
|
@ -75,7 +75,7 @@
|
|||
<script type="text/javascript" charset="utf-8">
|
||||
|
||||
var contextNames = <%= context_names_for_autocomplete %>;
|
||||
var projectNames = <%= project_names_for_autocomplete %>
|
||||
var projectNames = <%= project_names_for_autocomplete %>;
|
||||
|
||||
function askIfNewContextProvided() {
|
||||
var givenContextName = $('todo_context_name').value;
|
||||
|
|
@ -95,9 +95,17 @@
|
|||
todoContextNameElement.value = defaultContextName;
|
||||
}
|
||||
}
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('tag_list');
|
||||
defaultTags = todoTagListElement.projectDefaultTagsMap[this.value];
|
||||
if (defaultTags && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTags;
|
||||
}
|
||||
}
|
||||
Event.observe($('todo_project_name'), "focus", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('todo_project_name'), "click", projectAutoCompleter.activate.bind(projectAutoCompleter));
|
||||
Event.observe($('todo_project_name'), "blur", selectDefaultContext.bind($('todo_project_name')));
|
||||
Event.observe($('todo_project_name'), "blur", selectDefaultTags.bind($('todo_project_name')));
|
||||
|
||||
var contextAutoCompleter;
|
||||
function initializeNamesForAutoComplete(contextNamesForAutoComplete) {
|
||||
|
|
@ -106,6 +114,7 @@
|
|||
}
|
||||
contextAutoCompleter = new Autocompleter.Local('todo_context_name', 'context_list', contextNamesForAutoComplete, {choices:100,autoSelect:false});
|
||||
Event.observe($('todo_context_name'), "focus", function(){ $('todo_context_name').editedByTracksUser = true; });
|
||||
Event.observe($('tag_list'), "focus", function(){ $('tag_list').editedByTracksUser = true; });
|
||||
Event.observe($('todo_context_name'), "focus", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
Event.observe($('todo_context_name'), "click", contextAutoCompleter.activate.bind(contextAutoCompleter));
|
||||
}
|
||||
|
|
@ -119,6 +128,7 @@
|
|||
}
|
||||
initializeNamesForAutoComplete(contextNames);
|
||||
$('todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')');
|
||||
$('tag_list').projectDefaultTagsMap = eval('(' + <%= @default_project_tags_map %> + ')');
|
||||
</script>
|
||||
|
||||
<%= calendar_setup( "todo_due" ) %>
|
||||
|
|
|
|||
|
|
@ -24,9 +24,17 @@
|
|||
todoContextNameElement.value = defaultContextName;
|
||||
}
|
||||
}
|
||||
function selectDefaultTags() {
|
||||
todoTagListElement = $('<%= dom_id(@todo, 'tag_list') %>');
|
||||
defaultTagList = $('tag_list').projectDefaultTagsMap[this.value];
|
||||
if (defaultTagList && !todoTagListElement.editedByTracksUser) {
|
||||
todoTagListElement.value = defaultTagList;
|
||||
}
|
||||
}
|
||||
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "focus", <%= dom_id(@todo, 'project_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'project_autocompleter') %>));
|
||||
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "click", <%= dom_id(@todo, 'project_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'project_autocompleter') %>));
|
||||
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "blur", selectDefaultContext.bind($('<%= dom_id(@todo, 'project_name') %>')));
|
||||
Event.observe($('<%= dom_id(@todo, 'project_name') %>'), "blur", selectDefaultTags.bind($('<%= dom_id(@todo, 'project_name') %>')));
|
||||
</script>
|
||||
</div>
|
||||
|
||||
|
|
@ -38,6 +46,7 @@
|
|||
<script type="text/javascript">
|
||||
<%= dom_id(@todo, 'context_autocompleter') %> = new Autocompleter.Local('<%= dom_id(@todo, 'context_name') %>', '<%= dom_id(@todo, 'context_list') %>', contextNames, {choices:100,autoSelect:false});
|
||||
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "focus", function(){ $('<%= dom_id(@todo, 'context_name') %>').editedByTracksUser = true; });
|
||||
Event.observe($('<%= dom_id(@todo, 'tag_list') %>'), "focus", function(){ $('<%= dom_id(@todo, 'tag_list') %>').editedByTracksUser = true; });
|
||||
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "focus", <%= dom_id(@todo, 'context_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'context_autocompleter') %>));
|
||||
Event.observe($('<%= dom_id(@todo, 'context_name') %>'), "click", <%= dom_id(@todo, 'context_autocompleter') %>.activate.bind(<%= dom_id(@todo, 'context_autocompleter') %>));
|
||||
</script>
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue