Youpi : conservation de l'état de l'arborescence, même dans le cas du repliement.
[MosaicDocument.git] / default_blocks / tree_block_script.js
index c057e28..cda2925 100644 (file)
@@ -33,7 +33,7 @@ TreeMaker.prototype.refreshTree = function (evt) {
        var target = getTargetedObject(evt);
        if (target.blur)
                target.blur();
        var target = getTargetedObject(evt);
        if (target.blur)
                target.blur();
-       
+
        if (target.tagName == 'IMG') {
                target.parentNode.blur();
                var srcParts = target.src.split("/");
        if (target.tagName == 'IMG') {
                target.parentNode.blur();
                var srcParts = target.src.split("/");
@@ -63,15 +63,16 @@ TreeMaker.prototype.refreshTree = function (evt) {
                                                        tm.importRows(req, parentRow);
                                        };
                                };
                                                        tm.importRows(req, parentRow);
                                        };
                                };
-                               req.open("POST", obUrl + "/xml_nav_tree", true);
-                               req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
-                               req.send("filter=" + this.filter);
-                               
                                target.src = this.baseImgUrl + "mi_ani.gif";
                                this._lastAniImg = target;
                                target.src = this.baseImgUrl + "mi_ani.gif";
                                this._lastAniImg = target;
-
-
                                window.setTimeout(function(){tm._removeLastAniImg();}, 500);
                                window.setTimeout(function(){tm._removeLastAniImg();}, 500);
+
+                               req.open("POST", obUrl + "/xml_nav_tree", true);
+                               req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
+                               req.send("filter=" + encodeURIComponent(this.filter) +
+                                                "&root_name=" + encodeURIComponent(this.root.id) +
+                                                "&expansion=" + encodeURIComponent(this.getExpansion()));
+                               
                                break;
 
                        case "mi.gif" :
                                break;
 
                        case "mi.gif" :
@@ -81,6 +82,8 @@ TreeMaker.prototype.refreshTree = function (evt) {
                                this._lastAniImg = target;
                                var tm = this;
                                window.setTimeout(function(){tm._removeLastAniImg();}, 500);
                                this._lastAniImg = target;
                                var tm = this;
                                window.setTimeout(function(){tm._removeLastAniImg();}, 500);
+                               document.cookie = encodeURIComponent(this.root.id) + '-state=' + encodeURIComponent(this.getExpansion()) +
+                                                                 ';path=/';
                                break;
                } // end switch (imgId)
                disableDefault(evt);
                                break;
                } // end switch (imgId)
                disableDefault(evt);
@@ -95,6 +98,38 @@ TreeMaker.prototype._removeLastAniImg = function() {
        }
 };
 
        }
 };
 
+TreeMaker.prototype.getExpansion = function() {
+       var rows = this.root.getElementsByTagName('TR');
+       var row, cells, stateCell, button, expid, node_depth, last_depth = -1, dd, step;
+       var steps = new Array();
+       steps.push(this.root.getAttribute('name'));
+       
+       var expanded = (/.*mi\.gif$|.*mi_ani\.gif$/);
+       for(i=0 ; i < rows.length ; i++) {
+               row = rows[i];
+               cells = row.getElementsByTagName('TD');
+               stateCell = cells[cells.length-2]; // cell where the +/- button is
+               button = stateCell.getElementsByTagName('IMG');
+               if (! button.length)
+                       continue;
+               button = button[0];
+               if (expanded.test(button.src)) {
+                       expid = button.parentNode.getAttribute("name");
+                       node_depth = cells[0].getAttribute('colspan') || 0;
+                       dd = last_depth - node_depth + 1;
+                       last_depth = node_depth;
+                       if (dd > 0) {
+                               step = '';
+                               for (var j = 0 ;  j < dd ; j++)
+                                       step = step + '_';
+                               steps.push(step);
+                       }
+                       steps.push(expid);
+               }
+       }
+       return steps.join(':');
+};
+
 
 /*
 * expand the tree: sends request and imports rows based on xml response.
 
 /*
 * expand the tree: sends request and imports rows based on xml response.
@@ -157,6 +192,7 @@ TreeMaker.prototype.importRows = function(req, parentRow) {
                if (row.getAttribute("state") == "-1") {
                        var stateLink = document.createElement("A");
                        stateLink.href = ".";
                if (row.getAttribute("state") == "-1") {
                        var stateLink = document.createElement("A");
                        stateLink.href = ".";
+                       stateLink.setAttribute("name", row.getAttribute("name"));
                        var stateImg = document.createElement("IMG");
                        stateImg.src = this.baseImgUrl + "pl.gif";
                        stateImg.border = "0";
                        var stateImg = document.createElement("IMG");
                        stateImg.src = this.baseImgUrl + "pl.gif";
                        stateImg.border = "0";