mirror of
https://github.com/TracksApp/tracks.git
synced 2025-12-26 12:08:47 +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
|
|
@ -91,13 +91,18 @@ class ContextsController < ApplicationController
|
|||
@original_context_hidden = @context.hidden?
|
||||
@context.attributes = params["context"]
|
||||
|
||||
if @context.save
|
||||
@saved = @context.save
|
||||
|
||||
if @saved
|
||||
if boolean_param('wants_render')
|
||||
@context_state_changed = (@original_context_hidden != @context.hidden?)
|
||||
@new_state = (@context.hidden? ? "hidden" : "active") if @context_state_changed
|
||||
@state_changed = (@original_context_hidden != @context.hidden?)
|
||||
@new_state = (@context.hidden? ? "hidden" : "active") if @state_changed
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
||||
# TODO is this param ever used? is this dead code?
|
||||
|
||||
elsif boolean_param('update_context_name')
|
||||
@contexts = current_user.projects
|
||||
render :template => 'contexts/update_context_name.js.rjs'
|
||||
|
|
@ -106,8 +111,9 @@ class ContextsController < ApplicationController
|
|||
render :text => success_text || 'Success'
|
||||
end
|
||||
else
|
||||
notify :warning, "Couldn't update new context"
|
||||
render :text => ""
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
|
|
|
|||
|
|
@ -134,6 +134,9 @@ class ProjectsController < ApplicationController
|
|||
init_data_for_sidebar
|
||||
render :template => 'projects/update.js.erb'
|
||||
return
|
||||
|
||||
# TODO: are these params ever set? or is this dead code?
|
||||
|
||||
elsif boolean_param('update_status')
|
||||
render :template => 'projects/update_status.js.rjs'
|
||||
return
|
||||
|
|
|
|||
|
|
@ -116,6 +116,12 @@ module ApplicationHelper
|
|||
url_for({:controller => 'projects', :action => 'edit', :id => project.id}),
|
||||
{:id => "link_edit_#{dom_id(project)}", :class => "project_edit_settings"})
|
||||
end
|
||||
|
||||
def link_to_edit_context (context, descriptor = sanitize(context.name))
|
||||
link_to(descriptor,
|
||||
url_for({:controller => 'contexts', :action => 'edit', :id => context.id}),
|
||||
{:id => "link_edit_#{dom_id(context)}", :class => "context_edit_settings"})
|
||||
end
|
||||
|
||||
def link_to_delete_project(project, descriptor = sanitize(project.name))
|
||||
link_to(
|
||||
|
|
|
|||
|
|
@ -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());
|
||||
});
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -629,7 +629,8 @@ $(document).ready(function() {
|
|||
async: true,
|
||||
buttons_dom_elem: $(this),
|
||||
beforeSend: function() {
|
||||
this.buttons_dom_elem.block({message: null});}
|
||||
this.buttons_dom_elem.block({message: null});},
|
||||
complete: function() {this.buttons_dom_elem.unblock();}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
|
@ -654,6 +655,31 @@ $(document).ready(function() {
|
|||
}
|
||||
});
|
||||
|
||||
/* set behavior for edit context settings link in projects list page and project page
|
||||
* TODO: refactor this and the edit for project because the function looks the same */
|
||||
$("a.context_edit_settings").live('click', function (ev) {
|
||||
$.ajax({
|
||||
url: this.href,
|
||||
async: true,
|
||||
context_dom_elem: $(this).parent().parent(),
|
||||
dataType: 'script',
|
||||
beforeSend: function() {this.context_dom_elem.block({message: null});},
|
||||
complete:function() {this.context_dom_elem.unblock(); enable_rich_interaction();}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$("form.edit-context-form button.positive").live('click', function (ev) {
|
||||
$('form.edit-context-form').ajaxSubmit({
|
||||
type: 'POST',
|
||||
async: true,
|
||||
buttons_dom_elem: $(this),
|
||||
beforeSend: function() {
|
||||
this.buttons_dom_elem.block({message: null});},
|
||||
complete: function() {this.buttons_dom_elem.unblock();}
|
||||
});
|
||||
return false;
|
||||
});
|
||||
|
||||
$("form#context-form button.positive").live('click', function (ev) {
|
||||
$('form.#context-form').ajaxSubmit({
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue