From 3cb61e7528c2a8544083bf14e02ea4b9387671fb Mon Sep 17 00:00:00 2001
From: Aleksander Machniak <alec@alec.pl>
Date: Wed, 16 Jul 2014 05:08:11 -0400
Subject: [PATCH] Collapsible (and iconized) folders tree in folder manager (#1489648)

---
 program/js/treelist.js |   36 ++++++++++++++++++++++++++++++++++--
 1 files changed, 34 insertions(+), 2 deletions(-)

diff --git a/program/js/treelist.js b/program/js/treelist.js
index 6a5518a..ab13630 100644
--- a/program/js/treelist.js
+++ b/program/js/treelist.js
@@ -68,6 +68,8 @@
     tree_state,
     ui_droppable,
     ui_draggable,
+    draggable_opts,
+    droppable_opts,
     list_id = (container.attr('id') || p.id_prefix || '0'),
     me = this;
 
@@ -470,7 +472,7 @@
   /**
    *
    */
-  function reset()
+  function reset(keep_content)
   {
     select('');
 
@@ -478,7 +480,22 @@
     indexbyid = {};
     drag_active = false;
 
-    container.html('');
+    if (keep_content) {
+      if (draggable_opts) {
+        draggable('destroy');
+        draggable(draggable_opts);
+      }
+
+      if (droppable_opts) {
+        droppable('destroy');
+        droppable(droppable_opts);
+      }
+
+      update_data();
+    }
+    else {
+      container.html('');
+    }
 
     reset_search();
   }
@@ -1043,6 +1060,13 @@
   {
     if (!opts) opts = {};
 
+    if ($.type(opts) == 'string') {
+      $('li:not(.virtual)', container).droppable(opts);
+      return this;
+    }
+
+    droppable_opts = opts;
+
     var my_opts = $.extend({
         greedy: true,
         tolerance: 'pointer',
@@ -1084,8 +1108,16 @@
   {
     if (!opts) opts = {};
 
+    if ($.type(opts) == 'string') {
+      $('li:not(.virtual)', container).draggable(opts);
+      return this;
+    }
+
+    draggable_opts = opts;
+
     var my_opts = $.extend({
         appendTo: 'body',
+        revert: 'invalid',
         iframeFix: true,
         addClasses: false,
         cursorAt: {left: -20, top: 5},

--
Gitblit v1.9.1