diff --git a/app/controllers/projects_controller.rb b/app/controllers/projects_controller.rb index 163263c9..bd8c2f27 100644 --- a/app/controllers/projects_controller.rb +++ b/app/controllers/projects_controller.rb @@ -10,6 +10,7 @@ class ProjectsController < ApplicationController def index @source_view = params['_source_view'] || 'project_list' @projects = current_user.projects + @new_project = current_user.projects.build if params[:projects_and_actions] projects_and_actions else @@ -73,6 +74,7 @@ class ProjectsController < ApplicationController render_failure "Expected post format is valid xml like so: project name." return end + @project = current_user.projects.build params_are_invalid = true if (params['project'] || (params['request'] && params['request']['project'])) @@ -81,9 +83,11 @@ class ProjectsController < ApplicationController end @go_to_project = params['go_to_project'] @saved = @project.save + @project_not_done_counts = { @project.id => 0 } @active_projects_count = current_user.projects.active.count @contexts = current_user.contexts + respond_to do |format| format.js { @down_count = current_user.projects.size } format.xml do @@ -95,6 +99,7 @@ class ProjectsController < ApplicationController head :created, :location => project_url(@project), :text => @project.id end end + format.html {redirect_to :action => 'index'} end end diff --git a/app/views/projects/_new_project_form.rhtml b/app/views/projects/_new_project_form.rhtml new file mode 100644 index 00000000..1790fb65 --- /dev/null +++ b/app/views/projects/_new_project_form.rhtml @@ -0,0 +1,40 @@ +
+ + + +
+ <% form_for(@new_project, :html => {:id => 'project_form',:name=>'project',:class => "inline-form", :method => :post }) do -%> +
<%= error_messages_for("project") %>
+ +
+ <%= text_field 'project', 'name', "tabindex" => 1 %>
+ +
+ <%= text_area 'project', 'description', "cols" => 30, "rows" => 4, "tabindex" => 2 %>
+ + <% unless @contexts.empty? -%> +
+ <%= text_field_tag("project[default_context_name]", @new_project.default_context.name, :tabindex => 3) %> +
+ <% end -%> + +
+ <%= text_field_tag("project[default_tags]", @new_project.default_tags, :tabindex => 4) %> + +
+ +
+
+ +
+
+ +
+ + <% end -%> +
+
\ No newline at end of file diff --git a/app/views/projects/create.js.erb b/app/views/projects/create.js.erb new file mode 100644 index 00000000..a72af52f --- /dev/null +++ b/app/views/projects/create.js.erb @@ -0,0 +1,48 @@ +<% if @saved -%> + <% if @go_to_project %> + redirect_to ("<%= project_path(@project) %>") + <% end %> + hide_errors(); + hide_empty_msg(); + set_page_badge(<%= @down_count %>); + update_active_projects_container(); + add_project(); + clear_form(); +<% else -%> + show_errors(); +<% end -%> + +function show_errors() { + $('div#error_status').html(html_for_error_messages()); + $('div#error_status').show(); +} + +function hide_errors() { + $('div#error_status').hide(); +} + +function hide_empty_msg() { + $('projects-empty-nd').hide(); +} + +function add_project() { + $('#list-active-projects').append(html_for_project_listing); +} + +function clear_form() { + $('#project_form').clearForm(); + $('#project_form input:text:first').focus(); +} + +function update_active_projects_container() { + ProjectListPage.set_state_container_visibility('active', true); + ProjectListPage.update_state_count('active', <%=@active_projects_count%>); +} + +function html_for_error_messages() { + return "<%= escape_javascript(error_messages_for('project')) %>"; +} + +function html_for_project_listing() { + return "<%= @saved ? escape_javascript(render(:partial => 'project_listing', :locals => { :project_listing => @project })) : "" %>"; +} \ No newline at end of file diff --git a/app/views/projects/create.js.rjs b/app/views/projects/create.js.rjs deleted file mode 100644 index 0341fc8b..00000000 --- a/app/views/projects/create.js.rjs +++ /dev/null @@ -1,17 +0,0 @@ -if @saved and @go_to_project - page.redirect_to project_path(@project) -elsif @saved - page.hide 'status' - page['badge_count'].replace_html @down_count - page.hide 'projects-empty-nd' - page.show 'list-active-projects-container' - page.replace_html "active-projects-count", @active_projects_count - page.insert_html :bottom, "list-active-projects", :partial => 'project_listing', :locals => { :project_listing => @project } - page.sortable "list-active-projects", get_listing_sortable_options('list-active-projects') - page << "$('#project-form').clearForm();" - page << "$('#project-form input:text:first').focus();" -else - page.show 'status' - page.replace_html 'status', "#{error_messages_for('project')}" -end -page.hide "busy" diff --git a/app/views/projects/destroy.js.erb b/app/views/projects/destroy.js.erb index 8a843ad3..e92843da 100644 --- a/app/views/projects/destroy.js.erb +++ b/app/views/projects/destroy.js.erb @@ -1,7 +1,7 @@ remove_deleted_project(); -ProjectListPage.update_state_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>) -ProjectListPage.show_or_hide_state_container(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>); -page_notify('notice', "Deleted project '#{@project.name}'", 5); +ProjectListPage.update_all_states_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>) +ProjectListPage.show_or_hide_all_state_containers(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>); +page_notify('notice', "Deleted project '<%= @project.name%>'", 5); set_page_badge(<%=@down_count%>); function remove_deleted_project() { diff --git a/app/views/projects/index.html.erb b/app/views/projects/index.html.erb index 5e1d81d7..4a9902e8 100644 --- a/app/views/projects/index.html.erb +++ b/app/views/projects/index.html.erb @@ -7,60 +7,8 @@ <%= render :partial => 'project_state_group', :object => @completed_projects, :locals => { :state => 'completed'} %> -<% @project = @new_project -%>
-
- - - -
- <% form_remote_tag(:url => projects_path, :method => :post, - :html=> { :id=>'project-form', :name=>'project', :class => 'inline-form'}, - :before => "$('#project_new_project_submit').block({message:null})", - :complete => "$('#project_new_project_submit').unblock()") do -%> - -
<%= error_messages_for('project') %>
- -
- <%= text_field 'project', 'name', "tabindex" => 1 %>
- -
- <%= text_area 'project', 'description', "cols" => 30, "rows" => 4, "tabindex" => 2 %>
- - <% unless @contexts.empty? -%> -
- <%= text_field_tag("project[default_context_name]", @project.default_context.name, :tabindex => 3) %> -
- <% end -%> - -
- <%= text_field_tag("project[default_tags]", @project.default_tags, :tabindex => 4) %> -
- -
- -
-
- -
-
- -

-
- - <% end -%> -
-
+ <%= render :partial => 'new_project_form' %>
- - diff --git a/app/views/projects/update.js.erb b/app/views/projects/update.js.erb index feb09e9b..f0dc6407 100644 --- a/app/views/projects/update.js.erb +++ b/app/views/projects/update.js.erb @@ -10,9 +10,8 @@ replace_project_form_with_updated_project(); <% end -%> - update_sortable(); - ProjectListPage.update_state_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>) - ProjectListPage.show_or_hide_state_container(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>); + ProjectListPage.update_all_states_count(<%=@active_projects_count%>, <%=@hidden_projects_count%>, <%=@completed_projects_count%>) + ProjectListPage.show_or_hide_all_state_containers(<%= @show_active_projects %>, <%= @show_hidden_projects %>, <%= @show_completed_projects %>); <% else # assume source_view :project %> diff --git a/features/manage_list_of_projects.feature b/features/manage_list_of_projects.feature index 448f5a14..92b8ddc0 100644 --- a/features/manage_list_of_projects.feature +++ b/features/manage_list_of_projects.feature @@ -56,7 +56,7 @@ Feature: Manage the list of projects When I drag the project "manage me" below "upgrade jquery" Then the project "upgrade jquery" should be above the project "manage me" - @selenium, @wip + @selenium Scenario: Hiding and unhiding the new project form When I go to the projects page Then the new project form should be visible @@ -65,7 +65,14 @@ Feature: Manage the list of projects When I follow "Create a new project »" Then the new project form should be visible + @selenium, @wip Scenario: Adding a new project + When I go to the projects page + And I submit a new project with name "finish cucumber tests for project" + Then I should see "finish cucumber tests for project" + And the badge should show 4 + And the project list badge for "active" projects should show 4 + Scenario: Adding a new project and take me to the project page Scenario: Sorting the project alphabetically Scenario: Sorting the project by number of task \ No newline at end of file diff --git a/features/step_definitions/project_list_steps.rb b/features/step_definitions/project_list_steps.rb index 7f140a3a..d2e9ba56 100644 --- a/features/step_definitions/project_list_steps.rb +++ b/features/step_definitions/project_list_steps.rb @@ -26,6 +26,11 @@ When /^I drag the project "([^"]*)" below "([^"]*)"$/ do |project_drag, project_ selenium.mouse_up_at(drop_project_container_xpath,coord_string) end +When /^I submit a new project with name "([^"]*)"$/ do |project_name| + fill_in "project[name]", :with => project_name + submit_new_project_form +end + Then /^the project "([^"]*)" should be above the project "([^"]*)"$/ do |project_high, project_low| high_id = @current_user.projects.find_by_name(project_high).id low_id = @current_user.projects.find_by_name(project_low).id diff --git a/features/support/selenium.rb b/features/support/selenium.rb index 1d30db84..a66782d2 100644 --- a/features/support/selenium.rb +++ b/features/support/selenium.rb @@ -2,11 +2,18 @@ if ENV["RAILS_ENV"] == "selenium" puts "Configuring to use Selenium with Webrat for Cucumber stories" Webrat.configure do |config| config.mode = :selenium + config.application_environment = :selenium + # use only if you run a separate rails test server instance and do not + # want webrat to start one for you + # config.application_port = 3001 + config.selenium_browser_startup_timeout = 30 # use only if you run a separate selenium server instance and do not # want webrat to start one for you - #config.selenium_server_address = "localhost" + # config.selenium_server_address = "localhost" + # config.selenium_server_port = "4444" + end Cucumber::Rails::World.use_transactional_fixtures = false diff --git a/features/support/world.rb b/features/support/world.rb index 20870a4a..e630381a 100644 --- a/features/support/world.rb +++ b/features/support/world.rb @@ -11,6 +11,9 @@ module TracksStepHelper selenium.click("xpath=//form[@id='context-form']//button[@id='context_new_submit']", :wait_for => :ajax, :javascript_framework => :jquery) end + def submit_new_project_form + selenium.click("xpath=//form[@id='project_form']//button[@id='project_new_project_submit']", :wait_for => :ajax, :javascript_framework => :jquery) + end end World(TracksStepHelper) \ No newline at end of file diff --git a/public/javascripts/application.js b/public/javascripts/application.js index 817e06bc..ce8a36e2 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -45,26 +45,23 @@ var TracksForm = { } var ProjectListPage = { - update_state_count: function (active, hidden, completed) { - $('#active-projects-count').html(active); - $('#hidden-projects-count').html(hidden); - $('#completed-projects-count').html(completed); + update_state_count: function(state, count) { + $('#'+state+'-projects-count').html(count); }, - show_or_hide_state_container: function (show_active, show_hidden, show_completed) { - $(["active", "hidden", "completed"]).each(function() { - container = $('#list-'+this+'-projects-container'); - set_state_container_visibility(container, eval('show_'+this)); - }); - - function set_state_container_visibility (container, set_visible) { + update_all_states_count: function (active_count, hidden_count, completed_count) { + $(["active", "hidden", "completed"]).each(function() { ProjectListPage.update_state_count(this, eval(this+'_count')); }); + }, + show_or_hide_all_state_containers: function (show_active, show_hidden, show_completed) { + $(["active", "hidden", "completed"]).each(function() { ProjectListPage.set_state_container_visibility(this, eval('show_'+this)); }); + }, + set_state_container_visibility: function (state, set_visible) { if (set_visible) { - container.slideDown("fast"); + $('#list-'+state+'-projects-container').slideDown("fast"); } else { - container.slideUp("fast"); + $('#list-'+state+'-projects-container').slideUp("fast"); } - } } -} + } $.fn.clearForm = function() { return this.each(function() { @@ -147,6 +144,10 @@ todoItems = { } } +function redirect_to(path) { + $(window.location).attr('href', path); +} + function setup_container_toggles(){ // bind handlers $('.container_toggle').click(function(evt){ @@ -373,7 +374,8 @@ $(document).ready(function() { Nifty("div#feedicons-project","normal"); Nifty("div#feedicons-context","normal"); Nifty("div#todo_new_action_container","normal"); - + Nifty("div#project_new_project_container","normal"); + /* Moved from standard.html.erb layout */ $('ul.sf-menu').superfish({ delay: 250, @@ -604,6 +606,17 @@ $(document).ready(function() { return false; }); + $("form#project_form button.positive").live('click', function (ev) { + $('form.#project_form').ajaxSubmit({ + type: 'POST', + async: true, + buttons_dom_elem: $(this), + beforeSend: function() {this.buttons_dom_elem.block({message: null});}, + complete: function() {this.buttons_dom_elem.unblock();} + }); + return false; + }); + $('#toggle_project_new').click(function(evt){ TracksForm.toggle('toggle_project_new', 'project_new', 'project-form', '« Hide form', 'Hide new project form',