diff --git a/app/helpers/recurring_todos_helper.rb b/app/helpers/recurring_todos_helper.rb index b7f7e25d..5376a9cb 100644 --- a/app/helpers/recurring_todos_helper.rb +++ b/app/helpers/recurring_todos_helper.rb @@ -11,19 +11,15 @@ module RecurringTodosHelper 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 @@ -31,7 +27,6 @@ module RecurringTodosHelper 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 = '' + image_tag("blank.png") + " " end @@ -40,7 +35,6 @@ module RecurringTodosHelper 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 @@ -53,26 +47,4 @@ module RecurringTodosHelper 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 \ No newline at end of file +end diff --git a/app/views/recurring_todos/_edit_form.html.erb b/app/views/recurring_todos/_edit_form.html.erb index d0798cb8..8464bcf1 100644 --- a/app/views/recurring_todos/_edit_form.html.erb +++ b/app/views/recurring_todos/_edit_form.html.erb @@ -3,9 +3,9 @@ <% form_remote_tag( :url => recurring_todo_path(@recurring_todo), :method => :put, :html=> { :id=>'recurring-todo-form-edit-action', :name=>'recurring_todo', :class => 'inline-form' }, - :before => "$('recurring_todo_edit_action_submit').startWaiting()", - :complete => "$('recurring_todo_edit_action_submit').stopWaiting();", - :condition => "!$('recurring_todo_edit_action_submit').isWaiting()") do + :before => "$('#recurring_todo_edit_action_submit').block({message: null})", + :complete => "$('#recurring_todo_edit_action_submit').unblock();$('#recurring-todo-form-edit-action').clearForm();") do + -%>
<%= error_messages_for("item", :object_name => 'action') %>
@@ -20,59 +20,13 @@ " /> - - + - <%= text_field_tag "edit_recurring_todo_tag_list", @recurring_todo.tag_list, :size => 30, :tabindex => 5 -%> -
@@ -149,13 +103,11 @@ <%=image_tag("accept.png", :alt => "") %> Update -
<% end %> - <%= calendar_setup( "recurring_todo_edit_start_from" ) %> - <%= calendar_setup( "recurring_todo_edit_end_date" ) %> diff --git a/app/views/recurring_todos/_recurring_todo_form.erb b/app/views/recurring_todos/_recurring_todo_form.erb index 3a8b76d8..ef724f33 100644 --- a/app/views/recurring_todos/_recurring_todo_form.erb +++ b/app/views/recurring_todos/_recurring_todo_form.erb @@ -2,9 +2,8 @@ <% form_remote_tag( :url => recurring_todos_path, :method => :post, :html=> { :id=>'recurring-todo-form-new-action', :name=>'recurring_todo', :class => 'inline-form' }, - :before => "$('recurring_todo_new_action_submit').startWaiting()", - :complete => "$('recurring_todo_new_action_submit').stopWaiting();", - :condition => "!$('recurring_todo_new_action_submit').isWaiting()") do + :before => "$('#recurring_todo_new_action_submit').block({message: null})", + :complete => "$('#recurring_todo_new_action_submit').unblock();$('#recurring-todo-form-new-action').clearForm();") do -%>
<%= error_messages_for("item", :object_name => 'action') %>
@@ -17,59 +16,12 @@ - - - <%= text_field_tag "tag_list", nil, :size => 30, :tabindex => 5 -%> -
@@ -79,8 +31,6 @@ <%= radio_button_tag('recurring_todo[recurring_period]', 'weekly')%> Weekly
<%= radio_button_tag('recurring_todo[recurring_period]', 'monthly')%> Monthly
<%= radio_button_tag('recurring_todo[recurring_period]', 'yearly')%> Yearly
- <% apply_behaviour "#recurring_period:click", - "TracksForm.hide_all_recurring(); $('recurring_'+TracksForm.get_period()).show();" %>

@@ -147,13 +97,11 @@ <%=image_tag("accept.png", :alt => "") %> Create -
<% end %> - <%= calendar_setup( "recurring_todo_start_from" ) %> - <%= calendar_setup( "recurring_todo_end_date" ) %> diff --git a/app/views/recurring_todos/create.js.rjs b/app/views/recurring_todos/create.js.rjs index 1704cf02..790e2fc9 100644 --- a/app/views/recurring_todos/create.js.rjs +++ b/app/views/recurring_todos/create.js.rjs @@ -4,9 +4,8 @@ page.replace_html 'new_status', "#{error_messages_for('recurring_todo')}" page.notify :notice, @message, 5.0 if @recurring_saved # reset form - page << "TracksForm.hide_all_recurring(); $('recurring_daily').show();" - page << "Form.reset('recurring-todo-form-new-action');" - page << "Form.focusFirstElement('recurring-todo-form-new-action');" + page << "TracksForm.hide_all_recurring(); $('#recurring_daily').show();" + page << "$('#recurring_todo_new_action_submit').unblock();$('#recurring-todo-form-new-action').clearForm();" # hide overlayed edit form page << "TracksForm.toggle_overlay();" # insert new recurring todo diff --git a/app/views/recurring_todos/index.html.erb b/app/views/recurring_todos/index.html.erb index 40b586c5..4afa0528 100644 --- a/app/views/recurring_todos/index.html.erb +++ b/app/views/recurring_todos/index.html.erb @@ -33,16 +33,4 @@ -<% - -# need to add behaviour for edit form here. Behaviour defined in partials are -# not generated for -apply_behaviour "#recurring_edit_period:click", - "TracksForm.hide_all_edit_recurring(); $('recurring_edit_'+TracksForm.get_edit_period()).show();" --%> - - + diff --git a/app/views/recurring_todos/toggle_star.js.erb b/app/views/recurring_todos/toggle_star.js.erb new file mode 100644 index 00000000..437e22cc --- /dev/null +++ b/app/views/recurring_todos/toggle_star.js.erb @@ -0,0 +1,3 @@ +<% if @saved -%> + $('div#recurring_todo_<%= @recurring_todo.id %> a.star_item img').toggleClass('starred_todo').toggleClass('unstarred_todo'); +<% end -%> diff --git a/app/views/recurring_todos/toggle_star.js.rjs b/app/views/recurring_todos/toggle_star.js.rjs deleted file mode 100644 index f9846bdf..00000000 --- a/app/views/recurring_todos/toggle_star.js.rjs +++ /dev/null @@ -1,3 +0,0 @@ -if @saved - page[@recurring_todo].down('a.star_item').down('img').toggleClassName('starred_todo').toggleClassName('unstarred_todo') -end \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index e61fb90c..9f96a4d0 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -94,6 +94,20 @@ var TodoBehavior = { } } +$.fn.clearForm = function() { + return this.each(function() { + var type = this.type, tag = this.tagName.toLowerCase(); + if (tag == 'form') + return $(':input',this).clearForm(); + if (type == 'text' || type == 'password' || tag == 'textarea') + this.value = ''; + else if (type == 'checkbox' || type == 'radio') + this.checked = false; + else if (tag == 'select') + this.selectedIndex = -1; + }); +}; + /**************************************** * Unobtrusive jQuery written by Eric Allen ****************************************/ @@ -209,8 +223,11 @@ function setup_container_toggles(){ /* Unobtrusive jQuery behavior */ $(document).ready(function() { + /* Nifty corners */ + Nifty("div#recurring_new_container","normal"); + /* fade flashes and alerts in automatically */ - $(".alert").fadeOut(5000); + $(".alert").fadeOut(8000); /* set behavior for star icon */ $(".item-container a.star_item"). @@ -238,5 +255,59 @@ $(document).ready(function() { $(".date_clear").live('click', function() { /* add behavior to clear the date both buttons for show_from and due */ $(this).prev().val(''); - }) + }); + + /* recurring todo behavior */ + + /* behavior for delete icon */ + $('.item-container a.delete_icon').live('click', function(evt){ + evt.preventDefault(); + params = {}; + if(typeof(TAG_NAME) !== 'undefined'){ + params._tag_name = TAG_NAME; + } + if(confirm("Are you sure that you want to "+this.title+"?")){ + itemContainer = $(this).parents(".item-container"); + itemContainer.block({message: null}); + params._method = 'delete'; + $.post(this.href, params, function(){ + itemContainer.unblock(); + }, 'script'); + } + }); + + /* behavior for edit icon */ + $('.item-container a.edit_icon').live('click', function(evt){ + evt.preventDefault(); + params = {}; + if(typeof(TAG_NAME) !== 'undefined'){ + params._tag_name = TAG_NAME; + } + itemContainer = $(this).parents(".item-container"); + $(this).effect('pulsate', {times: 1}, 800); + $.get(this.href, params, function(){ + }, 'script'); + }); + + $("#recurring_todo_new_action_cancel").click(function(){ + $('#recurring-todo-form-new-action').clearForm(); + $('#recurring-todo-form-new-action input:first').focus(); + TracksForm.hide_all_recurring(); + $('#recurring_daily').show(); + TracksForm.toggle_overlay(); + }); + + $("#recurring_todo_edit_action_cancel").live('click', function(){ + $('#recurring-todo-form-edit-action').clearForm(); + $('#recurring-todo-form-edit-action input:first').focus(); + TracksForm.hide_all_recurring(); + $('#recurring_daily').show(); + TracksForm.toggle_overlay(); + }); + $("#recurring_edit_period input").live('click', function(){ + $.each(['daily', 'weekly', 'monthly', 'yearly'], function(){ + $('#recurring_edit_'+this).hide(); + }); + $('#recurring_edit_'+this.id.split('_')[5]).show(); + }); });