mirror of
https://github.com/TracksApp/tracks.git
synced 2026-02-22 07:04:09 +01:00
migrate editing a context and refactor project with it
This commit is contained in:
parent
4e9777dc88
commit
fb39d841a7
13 changed files with 163 additions and 43 deletions
|
|
@ -1,14 +1,22 @@
|
|||
<% context = context_form
|
||||
@context = context-%>
|
||||
<% form_remote_tag(:url => context_path(context), :html => {:id => dom_id(context, 'edit_form'), :class => "inline-form "+dom_id(context, 'edit_form')+"-edit-context-form edit-context-form", :method => :put}) do -%>
|
||||
<%= error_messages_for 'context' %>
|
||||
@context = context
|
||||
-%>
|
||||
|
||||
<% form_for(context, :html => {
|
||||
:id => dom_id(context, 'edit_form'),
|
||||
:class => "inline-form edit-project-form",
|
||||
:method => :put }) do
|
||||
-%>
|
||||
|
||||
<div id="edit_error_status"><%= error_messages_for("project") %></div>
|
||||
|
||||
|
||||
<label for="context_name">Context name</label><br/>
|
||||
<%= text_field('context', 'name', :class => 'context-name') %><br/>
|
||||
|
||||
<label for="context_hide">Hide from front page?</label>
|
||||
<label for="context_hide">Hide from front page?</label>
|
||||
<%= check_box('context', 'hide', :class => 'context-hide') %>
|
||||
<input type="hidden" name="wants_render" value="true" />
|
||||
<input type="hidden" name="wants_render" value="true" />
|
||||
|
||||
<div class="submit_box">
|
||||
<div class="widgets">
|
||||
|
|
@ -24,5 +32,5 @@
|
|||
</div>
|
||||
<br/><br/>
|
||||
|
||||
<% end %>
|
||||
<% end %>
|
||||
|
||||
|
|
|
|||
|
|
@ -21,16 +21,20 @@ suppress_edit_button ||= false
|
|||
<% end %>
|
||||
|
||||
<%= link_to_delete_context(context, image_tag( "blank.png", :title => t('contexts.delete_context'), :class=>"delete_item")) %>
|
||||
<%= suppress_edit_button ? "" : link_to_edit_context(context, image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item")) %>
|
||||
|
||||
<% # = # link_to_remote(
|
||||
#image_tag( "blank.png", :title => "Delete context", :class=>"delete_item"),
|
||||
#:url => {:controller => 'contexts', :action => 'destroy', :id => context.id},
|
||||
#:method => 'delete',
|
||||
#:with => "'_source_view=#{@source_view}'",
|
||||
#:before => "$('#{dom_id(context)}').block({message:null});",
|
||||
#:complete => "$('#{dom_id(context)}').unblock();",
|
||||
#:confirm => "Are you sure that you want to delete the context '#{context.name}'? Be aware that this will also delete all (repeating) actions in this context!",
|
||||
#:html => { :id => dom_id(context, 'delete') }
|
||||
#)
|
||||
%>
|
||||
|
||||
<%= link_to_remote(
|
||||
image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item"),
|
||||
:url => {:controller => 'contexts', :action => 'edit', :id => context.id},
|
||||
:method => 'get',
|
||||
:with => "'_source_view=#{@source_view}'",
|
||||
:before => "$('#{dom_id(context)}').block({message:null});",
|
||||
:complete => "$('#{dom_id(context)}').unblock();",
|
||||
:html => {:id => "edit_context_#{context.id}_link"}
|
||||
) %>
|
||||
</div>
|
||||
</div>
|
||||
<div id="<%= dom_id(context, 'edit') %>" class="edit-form" style="display:none;">
|
||||
|
|
|
|||
21
app/views/contexts/edit.js.erb
Normal file
21
app/views/contexts/edit.js.erb
Normal file
|
|
@ -0,0 +1,21 @@
|
|||
replace_context_with_edit_form();
|
||||
|
||||
function replace_context_with_edit_form() {
|
||||
$('div#<%=dom_id(@context)%>').fadeOut(250, function() {
|
||||
show_edit_form();
|
||||
set_focus();
|
||||
});
|
||||
}
|
||||
|
||||
function show_edit_form() {
|
||||
$('div#<%=dom_id(@context, 'edit')%>').html(html_for_edit_form());
|
||||
$('div#<%=dom_id(@context, 'edit')%>').fadeIn(500);
|
||||
}
|
||||
|
||||
function set_focus() {
|
||||
$('input.context-name').focus();
|
||||
}
|
||||
|
||||
function html_for_edit_form() {
|
||||
return "<%= escape_javascript(render(:partial => 'context_form', :locals => { :context_form => @context })) %>"
|
||||
}
|
||||
|
|
@ -1,4 +0,0 @@
|
|||
page[dom_id(@context, 'edit')].replace_html :partial => 'context_form', :locals => { :context_form => @context }
|
||||
page[@context].hide
|
||||
page[dom_id(@context, 'edit')].show
|
||||
page[dom_id(@context, 'edit_form')].find('input.context-name').focus
|
||||
47
app/views/contexts/update.js.erb
Normal file
47
app/views/contexts/update.js.erb
Normal file
|
|
@ -0,0 +1,47 @@
|
|||
<% if @saved -%>
|
||||
|
||||
page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
|
||||
|
||||
<% if @state_changed -%>
|
||||
remove_and_re_add_context();
|
||||
<% else -%>
|
||||
replace_context_form_with_updated_context();
|
||||
<% end -%>
|
||||
|
||||
<% else -%>
|
||||
show_errors();
|
||||
<% 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 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 show_errors() {
|
||||
$('div#edit_error_status').html(html_for_error_messages());
|
||||
$('div#edit_error_status').show();
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(error_messages_for('context')) %>";
|
||||
}
|
||||
|
||||
function html_for_context_listing() {
|
||||
return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
|
||||
}
|
||||
|
|
@ -1,9 +0,0 @@
|
|||
status_message = t('contexts.save_status_message')
|
||||
page.notify :notice, status_message, 5.0
|
||||
if @context_state_changed
|
||||
page.remove dom_id(@context, 'container')
|
||||
page.insert_html :bottom, "list-contexts-#{@new_state}", :partial => 'context_listing', :object => @context
|
||||
else
|
||||
page.replace_html dom_id(@context, 'container'), :partial => 'context_listing', :object => @context
|
||||
end
|
||||
page.visual_effect :highlight, dom_id(@context), :duration => 3
|
||||
|
|
@ -7,7 +7,7 @@ project = project_form
|
|||
:class => "inline-form edit-project-form",
|
||||
:method => :put }) do
|
||||
-%>
|
||||
<div id="error_status"><%= error_messages_for("project") %></div>
|
||||
<div id="edit_error_status"><%= error_messages_for("project") %></div>
|
||||
<%= source_view_tag( @source_view ) -%>
|
||||
|
||||
<label for="project_name">Name:</label><br/>
|
||||
|
|
|
|||
|
|
@ -1,9 +1,21 @@
|
|||
newHtml = "<%= escape_javascript(render(:partial => 'project_form', :locals => { :project_form => @project })) %>"
|
||||
replace_project_with_edit_form();
|
||||
|
||||
$('div#<%=dom_id(@project)%>').fadeOut(250, function() {
|
||||
$('div#<%=dom_id(@project, 'edit')%>').html(newHtml);
|
||||
function replace_project_with_edit_form() {
|
||||
$('div#<%=dom_id(@project)%>').fadeOut(250, function() {
|
||||
show_edit_form();
|
||||
set_focus();
|
||||
});
|
||||
}
|
||||
|
||||
function show_edit_form() {
|
||||
$('div#<%=dom_id(@project, 'edit')%>').html(html_for_edit_form());
|
||||
$('div#<%=dom_id(@project, 'edit')%>').fadeIn(500);
|
||||
}
|
||||
|
||||
function set_focus() {
|
||||
$('input.project-name').focus();
|
||||
});
|
||||
|
||||
}
|
||||
|
||||
function html_for_edit_form() {
|
||||
return "<%= escape_javascript(render(:partial => 'project_form', :locals => { :project_form => @project })) %>"
|
||||
}
|
||||
|
|
@ -39,8 +39,8 @@
|
|||
enable_rich_interaction();
|
||||
|
||||
function show_errors() {
|
||||
$('div#error_status').html(html_for_error_messages());
|
||||
$('div#error_status').show();
|
||||
$('div#edit_error_status').html(html_for_error_messages());
|
||||
$('div#edit_error_status').show();
|
||||
}
|
||||
|
||||
function remove_project_edit_form() {
|
||||
|
|
@ -73,7 +73,7 @@ function replace_project_form_with_updated_project() {
|
|||
function remove_and_re_add_project() {
|
||||
$('#<%=dom_id(@project, 'container')%>').slideUp(500, function() {
|
||||
$('#<%=dom_id(@project, 'container')%>').remove();
|
||||
$('#list-<%=@project.state%>-projects').append(html_for_project_listing);
|
||||
$('#list-<%=@project.state%>-projects').append(html_for_project_listing());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue