From a09b55d6b6ad07eb6aaf52bdf6ef9d8668399235 Mon Sep 17 00:00:00 2001 From: Eric Allen Date: Mon, 21 Sep 2009 22:59:46 -0400 Subject: [PATCH] New todo form working with Ajax --- app/views/layouts/standard.html.erb | 3 + app/views/shared/_add_new_item_form.rhtml | 72 +---------------------- app/views/todos/create.js.rjs | 6 +- public/javascripts/application.js | 9 +++ 4 files changed, 18 insertions(+), 72 deletions(-) diff --git a/app/views/layouts/standard.html.erb b/app/views/layouts/standard.html.erb index 5dbdb4d1..60f07f50 100644 --- a/app/views/layouts/standard.html.erb +++ b/app/views/layouts/standard.html.erb @@ -23,6 +23,9 @@ <%= javascript_tag "var AUTH_TOKEN = #{form_authenticity_token.inspect};" if protect_against_forgery? %> <%= javascript_tag "var SOURCE_VIEW = '#{@source_view}';" %> <%= javascript_tag "var TAG_NAME = '#{@tag_name}';" if @tag_name %> + <%= auto_discovery_link_tag(:rss, {:controller => "todos", :action => "index", :format => 'rss', :token => "#{current_user.token}"}, {:title => "RSS feed of next actions"}) %> diff --git a/app/views/shared/_add_new_item_form.rhtml b/app/views/shared/_add_new_item_form.rhtml index 92122405..8a813eaa 100644 --- a/app/views/shared/_add_new_item_form.rhtml +++ b/app/views/shared/_add_new_item_form.rhtml @@ -15,9 +15,9 @@ <% 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 -%> + :before => "$('todo_new_action_submit').block({message:null})", + :complete => "$('todo_new_action_submit').unblock()", + :condition => "askIfNewContextProvided()") do -%>
<%= error_messages_for("item", :object_name => 'action') %>
@@ -40,10 +40,6 @@ <%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 %> <%= content_tag("div", "", :id => "tag_list_auto_complete", :class => "auto_complete") %> - <%= auto_complete_field 'tag_list', { - :url => {:controller => 'todos', :action => 'auto_complete_for_tag'}, - :tokens => [','] - } %>
@@ -66,67 +62,5 @@
<% end -%> - - - - <%= calendar_setup( "todo_due" ) %> - <%= calendar_setup( "todo_show_from" ) %> diff --git a/app/views/todos/create.js.rjs b/app/views/todos/create.js.rjs index e7817d75..c746dda8 100644 --- a/app/views/todos/create.js.rjs +++ b/app/views/todos/create.js.rjs @@ -6,11 +6,11 @@ if @saved status_message = 'Added new context / ' + status_message if @new_context_created page.notify :notice, status_message, 5.0 page['badge_count'].replace_html @down_count - page.send :record, "Form.reset('todo-form-new-action');Form.focusFirstElement('todo-form-new-action')" + page.send :record, "$('#todo-form-new-action').clearForm();$('#todo-form-new-action input:first').focus();" page['todo_context_name'].value = @initial_context_name page['todo_project_name'].value = @initial_project_name - page << "updateContextNamesForAutoComplete(#{context_names_for_autocomplete})" if @new_context_created - page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created + #page << "updateContextNamesForAutoComplete(#{context_names_for_autocomplete})" if @new_context_created + #page << "projectAutoCompleter.options.array = #{project_names_for_autocomplete}" if @new_project_created if should_show_new_item() if @new_context_created page.insert_html :top, 'display_box', :partial => 'contexts/context', :locals => { :context => @todo.context, :collapsible => true } diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 9f96a4d0..c2e7a865 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -220,6 +220,15 @@ function setup_container_toggles(){ }); } +function askIfNewContextProvided() { + var givenContextName = $('#todo_context_name').val(); + if (givenContextName.length == 0) return true; // do nothing and depend on rails validation error + for (var i = 0; i < contextNames.length; ++i) { + if (contextNames[i] == givenContextName) return true; + } + return confirm('New context "' + givenContextName + '" will be also created. Are you sure?'); +} + /* Unobtrusive jQuery behavior */ $(document).ready(function() {