Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Ticket #6919 (new defect)

Opened 1 year ago

Last modified 1 year ago

[PATCH] Sorted tree: one level elements inheritance fault

Reported by: Riki_tiki_tavi Assigned to: madrobby
Priority: high Milestone: 2.x
Component: script.aculo.us Version: edge
Severity: major Keywords: dragdrop, typo, Sortable.options, oldParentNode
Cc: thomas@fesch.at

Description

If drag element from one leaf to another, it's hidden value becomes heighbour for target element, so, making one element child of another becomes possible if only it dragged there instantly.

I don't know, what's this, bug or feature, but it causes serious difficulties while editing sorted tree.


Patch:

Index: dragdrop.js
===================================================================
--- dragdrop.js (revision 5831)
+++ dragdrop.js (working copy)
@@ -720,8 +720,17 @@
   onHover: function(element, dropon, overlap) {
     if(Element.isParent(dropon, element)) return;

-    if(overlap > .33 && overlap < .66 && Sortable.options(dropon).tree) {
-      return;
+    if(Sortable.options(dropon).tree && overlap > .1 && overlap < .86) {
+      if(overlap>0.1&&overlap<0.6) {
+        var oldParentNode = element.parentNode;
+        var droponOptions = Sortable.options(dropon);
+        var children = Sortable.findElements(dropon, {tag: droponOptions.treeTag, only: droponOptions.only});
+        if(dropon.tagName.toUpperCase() == Sortable.options(dropon).tag.toUpperCase() && children.length==1){
+          children[0].insertBefore(element, null);
+         Sortable.options(oldParentNode).onChange(element);
+         droponOptions.onChange(element);
+        }
+      }
     } else if(overlap>0.5) {
       Sortable.mark(dropon, 'before');
       if(dropon.previousSibling != element) {
@@ -756,7 +765,7 @@
       var children = Sortable.findElements(dropon, {tag: droponOptions.tag, only: droponOptions.only});
       var child = null;

-      if(children) {
+      if(children.length) {
         var offset = Element.offsetSize(dropon, droponOptions.overlap) * (1.0 - overlap);

         for (index = 0; index < children.length; index += 1) {

When element dragged in half of dropon element and dropon element is empty and contains one <ul> node, element inserts into it. I've changed values of overlap interval, it makes dragging elements smoothly.


During search of the decision, i've noticed, that in some cases Sortable.findElements() returns empty string, it causes unnecessary calculations [Not a bug], so, i've changed "if(children) {" to "if(children.length) {"

Attachments

dragdrop.js.diff (1.4 kB) - added by Riki_tiki_tavi on 01/03/07 21:11:41.
Ticket 6919 Patch
dragdrop.js.diff.1 (2.2 kB) - added by Riki_tiki_tavi on 01/04/07 21:33:15.
last dragdrop.js diff

Change History

01/03/07 21:10:50 changed by Riki_tiki_tavi

  • cc set to thomas@fesch.at.

Forgot, i've test it only on Firefox 2, konqueror and Opera 9, and i don't have safari and IE :(

01/03/07 21:11:41 changed by Riki_tiki_tavi

  • attachment dragdrop.js.diff added.

Ticket 6919 Patch

(in reply to: ↑ description ) 01/04/07 21:31:37 changed by Riki_tiki_tavi

Well, i go further and have improved sorted tree: New elements in empty leafs would added if only Ctrl key is pressed, and if hold Shift key, leafs will move only in current leafs, it's powerful for sorting one leaf, if you have many others near it. New patch included

01/04/07 21:33:15 changed by Riki_tiki_tavi

  • attachment dragdrop.js.diff.1 added.

last dragdrop.js diff

05/29/07 22:18:01 changed by rhalff

  • type changed from enhancement to defect.

I can confirm this error, and the patch fixes things.

The error can be replicated by installing typo from trunk:

svn co http://svn.typosphere.org/typo/trunk typo mysqladmin -u root -p create typo_dev cd typo mv config/database.yml.example config/database.yml vim config/database.yml rake db:migrate ./script/server --port 4000

Creaet an account, log in and go to 'Design', then try to move one of them sidebars to the active list.

Firebug will show the reported error.

After applying the patch, the error is gone.

05/29/07 22:20:47 changed by rhalff

Sorry, next time I'll actually use the preview option..

Commands:

svn co http://svn.typosphere.org/typo/trunk typo
mysqladmin -u root -p create typo_dev
cd typo
mv config/database.yml.example config/database.yml
vim config/database.yml
rake db:migrate ./script/server --port 4000

05/29/07 22:33:06 changed by rhalff

  • keywords set to dragdrop, typo, Sortable.options, oldParentNode.
  • priority changed from normal to high.
  • version set to edge.
  • severity changed from normal to major.