diff --git a/app/controllers/contexts_controller.rb b/app/controllers/contexts_controller.rb index 98ddc344..887c96cd 100644 --- a/app/controllers/contexts_controller.rb +++ b/app/controllers/contexts_controller.rb @@ -10,7 +10,11 @@ class ContextsController < ApplicationController session :off, :only => :index, :if => Proc.new { |req| ['rss','atom','txt'].include?(req.parameters[:format]) } def index - @contexts = current_user.contexts(true) #true is passed here to force an immediate load so that size and empty? checks later don't result in separate SQL queries + # #true is passed here to force an immediate load so that size and empty? + # checks later don't result in separate SQL queries + @active_contexts = current_user.contexts.active(true) + @hidden_contexts = current_user.contexts.hidden(true) + @count = @active_contexts.size + @hidden_contexts.size init_not_done_counts(['context']) respond_to do |format| format.html &render_contexts_html @@ -44,7 +48,7 @@ class ContextsController < ApplicationController # -u username:password # -d 'new context_name' # http://our.tracks.host/contexts - # + # def create if params[:format] == 'application/xml' && params['exception'] render_failure "Expected post format is valid xml like so: context name.", 400 @@ -75,16 +79,21 @@ class ContextsController < ApplicationController end # Edit the details of the context - # + # def update params['context'] ||= {} success_text = if params['field'] == 'name' && params['value'] params['context']['id'] = params['id'] params['context']['name'] = params['value'] end + + @original_context_hidden = @context.hidden? @context.attributes = params["context"] + if @context.save if boolean_param('wants_render') + @context_state_changed = (@orgininal_context_hidden != @context.hidden?) + @new_state = (@context.hidden? ? "hidden" : "active") if @context_state_changed respond_to do |format| format.js end @@ -113,9 +122,10 @@ class ContextsController < ApplicationController end # Methods for changing the sort order of the contexts in the list - # + # def order - params["list-contexts"].each_with_index do |id, position| + list = params["list-contexts-hidden"] || params["list-contexts-active"] + list.each_with_index do |id, position| current_user.contexts.update(id, :position => position + 1) end render :nothing => true @@ -126,8 +136,10 @@ class ContextsController < ApplicationController def render_contexts_html lambda do @page_title = "TRACKS::List Contexts" - @no_contexts = @contexts.empty? - @count = @contexts.size + @no_active_contexts = @active_contexts.empty? + @no_hidden_contexts = @hidden_contexts.empty? + @active_count = @active_contexts.size + @hidden_count = @hidden_contexts.size render end end diff --git a/app/views/contexts/_context_state_group.rhtml b/app/views/contexts/_context_state_group.rhtml new file mode 100644 index 00000000..835d2f44 --- /dev/null +++ b/app/views/contexts/_context_state_group.rhtml @@ -0,0 +1,9 @@ +
+

<%= context_state_group.length %><%= state.titlecase %> Contexts

+
+

Currently there are no <%= state %> contexts

+
+
+ <%= render :partial => 'context_listing', :collection => context_state_group %> +
+
diff --git a/app/views/contexts/index.html.erb b/app/views/contexts/index.html.erb index ef915ac1..418e637d 100644 --- a/app/views/contexts/index.html.erb +++ b/app/views/contexts/index.html.erb @@ -1,44 +1,38 @@
-
-
-

Currently there are no contexts

-
-
- <%= render :partial => 'context_listing', :collection => @contexts %> -
-
+ <%= 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} %>
- +
« Hide form <% apply_behavior '#toggle_context_new a:click', :prevent_default => true do |page| - page << "TracksForm.toggle('toggle_context_new', 'context_new', 'context-form', - '« Hide form', 'Hide new context form', - 'Create a new context »', 'Add a context');" - end - %> + page << "TracksForm.toggle('toggle_context_new', 'context_new', 'context-form', + '« Hide form', 'Hide new context form', + 'Create a new context »', 'Add a context');" + end + %>
- +
<% form_remote_tag( - :url => contexts_path, - :method => :post, + :url => contexts_path, + :method => :post, :html=> { :id => 'context-form', :name => 'context', :class => 'inline-form'}, :before => "$('context_new_submit').startWaiting()", :complete => "$('context_new_submit').stopWaiting()", :condition => "!$('context_new_submit').isWaiting()") do -%> - +
<%= error_messages_for('context') %>
- -
+ +
<%= text_field( "context", "name" ) %>
- + <%= check_box( "context", "hide" ) %>
- +
-

+

<% end -%>
<% -sortable_element 'list-contexts', get_listing_sortable_options +sortable_element 'list-contexts-active', get_listing_sortable_options +sortable_element 'list-contexts-hidden', get_listing_sortable_options -%> diff --git a/app/views/contexts/update.js.rjs b/app/views/contexts/update.js.rjs index 6387842a..33c633da 100644 --- a/app/views/contexts/update.js.rjs +++ b/app/views/contexts/update.js.rjs @@ -1,6 +1,12 @@ status_message = 'Context saved' page.notify :notice, status_message, 5.0 -page.replace_html dom_id(@context, 'container'), :partial => 'context_listing', :object => @context -page.sortable "list-contexts", get_listing_sortable_options +if @context_state_changed + page << "jQuery('##{dom_id(@context, 'edit')}').hide();" + 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.sortable "list-contexts-active", get_listing_sortable_options +page.sortable "list-contexts-hidden", get_listing_sortable_options page.hide "busy" \ No newline at end of file diff --git a/public/stylesheets/standard.css b/public/stylesheets/standard.css index 17e0ce44..8ad037b7 100644 --- a/public/stylesheets/standard.css +++ b/public/stylesheets/standard.css @@ -697,7 +697,8 @@ div#list-active-projects, div#list-hidden-projects, div#list-completed-projects, clear:right; border: 1px solid #999; } -.project-state-group h2 { + +.project-state-group h2, .list-stategroup-contexts-container h2 { margin:20px 0px 8px 13px; }