[76] | 1 | /** |
---|
| 2 | * Copyright (c) 2008-2009 The Open Source Geospatial Foundation |
---|
| 3 | * |
---|
| 4 | * Published under the BSD license. |
---|
| 5 | * See http://svn.geoext.org/core/trunk/geoext/license.txt for the full text |
---|
| 6 | * of the license. |
---|
| 7 | */ |
---|
| 8 | |
---|
| 9 | Ext.namespace("GeoExt.plugins"); |
---|
| 10 | |
---|
| 11 | /** api: (define) |
---|
| 12 | * module = GeoExt.plugins |
---|
| 13 | * class = TreeNodeComponent |
---|
| 14 | */ |
---|
| 15 | |
---|
| 16 | /** api: constructor |
---|
| 17 | * A plugin to create tree node UIs that can have an Ext.Component below the |
---|
| 18 | * node's title. Can be plugged into any ``Ext.tree.TreePanel`` and will be |
---|
| 19 | * applied to nodes that are extended with the |
---|
| 20 | * :class:`GeoExt.Tree.TreeNodeUIEventMixin`. |
---|
| 21 | * |
---|
| 22 | * If a node is configured with a ``component`` attribute, it will be rendered |
---|
| 23 | * with the component in addition to icon and title. |
---|
| 24 | */ |
---|
| 25 | |
---|
| 26 | /** api: example |
---|
| 27 | * Sample code to create a tree with a node that has a component: |
---|
| 28 | * |
---|
| 29 | * .. code-block:: javascript |
---|
| 30 | * |
---|
| 31 | * var uiClass = Ext.extend( |
---|
| 32 | * Ext.tree.TreeNodeUI, |
---|
| 33 | * GeoExt.tree.TreeNodeUIEventMixin |
---|
| 34 | * ); |
---|
| 35 | * var tree = new Ext.tree.TreePanel({ |
---|
| 36 | * plugins: [ |
---|
| 37 | * new GeoExt.plugins.TreeNodeRadioButton({ |
---|
| 38 | * listeners: { |
---|
| 39 | * "radiochange": function(node) { |
---|
| 40 | * alert(node.text + "'s radio button was clicked."); |
---|
| 41 | * } |
---|
| 42 | * } |
---|
| 43 | * }) |
---|
| 44 | * ], |
---|
| 45 | * root: { |
---|
| 46 | * nodeType: "node", |
---|
| 47 | * uiProvider: uiClass, |
---|
| 48 | * text: "My Node", |
---|
| 49 | * component: { |
---|
| 50 | * xtype: "box", |
---|
| 51 | * autoEl: { |
---|
| 52 | * tag: "img", |
---|
| 53 | * src: "/images/my-image.jpg" |
---|
| 54 | * } |
---|
| 55 | * } |
---|
| 56 | * } |
---|
| 57 | * } |
---|
| 58 | * |
---|
| 59 | * Sample code to create a layer node UI with a radio button: |
---|
| 60 | * |
---|
| 61 | * .. code-block:: javascript |
---|
| 62 | * |
---|
| 63 | * var uiClass = Ext.extend( |
---|
| 64 | * GeoExt.tree.LayerNodeUI, |
---|
| 65 | * new GeoExt.tree.TreeNodeUIEventMixin |
---|
| 66 | * ); |
---|
| 67 | */ |
---|
| 68 | |
---|
| 69 | GeoExt.plugins.TreeNodeComponent = Ext.extend(Ext.util.Observable, { |
---|
| 70 | |
---|
| 71 | /** private: method[constructor] |
---|
| 72 | * :param config: ``Object`` |
---|
| 73 | */ |
---|
| 74 | constructor: function(config) { |
---|
| 75 | Ext.apply(this.initialConfig, Ext.apply({}, config)); |
---|
| 76 | Ext.apply(this, config); |
---|
| 77 | |
---|
| 78 | GeoExt.plugins.TreeNodeComponent.superclass.constructor.apply(this, arguments); |
---|
| 79 | }, |
---|
| 80 | |
---|
| 81 | /** private: method[init] |
---|
| 82 | * :param tree: ``Ext.tree.TreePanel`` The tree. |
---|
| 83 | */ |
---|
| 84 | init: function(tree) { |
---|
| 85 | tree.on({ |
---|
| 86 | "rendernode": this.onRenderNode, |
---|
| 87 | scope: this |
---|
| 88 | }); |
---|
| 89 | }, |
---|
| 90 | |
---|
| 91 | /** private: method[onRenderNode] |
---|
| 92 | * :param node: ``Ext.tree.TreeNode`` |
---|
| 93 | */ |
---|
| 94 | onRenderNode: function(node) { |
---|
| 95 | var rendered = node.rendered; |
---|
| 96 | var attr = node.attributes; |
---|
| 97 | var component = attr.component || this.component; |
---|
| 98 | if(!rendered && component) { |
---|
| 99 | var elt = Ext.DomHelper.append(node.ui.elNode, [ |
---|
| 100 | {"tag": "div"} |
---|
| 101 | ]); |
---|
| 102 | if(typeof component == "function") { |
---|
| 103 | component = component(node, elt); |
---|
| 104 | } else if (typeof component == "object" && |
---|
| 105 | typeof component.fn == "function") { |
---|
| 106 | component = component.fn.apply( |
---|
| 107 | component.scope, [node, elt] |
---|
| 108 | ); |
---|
| 109 | } |
---|
| 110 | if(typeof component == "object" && |
---|
| 111 | typeof component.xtype == "string") { |
---|
| 112 | component = Ext.ComponentMgr.create(component); |
---|
| 113 | } |
---|
| 114 | if(component instanceof Ext.Component) { |
---|
| 115 | component.render(elt); |
---|
| 116 | node.component = component; |
---|
| 117 | } |
---|
| 118 | } |
---|
| 119 | }, |
---|
| 120 | |
---|
| 121 | /** private: method[destroy] |
---|
| 122 | */ |
---|
| 123 | destroy: function() { |
---|
| 124 | tree.un("rendernode", this.onRenderNode, this); |
---|
| 125 | } |
---|
| 126 | |
---|
| 127 | }); |
---|
| 128 | |
---|
| 129 | /** api: ptype = gx_TreeNodeComponent */ |
---|
| 130 | Ext.preg && Ext.preg("gx_treenodecomponent", GeoExt.plugins.TreeNodeComponent); |
---|