Improve and clean up the Ajax interactions involved in deleting projects and contexts from their listing pages.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@449 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-02-21 14:12:54 +00:00
parent 4c7d27004d
commit 10417aca20
9 changed files with 97 additions and 37 deletions

View file

@ -4,6 +4,7 @@ class ContextsController < ApplicationController
before_filter :init, :except => [:create, :destroy, :order]
before_filter :init_todos, :only => :show
before_filter :check_user_set_context, :only => [:update, :destroy]
skip_before_filter :login_required, :only => [:index]
prepend_before_filter :login_or_feed_token_required, :only => [:index]
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
@ -69,7 +70,6 @@ class ContextsController < ApplicationController
# Edit the details of the context
#
def update
check_user_set_context
params['context'] ||= {}
success_text = if params['field'] == 'name' && params['value']
params['context']['id'] = params['id']
@ -92,12 +92,10 @@ class ContextsController < ApplicationController
# If the context contains actions, you'll get a warning dialogue.
# If you choose to go ahead, any actions in the context will also be deleted.
def destroy
check_user_set_context
if @context.destroy
render_text ""
else
notify :warning, "Couldn't delete context \"#{@context.name}\""
redirect_to :action => 'index'
@context.destroy
respond_to do |format|
format.js
format.xml { render :text => "Deleted context #{@context.name}" }
end
end

View file

@ -2,6 +2,7 @@ class ProjectsController < ApplicationController
helper :application, :todos, :notes
before_filter :init, :except => [:create, :destroy, :order]
before_filter :check_user_set_project, :only => [:update, :destroy, :show]
skip_before_filter :login_required, :only => [:index]
prepend_before_filter :login_or_feed_token_required, :only => [:index]
session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) }
@ -30,7 +31,6 @@ class ProjectsController < ApplicationController
end
def show
check_user_set_project
@page_title = "TRACKS::Project: #{@project.name}"
@not_done = @project.not_done_todos(:include_project_hidden_todos => true)
@deferred = @project.deferred_todos
@ -73,7 +73,6 @@ class ProjectsController < ApplicationController
# Edit the details of the project
#
def update
check_user_set_project
params['project'] ||= {}
if params['project']['state']
@project.transition_to(params['project']['state'])
@ -104,18 +103,14 @@ class ProjectsController < ApplicationController
end
end
# Delete a project
#
def destroy
check_user_set_project
if @project.destroy
render :text => ''
else
notify :warning, "Couldn't delete project \"#{@project.name}\""
redirect_to :action => 'index'
@project.destroy
respond_to do |format|
format.js
format.xml { render :text => "Deleted project #{@project.name}" }
end
end
# Methods for changing the sort order of the projects in the list
#
def order

View file

@ -15,12 +15,10 @@
<span class="grey">VISIBLE</span>
<% end %>
<a class="delete_context_button" href="<%= formatted_context_path(context, :js) %>" title="delete the context '<%= context.name %>'"><%= image_tag( "blank.png", :title => "Delete context", :class=>"delete_item") %></a>
<%= apply_behavior "a.delete_context_button:click", :prevent_default => true do |page|
<%= apply_behavior "a.delete_context_button:click", { :prevent_default => true, :external => true} do |page|
page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {"
page << " new Ajax.Updater(this.up('.list'),"
page << " this.href, {asynchronous:true,"
page << " evalScripts:true, method:'delete',"
page << " onLoading:function(request){ Effect.Fade(this.up('.list'));}}); };"
page << " new Ajax.Request(this.href, {asynchronous:true,"
page << " evalScripts:true, method:'delete'}); };"
end -%>
<a class="edit_context_button" href="#"><%= image_tag( "blank.png", :title => "Edit context", :class=>"edit_item") %></a>
<%= apply_behavior 'a.edit_context_button:click', :prevent_default => true do |page, element|

View file

@ -0,0 +1,5 @@
page.visual_effect :fade, dom_id(@context, "container"), :duration => 0.5
page.delay(0.5) do
page[dom_id(@context, "container")].remove
end
page.notify :notice, "Deleted context '#{@context.name}'", 5.0

View file

@ -1,6 +1,6 @@
<% project = project_listing %>
<div id="<%= dom_id(project, "container") %>" class="list">
<div id="<%= dom_id(project) %>" class="even_row" style="display:'';">
<div id="<%= dom_id(project) %>" class="project even_row" style="display:'';">
<div class="position">
<span class="handle">DRAG</span>
</div>
@ -9,30 +9,40 @@
</div>
<div class="buttons">
<span class="grey"><%= project.current_state.to_s.upcase %></span>
<%= link_to_remote( image_tag("blank.png", :title =>"Delete project", :class=>"delete_item"),
:update => dom_id(project, "container"),
:loading => visual_effect(:fade, dom_id(project, "container")),
:url => project_path(project),
:method => :delete,
:confirm => "Are you sure that you want to delete the project \'#{project.name}\'?" ) %>
<%= link_to_function( image_tag("blank.png", :title => "Edit item", :class=>"edit_item"),
"Element.toggle('#{dom_id(project)}'); Element.toggle('#{dom_id(project, 'edit')}'); new Effect.Appear('#{dom_id(project, 'edit')}'); Form.focusFirstElement('#{dom_id(project, "edit_form")}');" ) %>
<a class="delete_project_button" href="<%= formatted_project_path(project, :js) %>" title="delete the project '<%= project.name %>'"><%= image_tag( "blank.png", :title => "Delete project", :class=>"delete_item") %></a>
<%= apply_behavior "a.delete_project_button:click", { :prevent_default => true, :external => true} do |page|
page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {"
page << " new Ajax.Request(this.href, {asynchronous:true,"
page << " evalScripts:true, method:'delete'}); };"
end -%>
<a class="edit_project_button" href="#"><%= image_tag( "blank.png", :title => "Edit project", :class=>"edit_item") %></a>
<%= apply_behavior 'a.edit_project_button:click', :prevent_default => true do |page, element|
element.up('.project').toggle
editform = element.up('.list').down('.edit-form')
editform.toggle
editform.visual_effect(:appear)
editform.down('input').focus
end
-%>
</div>
</div>
<div id="<%= dom_id(project, 'edit') %>" class="edit-form" style="display:none;">
<% form_remote_tag :url => project_path(project),
:method => :put,
:html => { :id => dom_id(project, 'edit_form'), :class => "form" },
:complete => visual_effect(:appear, dom_id(project, 'container')) do -%>
<% form_tag project_path(project), { :id => dom_id(project, 'edit_form'), :class => "inline-form edit-project-form", :method => :put } do -%>
<table style="table-layout: fixed;" width="450">
<%= render :partial => 'project_form', :object => project %>
<tr>
<td width="150">&nbsp; <input type="hidden" name="wants_render" value="true" /></td>
<td width="300"><input type="submit" value="Update" />&nbsp;<a href="javascript:void(0);" onclick="Element.toggle('<%= dom_id(project) %>'); Element.toggle('<%= dom_id(project, 'edit') %>');Form.reset('<%= dom_id(project, 'edit_form') %>');">Cancel</a></td>
<td width="300"><input type="submit" value="Update" />&nbsp;<a href="#" class="form_reset">Cancel</a></td>
</tr>
</table>
<% end -%>
<%= apply_behavior ".edit-project-form", make_remote_form(:complete => "Effect.Appear($(this).up('.list'));" ), :external => true %>
<%= apply_behavior "a.form_reset:click", :prevent_default => true do |page, element|
element.up('.list').down('.project').toggle
element.up('.edit-form').toggle
element.up('form').reset
end %>
</div>
</div>
<% if controller.action_name == 'create' %>

View file

@ -0,0 +1,5 @@
page.visual_effect :fade, dom_id(@project, "container"), :duration => 0.5
page.delay(0.5) do
page[dom_id(@project, "container")].remove
end
page.notify :notice, "Deleted project '#{@project.name}'", 5.0

View file

@ -0,0 +1,15 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
open "/contexts"
click "css=#context_3 .buttons img.edit_item"
wait_for_visible "edit_context_3"
wait_for_not_visible "context_3"
type "//div[@id='edit_context_3'] //input[@name='context[name]']", "telegraph"
click "//div[@id='edit_context_3'] //input[@value='Update']"
wait_for_not_visible "edit_context_3"
wait_for_visible "context_3"
click "css=#context_3 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the context 'telegraph'?"
wait_for_visible "flash"
assert_text "flash", "Deleted context 'telegraph'"
assert_element_not_present "context_3"

View file

@ -0,0 +1,15 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a billionaire"
click "//div[@id='edit_project_2'] //input[@value='Update']"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
click "css=#project_2 .buttons img.delete_item"
assert_confirmation "Are you sure that you want to delete the project 'become a billionaire'?"
wait_for_visible "flash"
assert_text "flash", "Deleted project 'become a billionaire'"
wait_for_element_not_present "project_2"

View file

@ -0,0 +1,19 @@
setup :fixtures => :all
include_partial 'login/login', :username => 'admin', :password => 'abracadabra'
open "/projects"
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a billionaire"
click "//div[@id='edit_project_2'] //input[@value='Update']"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
assert_text 'css=#project_2 .data a', 'become a billionaire'
click "css=#project_2 .buttons img.edit_item"
wait_for_visible "edit_project_2"
wait_for_not_visible "project_2"
type "//div[@id='edit_project_2'] //input[@name='project[name]']", "become a multi-millionaire"
click "//div[@id='edit_project_2'] //input[@value='Update']"
wait_for_not_visible "edit_project_2"
wait_for_visible "project_2"
assert_text 'css=#project_2 .data a', 'become a multi-millionaire'