From 8612c1a677302fc754f1a6d7a7bfa9e4d43fe3e6 Mon Sep 17 00:00:00 2001 From: Reinier Balt Date: Fri, 27 Mar 2009 17:03:18 +0100 Subject: [PATCH] tidy up the templates and the js in them --- app/views/contexts/_context.rhtml | 62 +++--- app/views/layouts/standard.html.erb | 227 +++++++++++----------- app/views/shared/_add_new_item_form.rhtml | 216 ++++++++++---------- app/views/shared/_footer.rhtml | 2 +- app/views/sidebar/_context.rhtml | 2 +- app/views/sidebar/_context_list.rhtml | 10 +- app/views/sidebar/_project.rhtml | 2 +- app/views/sidebar/_project_list.rhtml | 10 +- app/views/sidebar/sidebar.html.erb | 51 +++-- 9 files changed, 281 insertions(+), 301 deletions(-) diff --git a/app/views/contexts/_context.rhtml b/app/views/contexts/_context.rhtml index 055c89d5..fafe99fe 100644 --- a/app/views/contexts/_context.rhtml +++ b/app/views/contexts/_context.rhtml @@ -1,47 +1,47 @@ <% @not_done = @not_done_todos.select {|t| t.context_id == context.id } %>
>

-<% if collapsible -%> - <%= image_tag("collapse.png") %> - <% apply_behavior '.container_toggle:click', :prevent_default => true do |page| - page << " /* only handle the click if a previous click had finished its animation */ - if (todoItems.lastEffect == null || todoItems.lastEffect.state=='finished') { - containerElem = this.up('.container') - toggleTarget = containerElem.down('.toggle_target') - if (Element.visible(toggleTarget)) - { - todoItems.collapseNextActionListing(this, toggleTarget); - todoItems.contextCollapseCookieManager.setCookie(todoItems.buildCookieName(containerElem), true) - } - else - { - todoItems.expandNextActionListing(this, toggleTarget); - todoItems.contextCollapseCookieManager.clearCookie(todoItems.buildCookieName(containerElem)) - } - } + <% if collapsible -%> + <%= image_tag("collapse.png") %> + <% apply_behavior '.container_toggle:click', :prevent_default => true do |page| + page << " /* only handle the click if a previous click had finished its animation */ + if (todoItems.lastEffect == null || todoItems.lastEffect.state=='finished') { + containerElem = this.up('.container') + toggleTarget = containerElem.down('.toggle_target') + if (Element.visible(toggleTarget)) + { + todoItems.collapseNextActionListing(this, toggleTarget); + todoItems.contextCollapseCookieManager.setCookie(todoItems.buildCookieName(containerElem), true) + } + else + { + todoItems.expandNextActionListing(this, toggleTarget); + todoItems.contextCollapseCookieManager.clearCookie(todoItems.buildCookieName(containerElem)) + } + } " - end - %> -<% end -%> -<% if source_view_is :context %> - <%= context.name %> - <%= in_place_editor 'context_name_in_place_editor', { - :url => { :controller => 'contexts', :action => 'update', :id => context.id, :field => 'name', :update_context_name => true, :escape => false}, - :options=>"{method:'put'}", :script => true } %> -<% else %> - <%= link_to_context( context ) %> -<% end %> + end + -%> + <% end -%> + <% if source_view_is :context %> + <%= context.name %> + <%= in_place_editor 'context_name_in_place_editor', { + :url => { :controller => 'contexts', :action => 'update', :id => context.id, :field => 'name', :update_context_name => true, :escape => false}, + :options=>"{method:'put'}", :script => true } %> + <% else %> + <%= link_to_context( context ) %> + <% end %>

Currently there are no incomplete actions in this context

<%= render :partial => "todos/todo", :collection => @not_done, :locals => { :parent_container_type => "context" } %> - <% if @not_done.empty? + <% if @not_done.empty? # fix (hack) for #713 set_behavior_for_star_icon set_behavior_for_toggle_checkbox end -%>
-
+ \ No newline at end of file diff --git a/app/views/layouts/standard.html.erb b/app/views/layouts/standard.html.erb index 7bc4d623..0ee34aa6 100644 --- a/app/views/layouts/standard.html.erb +++ b/app/views/layouts/standard.html.erb @@ -1,129 +1,122 @@ - - + + <% if @prefs.refresh != 0 -%> ;url=<%= request.request_uri %>"> <% end -%> <%= javascript_include_tag "jquery-1.2.6.min" %> - <% bundle do %> - <%= javascript_include_tag *%w[ - hoverIntent superfish prototype - effects dragdrop controls application - calendar calendar-en calendar-setup - accesskey-hints todo-items niftycube - protoload flashobject lowpro - ] %> - <%= stylesheet_link_tag *%w[ standard superfish calendar-system niftyCorners] %> - <% end %> - <%= javascript_include_tag :unobtrusive %> - <%= stylesheet_link_tag "print", :media => "print" %> - - - <%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %> - + <% bundle do %> + <%= javascript_include_tag *%w[ + hoverIntent superfish prototype + effects dragdrop controls application + calendar calendar-en calendar-setup + accesskey-hints todo-items niftycube + protoload flashobject lowpro + ] %> + <%= stylesheet_link_tag *%w[ standard superfish calendar-system niftyCorners] %> + <% end %> + <%= javascript_include_tag :unobtrusive %> + <%= stylesheet_link_tag "print", :media => "print" %> + + <%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %> + - + + <%= @page_title %> + -<%= @page_title %> + +
+
+

+ <% if @count -%> + <%= @count %> + <% end -%> + <%= user_time.strftime(@prefs.title_date_format) %> +

+
+ + + <%= render_flash %> +
- - -
-
-

- <% if @count %> - <%= @count %> - <% end %> - <%= user_time.strftime(@prefs.title_date_format) %> -

-
- - - + <%= periodically_call_remote( :url => formatted_check_deferred_todos_path(:js), + :method => :post, + :frequency => (10*60)) %> + <%= yield %> +
-<%= render_flash %> - - -
- -<% unless @controller_name == 'feed' or session['noexpiry'] == "on" -%> -<%= periodically_call_remote( :url => {:controller => "login", :action => "check_expiry"}, - :frequency => (5*60)) %> -<% end -%> -<%= periodically_call_remote( :url => formatted_check_deferred_todos_path(:js), - :method => :post, - :frequency => (10*60)) %> -<%= yield %> -
- -<%= render :partial => "shared/footer" %> - + <%= render :partial => "shared/footer" %> + diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 2cc96c5e..c40c1fb9 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -1,129 +1,121 @@ <% - @todo = nil - @initial_context_name = @context.name unless @context.nil? - @initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil? - @initial_context_name ||= current_user.contexts.first.name unless current_user.contexts.first.nil? - @initial_project_name = @project.name unless @project.nil? -%> +@todo = nil +@initial_context_name = @context.name unless @context.nil? +@initial_context_name ||= @project.default_context.name unless @project.nil? || @project.default_context.nil? +@initial_context_name ||= current_user.contexts.first.name unless current_user.contexts.first.nil? +@initial_project_name = @project.name unless @project.nil? +-%>
« Hide form <% apply_behavior '#toggle_action_new a:click', :prevent_default => true do |page| - page << "TracksForm.toggle('toggle_action_new', 'todo_new_action', 'todo-form-new-action', - '« Hide form', 'Hide next action form', - 'Add a next action »', 'Add a next action');" - end - %> + page << "TracksForm.toggle('toggle_action_new', 'todo_new_action', 'todo-form-new-action', + '« Hide form', 'Hide next action form', + 'Add a next action »', 'Add a next action');" + end + -%>
-
+
+ <% form_remote_tag( + :url => todos_path, :method => :post, + :html=> { :id=>'todo-form-new-action', :name=>'todo', :class => 'inline-form' }, + :before => "$('todo_new_action_submit').startWaiting()", + :complete => "$('todo_new_action_submit').stopWaiting()", + :condition => "!$('todo_new_action_submit').isWaiting() && askIfNewContextProvided()") do -%> -<% form_remote_tag( - :url => todos_path, :method => :post, - :html=> { :id=>'todo-form-new-action', :name=>'todo', :class => 'inline-form' }, - :before => "$('todo_new_action_submit').startWaiting()", - :complete => "$('todo_new_action_submit').stopWaiting()", - :condition => "!$('todo_new_action_submit').isWaiting() && askIfNewContextProvided()") do -%> +
<%= error_messages_for("item", :object_name => 'action') %>
- -
<%= error_messages_for("item", :object_name => 'action') %>
+ var projectAutoCompleter = new Autocompleter.Local('todo_project_name', 'project_list', <%= project_names_for_autocomplete %>, {choices:100,autoSelect:false}); - -<%= text_field( "todo", "description", "size" => 30, "tabindex" => 1, "maxlength" => 100, "autocomplete" => "off") %> + function selectDefaultContext() { + todoContextNameElement = $('todo_context_name'); + defaultContextName = todoContextNameElement.projectDefaultContextsMap[this.value]; + if (defaultContextName && !todoContextNameElement.editedByTracksUser) { + todoContextNameElement.value = defaultContextName; + } + } + 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'))); - -<%= text_area( "todo", "notes", "cols" => 29, "rows" => 6, "tabindex" => 2) %> + var contextAutoCompleter; + function initializeNamesForAutoComplete(contextNamesForAutoComplete) { + if (contextNamesForAutoComplete.length == 0 || contextNamesForAutoComplete[0].length == 0) { + return; + } + 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($('todo_context_name'), "focus", contextAutoCompleter.activate.bind(contextAutoCompleter)); + Event.observe($('todo_context_name'), "click", contextAutoCompleter.activate.bind(contextAutoCompleter)); + } - - - - + function updateContextNamesForAutoComplete(contextNamesForAutoComplete) { + if (contextAutoCompleter) { // i.e. if we're already initialized + contextAutoCompleter.options.array = contextNamesForAutoComplete + } else { + initializeNamesForAutoComplete(contextNamesForAutoComplete) + } + } + initializeNamesForAutoComplete(contextNames); + $('todo_context_name').projectDefaultContextsMap = eval('(' + <%= @default_project_context_name_map %> + ')'); + - - - - - - - - - - -<%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 %> - -
- -<%= text_field("todo", "due", "size" => 12, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 6, "autocomplete" => "off") %> -
- -
- - <%= text_field("todo", "show_from", "size" => 12, "class" => "Date", "onfocus" => "Calendar.setup", "tabindex" => 7, "autocomplete" => "off") %> -
- -<%= source_view_tag( @source_view ) %> - -
-
- + <%= calendar_setup( "todo_due" ) %> + <%= calendar_setup( "todo_show_from" ) %>
-
-<% end -%> - - -<%= calendar_setup( "todo_due" ) %> -<%= calendar_setup( "todo_show_from" ) %> -
-
+
\ No newline at end of file diff --git a/app/views/shared/_footer.rhtml b/app/views/shared/_footer.rhtml index 95fd3a78..007b24f6 100644 --- a/app/views/shared/_footer.rhtml +++ b/app/views/shared/_footer.rhtml @@ -1,3 +1,3 @@ + \ No newline at end of file diff --git a/app/views/sidebar/_context.rhtml b/app/views/sidebar/_context.rhtml index 61b254fe..70d8d493 100644 --- a/app/views/sidebar/_context.rhtml +++ b/app/views/sidebar/_context.rhtml @@ -1 +1 @@ -
  • <%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%>
  • +
  • <%= link_to_context( context ) + " (" + count_undone_todos_phrase(context,"actions") + ")"%>
  • \ No newline at end of file diff --git a/app/views/sidebar/_context_list.rhtml b/app/views/sidebar/_context_list.rhtml index 21702d8d..8f985ebd 100644 --- a/app/views/sidebar/_context_list.rhtml +++ b/app/views/sidebar/_context_list.rhtml @@ -1,8 +1,8 @@

    <%= list_name %> (<%= contexts.length %>)

    \ No newline at end of file diff --git a/app/views/sidebar/_project.rhtml b/app/views/sidebar/_project.rhtml index c9dd678e..d7fade18 100644 --- a/app/views/sidebar/_project.rhtml +++ b/app/views/sidebar/_project.rhtml @@ -1 +1 @@ -
  • <%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %>
  • +
  • <%= link_to_project( project ) + " (" + count_undone_todos_phrase(project,"actions") + ")" %>
  • \ No newline at end of file diff --git a/app/views/sidebar/_project_list.rhtml b/app/views/sidebar/_project_list.rhtml index 6fcf889a..3cb73df1 100644 --- a/app/views/sidebar/_project_list.rhtml +++ b/app/views/sidebar/_project_list.rhtml @@ -1,8 +1,8 @@

    <%= list_name %> (<%= projects.length %>)

    \ No newline at end of file diff --git a/app/views/sidebar/sidebar.html.erb b/app/views/sidebar/sidebar.html.erb index 3de85ff3..eb229b3b 100644 --- a/app/views/sidebar/sidebar.html.erb +++ b/app/views/sidebar/sidebar.html.erb @@ -1,35 +1,30 @@ \ No newline at end of file