diff --git a/app/assets/javascripts/application.js b/app/assets/javascripts/application.js index 4ad38323..9d3bd17d 100644 --- a/app/assets/javascripts/application.js +++ b/app/assets/javascripts/application.js @@ -14,7 +14,8 @@ //= require jquery_ujs // Stuff in app/assets -//= require tracks.js +//= require tracks +//= require tracks_pages //= require disable_fx_in_test // Stuff in vendor/assets diff --git a/app/assets/javascripts/tracks.js b/app/assets/javascripts/tracks.js index 2b969cc5..49f0f170 100644 --- a/app/assets/javascripts/tracks.js +++ b/app/assets/javascripts/tracks.js @@ -152,195 +152,6 @@ var TracksForm = { } }; -var TracksPages = { - show_errors: function (html) { - $('div#error_status').html(html); - $('div#error_status').show(); - }, - show_edit_errors: function(html) { - $('div#edit_error_status').html(html); - $('div#edit_error_status').show(); - }, - show_errors_for_multi_add: function(html) { - $('div#multiple_error_status').html(html); - $('div#multiple_error_status').show(); - }, - hide_errors: function() { - $('div#error_status').hide(); - $('div#edit_error_status').hide(); - $('div#multiple_error_status').hide(); - }, - update_sidebar: function(html) { - $('#sidebar').html(html); - }, - setup_nifty_corners: function() { - Nifty("div#recurring_new_container","normal"); - Nifty("div#context_new_container","normal"); - Nifty("div#feedlegend","normal"); - Nifty("div#feedicons-project","normal"); - Nifty("div#feedicons-context","normal"); - Nifty("div#todo_new_action_container","normal"); - Nifty("div#project_new_project_container","normal"); - }, - page_notify: function(type, message, fade_duration_in_sec) { - var flash = $('div#message_holder'); - flash.html("

"+message+"

"); - flash = $('h4#flash'); - - var fadein_duration = 1500; - var fadeout_duration = 1500; - var show_duration = fade_duration_in_sec*1000 - fadein_duration - fadeout_duration; - if (show_duration < 0) { - show_duration = 1000; - } - flash.fadeIn(fadein_duration).delay(show_duration).fadeOut(fadeout_duration); - }, - set_page_badge: function(count) { - $('#badge_count').html(count); - }, - setup_autocomplete_for_tag_list: function(id) { - $(id+':not(.ac_input)') - .bind( "keydown", function( event ) { // don't navigate away from the field on tab when selecting an item - if ( event.keyCode === $.ui.keyCode.TAB && - $( this ).data( "autocomplete" ).menu.active ) { - event.preventDefault(); - } - }) - .autocomplete({ - minLength: 2, - autoFocus: true, - delay: 400, /* increase a bit over the default of 300 */ - source: function( request, response ) { - var last_term = extractLast( request.term ); - if (last_term !== "" && last_term !== " ") { - $.ajax( { - url: relative_to_root('tags.autocomplete'), - dataType: 'json', - data: { - term: last_term - }, - success: function(data, textStatus, jqXHR) { - // remove spinner as removing the class is not always done by response - $(id).removeClass('ui-autocomplete-loading'); - response(data, textStatus, jqXHR); // call jquery callback to handle data - } - }); - } - else { - // remove spinner as typing will always add the spinner - $(id).removeClass('ui-autocomplete-loading'); - } - }, - focus: function() { - // prevent value inserted on focus - return false; - }, - select: function( event, ui ) { - var terms = split( this.value ); - // remove the current input - terms.pop(); - // add the selected item - terms.push( ui.item.value ); - // add placeholder to get the comma-and-space at the end - //terms.push( "" ); - this.value = terms.join( ", " ); - return false; - } - }); - }, - setup_all_autocompleters: function() { - //fix for #1036 where closing a edit form before the autocomplete was filled - //resulted in a dropdown box that could not be removed. We remove all - //autocomplete boxes the hard way - $('.ac_results').remove(); - - // initialize autocompleters - ProjectItems.setup_autocomplete_for_projects('input[name=project_name]'); - ContextItems.setup_autocomplete_for_contexts('input[name=context_name]'); - ContextItems.setup_autocomplete_for_contexts('input[id="project_default_context_name"]'); - TracksPages.setup_autocomplete_for_tag_list('input[name=tag_list]'); // todo edit form - TracksPages.setup_autocomplete_for_tag_list('input[name=edit_recurring_todo_tag_list]'); - TracksPages.setup_autocomplete_for_tag_list('input[id="project_default_tags"]'); - TodoItems.setup_autocomplete_for_predecessor(); - }, - setup_datepicker: function() { - $('input.Date').datepicker({ - 'dateFormat': dateFormat, - 'firstDay': weekStart, - 'showButtonPanel': true, - 'showWeek': true, - 'changeMonth': true, - 'changeYear': true, - 'maxDate': '+5y', - 'minDate': '-1y', - 'showAnim': '' /* leave empty, see #1117 */ - }); - }, - setup_behavior: function () { - /* main menu */ - $('ul.sf-menu').superfish({ - delay: 250, - animation: { - opacity:'show', - height:'show' - }, - autoArrows: false, - dropShadows: false, - speed: 'fast' - }); - - /* context menu */ - $('ul.sf-item-menu').superfish({ - delay: 100, - animation: { - opacity:'show', - height:'show' - }, - autoArrows: false, - dropShadows: false, - speed: 'fast', - onBeforeShow: function() { /* highlight todo */ - $(this.parent().parent().parent()).addClass("sf-item-selected"); - }, - onHide: function() { /* remove hightlight from todo */ - $(this.parent().parent().parent()).removeClass("sf-item-selected"); - } - }); - - /* for toggle notes link in mininav */ - $("#toggle-notes-nav").click(function () { - $(".todo_notes").toggle(); - }); - - - /* Poor man's perspectives, allows to hide any context that is collapsed */ - $("#toggle-contexts-nav").click(function () { - /* Need to keep a single toggle across all contexts */ - $(this).toggleClass("context_visibility"); - if ($(this).hasClass("context_visibility")) { - $(".context_collapsed").hide(); /* Hide all collapsed contexts together*/ - } - else { - $(".context_collapsed").show(); - } - }); - - $("a#group_view_by_link").click(function () { - var state = $(this).attr("x_current_group_by"); - if(state === 'context'){ - state='project'; - } else { - state='context'; - } - $.cookie('group_view_by', state); - refresh_page(); - }); - - /* fade flashes and alerts in automatically */ - $(".alert").fadeOut(8000); - } -}; - var TodoItemsContainer = { // public ensureVisibleWithEffectAppear: function(elemId){ @@ -1363,4 +1174,4 @@ $(document).ready(function() { /* Gets called from all AJAX callbacks, too */ enable_rich_interaction(); -}); +}); \ No newline at end of file diff --git a/app/assets/javascripts/tracks_pages.js b/app/assets/javascripts/tracks_pages.js new file mode 100644 index 00000000..3828de58 --- /dev/null +++ b/app/assets/javascripts/tracks_pages.js @@ -0,0 +1,192 @@ +var TracksPages = { + show_errors: function (html) { + $('div#error_status').html(html); + $('div#error_status').show(); + }, + show_edit_errors: function(html) { + $('div#edit_error_status').html(html); + $('div#edit_error_status').show(); + }, + show_errors_for_multi_add: function(html) { + $('div#multiple_error_status').html(html); + $('div#multiple_error_status').show(); + }, + hide_errors: function() { + $('div#error_status').hide(); + $('div#edit_error_status').hide(); + $('div#multiple_error_status').hide(); + }, + update_sidebar: function(html) { + $('#sidebar').html(html); + }, + setup_nifty_corners: function() { + Nifty("div#recurring_new_container","normal"); + Nifty("div#context_new_container","normal"); + Nifty("div#feedlegend","normal"); + Nifty("div#feedicons-project","normal"); + Nifty("div#feedicons-context","normal"); + Nifty("div#todo_new_action_container","normal"); + Nifty("div#project_new_project_container","normal"); + }, + page_notify: function(type, message, fade_duration_in_sec) { + var flash = $('div#message_holder'); + flash.html("

"+message+"

"); + flash = $('h4#flash'); + + var fadein_duration = 1500; + var fadeout_duration = 1500; + var show_duration = fade_duration_in_sec*1000 - fadein_duration - fadeout_duration; + if (show_duration < 0) { + show_duration = 1000; + } + flash.fadeIn(fadein_duration).delay(show_duration).fadeOut(fadeout_duration); + }, + page_error: function(message) { + TracksPages.page_notify('error', message, 5); + }, + page_inform: function(message) { + TracksPages.page_notify('notice', message, 5); + }, + set_page_badge: function(count) { + $('#badge_count').html(count); + }, + setup_autocomplete_for_tag_list: function(id) { + $(id+':not(.ac_input)') + .bind( "keydown", function( event ) { // don't navigate away from the field on tab when selecting an item + if ( event.keyCode === $.ui.keyCode.TAB && + $( this ).data( "autocomplete" ).menu.active ) { + event.preventDefault(); + } + }) + .autocomplete({ + minLength: 2, + autoFocus: true, + delay: 400, /* increase a bit over the default of 300 */ + source: function( request, response ) { + var last_term = extractLast( request.term ); + if (last_term !== "" && last_term !== " ") { + $.ajax( { + url: relative_to_root('tags.autocomplete'), + dataType: 'json', + data: { + term: last_term + }, + success: function(data, textStatus, jqXHR) { + // remove spinner as removing the class is not always done by response + $(id).removeClass('ui-autocomplete-loading'); + response(data, textStatus, jqXHR); // call jquery callback to handle data + } + }); + } else { + // remove spinner as typing will always add the spinner + $(id).removeClass('ui-autocomplete-loading'); + } + }, + focus: function() { + // prevent value inserted on focus + return false; + }, + select: function( event, ui ) { + var terms = split( this.value ); + // remove the current input + terms.pop(); + // add the selected item + terms.push( ui.item.value ); + // add placeholder to get the comma-and-space at the end + //terms.push( "" ); + this.value = terms.join( ", " ); + return false; + } + }); + }, + setup_all_autocompleters: function() { + //fix for #1036 where closing a edit form before the autocomplete was filled + //resulted in a dropdown box that could not be removed. We remove all + //autocomplete boxes the hard way + $('.ac_results').remove(); + + // initialize autocompleters + ProjectItems.setup_autocomplete_for_projects('input[name=project_name]'); + ContextItems.setup_autocomplete_for_contexts('input[name=context_name]'); + ContextItems.setup_autocomplete_for_contexts('input[id="project_default_context_name"]'); + TracksPages.setup_autocomplete_for_tag_list('input[name=tag_list]'); // todo edit form + TracksPages.setup_autocomplete_for_tag_list('input[name=edit_recurring_todo_tag_list]'); + TracksPages.setup_autocomplete_for_tag_list('input[id="project_default_tags"]'); + TodoItems.setup_autocomplete_for_predecessor(); + }, + setup_datepicker: function() { + $('input.Date').datepicker({ + 'dateFormat': dateFormat, + 'firstDay': weekStart, + 'showButtonPanel': true, + 'showWeek': true, + 'changeMonth': true, + 'changeYear': true, + 'maxDate': '+5y', + 'minDate': '-1y', + 'showAnim': '' /* leave empty, see #1117 */ + }); + }, + setup_behavior: function () { + /* main menu */ + $('ul.sf-menu').superfish({ + delay: 250, + animation: { + opacity:'show', + height:'show' + }, + autoArrows: false, + dropShadows: false, + speed: 'fast' + }); + + /* context menu */ + $('ul.sf-item-menu').superfish({ + delay: 100, + animation: { + opacity:'show', + height:'show' + }, + autoArrows: false, + dropShadows: false, + speed: 'fast', + onBeforeShow: function() { /* highlight todo */ + $(this.parent().parent().parent()).addClass("sf-item-selected"); + }, + onHide: function() { /* remove hightlight from todo */ + $(this.parent().parent().parent()).removeClass("sf-item-selected"); + } + }); + + /* for toggle notes link in mininav */ + $("#toggle-notes-nav").click(function () { + $(".todo_notes").toggle(); + }); + + /* Poor man's perspectives, allows to hide any context that is collapsed */ + $("#toggle-contexts-nav").click(function () { + /* Need to keep a single toggle across all contexts */ + $(this).toggleClass("context_visibility"); + if ($(this).hasClass("context_visibility")) { + $(".context_collapsed").hide(); /* Hide all collapsed contexts together*/ + } + else { + $(".context_collapsed").show(); + } + }); + + $("a#group_view_by_link").click(function () { + var state = $(this).attr("x_current_group_by"); + if(state === 'context'){ + state='project'; + } else { + state='context'; + } + $.cookie('group_view_by', state); + refresh_page(); + }); + + /* fade flashes and alerts in automatically */ + $(".alert").fadeOut(8000); + } +}; \ No newline at end of file diff --git a/app/helpers/application_helper.rb b/app/helpers/application_helper.rb index 6c224815..0b053c6a 100644 --- a/app/helpers/application_helper.rb +++ b/app/helpers/application_helper.rb @@ -242,4 +242,8 @@ module ApplicationHelper "#{name}_#{SecureRandom.hex(5)}" end + def js_render(object, locals = {}) + escape_javascript(render(partial: object, locals: locals)) + end + end diff --git a/app/views/todos/_update_has_errors.js.erb b/app/views/todos/_update_has_errors.js.erb new file mode 100644 index 00000000..be3ae7a1 --- /dev/null +++ b/app/views/todos/_update_has_errors.js.erb @@ -0,0 +1,6 @@ +animate: function() { + TracksPages.show_edit_errors(<%=object_name%>.html_for_error_messages()); +}, +html_for_error_messages: function() { + return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>"; +} \ No newline at end of file diff --git a/app/views/todos/_update_succesfull.js.erb b/app/views/todos/_update_succesfull.js.erb new file mode 100644 index 00000000..727086f4 --- /dev/null +++ b/app/views/todos/_update_succesfull.js.erb @@ -0,0 +1,115 @@ +animate: function() { + <%- + animation = [] + animation << "remove_todo" if update_needs_to_remove_todo_from_container + if replace_with_updated_todo + animation << "replace_todo" + elsif append_updated_todo + animation << ( update_needs_to_add_new_container ? "insert_new_container_with_updated_todo" : "add_to_existing_container") + end + animation << "hide_container" if update_needs_to_hide_container + animation << "highlight_updated_todo" + animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred, :project, :context) + animation << "update_predecessors" + -%> + TracksPages.page_inform('<%=escape_javascript @status_message%>'); + TracksPages.set_page_badge(<%= @down_count %>); + <%= render_animation(animation, object_name) %> +}, +remove_todo: function(next_steps) { + $('#<%= dom_id(@todo) %>').fadeOut(400, function() { + $('#<%= dom_id(@todo) %>').remove(); + <% if source_view_is :calendar + # in calendar view it is possible to have a todo on the page twice + -%> + $('#<%= dom_id(@todo) %>').remove(); + <% end -%> + <%= show_empty_message_in_source_container -%> + next_steps.go(); + }); +}, +add_to_existing_container: function(next_steps) { + $('#<%= item_container_id(@todo) %>_items').append(<%=object_name%>.html_for_todo()); + <% if source_view_is_one_of(:calendar) -%> + next_steps.go(); + <% if (@target_context_count==1) || ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) -%> + $("#<%= empty_container_msg_div_id %>").slideUp(100); + <% end -%> + <% else -%> + <% unless (@todo_hidden_state_changed && @todo.hidden?) || @todo_was_deferred_from_active_state -%> + $('#<%= item_container_id(@todo) %>').fadeIn(500, function() { + next_steps.go(); + <% if @target_context_count==1 -%> + $("#<%= empty_container_msg_div_id %>").slideUp(100); + <% end -%> + }); + <% else -%> + next_steps.go(); + <% if (@target_context_count==1) || + ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) || + ( @todo.hidden? && @remaining_hidden_count == 1) + -%> + $("#<%= empty_container_msg_div_id %>").slideUp(100); + <% end -%> + <% end -%> + <% end -%> +}, +replace_todo: function(next_steps) { + $('#<%= dom_id(@todo) %>').html(<%=object_name%>.html_for_todo()); + next_steps.go(); +}, +hide_container: function(next_steps) { + $('#<%= item_container_id(@original_item) %>').fadeOut(400, function(){ next_steps.go(); }); + <%= "$('#deferred_pending_container_empty-nd').slideDown(400);".html_safe if source_view_is(:deferred) && @down_count == 0 %> +}, +highlight_updated_todo: function(next_steps) { + $('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000, function(){ }); + next_steps.go(); +}, +update_empty_container: function(next_steps) { + <% if should_show_empty_container -%> + $('div#no_todos_in_view').slideDown(400, function(){ next_steps.go(); }); + <% else -%> + $('div#no_todos_in_view').fadeOut(100, function(){ next_steps.go(); }); + <% end -%> +}, +update_badge_count: function() { + <% + count = source_view_is(:context) ? @remaining_in_context : @down_count + count = @project_changed ? @remaining_undone_in_project : count + -%> + TracksPages.set_page_badge(<%= count %>); +}, +insert_new_container_with_updated_todo: function(next_steps) { + $('#display_box').prepend(<%=object_name%>.html_for_new_container()); + $('#<%= item_container_id(@todo) %>').fadeIn(500, function() { next_steps.go(); }); +}, +html_for_todo: function() { + return "<%= escape_javascript(render(:partial => @todo, :locals => { :parent_container_type => parent_container_type })) %>"; +}, +html_for_new_container: function() { + return "<%= ( @new_context_created || @new_project_created ) ? escape_javascript(render(:partial => @new_container, :locals => { :settings => {:collapsible => true }})) : "" %>"; +}, +update_predecessors: function(next_steps) { + <%=object_name%>.regenerate_predecessor_family(); + <% if @removed_predecessors + @removed_predecessors.each do |p| -%> + if ($('#<%=item_container_id(p)%>')) { + $('#<%=dom_id(p)%>').html('<%=escape_javascript(render(:partial => p, :locals => { :settings => {:parent_container_type => parent_container_type }}))%>'); + } + <% end -%> + <% end -%> + next_steps.go(); +}, +regenerate_predecessor_family: function() { + <% + parents = @todo.predecessors.to_a + until parents.empty? + parent = parents.pop + parents += parent.predecessors + -%> + $('#<%= dom_id(parent) %>').html("<%= escape_javascript(render(:partial => parent, :locals => { :settings => {:parent_container_type => parent_container_type }})) %>"); + <% + end + -%> +} \ No newline at end of file diff --git a/app/views/todos/toggle_check.js.erb b/app/views/todos/toggle_check.js.erb index 7633833b..e2ad55b5 100644 --- a/app/views/todos/toggle_check.js.erb +++ b/app/views/todos/toggle_check.js.erb @@ -1,5 +1,5 @@ <% unless @saved -%> - TracksPages.page_notify('error', "<%= t('todos.error_toggle_complete') %>", 5); + TracksPages.page_error("<%= t('todos.error_toggle_complete') %>"); <% else # create a unique object name to prevent concurrent toggles to overwrite each other functions object_name = unique_object_name_for("toggle_check") @@ -142,8 +142,7 @@ var <%= object_name %> = { $('#<%= dom_id(t) %>').slideUp(400, function() { $('#<%= dom_id(t) %>').remove(); <% if source_view_is(:project) or source_view_is(:tag) # Insert it in deferred/pending block if existing -%> - $('#<%= item_container_id(t) %>_items').append("<%= escape_javascript(render(:partial => t, :locals => { :parent_container_type => parent_container_type }))%>"); - TodoItems.highlight_todo('#<%= dom_id(t)%>'); + $('#<%= item_container_id(t) %>_items').append("<%= js_render(t, { :parent_container_type => parent_container_type }) %>"); <% end -%> }); <% end -%> @@ -157,7 +156,7 @@ var <%= object_name %> = { until parents.empty? parent = parents.pop parents += parent.predecessors -%> - $('#<%= dom_id(parent) %>').html("<%= escape_javascript(render(:partial => parent, :locals => { :parent_container_type => parent_container_type })) %>"); + $('#<%= dom_id(parent) %>').html("<%= js_render(parent, { :parent_container_type => parent_container_type }) %>"); <%end end -%> @@ -165,23 +164,18 @@ var <%= object_name %> = { }, html_for_recurring_todo: function() { <%- - js = @new_recurring_todo ? escape_javascript(render(:partial => @new_recurring_todo, :locals => { :parent_container_type => parent_container_type })) : "" + js = @new_recurring_todo ? js_render(@new_recurring_todo, { :parent_container_type => parent_container_type }) : "" -%> return "<%= js %>"; }, html_for_todo: function() { <%- - js = "" - if !source_view_is(:done) - js = escape_javascript(render( - :partial => @todo, - :locals => { - :parent_container_type => parent_container_type, - :suppress_project => source_view_is(:project), - :suppress_context => source_view_is(:context) - } - )) - end + locals = { + :parent_container_type => parent_container_type, + :suppress_project => source_view_is(:project), + :suppress_context => source_view_is(:context) + } + js = source_view_is(:done) ? "" : js_render(@todo, locals) -%> return "<%= js %>"; } diff --git a/app/views/todos/update.js.erb b/app/views/todos/update.js.erb index 3481ffd2..68049d38 100644 --- a/app/views/todos/update.js.erb +++ b/app/views/todos/update.js.erb @@ -1,130 +1,5 @@ -<%- - object_name = unique_object_name_for("update_context_#{@context.id}") --%> +<%- object_name = unique_object_name_for("update_todo_#{@todo.id}") -%> var <%=object_name%> = { - <% unless @saved -%> - animate: function() { - TracksPages.show_edit_errors(html_for_error_messages()); - }, - html_for_error_messages: function() { - return "<%= escape_javascript(get_list_of_error_messages_for(@todo)) %>"; - } - <% else -%> - animate: function() { - <%- - animation = [] - animation << "remove_todo" if update_needs_to_remove_todo_from_container - if replace_with_updated_todo - animation << "replace_todo" - elsif append_updated_todo - animation << ( update_needs_to_add_new_container ? "insert_new_container_with_updated_todo" : "add_to_existing_container") - end - animation << "hide_container" if update_needs_to_hide_container - animation << "highlight_updated_todo" - animation << "update_empty_container" if source_view_is_one_of(:tag, :todo, :deferred, :project, :context) - animation << "update_predecessors" - -%> - TracksPages.page_notify('notice', '<%=escape_javascript @status_message%>', 5); - TracksPages.set_page_badge(<%= @down_count %>); - <%= render_animation(animation, object_name) %> - }, - remove_todo: function(next_steps) { - $('#<%= dom_id(@todo) %>').fadeOut(400, function() { - $('#<%= dom_id(@todo) %>').remove(); - <% if source_view_is :calendar - # in calendar view it is possible to have a todo on the page twice - -%> - $('#<%= dom_id(@todo) %>').remove(); - <% end -%> - <%= show_empty_message_in_source_container -%> - next_steps.go(); - }); - }, - add_to_existing_container: function(next_steps) { - $('#<%= item_container_id(@todo) %>_items').append(<%=object_name%>.html_for_todo()); - <% if source_view_is_one_of(:calendar) -%> - next_steps.go(); - <% if (@target_context_count==1) || ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) -%> - $("#<%= empty_container_msg_div_id %>").slideUp(100); - <% end -%> - <% else -%> - <% unless (@todo_hidden_state_changed && @todo.hidden?) || @todo_was_deferred_from_active_state -%> - $('#<%= item_container_id(@todo) %>').fadeIn(500, function() { - next_steps.go(); - <% if @target_context_count==1 -%> - $("#<%= empty_container_msg_div_id %>").slideUp(100); - <% end -%> - }); - <% else -%> - next_steps.go(); - <% if (@target_context_count==1) || - ( (@todo.deferred? || @todo.pending?) && @remaining_deferred_or_pending_count == 1) || - ( @todo.hidden? && @remaining_hidden_count == 1) - -%> - $("#<%= empty_container_msg_div_id %>").slideUp(100); - <% end -%> - <% end -%> - <% end -%> - }, - replace_todo: function(next_steps) { - $('#<%= dom_id(@todo) %>').html(<%=object_name%>.html_for_todo()); - next_steps.go(); - }, - hide_container: function(next_steps) { - $('#<%= item_container_id(@original_item) %>').fadeOut(400, function(){ next_steps.go(); }); - <%= "$('#deferred_pending_container_empty-nd').slideDown(400);".html_safe if source_view_is(:deferred) && @down_count == 0 %> - }, - highlight_updated_todo: function(next_steps) { - $('#<%= dom_id(@todo)%>').effect('highlight', {}, 2000, function(){ }); - next_steps.go(); - }, - update_empty_container: function(next_steps) { - <% if should_show_empty_container -%> - $('div#no_todos_in_view').slideDown(400, function(){ next_steps.go(); }); - <% else -%> - $('div#no_todos_in_view').fadeOut(100, function(){ next_steps.go(); }); - <% end -%> - }, - update_badge_count: function() { - <% - count = source_view_is(:context) ? @remaining_in_context : @down_count - count = @project_changed ? @remaining_undone_in_project : count - -%> - TracksPages.set_page_badge(<%= count %>); - }, - insert_new_container_with_updated_todo: function(next_steps) { - $('#display_box').prepend(<%=object_name%>.html_for_new_container()); - $('#<%= item_container_id(@todo) %>').fadeIn(500, function() { next_steps.go(); }); - }, - html_for_todo: function() { - return "<%= escape_javascript(render(:partial => @todo, :locals => { :parent_container_type => parent_container_type })) %>"; - }, - html_for_new_container: function() { - return "<%= ( @new_context_created || @new_project_created ) ? escape_javascript(render(:partial => @new_container, :locals => { :settings => {:collapsible => true }})) : "" %>"; - }, - update_predecessors: function(next_steps) { - regenerate_predecessor_family(); - <% if @removed_predecessors - @removed_predecessors.each do |p| -%> - if ($('#<%=item_container_id(p)%>')) { - $('#<%=dom_id(p)%>').html('<%=escape_javascript(render(:partial => p, :locals => { :settings => {:parent_container_type => parent_container_type }}))%>'); - } - <% end -%> - <% end -%> - next_steps.go(); - }, - regenerate_predecessor_family: function() { - <% - parents = @todo.predecessors.to_a - until parents.empty? - parent = parents.pop - parents += parent.predecessors - -%> - $('#<%= dom_id(parent) %>').html("<%= escape_javascript(render(:partial => parent, :locals => { :settings => {:parent_container_type => parent_container_type }})) %>"); - <% - end - -%> - } - <% end # if @saved -%> + <%= render :partial => (@saved ? "update_succesfull" : "update_has_errors"), locals: {object_name: object_name} %> } <%=object_name%>.animate(); \ No newline at end of file