Reduced the amount of inline javascript for each todo item rendered by half.

git-svn-id: http://www.rousette.org.uk/svn/tracks-repos/trunk@432 a4c988fc-2ded-0310-b66e-134b36920a42
This commit is contained in:
lukemelia 2007-02-05 07:23:49 +00:00
parent 3374679bac
commit 87e08a10e8
4 changed files with 17 additions and 11 deletions

View file

@ -8,9 +8,10 @@ module TodosHelper
end
def form_remote_tag_edit_todo( item, &block )
form_remote_tag( :url => todo_path(item), :method => :put,
:html => { :id => dom_id(item, 'form'), :class => "inline-form" }, &block
)
form_tag( todo_path(item), {:method => :put, :id => dom_id(item, 'form'), :class => "edit_todo_form inline-form" }, &block )
apply_behavior 'form.edit_todo_form:submit',
remote_function(:url => javascript_variable('this.action'), :method => :put, :form => true),
:prevent_default => true
end
def link_to_remote_todo(item)
@ -134,7 +135,7 @@ module TodosHelper
return array_or_string_for_javascript(['Create a new context']) if @contexts.empty?
array_or_string_for_javascript( @contexts.collect{|c| escape_javascript(c.name) } )
end
private
def image_tag_for_delete

View file

@ -17,7 +17,10 @@
<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|
page << "if (confirm('Are you sure that you want to ' + this.title + '?')) {"
page << "new Ajax.Updater(this.up('.list'), this.href, {asynchronous:true, evalScripts:true, method:'delete', onLoading:function(request){Effect.Fade(this.up('.list'));}}); };"
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'));}}); };"
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|
@ -41,7 +44,7 @@
</table>
<% end -%>
<% apply_behavior ".context form.inline-form'", make_remote_form(
:complete => "Effect.Appear(this.up('.list'));" ) %>
:complete => "Effect.Appear($(this).up('.list'));" ) %>
<% apply_behavior "a.form_reset:click", :prevent_default => true do |page, element|
element.up('.list').down('.context').toggle
element.up('.edit-form').toggle

View file

@ -4,9 +4,10 @@
<%= link_to_remote_todo item %>
<% unless source_view_is :deferred -%>
<input type="checkbox" class="item-checkbox"
onclick="new Ajax.Request('<%= toggle_check_todo_path(:id => item.id, :_source_view => @source_view) %>', {asynchronous:true, evalScripts:true});"
name="item_id" value="<%= item.id %>"<% if item.completed? %> checked="checked" <% end %> />
<input type="checkbox" class="item-checkbox" name="item_id" url="<%= toggle_check_todo_path(item) %>"
value="<%= item.id %>"<% if item.completed? %> checked="checked" <% end %> />
<% apply_behavior '.item-container input.item-checkbox:click',
remote_function(:url => javascript_variable('this.attributes.url.value'), :with => "{ method : 'post', _source_view : '#{@source_view}' }") %>
<% end -%>
<div class="description<%= staleness_class( item ) %>"><% # start of div which has a class 'description', and possibly 'stale_11', 'stale_12', 'stale_13' etc %>
@ -58,6 +59,7 @@
<div id="<%= dom_id(item, 'edit') %>" class="edit-form" style="display:none">
<% form_remote_tag_edit_todo( item ) do -%>
<% #note: edit form will load here remotely -%>
<div class="placeholder"> </div>
<% end -%>
</div><!-- [end:<%= dom_id(item, 'edit') %>] -->
</div><!-- [end:<%= dom_id(item) %>] -->

View file

@ -1,4 +1,4 @@
page[dom_id(@item, 'form')].replace_html :partial => 'todos/edit_form'
page[dom_id(@item, 'form')].down('.placeholder').replace_html :partial => 'todos/edit_form'
page[dom_id(@item, 'line')].hide
page[dom_id(@item, 'edit')].show
page.call "Form.focusFirstElement", dom_id(@item, 'form')
page[dom_id(@item, 'form')].down('table').down('input').focus