1 /** 2 * @fileOverview 3 * Copyright (c) 2013 Regione Autonoma della Sardegna 4 * Published under the GPL license.<br> 5 * See <a href="https://sardegnageoportale.it/webgis/license.txt">https://sardegnageoportale.it/webgis/license.txt</a> 6 * for the full text of the license. 7 * @version 0.1 8 */ 9 10 /** 11 * @namespace framework.plugins 12 */ 13 Ext.namespace("GeoExt.tree"); 14 15 /** 16 * Group node implementation for customizing tree nodes behavior and layout 17 * @name_ RASGroupNode 18 * @class Group node implementation. 19 * @constructor 20 * @extends <a target="_blank" href="http://geoext.org/lib/GeoExt/widgets/tree/LayerContainer.html">Ext.tree.LayerContainer</a> 21 */ 22 framework.plugins.RASGroupNode = Ext.extend(GeoExt.tree.LayerContainer, 23 /** 24 * @lends framework.plugins.RASGroupNode.prototype 25 */ 26 { 27 28 /** 29 * @private 30 * @param {Object} config configurations object 31 */ 32 constructor: function(config) { 33 framework.plugins.RASGroupNode.superclass.constructor.apply(this, arguments); 34 this.addEvents( 35 "childcheckchange" 36 ); 37 this.addListener("childcheckchange",function(node,checked){ 38 if(checked === true) 39 this.setCheckBoxForCheckLayer(node); 40 else 41 this.setCheckBoxForUncheckLayer(node); 42 }); 43 }, 44 45 /** 46 * @private override 47 */ 48 appendChild : function(n){ 49 if(!n.render && !Ext.isArray(n)){ 50 n = this.getLoader().createNode(n); 51 } 52 if(n.layer){ 53 var node = Ext.tree.TreeNode.superclass.appendChild.call(this, n); 54 if(node && this.childrenRendered){ 55 node.render(); 56 } 57 this.ui.updateExpandIcon(); 58 this.setCheckBoxForAppendChild(node); 59 return node; 60 } 61 }, 62 63 /** 64 * @private override 65 */ 66 insertBefore : function(node, refNode){ 67 if(!node.render){ 68 node = this.getLoader().createNode(node); 69 } 70 var newNode = Ext.tree.TreeNode.superclass.insertBefore.call(this, node, refNode); 71 if(newNode && refNode && this.childrenRendered){ 72 node.render(); 73 } 74 this.ui.updateExpandIcon(); 75 this.setCheckBoxForAppendChild(node); 76 return newNode; 77 }, 78 79 /** 80 * @private override 81 */ 82 removeChild : function(node, destroy){ 83 this.setCheckBoxForRemoveChild(node); 84 this.ownerTree.getSelectionModel().unselect(node); 85 Ext.tree.TreeNode.superclass.removeChild.apply(this, arguments); 86 // only update the ui if we're not destroying 87 if(!destroy){ 88 var rendered = node.ui.rendered; 89 // if it's been rendered remove dom node 90 if(rendered){ 91 node.ui.remove(); 92 } 93 if(rendered && this.childNodes.length < 1){ 94 this.collapse(false, false); 95 }else{ 96 this.ui.updateExpandIcon(); 97 } 98 if(!this.firstChild && !this.isHiddenRoot()){ 99 this.childrenRendered = false; 100 } 101 } 102 103 return node; 104 }, 105 106 /** 107 * @private control for checkbox 108 */ 109 setCheckBoxForAppendChild : function(node){ 110 if(node.parentNode.ui.checkbox && 111 ((node.layer && node.layer.visibility === true) || (node.ui && node.ui.checkbox && node.ui && node.ui.checkbox.checked === true ))){ 112 node.parentNode.ui.checkbox.checked = true; 113 node.parentNode.ui.checkbox.defaultChecked = true; 114 } 115 }, 116 117 /** 118 * @private control for checkbox 119 */ 120 setCheckBoxForRemoveChild : function(node){ 121 if(node && node.ui.checkbox && node.parentNode.ui.checkbox){ 122 var parent = node.parentNode; 123 parent.ui.checkbox.checked = false; 124 parent.ui.checkbox.defaultChecked = false; 125 for(var child=0;child<parent.childNodes.length;child++){ 126 if(node != parent.childNodes[child] && 127 ((parent.childNodes[child].ui && parent.childNodes[child].ui.checkbox && parent.childNodes[child].ui.checkbox.checked == true) || 128 (parent.childNodes[child].layer && parent.childNodes[child].layer.visibility == true))){ 129 parent.ui.checkbox.checked = true; 130 parent.ui.checkbox.defaultChecked = true; 131 return; 132 } 133 } 134 } 135 }, 136 137 /** 138 * @private control for checkbox 139 */ 140 setCheckBoxForCheckLayer : function(node){ 141 if(node.parentNode.ui.checkbox && 142 ((node.layer && node.layer.visibility == true) || (node.ui && node))){ 143 node.parentNode.ui.checkbox.checked = true; 144 node.parentNode.ui.checkbox.defaultChecked = true; 145 } 146 }, 147 148 /** 149 * @private control for checkbox 150 */ 151 setCheckBoxForUncheckLayer : function(node){ 152 var parent = node.parentNode; 153 if(parent && parent.ui.checkbox){ 154 parent.ui.checkbox.checked = false; 155 parent.ui.checkbox.defaultChecked = false; 156 for(var child=0;child<parent.childNodes.length;child++){ 157 if(parent.childNodes[child].ui && parent.childNodes[child].ui.checkbox && parent.childNodes[child].ui.checkbox.checked == true){ 158 parent.ui.checkbox.checked = true; 159 parent.ui.checkbox.defaultChecked = true; 160 return; 161 } 162 } 163 } 164 }, 165 166 /** 167 * @private add Events 168 */ 169 addVisibilityEventHandlers: function() { 170 this.on({ 171 "checkchange": this.onCheckChange, 172 scope: this 173 }); 174 }, 175 176 /** 177 * @private event implementation 178 */ 179 onCheckChange: function(node, checked) { 180 if(node.childNodes.length > 0){ 181 for(var child in node.childNodes){ 182 if(node.childNodes[child].ui){ 183 node.childNodes[child].ui.checkbox.checked = checked; 184 node.childNodes[child].ui.checkbox.defaultChecked = checked; 185 node.childNodes[child].fireEvent('checkchange', node.childNodes[child], checked); 186 } 187 } 188 }else{ 189 node.ui.checkbox.checked = false; 190 node.ui.checkbox.defaultChecked = false; 191 } 192 } 193 }); 194 195 Ext.preg(framework.plugins.RASGroupNode.prototype.ptype, framework.plugins.RASGroupNode);