+
<%= context_state_group.length %><%= t("states."+ state +"_plural")%> <%= t('common.contexts') %>
<%= t('contexts.no_contexts_' + state) %>
diff --git a/app/views/contexts/destroy.js.erb b/app/views/contexts/destroy.js.erb
new file mode 100644
index 00000000..387670fd
--- /dev/null
+++ b/app/views/contexts/destroy.js.erb
@@ -0,0 +1,15 @@
+remove_deleted_context();
+
+ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>)
+ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>);
+
+set_page_badge(<%=@down_count%>);
+page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
+
+
+function remove_deleted_context() {
+ $('div#<%=dom_id(@context, "container")%>').slideUp(1000,
+ function() {
+ $('div#<%=dom_id(@context, "container")%>').remove();
+ });
+}
\ No newline at end of file
diff --git a/app/views/contexts/destroy.js.rjs b/app/views/contexts/destroy.js.rjs
deleted file mode 100644
index 56c32f53..00000000
--- a/app/views/contexts/destroy.js.rjs
+++ /dev/null
@@ -1,6 +0,0 @@
-page.visual_effect :fade, dom_id(@context, "container"), :duration => 0.5
-page.delay(0.5) do
- page[dom_id(@context, "container")].remove
-end
-page['badge_count'].replace_html @down_count
-page.notify :notice, t('contexts.context_deleted', :name=>@context.name), 5.0
diff --git a/features/context_list.feature b/features/context_list.feature
index 28ac77e3..aad38e80 100644
--- a/features/context_list.feature
+++ b/features/context_list.feature
@@ -10,14 +10,29 @@ Feature: Manage the list of contexts
| testuser | secret | false |
And I have logged in as "testuser" with password "secret"
- @selenium, @wip
+ @selenium
Scenario: Delete context from context page should update badge
Given I have a context called "@computer"
+ And I have a context called "@ipad"
When I go to the contexts page
- Then the badge should show 1
+ Then the badge should show 2
+ And the context list badge for active contexts should show 2
When I delete the context "@computer"
Then he should see that a context named "@computer" is not present
- And the badge should show 0
+ And the badge should show 1
+ And the context list badge for active contexts should show 1
+
+ @selenium, @wip
+ Scenario: Delete last context from context page should remove the contexts container for hidden or active contexts
+ Given I have a context called "@computer"
+ And I have a hidden context called "@ipad"
+ When I go to the contexts page
+ 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
@selenium, @wip
Scenario: Delete context from context page right after an edit
diff --git a/features/step_definitions/context_list_steps.rb b/features/step_definitions/context_list_steps.rb
index 6af5fea7..c0075867 100644
--- a/features/step_definitions/context_list_steps.rb
+++ b/features/step_definitions/context_list_steps.rb
@@ -36,14 +36,27 @@ When /^I add a new active context "([^"]*)"$/ do |context_name|
When "I add a new context \"#{context_name}\""
end
-
When /^I add a new hidden context "([^"]*)"$/ do |context_name|
fill_in "context[name]", :with => context_name
check "context_hide"
submit_new_context_form
end
+Then /^I should see that a context named "([^"]*)" is not present$/ do |context_name|
+ Then "I should not see \"#{context_name}\""
+end
+
+Then /^I should see that the context container for (.*) contexts is not present$/ do |state|
+ present = selenium.is_element_present("list-contexts-#{state}'")
+ present.should_not be_true
+end
+
Then /^I should see the context "([^"]*)" under "([^"]*)"$/ do |context_name, state|
context = Context.find_by_name(context_name)
+ context.should_not be_nil
response.should have_xpath("//div[@id='list-contexts-#{state}']//div[@id='context_#{context.id}']")
end
+
+Then /^the context list badge for ([^"]*) contexts should show (\d+)$/ do |state_name, count|
+ selenium.get_text("xpath=//span[@id='#{state_name}-contexts-count']").should == count
+end
diff --git a/features/step_definitions/context_steps.rb b/features/step_definitions/context_steps.rb
index 0e0fae48..e34be480 100644
--- a/features/step_definitions/context_steps.rb
+++ b/features/step_definitions/context_steps.rb
@@ -3,14 +3,28 @@ Given /^I have no contexts$/ do
Context.delete_all
end
-Given /^there exists a context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
+Given /^there exists an active context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
user = User.find_by_login(login)
user.should_not be_nil
- @context = user.contexts.create!(:name => context_name)
+ @context = user.contexts.create!(:name => context_name, :hide => false)
+end
+
+Given /^there exists a hidden context called "([^"]*)" for user "([^"]*)"$/ do |context_name, login|
+ user = User.find_by_login(login)
+ user.should_not be_nil
+ @context = user.contexts.create!(:name => context_name, :hide => true)
end
Given /^I have a context called "([^\"]*)"$/ do |context_name|
- Given "there exists a context called \"#{context_name}\" for user \"#{@current_user.login}\""
+ Given "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
+end
+
+Given /^I have an active context called "([^\"]*)"$/ do |context_name|
+ Given "there exists an active context called \"#{context_name}\" for user \"#{@current_user.login}\""
+end
+
+Given /^I have a hidden context called "([^\"]*)"$/ do |context_name|
+ Given "there exists a hidden context called \"#{context_name}\" for user \"#{@current_user.login}\""
end
Given /^I have the following contexts:$/ do |table|
diff --git a/public/javascripts/application.js b/public/javascripts/application.js
index 2dc949e6..fdfbc319 100644
--- a/public/javascripts/application.js
+++ b/public/javascripts/application.js
@@ -51,6 +51,7 @@ var TracksForm = {
}
}
+/* TODO, refactor the following two objects into three without obvious duplication */
var ProjectListPage = {
update_state_count: function(state, count) {
$('#'+state+'-projects-count').html(count);
@@ -70,6 +71,26 @@ var ProjectListPage = {
}
}
+var ContextListPage = {
+ update_state_count: function(state, count) {
+ $('#'+state+'-contexts-count').html(count);
+ },
+ update_all_states_count: function (active_count, hidden_count, completed_count) {
+ $(["active", "hidden"]).each(function() { ContextListPage.update_state_count(this, eval(this+'_count')); });
+ },
+ show_or_hide_all_state_containers: function (show_active, show_hidden, show_completed) {
+ $(["active", "hidden"]).each(function() { ContextListPage.set_state_container_visibility(this, eval('show_'+this)); });
+ },
+ set_state_container_visibility: function (state, set_visible) {
+ if (set_visible) {
+ $('#list-'+state+'-contexts-container').slideDown("fast");
+ } else {
+ $('#list-'+state+'-contexts-container').slideUp("fast");
+ }
+ }
+ }
+
+
$.fn.clearForm = function() {
return this.each(function() {
var type = this.type, tag = this.tagName.toLowerCase();
@@ -624,6 +645,16 @@ $(document).ready(function() {
return false;
});
+ $('a.delete_context_button').live('click', function(evt){
+ evt.preventDefault();
+ if(confirm("Are you sure that you want to "+this.title+"? Be aware that this will also delete all (repeating) actions in this context!")){
+ $(this).parents('.project').block({message: null});
+ params = {_method: 'delete'};
+ $.post(this.href, params, null, 'script');
+ }
+ });
+
+
$("form#context-form button.positive").live('click', function (ev) {
$('form.#context-form').ajaxSubmit({
type: 'POST',