Changeset 1241
- Timestamp:
- 10/23/08 11:27:48 (3 months ago)
- Files:
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
sandbox/camptocamp/MapFishUnhcr/client/mfbase/mapfish/widgets/tree/LayerTree.js
r1046 r1241 40 40 41 41 var cb = typeof a.checked == 'boolean'; 42 var radioGrp = n.attributes.radioGrp || "radioGrp"; 42 43 43 44 var href = a.href ? a.href : Ext.isGecko ? "" : "#"; … … 46 47 '<img src="', this.emptyIcon, '" class="x-tree-ec-icon x-tree-elbow" />', 47 48 '<img src="', a.icon || this.emptyIcon, '" class="x-tree-node-icon',(a.icon ? " x-tree-node-inline-icon" : ""),(a.iconCls ? " "+a.iconCls : ""),'" unselectable="on" />', 48 cb ? ('<input class="x-tree-node-cb" type="radio" name="radio_' + n.id+ '" ' + (a.checked ? 'checked="checked" />' : '/>')) : '',49 cb ? ('<input class="x-tree-node-cb" type="radio" id="'+ n.id + '" name="' + radioGrp + '" ' + (a.checked ? 'checked="checked" />' : '/>')) : '', 49 50 '<a hidefocus="on" class="x-tree-node-anchor" href="',href,'" tabIndex="1" ', 50 51 a.hrefTarget ? ' target="'+a.hrefTarget+'"' : "", '><span unselectable="on">',n.text,"</span></a></div>", … … 79 80 .apply(this, arguments); 80 81 var cbNode = Ext.DomQuery.selectNode(".x-tree-node-cb", this.elNode); 82 var radioGrp = n.attributes.radioGrp || "radioGrp"; 81 83 cbNode.setAttribute("type", "radio"); 82 cbNode.setAttribute("name", "radio_" + n.id); 84 cbNode.setAttribute("id", n.id); 85 cbNode.setAttribute("name", radioGrp); 83 86 }, 84 87 … … 602 605 } 603 606 }, this); 604 605 607 return layerVisibility; 606 608 } … … 624 626 this.getRootNode().cascade(function(node) { 625 627 var checked = node.attributes.checked; 626 627 628 var layerNames = node.attributes.layerNames; 629 var radioGrp = null; 630 628 631 if (!layerNames) 629 632 return; … … 636 639 if (layerVisibility[layerName] == undefined) 637 640 OpenLayers.Console.error("Invalid layer: ", layerName); 641 642 if (node.attributes.radio) { 643 radioGrp = node.attributes.radioGrp || "radioGrp"; 644 645 if (!radioButton[radioGrp]) 646 radioButton[radioGrp] = {}; 647 648 radioButton[radioGrp][layerName] = checked; 649 } 638 650 639 651 if (forcedVisibility[layerName]) … … 642 654 if (this.baseLayerNames.indexOf(layerName) != -1) { 643 655 clickedBaseLayer = layerName; 656 } 657 if (radioGrp) { 658 clickedRadioButton[0] = radioGrp; 659 clickedRadioButton[1] = layerName; 644 660 } 645 661 forcedVisibility[layerName] = true; … … 703 719 704 720 /** 721 * Ensure only one radio button is checked by group. 722 * 723 * Parameters: 724 * layerVisibility - {Object} Map of layer name to {Boolean} 725 * clickedRadiButton - {Array} group name & layer name of the radio button that was clicked. 726 * radioButton - {Object} name of all radio button with checked state. 727 * Contain the group name and the layer name. 728 * Returns: 729 * {Object} updated layerVisibility map 730 */ 731 function applyRadioButtonRestriction(layerVisibility, clickedRadioButton, 732 radioButton) { 733 for (var radioGrp in radioButton) { 734 for (var layerName in radioButton[radioGrp]) { 735 if (clickedRadioButton[0] == radioGrp) { 736 layerVisibility[layerName] = layerName == clickedRadioButton[1]; 737 } else { 738 layerVisibility[layerName] = radioButton[radioGrp][layerName]; 739 } 740 } 741 } 742 return layerVisibility; 743 } 744 745 /** 705 746 * Updates the tree from the given layerVisibility object. 706 747 * … … 754 795 755 796 for (var layerName in layerVisibility) { 756 757 797 var visible = layerVisibility[layerName]; 758 798 … … 842 882 843 883 var currentBaseLayerName; 884 844 885 if (this.map.baseLayer) 845 886 currentBaseLayerName = this.map.baseLayer.name; 846 887 var clickedBaseLayer; 888 var radioButton = {}; 889 var clickedRadioButton = []; 847 890 848 891 // Definition: … … 855 898 applyBaseLayerRestriction.call(this, layerVisibility, clickedBaseLayer, 856 899 currentBaseLayerName); 900 901 applyRadioButtonRestriction.call(this, layerVisibility, clickedRadioButton, 902 radioButton); 857 903 858 904 updateTreeFromVisibility.call(this, layerVisibility); … … 1034 1080 this.getRootNode().cascade(function(node) { 1035 1081 var layers; 1036 if (! this.map || !(layers = this.nodeIdToLayers[node.id]))1082 if (!node.attributes.radio && (!this.map || !(layers = this.nodeIdToLayers[node.id]))) 1037 1083 return; 1038 1084 1039 var isBaseLayer = true; 1040 Ext.each(layers, function(layer) { 1041 if (!layer.isBaseLayer) { 1042 isBaseLayer = false; 1043 return false; 1044 } 1045 }, this); 1046 1047 if (isBaseLayer) { 1085 1086 var isBaseLayer = false; 1087 if (layers) { 1088 isBaseLayer = true; 1089 Ext.each(layers, function(layer) { 1090 if (!layer.isBaseLayer) { 1091 isBaseLayer = false; 1092 return false; 1093 } 1094 }, this); 1095 } 1096 1097 if (isBaseLayer || node.attributes.radio) { 1048 1098 node.attributes.uiProvider = mapfish.widgets.RadioTreeNodeUI; 1049 1099 // The ui may already habe been instanciated here, so we