diff --git a/app/views/contexts/update.js.erb b/app/views/contexts/update.js.erb
index b88b538e..27feb521 100644
--- a/app/views/contexts/update.js.erb
+++ b/app/views/contexts/update.js.erb
@@ -1,42 +1,48 @@
-<% if @saved -%>
+<% unless @saved -%>
+ TracksPages.show_edit_errors(html_for_error_messages());
+ function html_for_error_messages() {
+ return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
+ }
+
+<% else -%>
TracksPages.page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
<% if @state_changed -%>
remove_and_re_add_context();
+ update_container_states();
<% else -%>
replace_context_form_with_updated_context();
<% end -%>
-<% else -%>
- TracksPages.show_edit_errors(html_for_error_messages());
-<% end -%>
+ function remove_and_re_add_context() {
+ $('#<%=dom_id(@context, 'container')%>').slideUp(500, function() {
+ $('#<%=dom_id(@context, 'container')%>').remove();
+ $('#list-contexts-<%=@new_state%>').append(html_for_context_listing());
+ });
+ }
-function remove_and_re_add_context() {
- $('#<%=dom_id(@context, 'container')%>').slideUp(500, function() {
- $('#<%=dom_id(@context, 'container')%>').remove();
- $('#list-contexts-<%=@new_state%>').append(html_for_context_listing());
- });
-}
+ function replace_context_form_with_updated_context() {
+ $('#<%=dom_id(@context, 'container')%>').fadeOut(250, function() {
+ <%
+ # first add the updated context after the old one, then remove old one
+ # using html() does not work, because it will replace the _content_ of
+ # the container instead of the container itself, i.e. you will get
+ # a container within a container which will break drag-and-drop sorting
+ -%>
+ $('#<%=dom_id(@context, 'container')%>').after(html_for_context_listing());
+ $('#<%=dom_id(@context, 'container')%>').remove();
+ $('#<%=dom_id(@context, 'container')%>').fadeIn(500);
+ });
+ }
-function replace_context_form_with_updated_context() {
- $('#<%=dom_id(@context, 'container')%>').fadeOut(250, function() {
-<%
- # first add the updated context after the old one, then remove old one
- # using html() does not work, because it will replace the _content_ of
- # the container instead of the container itself, i.e. you will get
- # a container within a container which will break drag-and-drop sorting
--%>
- $('#<%=dom_id(@context, 'container')%>').after(html_for_context_listing());
- $('#<%=dom_id(@context, 'container')%>').remove();
- $('#<%=dom_id(@context, 'container')%>').fadeIn(500);
- });
-}
+ function update_container_states() {
+ ContextListPage.update_all_states_count(<%=@active_contexts.count%>, <%=@hidden_contexts.count%>, <%=@closed_contexts.count%>);
+ ContextListPage.show_or_hide_all_state_containers(<%= !@active_contexts.empty? %>, <%= !@hidden_contexts.empty? %>, <%= !@closed_contexts.empty? %>);
+ }
-function html_for_error_messages() {
- return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
-}
+ function html_for_context_listing() {
+ return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
+ }
-function html_for_context_listing() {
- return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
-}
\ No newline at end of file
+<% end -%>
\ No newline at end of file
diff --git a/config/locales/en.yml b/config/locales/en.yml
index c030ccac..ed42c4dc 100644
--- a/config/locales/en.yml
+++ b/config/locales/en.yml
@@ -892,6 +892,7 @@ en:
edit_context: Edit context
hide_form_title: Hide new context form
context_hide: Hide from front page?
+ context_state: Context state
hidden_contexts: Hidden contexts
no_contexts_active: Currently there are no active contexts
show_form: Create a new context
diff --git a/features/context_list.feature b/features/context_list.feature
index e2afe018..dcebd5a5 100644
--- a/features/context_list.feature
+++ b/features/context_list.feature
@@ -49,18 +49,23 @@ Feature: Manage the list of contexts
And the context list badge for active contexts should show 1
@javascript
- Scenario: Delete last context from context page should remove the contexts container for hidden or active contexts
+ Scenario: Delete last context from context page should remove the contexts container
Given I have a context called "@computer"
And I have a hidden context called "@ipad"
+ And I have a closed context called "@ibm-pc"
When I go to the contexts page
And I should see that the context container for active contexts is present
And I should see that the context container for hidden contexts is present
+ And I should see that the context container for closed contexts is present
When I delete the context "@computer"
Then I should see that a context named "@computer" is not present
And I should see that the context container for active contexts is not present
When I delete the context "@ipad"
Then I should see that a context named "@ipad" is not present
And I should see that the context container for hidden contexts is not present
+ When I delete the context "@ibm-pc"
+ Then I should see that a context named "@ibm-pc" is not present
+ And I should see that the context container for closed contexts is not present
@javascript
Scenario: Delete context from context page right after an edit
@@ -102,12 +107,16 @@ Feature: Manage the list of contexts
When I go to the contexts page
Then I should see empty message for active contexts
And I should see empty message for hidden contexts
+ And I should see empty message for closed contexts
When I add a new active context "@active"
Then I should see the context "@active" under "active"
And I should not see empty message for active contexts
When I add a new hidden context "@hidden"
Then I should see the context "@hidden" under "hidden"
And I should not see empty message for hidden contexts
+ When I edit the state of context "@hidden" to closed
+ Then I should not see empty message for closed contexts
+ And I should see the context "@hidden" under "closed"
@javascript
Scenario: I can drag and drop to order the contexts
diff --git a/features/step_definitions/context_list_steps.rb b/features/step_definitions/context_list_steps.rb
index 51a5691e..68217821 100644
--- a/features/step_definitions/context_list_steps.rb
+++ b/features/step_definitions/context_list_steps.rb
@@ -39,7 +39,7 @@ end
When /^I add a new hidden context "([^"]*)"$/ do |context_name|
fill_in "context[name]", :with => context_name
- check "context_hide"
+ check "context_state_hide"
submit_new_context_form
end
@@ -53,6 +53,28 @@ When /^I drag context "([^"]*)" above context "([^"]*)"$/ do |context_drag, cont
page.execute_script "$('#{sortable_css}').simulateDragSortable({move: #{drop_index-drag_index}, handle: '.grip'});"
end
+When /^I edit the state of context "(.*?)" to closed$/ do |context_name|
+ context = @current_user.contexts.where(:name => context_name).first
+ context.should_not be_nil
+
+ # open edit form
+ page.find("a#link_edit_context_#{context.id}").click
+
+ # wait for the form to appear (which included a submit button)
+ page.should have_css("button#submit_context_#{context.id}", :visible=>true)
+
+ # change state
+ within "form#edit_form_context_#{context.id}" do
+ find("input#context_state_closed").click
+ click_button "submit_context_#{context.id}"
+ end
+
+ # wait for the form to go away
+ page.should_not have_css("button#submit_context_#{context.id}", :visible => true)
+ # wait for the changed context to appear
+ page.should have_css("a#link_edit_context_#{context.id}", :visible=> true)
+end
+
Then /^context "([^"]*)" should be above context "([^"]*)"$/ do |context_high, context_low|
context_list_find_index(context_high).should < context_list_find_index(context_low)
end
@@ -64,12 +86,8 @@ Then /^I should see that a context named "([^"]*)" (is|is not) present$/ do |con
end
end
-Then /^I should see that the context container for (.*) contexts is not present$/ do |state|
- page.should_not have_css("div#list-#{state}-contexts-container", :visible => true)
-end
-
-Then /^I should see that the context container for (.*) contexts is present$/ do |state|
- page.should have_css("div#list-#{state}-contexts-container", :visible => true)
+Then /^I should see that the context container for (.*) contexts (is|is not) present$/ do |state, visible|
+ page.send(visible=="is" ? :should : :should_not, have_css("div#list-#{state}-contexts-container", :visible => true))
end
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
@@ -79,20 +97,16 @@ Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, st
page.has_css?("div#list-contexts-#{state} div#context_#{context.id}").should be_true
end
-Then /^the new context form should be visible$/ do
- page.has_css?("div#context_new", :visible => true).should be_true
-end
-
-Then /^the new context form should not be visible$/ do
- page.has_css?("div#context_new", :visible => true).should be_false
+Then /^the new context form should (be|not be) visible$/ do |visible|
+ page.has_css?("div#context_new", :visible => true).should (visible=="be" ? be_true : be_false)
end
Then /^the context list badge for ([^"]*) contexts should show (\d+)$/ do |state_name, count|
find("span##{state_name}-contexts-count").text.should == count
end
-Then /^I should (see|not see) empty message for (active|hidden) contexts$/ do |visible, state|
- box = (state=='active') ? "div#active-contexts-empty-nd" : "div#hidden-contexts-empty-nd"
+Then /^I should (see|not see) empty message for (active|hidden|closed) contexts$/ do |visible, state|
+ box = "div##{state}-contexts-empty-nd"
elem = page.find(box)
elem.should_not be_nil
diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb
index d9f5ae82..b36af78d 100644
--- a/features/step_definitions/context_steps.rb
+++ b/features/step_definitions/context_steps.rb
@@ -3,32 +3,23 @@ Given /^I have no contexts$/ do
Context.delete_all
end
-Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
+Given /^there exists (an active|a hidden|a closed) context called "([^"]*)" for user "([^"]*)"$/ do |state, context_name, login|
user = User.where(:login => login).first
user.should_not be_nil
- @context = user.contexts.where(:name => context_name, :state => 'active').first_or_create
+ context_state = {"an active" => "active", "a hidden" => "hidden", "a closed" => "closed"}[state]
+ @context = user.contexts.where(:name => context_name, :state => context_state).first_or_create
end
Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
step "there exists an active context called \"#{context_name}\" for user \"#{login}\""
end
-Given /^there exists a hidden context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
- user = User.where(:login => login).first
- user.should_not be_nil
- @context = user.contexts.create!(:name => context_name, :state => 'hidden')
-end
-
Given /^I have a context called "([^\"]*)"$/ do |context_name|
step "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
-Given /^I have an active context called "([^\"]*)"$/ do |context_name|
- step "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
-end
-
-Given /^I have a hidden context called "([^\"]*)"$/ do |context_name|
- step "there exists a hidden context called \"#{context_name}\" for user \"#{@current_user.login}\""
+Given /^I have (an active|a hidden|a closed) context called "([^\"]*)"$/ do |state, context_name|
+ step "there exists #{state} context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have the following contexts:$/ do |table|