mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-08 18:28:50 +01:00
migrate deleting of contexts
This commit is contained in:
parent
15fdb1e572
commit
e52a8609c7
10 changed files with 124 additions and 31 deletions
|
|
@ -127,7 +127,10 @@ class ContextsController < ApplicationController
|
|||
|
||||
@context.destroy
|
||||
respond_to do |format|
|
||||
format.js { @down_count = current_user.contexts.size }
|
||||
format.js do
|
||||
@down_count = current_user.contexts.size
|
||||
update_state_counts
|
||||
end
|
||||
format.xml { render :text => "Deleted context #{@context.name}" }
|
||||
end
|
||||
end
|
||||
|
|
@ -145,6 +148,13 @@ class ContextsController < ApplicationController
|
|||
|
||||
protected
|
||||
|
||||
def update_state_counts
|
||||
@active_contexts_count = current_user.contexts.active.count
|
||||
@hidden_contexts_count = current_user.contexts.hidden.count
|
||||
@show_active_contexts = @active_contexts_count > 0
|
||||
@show_hidden_contexts = @hidden_contexts_count > 0
|
||||
end
|
||||
|
||||
def render_contexts_html
|
||||
lambda do
|
||||
@page_title = "TRACKS::List Contexts"
|
||||
|
|
|
|||
|
|
@ -124,7 +124,15 @@ module ApplicationHelper
|
|||
{:id => "delete_project_#{project.id}", :class => "delete_project_button", :title => "#{t('projects.delete_project_title')} '#{project.name}'"}
|
||||
)
|
||||
end
|
||||
|
||||
|
||||
def link_to_delete_context(context, descriptor = sanitize(context.name))
|
||||
link_to(
|
||||
descriptor,
|
||||
context_path(context, :format => 'js'),
|
||||
{:id => "delete_context_#{context.id}", :class => "delete_context_button", :title => t('contexts.delete_context_confirmation', :name => context.name)}
|
||||
)
|
||||
end
|
||||
|
||||
def link_to_project_mobile(project, accesskey, descriptor = sanitize(project.name))
|
||||
link_to( descriptor, project_path(project, :format => 'm'), {:title => "View project: #{project.name}", :accesskey => accesskey} )
|
||||
end
|
||||
|
|
|
|||
|
|
@ -1,6 +1,6 @@
|
|||
<% context = context_listing
|
||||
suppress_drag_handle ||= false
|
||||
suppress_edit_button ||= false
|
||||
suppress_drag_handle ||= false
|
||||
suppress_edit_button ||= false
|
||||
%>
|
||||
<div id="<%= dom_id(context, "container") %>" class="list">
|
||||
<div id="<%= dom_id(context) %>" class="context sortable_row" style="display:'';">
|
||||
|
|
@ -12,23 +12,16 @@
|
|||
<div class="data">
|
||||
<%= link_to_context( context ) %> <%= " (" + count_undone_todos_phrase(context,"actions") + ")" %>
|
||||
</div>
|
||||
|
||||
|
||||
<div class="buttons">
|
||||
<% if context.hide? %>
|
||||
<span class="grey"><%= t('states.hidden') %></span>
|
||||
<% else %>
|
||||
<span class="grey"><%= t('states.visible') %></span>
|
||||
<% end %>
|
||||
<%= link_to_remote(
|
||||
image_tag( "blank.png", :title => t('contexts.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 => t('contexts.delete_context_confirmation', :name => context.name),
|
||||
:html => { :id => dom_id(context, 'delete') }
|
||||
) %>
|
||||
|
||||
<%= link_to_delete_context(context, image_tag( "blank.png", :title => t('contexts.delete_context'), :class=>"delete_item")) %>
|
||||
|
||||
<%= link_to_remote(
|
||||
image_tag( "blank.png", :title => t('contexts.edit_context'), :class=>"edit_item"),
|
||||
:url => {:controller => 'contexts', :action => 'edit', :id => context.id},
|
||||
|
|
@ -37,7 +30,7 @@
|
|||
: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;">
|
||||
|
|
|
|||
|
|
@ -1,5 +1,5 @@
|
|||
<div class="list-stategroup-contexts-container">
|
||||
<h2><span id="<%= state %>-contexts-count" class="badge"><%= context_state_group.length %></span><%= t('states.'+ state +'_plural')%> <%= t('common.contexts') %></h2>
|
||||
<div class="list-stategroup-contexts-container" id="list-<%= state %>-contexts-container">
|
||||
<h2><span id="<%= state %>-contexts-count" class="badge"><%= context_state_group.length %></span><%= t("states."+ state +"_plural")%> <%= t('common.contexts') %></h2>
|
||||
<div id="<%= state%>-contexts-empty-nd" style="<%= no_contexts ? 'display:block' : 'display:none'%>">
|
||||
<div class="message"><p><%= t('contexts.no_contexts_' + state) %></p></div>
|
||||
</div>
|
||||
|
|
|
|||
15
app/views/contexts/destroy.js.erb
Normal file
15
app/views/contexts/destroy.js.erb
Normal file
|
|
@ -0,0 +1,15 @@
|
|||
remove_deleted_context();
|
||||
|
||||
ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>)
|
||||
ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>);
|
||||
|
||||
set_page_badge(<%=@down_count%>);
|
||||
page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
|
||||
|
||||
|
||||
function remove_deleted_context() {
|
||||
$('div#<%=dom_id(@context, "container")%>').slideUp(1000,
|
||||
function() {
|
||||
$('div#<%=dom_id(@context, "container")%>').remove();
|
||||
});
|
||||
}
|
||||
|
|
@ -1,6 +0,0 @@
|
|||
page.visual_effect :fade, dom_id(@context, "container"), :duration => 0.5
|
||||
page.delay(0.5) do
|
||||
page[dom_id(@context, "container")].remove
|
||||
end
|
||||
page['badge_count'].replace_html @down_count
|
||||
page.notify :notice, t('contexts.context_deleted', :name=>@context.name), 5.0
|
||||
Loading…
Add table
Add a link
Reference in a new issue