mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-16 06:05:29 +01:00
Convert edit action to use RJS; share edit views between deferred and todo controllers; rename update_action to update in todo controller. Another step in the process of making Tracks more CRUDdy!
git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@301 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
parent
9392d4d696
commit
cf7b90101a
9 changed files with 30 additions and 85 deletions
|
|
@ -51,7 +51,7 @@ class DeferredController < ApplicationController
|
|||
@source_view = 'deferred'
|
||||
init_projects_and_contexts
|
||||
@item = check_user_return_item
|
||||
render :layout => false
|
||||
render :template => 'todo/edit.rjs'
|
||||
end
|
||||
|
||||
def update
|
||||
|
|
|
|||
|
|
@ -89,7 +89,6 @@ class TodoController < ApplicationController
|
|||
def edit
|
||||
self.init
|
||||
@item = check_user_return_item
|
||||
render :layout => false
|
||||
end
|
||||
|
||||
def show
|
||||
|
|
@ -125,7 +124,7 @@ class TodoController < ApplicationController
|
|||
|
||||
# Edit the details of an action
|
||||
#
|
||||
def update_action
|
||||
def update
|
||||
self.init
|
||||
@item = check_user_return_item
|
||||
@original_item_context_id = @item.context_id
|
||||
|
|
@ -149,7 +148,7 @@ class TodoController < ApplicationController
|
|||
@item.context_id = context.id
|
||||
@item.context = context
|
||||
@saved = @item.save
|
||||
render :action => 'update_action'
|
||||
render :action => 'update'
|
||||
else
|
||||
render :update do |page|
|
||||
page.replace_html "info", content_tag("div", "Error updating the context of the dragged item. Item and context user mis-match: #{@item.user.name} and #{@context.user.name}! - refresh the page to see them.", "class" => "warning")
|
||||
|
|
@ -166,7 +165,7 @@ class TodoController < ApplicationController
|
|||
@item.project_id = project.id
|
||||
@item.project = project
|
||||
@saved = @item.save
|
||||
render :action => 'update_action'
|
||||
render :action => 'update'
|
||||
else
|
||||
render :update do |page|
|
||||
page.replace_html "info", content_tag("div", "Error updating the project of the dragged item. Item and project user mis-match: #{@item.user.name} and #{@project.user.name}! - refresh the page to see them.", "class" => "warning")
|
||||
|
|
|
|||
|
|
@ -8,9 +8,8 @@ module TodoHelper
|
|||
end
|
||||
|
||||
def form_remote_tag_edit_todo( item, type )
|
||||
(type == "deferred") ? act = 'update' : act = 'update_action'
|
||||
(type == "deferred") ? controller_name = 'deferred' : controller_name = 'todo'
|
||||
form_remote_tag( :url => { :controller => controller_name, :action => act, :id => item.id },
|
||||
form_remote_tag( :url => { :controller => controller_name, :action => 'update', :id => item.id },
|
||||
:html => { :id => "form-action-#{item.id}", :class => "inline-form" }
|
||||
)
|
||||
end
|
||||
|
|
@ -18,21 +17,17 @@ module TodoHelper
|
|||
def link_to_remote_todo( item, options = {})
|
||||
(options[:type] == "deferred") ? controller_name = 'deferred' : controller_name = 'todo'
|
||||
url_options = { :controller => controller_name, :action => 'destroy', :id => item.id, :_source_view => @source_view }
|
||||
str = link_to_remote( image_tag("blank", :title =>"Delete action", :class=>"delete_item"),
|
||||
|
||||
str = link_to_remote( image_tag_for_delete,
|
||||
{ :url => url_options, :confirm => "Are you sure that you want to delete the action, \'#{item.description}\'?" },
|
||||
{ :class => "icon" }
|
||||
) + "\n"
|
||||
if !item.done?
|
||||
str << link_to_remote( image_tag("blank", :title =>"Edit action", :class=>"edit_item", :id=>"action-#{item.id}-edit-icon"),
|
||||
{
|
||||
:update => "form-action-#{item.id}",
|
||||
:loading => visual_effect(:pulsate, "action-#{item.id}-edit-icon"),
|
||||
:url => { :controller => 'todo', :action => 'edit', :id => item.id, :_source_view => @source_view },
|
||||
:success => "Element.toggle('item-#{item.id}','action-#{item.id}-edit-form'); new Effect.Appear('action-#{item.id}-edit-form', { duration: .2 }); Form.focusFirstElement('form-action-#{item.id}')"
|
||||
},
|
||||
{
|
||||
:class => "icon"
|
||||
})
|
||||
url_options[:action] = 'edit'
|
||||
str << link_to_remote( image_tag_for_edit(item),
|
||||
{ :url => url_options, :loading => visual_effect(:pulsate, "action-#{item.id}-edit-icon") },
|
||||
{ :class => "icon" }
|
||||
)
|
||||
else
|
||||
str << '<a class="icon">' + image_tag("blank") + "</a> "
|
||||
end
|
||||
|
|
@ -111,5 +106,15 @@ module TodoHelper
|
|||
str << ",step:1,inputField:\"" + input_field + "\",cache:true,align:\"TR\" })\n"
|
||||
javascript_tag str
|
||||
end
|
||||
|
||||
|
||||
private
|
||||
|
||||
def image_tag_for_delete
|
||||
image_tag("blank", :title =>"Delete action", :class=>"delete_item")
|
||||
end
|
||||
|
||||
def image_tag_for_edit(item)
|
||||
image_tag("blank", :title =>"Edit action", :class=>"edit_item", :id=>"action-#{item.id}-edit-icon")
|
||||
end
|
||||
|
||||
end
|
||||
|
|
|
|||
|
|
@ -46,7 +46,7 @@
|
|||
<%= end_form_tag %>
|
||||
|
||||
<div id="action-<%= item.id %>-edit-form" class="edit-form" style="display:none;">
|
||||
<%= form_remote_tag :url => { :controller => 'todo', :action => 'update_action', :id => item.id },
|
||||
<%= form_remote_tag :url => { :controller => 'todo', :action => 'update', :id => item.id },
|
||||
:html => { :id => "form-action-#{item.id}", :class => "inline-form" },
|
||||
:update => "item-#{item.id}-container",
|
||||
:complete => visual_effect(:appear, "item-#{item.id}-container") %>
|
||||
|
|
|
|||
|
|
@ -1,64 +0,0 @@
|
|||
<%= error_messages_for("item") %>
|
||||
|
||||
<%= hidden_field( "item", "id" ) %>
|
||||
<table>
|
||||
<tr>
|
||||
<td class="label"><label for="item_description">Next action</label></td>
|
||||
<td><%= text_field( "item", "description", "tabindex" => 1) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="item_notes">Notes</label></td>
|
||||
<td><%= text_area( "item", "notes", "cols" => 20, "rows" => 5, "tabindex" => 2) %></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="item_context_id">Context</label></td>
|
||||
<td><select name="item[context_id]" id="item_context_id" tabindex="3">
|
||||
<% for @place in @contexts %>
|
||||
<% if @item %>
|
||||
<% if @place.id == @item.context_id %>
|
||||
<option value="<%= @place.id %>" selected="selected"><%= @place.name %></option>
|
||||
<% else %>
|
||||
<option value="<%= @place.id %>"><%= @place.name %></option>
|
||||
<% end %>
|
||||
<% else %>
|
||||
<option value="<%= @place.id %>"><%= @place.name %></option>
|
||||
<% end %>
|
||||
<% end %>
|
||||
</select></td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="item_project_id">Project</label></td>
|
||||
<td>
|
||||
<select name="item[project_id]" id="item_project_id" tabindex="4">
|
||||
<% if !@item.project_id? %>
|
||||
<option selected="selected"></option>
|
||||
<%= options_from_collection_for_select(@projects, "id", "name") %>
|
||||
<% else %>
|
||||
<option></option>
|
||||
<%= options_from_collection_for_select(@projects, "id", "name", @item.project_id) %>
|
||||
<% end %>
|
||||
</select>
|
||||
</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="label"><label for="item_due">Due</td>
|
||||
<td><input name="item[due]" id="due_<%= @item.id %>" type="text" value="<%= format_date(@item.due) %>" tabindex="5" size="10" onFocus="Calendar.setup" /></td>
|
||||
</tr>
|
||||
<% if @item.class == Deferred -%>
|
||||
<tr>
|
||||
<td class="label"><label for="item_show_from">Show from</td>
|
||||
<td><input name="item[show_from]" id="show_from_<%= @item.id %>" type="text" value="<%= format_date(@item.show_from) %>" tabindex="5" size="10" onFocus="Calendar.setup" /></td>
|
||||
</tr>
|
||||
<% end -%>
|
||||
<% if controller.controller_name == "project" || @item.class == 'Deferred' -%>
|
||||
<input type="hidden" name="on_project_page" value="true" />
|
||||
<% end -%>
|
||||
<tr>
|
||||
<td><input type="submit" value="Update" tabindex="6" />
|
||||
<a href="javascript:void(0);" onclick="Element.toggle('item-<%= @item.id %>','action-<%= @item.id %>-edit-form');Form.reset('form-action-<%= @item.id %>');">Cancel</a></td>
|
||||
</tr>
|
||||
</table>
|
||||
<%= calendar_setup( "due_#{@item.id}" ) %>
|
||||
<% if @item.class == Deferred -%>
|
||||
<%= calendar_setup( "show_from_#{@item.id}" ) %>
|
||||
<% end -%>
|
||||
|
|
@ -47,7 +47,7 @@
|
|||
<%= end_form_tag %>
|
||||
|
||||
<div id="action-<%= item.id %>-edit-form" class="edit-form" style="display:none;">
|
||||
<%= form_remote_tag :url => { :controller => 'todo', :action => 'update_action', :id => item.id },
|
||||
<%= form_remote_tag :url => { :controller => 'todo', :action => 'update', :id => item.id },
|
||||
:html => { :id => "form-action-#{item.id}", :class => "inline-form" },
|
||||
:update => "item-#{item.id}-container",
|
||||
:complete => visual_effect(:appear, "item-#{item.id}-container") %>
|
||||
|
|
|
|||
5
tracks/app/views/todo/edit.rjs
Normal file
5
tracks/app/views/todo/edit.rjs
Normal file
|
|
@ -0,0 +1,5 @@
|
|||
page["form-action-#{@item.id}"].replace_html :partial => 'todo/edit_form'
|
||||
page["item-#{@item.id}"].hide
|
||||
page["action-#{@item.id}-edit-form"].show
|
||||
page.visual_effect :appear, "action-#{@item.id}-edit-form", :duration => 0.2
|
||||
page.call "Form.focusFirstElement", "form-action-#{@item.id}"
|
||||
Loading…
Add table
Add a link
Reference in a new issue