mirror of
https://github.com/TracksApp/tracks.git
synced 2026-01-09 18:58:51 +01:00
add ui for changing state of context to closed. This fixes #645
This commit is contained in:
parent
acab98d4c7
commit
4df340bd7b
12 changed files with 114 additions and 86 deletions
|
|
@ -783,16 +783,24 @@ var ContextListPage = {
|
|||
update_state_count: function(state, count) {
|
||||
$('#'+state+'-contexts-count').html(count);
|
||||
},
|
||||
update_all_states_count: function (active_count, hidden_count, completed_count) {
|
||||
$(["active", "hidden"]).each(function() {
|
||||
update_all_states_count: function (active_count, hidden_count, closed_count) {
|
||||
$(["active", "hidden", "closed"]).each(function() {
|
||||
ContextListPage.update_state_count(this, eval(this+'_count'));
|
||||
});
|
||||
},
|
||||
show_or_hide_all_state_containers: function (show_active, show_hidden, show_completed) {
|
||||
$(["active", "hidden"]).each(function() {
|
||||
show_or_hide_all_state_containers: function (show_active, show_hidden, show_closed) {
|
||||
$(["active", "hidden", "closed"]).each(function() {
|
||||
ContextListPage.set_state_container_visibility(this, eval('show_'+this));
|
||||
ContextListPage.hide_empty_message(this, !eval('show_'+this));
|
||||
});
|
||||
},
|
||||
hide_empty_message: function(state, set_visible) {
|
||||
if(set_visible) {
|
||||
$('div#'+state+'-contexts-empty-nd').slideDown("fast");
|
||||
} else {
|
||||
$('div#'+state+'-contexts-empty-nd').slideUp("fast");
|
||||
}
|
||||
},
|
||||
set_state_container_visibility: function (state, set_visible) {
|
||||
if (set_visible) {
|
||||
$('#list-'+state+'-contexts-container').slideDown("fast");
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ class ContextsController < ApplicationController
|
|||
@all_contexts = current_user.contexts
|
||||
@active_contexts = current_user.contexts.active
|
||||
@hidden_contexts = current_user.contexts.hidden
|
||||
@closed_contexts = current_user.contexts.closed
|
||||
init_not_done_counts(['context']) unless request.format == :autocomplete
|
||||
|
||||
respond_to do |format|
|
||||
|
|
@ -96,24 +97,17 @@ class ContextsController < ApplicationController
|
|||
params['context']['name'] = params['value']
|
||||
end
|
||||
|
||||
@original_context_hidden = @context.hidden?
|
||||
@original_context_state = @context.state
|
||||
@context.attributes = params["context"]
|
||||
if params['context_state']
|
||||
if params['context_state']['hide'] == '1'
|
||||
@context.hide! if !@context.hidden?
|
||||
else
|
||||
@context.activate! if @context.hidden?
|
||||
end
|
||||
else
|
||||
@context.activate! if @context.hidden?
|
||||
end
|
||||
|
||||
@saved = @context.save
|
||||
|
||||
if @saved
|
||||
if boolean_param('wants_render')
|
||||
@state_changed = (@original_context_hidden != @context.hidden?)
|
||||
@state_changed = (@original_context_state != @context.state)
|
||||
@new_state = @context.state if @state_changed
|
||||
@active_contexts = current_user.contexts.active
|
||||
@hidden_contexts = current_user.contexts.hidden
|
||||
@closed_contexts = current_user.contexts.closed
|
||||
respond_to do |format|
|
||||
format.js
|
||||
end
|
||||
|
|
@ -202,8 +196,10 @@ class ContextsController < ApplicationController
|
|||
def update_state_counts
|
||||
@active_contexts_count = current_user.contexts.active.count
|
||||
@hidden_contexts_count = current_user.contexts.hidden.count
|
||||
@closed_contexts_count = current_user.contexts.closed.count
|
||||
@show_active_contexts = @active_contexts_count > 0
|
||||
@show_hidden_contexts = @hidden_contexts_count > 0
|
||||
@show_closed_contexts = @closed_contexts_count > 0
|
||||
end
|
||||
|
||||
def render_contexts_html
|
||||
|
|
@ -211,9 +207,11 @@ class ContextsController < ApplicationController
|
|||
@page_title = "TRACKS::List Contexts"
|
||||
@no_active_contexts = @active_contexts.empty?
|
||||
@no_hidden_contexts = @hidden_contexts.empty?
|
||||
@no_closed_contexts = @closed_contexts.empty?
|
||||
@active_count = @active_contexts.size
|
||||
@hidden_count = @hidden_contexts.size
|
||||
@count = @active_count + @hidden_count
|
||||
@closed_count = @closed_contexts.size
|
||||
@count = @active_count + @hidden_count + @closed_count
|
||||
@new_context = current_user.contexts.build
|
||||
|
||||
render
|
||||
|
|
|
|||
|
|
@ -7,6 +7,7 @@ class Context < ActiveRecord::Base
|
|||
|
||||
scope :active, :conditions => { :state => :active }
|
||||
scope :hidden, :conditions => { :state => :hidden }
|
||||
scope :closed, :conditions => { :state => :closed }
|
||||
|
||||
acts_as_list :scope => :user, :top_of_list => 0
|
||||
|
||||
|
|
|
|||
|
|
@ -12,8 +12,11 @@
|
|||
<label for="context_name"><%= t 'contexts.context_name' %></label><br/>
|
||||
<%= text_field('context', 'name', :class => 'context-name', :tabindex => next_tab_index) %><br/>
|
||||
|
||||
<label for="context_hide"><%= t 'contexts.context_hide' %> </label>
|
||||
<%= check_box_tag('context_state[hide]', 1, context.hidden?, {:class => 'context-hide', :tabindex => next_tab_index}) %>
|
||||
<label for="context_hide"><%= t 'contexts.context_state' %> </label><br/>
|
||||
<% ['active', 'hidden', 'closed'].each do | state | %>
|
||||
<%= radio_button(:context, 'state', state, {:tabindex => next_tab_index}) %> <%= state.titlecase %>
|
||||
<% end %>
|
||||
|
||||
<input type="hidden" name="wants_render" value="true" />
|
||||
|
||||
<div class="submit_box">
|
||||
|
|
|
|||
|
|
@ -2,18 +2,14 @@
|
|||
hide_empty_message();
|
||||
TracksPages.hide_errors();
|
||||
TracksPages.set_page_badge(<%= @down_count %>);
|
||||
add_context("<%=@context.hidden? ? 'hidden' : 'active'%>");
|
||||
add_context("<%=@context.state%>");
|
||||
clear_form();
|
||||
<% else -%>
|
||||
TracksPages.show_errors(html_for_error_messages());
|
||||
<% end -%>
|
||||
|
||||
function hide_empty_message() {
|
||||
<% if @context.hidden? -%>
|
||||
$('div#hidden-contexts-empty-nd').hide();
|
||||
<% else -%>
|
||||
$('div#active-contexts-empty-nd').hide();
|
||||
<% end -%>
|
||||
$('div#<%=@context.state%>-contexts-empty-nd').hide();
|
||||
}
|
||||
|
||||
function add_context(state) {
|
||||
|
|
|
|||
|
|
@ -1,7 +1,7 @@
|
|||
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 %>);
|
||||
ContextListPage.update_all_states_count(<%=@active_contexts_count%>, <%=@hidden_contexts_count%>, <%=@closed_contexts_count%>)
|
||||
ContextListPage.show_or_hide_all_state_containers(<%= @show_active_contexts %>, <%= @show_hidden_contexts %>, <%= @show_closed_contexts %>);
|
||||
|
||||
TracksPages.set_page_badge(<%=@down_count%>);
|
||||
TracksPages.page_notify('notice', "<%= t('contexts.context_deleted', :name=>@context.name)%>", 5);
|
||||
|
|
|
|||
|
|
@ -1,6 +1,7 @@
|
|||
<div id="display_box">
|
||||
<%= render :partial => 'context_state_group', :object => @active_contexts, :locals => { :state => 'active', :no_contexts => @no_active_contexts} %>
|
||||
<%= render :partial => 'context_state_group', :object => @hidden_contexts, :locals => { :state => 'hidden', :no_contexts => @no_hidden_contexts} %>
|
||||
<%= render :partial => 'context_state_group', :object => @closed_contexts, :locals => { :state => 'closed', :no_contexts => @no_closed_contexts} %>
|
||||
</div>
|
||||
|
||||
<div id="input_box">
|
||||
|
|
|
|||
|
|
@ -1,42 +1,48 @@
|
|||
<% if @saved -%>
|
||||
<% unless @saved -%>
|
||||
TracksPages.show_edit_errors(html_for_error_messages());
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
|
||||
}
|
||||
|
||||
<% else -%>
|
||||
TracksPages.page_notify('notice', '<%= t('contexts.save_status_message') %>', 5);
|
||||
|
||||
<% if @state_changed -%>
|
||||
remove_and_re_add_context();
|
||||
update_container_states();
|
||||
<% else -%>
|
||||
replace_context_form_with_updated_context();
|
||||
<% end -%>
|
||||
|
||||
<% else -%>
|
||||
TracksPages.show_edit_errors(html_for_error_messages());
|
||||
<% 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 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 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 update_container_states() {
|
||||
ContextListPage.update_all_states_count(<%=@active_contexts.count%>, <%=@hidden_contexts.count%>, <%=@closed_contexts.count%>);
|
||||
ContextListPage.show_or_hide_all_state_containers(<%= !@active_contexts.empty? %>, <%= !@hidden_contexts.empty? %>, <%= !@closed_contexts.empty? %>);
|
||||
}
|
||||
|
||||
function html_for_error_messages() {
|
||||
return "<%= escape_javascript(get_list_of_error_messages_for(@context)) %>";
|
||||
}
|
||||
function html_for_context_listing() {
|
||||
return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
|
||||
}
|
||||
|
||||
function html_for_context_listing() {
|
||||
return "<%= escape_javascript(render(:partial => 'context_listing', :object => @context))%>";
|
||||
}
|
||||
<% end -%>
|
||||
Loading…
Add table
Add a link
Reference in a new issue