Conservation de l'état de déroulement de l'arborescence (seulement pour le déroulement).
authorBenoît Pin <benoit.pin@gmail.com>
Wed, 24 Nov 2010 22:41:40 +0000 (23:41 +0100)
committerBenoît Pin <benoit.pin@gmail.com>
Wed, 24 Nov 2010 22:41:40 +0000 (23:41 +0100)
default_blocks/tree_block_script.js
default_blocks/tree_block_template.pt
skins/xml_nav_tree.py

index 228d405..cd0114c 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" :
@@ -95,6 +96,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.
index 606d136..468305d 100755 (executable)
@@ -41,7 +41,7 @@
                      rows       treeDict/rows;
                      height                    tree/height;
                      rootNode   python:rows.pop(0);
                      rows       treeDict/rows;
                      height                    tree/height;
                      rootNode   python:rows.pop(0);
-                     box_id     rootNode/id;
+                     box_id     tree/tree_pre;
                      portal_url here/portal_url"
          tal:condition="python:displayAction=='view' and rows"
          tal:omit-tag=""
                      portal_url here/portal_url"
          tal:condition="python:displayAction=='view' and rows"
          tal:omit-tag=""
@@ -63,8 +63,8 @@
 
                                <tr>
                                        <td>
 
                                <tr>
                                        <td>
-                                               <table  cellspacing="0">
-                                                       <tbody tal:attributes="id  box_id">
+                                               <table cellspacing="0">
+                                                       <tbody tal:attributes="id  box_id; name rootNode/id">
                                                                <tr tal:repeat="row rows">
                                                                <td tal:define="indent python: row.depth - 1" tal:attributes="colspan indent" tal:condition="indent">&nbsp;</td>
                                                                <td tal:define="state row/state ; rlink row/branch ; msg python:state > 0 and 'collapse' or 'expand'" width="16"
                                                                <tr tal:repeat="row rows">
                                                                <td tal:define="indent python: row.depth - 1" tal:attributes="colspan indent" tal:condition="indent">&nbsp;</td>
                                                                <td tal:define="state row/state ; rlink row/branch ; msg python:state > 0 and 'collapse' or 'expand'" width="16"
index 05967d9..79c069c 100644 (file)
@@ -1,4 +1,4 @@
-##parameters=filter=''
+##parameters=root_name='',expansion='',filter=''
 from ZTUtils import SimpleTreeMaker
 stm = SimpleTreeMaker()
 def replaceXMLEntities(text) :
 from ZTUtils import SimpleTreeMaker
 stm = SimpleTreeMaker()
 def replaceXMLEntities(text) :
@@ -11,10 +11,12 @@ rmBadAttrChars = maketrans('<&"', '   ')
        
 filter = filter.split(',')
 
        
 filter = filter.split(',')
 
-root = context
+childs = list(context.listNearestFolderContents(contentFilter={'portal_type':filter}))
+childs.sort(lambda x, y : cmp(y.title_or_id().lower(), x.title_or_id().lower()))
+
 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
 print '<xml>'
 context.REQUEST.RESPONSE.setHeader('content-type', 'text/xml; charset=utf-8')
 print '<xml>'
-for ob in context.listNearestFolderContents(contentFilter={'portal_type':filter}) :
+for ob in childs :
        icon = context.restrictedTraverse(ob.getIcon())
        state = 0
        if not getattr(ob, 'isPortalContent', False) :
        icon = context.restrictedTraverse(ob.getIcon())
        state = 0
        if not getattr(ob, 'isPortalContent', False) :
@@ -33,5 +35,5 @@ for ob in context.listNearestFolderContents(contentFilter={'portal_type':filter}
 
 
 print '</xml>'
 
 
 print '</xml>'
-
+context.REQUEST.RESPONSE.setCookie('%s-state' % root_name, expansion, path='/')        
 return printed
\ No newline at end of file
 return printed
\ No newline at end of file