Skip to content

Commit

Permalink
Merge branch 'jquery' of epall/tracks
Browse files Browse the repository at this point in the history
This concludes the transition from Prototype to
jQuery throughout Tracks. Closes #944.
  • Loading branch information
epall committed Nov 5, 2009
2 parents f25ee06 + 7ef9140 commit 45d9ab6
Show file tree
Hide file tree
Showing 185 changed files with 3,852 additions and 14,119 deletions.
9 changes: 1 addition & 8 deletions app/controllers/application.rb
Expand Up @@ -27,6 +27,7 @@ class ApplicationController < ActionController::Base
helper_method :current_user, :prefs

layout proc{ |controller| controller.mobile? ? "mobile" : "standard" }
exempt_from_layout /\.js\.erb$/

before_filter :set_session_expiration
before_filter :set_time_zone
Expand Down Expand Up @@ -129,14 +130,6 @@ def markdown(text)
RedCloth.new(text).to_html
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
# 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
Expand Down
20 changes: 13 additions & 7 deletions app/controllers/contexts_controller.rb
Expand Up @@ -92,7 +92,7 @@ def update

if @context.save
if boolean_param('wants_render')
@context_state_changed = (@orgininal_context_hidden != @context.hidden?)
@context_state_changed = (@original_context_hidden != @context.hidden?)
@new_state = (@context.hidden? ? "hidden" : "active") if @context_state_changed
respond_to do |format|
format.js
Expand All @@ -110,6 +110,13 @@ def update
end
end

def edit
@context = Context.find(params[:id])
respond_to do |format|
format.js
end
end

# Fairly self-explanatory; deletes the context If the context contains
# actions, you'll get a warning dialogue. If you choose to go ahead, any
# actions in the context will also be deleted.
Expand All @@ -124,11 +131,12 @@ def destroy
# Methods for changing the sort order of the contexts in the list
#
def order
list = params["list-contexts-hidden"] || params["list-contexts-active"]
list.each_with_index do |id, position|
current_user.contexts.update(id, :position => position + 1)
end
context_ids = params["container_context"]
@projects = current_user.contexts.update_positions( context_ids )
render :nothing => true
rescue
notify :error, $!
redirect_to :action => 'index'
end

protected
Expand Down Expand Up @@ -218,8 +226,6 @@ def init_todos
@projects = current_user.projects

@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

Expand Down
8 changes: 5 additions & 3 deletions app/controllers/projects_controller.rb
Expand Up @@ -53,8 +53,7 @@ def show
@down_count = @count + @deferred.size
@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
@default_tags = @project.default_tags
respond_to do |format|
format.html
format.m &render_project_mobile
Expand Down Expand Up @@ -127,6 +126,7 @@ def update
@active_projects_count = current_user.projects.active.count
@hidden_projects_count = current_user.projects.hidden.count
@completed_projects_count = current_user.projects.completed.count
init_data_for_sidebar
render :template => 'projects/update.js.rjs'
return
elsif boolean_param('update_status')
Expand Down Expand Up @@ -173,7 +173,7 @@ def destroy
end

def order
project_ids = params["list-active-projects"] || params["list-hidden-projects"] || params["list-completed-projects"]
project_ids = params["container_project"]
@projects = current_user.projects.update_positions( project_ids )
render :nothing => true
rescue
Expand All @@ -186,13 +186,15 @@ def alphabetize
@projects = current_user.projects.alphabetize(:state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
end

def actionize
@state = params['state']
@projects = current_user.projects.actionize(current_user.id, :state => @state) if @state
@contexts = current_user.contexts
init_not_done_counts(['project'])
init_project_hidden_todo_counts(['project']) if @state == 'hidden'
end

protected
Expand Down
4 changes: 1 addition & 3 deletions app/controllers/recurring_todos_controller.rb
Expand Up @@ -251,8 +251,6 @@ def init
@xth_day = [['first',1],['second',2],['third',3],['fourth',4],['last',5]]
@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
Expand All @@ -265,4 +263,4 @@ def find_and_inactivate
recurring_todos.each { |rt| rt.toggle_completion! if rt.todos.not_completed.count == 0}
end

end
end
13 changes: 2 additions & 11 deletions app/controllers/todos_controller.rb
Expand Up @@ -95,6 +95,7 @@ def create
@projects = current_user.projects.find(:all) if @new_project_created
@initial_context_name = params['default_context_name']
@initial_project_name = params['default_project_name']
@default_tags = @todo.project.default_tags unless @todo.project.nil?
render :action => 'create'
end
format.xml do
Expand Down Expand Up @@ -358,8 +359,6 @@ def list_deferred
@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
@default_project_tags_map = build_default_project_tags_map(@projects).to_json

respond_to do |format|
format.html
Expand Down Expand Up @@ -434,10 +433,7 @@ def tag
@down_count = @count

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.html
format.m {
cookies[:mobile_url]= {:value => request.request_uri, :secure => SITE_CONFIG['secure_cookies']}
render :action => "mobile_tag"
Expand Down Expand Up @@ -471,8 +467,6 @@ def calendar
@page_title = "TRACKS::Calendar"

@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
Expand Down Expand Up @@ -757,9 +751,6 @@ def render_todos_html
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
end
end
Expand Down
13 changes: 13 additions & 0 deletions app/helpers/application_helper.rb
Expand Up @@ -166,4 +166,17 @@ def recurrence_pattern_as_text(recurring_todo)
return rt+rp+rts
end

def date_format_for_date_picker()
standard_format = current_user.prefs.date_format
translations = [
['%m', 'mm'],
['%d', 'dd'],
['%Y', 'yy'],
['%y', 'y']
]
translations.inject(standard_format) do |str, translation|
str.gsub(*translation)
end
end

end
34 changes: 3 additions & 31 deletions app/helpers/recurring_todos_helper.rb
Expand Up @@ -11,27 +11,22 @@ def recurring_todo_tag_list
end

def recurring_todo_remote_delete_icon
str = link_to( image_tag_for_delete,
link_to( image_tag_for_delete,
recurring_todo_path(@recurring_todo), :id => "delete_icon_"+@recurring_todo.id.to_s,
:class => "icon delete_icon", :title => "delete the recurring action '#{@recurring_todo.description}'")
set_behavior_for_delete_icon
str
end

def recurring_todo_remote_star_icon
str = link_to( image_tag_for_star(@recurring_todo),
link_to( image_tag_for_star(@recurring_todo),
toggle_star_recurring_todo_path(@recurring_todo),
:class => "icon star_item", :title => "star the action '#{@recurring_todo.description}'")
set_behavior_for_star_icon
str
end

def recurring_todo_remote_edit_icon
if !@recurring_todo.completed?
str = link_to( image_tag_for_edit(@recurring_todo),
edit_recurring_todo_path(@recurring_todo),
:class => "icon edit_icon")
set_behavior_for_edit_icon
else
str = '<a class="icon">' + image_tag("blank.png") + "</a> "
end
Expand All @@ -40,7 +35,6 @@ def recurring_todo_remote_edit_icon

def recurring_todo_remote_toggle_checkbox
str = check_box_tag('item_id', toggle_check_recurring_todo_path(@recurring_todo), @recurring_todo.completed?, :class => 'item-checkbox')
set_behavior_for_toggle_checkbox
str
end

Expand All @@ -53,26 +47,4 @@ def image_tag_for_delete
def image_tag_for_edit(todo)
image_tag("blank.png", :title =>"Edit action", :class=>"edit_item", :id=> dom_id(todo, 'edit_icon'))
end

def set_behavior_for_delete_icon
parameters = "_source_view=#{@source_view}"
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
apply_behavior '.item-container a.delete_icon:click', :prevent_default => true do |page|
page.confirming "'Are you sure that you want to ' + this.title + '?'" do
page << "itemContainer = this.up('.item-container'); itemContainer.startWaiting();"
page << remote_to_href(:method => 'delete', :with => "'#{parameters}'", :complete => "itemContainer.stopWaiting();")
end
end
end

def set_behavior_for_edit_icon
parameters = "_source_view=#{@source_view}"
parameters += "&_tag_name=#{@tag_name}" if @source_view == 'tag'
apply_behavior '.item-container a.edit_icon:click', :prevent_default => true do |page|
page << "Effect.Pulsate(this);"
page << remote_to_href(:method => 'get', :with => "'#{parameters}'")
end
end


end
end

0 comments on commit 45d9ab6

Please sign in to comment.