Utilisation des png24 (et apng) pour l'affichage des boutons de déploiement de l...
[MosaicDocument.git] / default_blocks / tree_block_script.js
index c057e28..d115432 100644 (file)
@@ -18,7 +18,7 @@ TreeMaker = function (root, filter, baseImgUrl) {
        this._lastAniImg = null;
        
        // preload images
        this._lastAniImg = null;
        
        // preload images
-       var images = ['pl.gif', 'pl_ani.gif', 'mi.gif', 'mi_ani.gif'], img;
+       var images = ['pl.png', 'pl_ani.png', 'mi.png', 'mi_ani.png'], img;
        for (var i=0 ; i < images.length ; i++) {
                img = new Image();
                img.src = this.baseImgUrl + images[i];
        for (var i=0 ; i < images.length ; i++) {
                img = new Image();
                img.src = this.baseImgUrl + images[i];
@@ -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("/");
@@ -43,8 +43,8 @@ TreeMaker.prototype.refreshTree = function (evt) {
                
 
                switch (imgId) {
                
 
                switch (imgId) {
-                       case "pl.gif" :
-                       case "pl_ani.gif" :
+                       case "pl.png" :
+                       case "pl_ani.png" :
                                var linkCell = parentTd.nextSibling;
                                while (linkCell.nodeType != 1)
                                        linkCell = linkCell.nextSibling;
                                var linkCell = parentTd.nextSibling;
                                while (linkCell.nodeType != 1)
                                        linkCell = linkCell.nextSibling;
@@ -63,24 +63,27 @@ TreeMaker.prototype.refreshTree = function (evt) {
                                                        tm.importRows(req, parentRow);
                                        };
                                };
                                                        tm.importRows(req, parentRow);
                                        };
                                };
+                               target.src = this.baseImgUrl + "mi_ani.png";
+                               this._lastAniImg = target;
+                               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.open("POST", obUrl + "/xml_nav_tree", true);
                                req.setRequestHeader("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
-                               req.send("filter=" + this.filter);
+                               req.send("filter=" + encodeURIComponent(this.filter) +
+                                                "&root_name=" + encodeURIComponent(this.root.id) +
+                                                "&expansion=" + encodeURIComponent(this.getExpansion()));
                                
                                
-                               target.src = this.baseImgUrl + "mi_ani.gif";
-                               this._lastAniImg = target;
-
-
-                               window.setTimeout(function(){tm._removeLastAniImg();}, 500);
                                break;
 
                                break;
 
-                       case "mi.gif" :
-                       case "mi_ani.gif" :
+                       case "mi.png" :
+                       case "mi_ani.png" :
                                this.removeChildNodes(parentRow);
                                this.removeChildNodes(parentRow);
-                               target.src = this.baseImgUrl + "pl_ani.gif";
+                               target.src = this.baseImgUrl + "pl_ani.png";
                                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\.png$|.*mi_ani\.png$/);
+       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,8 +192,9 @@ 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");
                        var stateImg = document.createElement("IMG");
-                       stateImg.src = this.baseImgUrl + "pl.gif";
+                       stateImg.src = this.baseImgUrl + "pl.png";
                        stateImg.border = "0";
                        stateImg.height = "16";
                        stateImg.width = "16";
                        stateImg.border = "0";
                        stateImg.height = "16";
                        stateImg.width = "16";