diff --git a/app/helpers/todos_helper.rb b/app/helpers/todos_helper.rb index b5617913..5aa674c4 100644 --- a/app/helpers/todos_helper.rb +++ b/app/helpers/todos_helper.rb @@ -11,6 +11,7 @@ module TodosHelper image_tag("blank.png", :alt => t('todos.edit'), :align => "absmiddle", :id => 'edit_icon_todo_'+todo.id.to_s, :class => 'edit_item'), {:controller => 'todos', :action => 'edit', :id => todo.id}, :class => "icon edit_item", + :id => "icon_edit_todo_#{todo.id}", :title => t('todos.edit_action_with_description', :description => todo.description)) end diff --git a/app/views/todos/edit.js.erb b/app/views/todos/edit.js.erb index 64c0d0c4..ffd71cc4 100644 --- a/app/views/todos/edit.js.erb +++ b/app/views/todos/edit.js.erb @@ -1,5 +1,6 @@ hide_todo(); replace_placeholder_with_form(); +fill_dependency_array(); enable_rich_interaction(); function hide_todo() { @@ -12,6 +13,14 @@ function replace_placeholder_with_form() { $('#<%=dom_id(@todo, 'form')%> input#todo_description').focus(); } +function fill_dependency_array() { + spec_of_todo = new Array(); +<% +@todo.predecessors.each do |dep| -%> + spec_of_todo['<%=dep.id%>'] = "<%= escape_javascript(dep.specification)%>"; +<% end -%> +} + function html_for_edit_form() { return "<%= escape_javascript(render(:partial => 'todos/edit_form', :object => @todo)) %>" } diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 66751c12..4ef4c974 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -90,16 +90,16 @@ var TracksForm = { }, enable_dependency_delete: function() { $('a[class=icon_delete_dep]').live('click', function() { - predecessor_list = $('input[name=predecessor_list]'); - id_list = split( predecessor_list.val() ); + var predecessor_list = $('input[name=predecessor_list]'); + var id_list = split( predecessor_list.val() ); // remove from ul $("li#pred_"+this.id).slideUp(500).remove(); // remove from array - new_list = new Array(); + var new_list = new Array(); while (id_list.length > 0) { - elem = id_list.pop(); + var elem = id_list.pop(); if (elem != this.id && elem != '' && elem != ' ') { new_list.push ( elem ); } @@ -116,8 +116,24 @@ var TracksForm = { return false; // prevent submit/follow link }) }, - generate_dependency_list: function(item) { - alert("nyi"); + generate_dependency_list: function(todo_id) { + // find edit form + var form_selector = "#form_todo_"+todo_id; + var form = $(form_selector); + + var predecessor_list = form.find('input[name=predecessor_list]'); + var id_list = split( predecessor_list.val() ); + + var label = form.find("label#label_for_predecessor_input").first(); + label.show(); + + while (id_list.length > 0) { + var elem = id_list.pop(); + var new_li = TodoItems.generate_predecessor(elem, spec_of_todo[elem]); + var ul = form.find('ul#predecessor_ul'); + ul.html(ul.html() + new_li); + form.find('li#pred_'+elem).show(); + } } } @@ -349,8 +365,12 @@ var TodoItems = { /* set behavior for edit icon */ $(".item-container a.edit_item").live('click', function (ev){ - get_with_ajax_and_block_element(this.href, $(this).parents(".item-container")); - TracksForm.generate_dependency_list($(this).parents(".item-container")); + var ajax_options = default_ajax_options_for_scripts('GET', this.href, $(this).parents('.item-container')); + var id = this.id.substr(15); + ajax_options.complete.push( function(){ + TracksForm.generate_dependency_list(id); + }); + $.ajax(ajax_options); return false; }); @@ -812,6 +832,8 @@ function generic_get_script_for_list(element, getter, param){ } function default_ajax_options_for_submit(ajax_type, element_to_block) { + // the complete is not a function but an array so you can push other + // functions that will be executed after the ajax call completes var options = { type: ajax_type, async: true, @@ -824,12 +846,12 @@ function default_ajax_options_for_submit(ajax_type, element_to_block) { }); } }, - complete:function() { + complete: [function() { if (this.context) { $(this.context).unblock(); } enable_rich_interaction(); - }, + }], error: function(req, status) { TracksPages.page_notify('error', i18n['common.ajaxError']+': '+status, 8); }