From 33003e5b2d881a30df7dc37a0c2a7b07b2a67ebe Mon Sep 17 00:00:00 2001 From: Jean-Philippe Lang Date: Mon, 22 Oct 2007 19:34:21 +0000 Subject: [PATCH] SCM browser: directories can now be collapsed and re-expanded with no additional request. git-svn-id: http://redmine.rubyforge.org/svn/trunk@863 e93f8b46-1217-0410-a6f0-8f06a7374b81 --- app/views/repositories/_dir_list.rhtml | 2 +- .../repositories/_dir_list_content.rhtml | 8 ++--- public/javascripts/application.js | 34 +++++++++++++++++++ 3 files changed, 39 insertions(+), 5 deletions(-) diff --git a/app/views/repositories/_dir_list.rhtml b/app/views/repositories/_dir_list.rhtml index b9c3fd54..1ed623ae 100644 --- a/app/views/repositories/_dir_list.rhtml +++ b/app/views/repositories/_dir_list.rhtml @@ -1,4 +1,4 @@ - +
diff --git a/app/views/repositories/_dir_list_content.rhtml b/app/views/repositories/_dir_list_content.rhtml index 742da495..3dfe4319 100644 --- a/app/views/repositories/_dir_list_content.rhtml +++ b/app/views/repositories/_dir_list_content.rhtml @@ -1,15 +1,15 @@ <% @entries.each do |entry| %> <% tr_id = Digest::MD5.hexdigest(entry.path) depth = params[:depth].to_i %> - +
<%= l(:field_name) %>
<%= if entry.is_dir? link_to_remote h(entry.name), - {:url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1)}, + {:url => {:action => 'browse', :id => @project, :path => entry.path, :rev => @rev, :depth => (depth + 1), :parent_id => tr_id}, :update => tr_id, :position => :after, - :success => "Element.addClassName('#{tr_id}', 'open');", - :condition => "!Element.hasClassName('#{tr_id}', 'open')" + :success => "scmEntryLoaded('#{tr_id}')", + :condition => "scmEntryClick('#{tr_id}')" }, {:href => url_for({:action => 'browse', :id => @project, :path => entry.path, :rev => @rev}), :class => ('icon icon-folder'), diff --git a/public/javascripts/application.js b/public/javascripts/application.js index bf86f398..8432685d 100644 --- a/public/javascripts/application.js +++ b/public/javascripts/application.js @@ -59,6 +59,40 @@ function checkBulkEdit(form) { return false; } +function collapseScmEntry(id) { + var els = document.getElementsByClassName(id, 'browser'); + for (var i = 0; i < els.length; i++) { + collapseScmEntry(els[i].id); + Element.hide(els[i]); + } + $(id).removeClassName('open'); +} + +function expandScmEntry(id) { + var els = document.getElementsByClassName(id, 'browser'); + for (var i = 0; i < els.length; i++) { + Element.show(els[i]); + } + $(id).addClassName('open'); +} + +function scmEntryClick(id) { + el = $(id); + if (el.hasClassName('open')) { + collapseScmEntry(id); + return false; + } else if (el.hasClassName('loaded')) { + expandScmEntry(id); + return false; + } + return true; +} + +function scmEntryLoaded(id) { + Element.addClassName(id, 'open'); + Element.addClassName(id, 'loaded'); +} + /* shows and hides ajax indicator */ Ajax.Responders.register({ onCreate: function(){