Web Interface For Lite Argus Control modules
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

106 lines
3.5 KiB

​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
​
  1. /*!
  2. * Ext JS Library 3.3.1
  3. * Copyright(c) 2006-2010 Sencha Inc.
  4. * licensing@sencha.com
  5. * http://www.sencha.com/license
  6. */
  7. Ext.ns('Ext.ux.tree');
  8. /**
  9. * @class Ext.ux.tree.XmlTreeLoader
  10. * @extends Ext.tree.TreeLoader
  11. * <p>A TreeLoader that can convert an XML document into a hierarchy of {@link Ext.tree.TreeNode}s.
  12. * Any text value included as a text node in the XML will be added to the parent node as an attribute
  13. * called <tt>innerText</tt>. Also, the tag name of each XML node will be added to the tree node as
  14. * an attribute called <tt>tagName</tt>.</p>
  15. * <p>By default, this class expects that your source XML will provide the necessary attributes on each
  16. * node as expected by the {@link Ext.tree.TreePanel} to display and load properly. However, you can
  17. * provide your own custom processing of node attributes by overriding the {@link #processNode} method
  18. * and modifying the attributes as needed before they are used to create the associated TreeNode.</p>
  19. * @constructor
  20. * Creates a new XmlTreeloader.
  21. * @param {Object} config A config object containing config properties.
  22. */
  23. Ext.ux.tree.XmlTreeLoader = Ext.extend(Ext.tree.TreeLoader, {
  24. /**
  25. * @property XML_NODE_ELEMENT
  26. * XML element node (value 1, read-only)
  27. * @type Number
  28. */
  29. XML_NODE_ELEMENT : 1,
  30. /**
  31. * @property XML_NODE_TEXT
  32. * XML text node (value 3, read-only)
  33. * @type Number
  34. */
  35. XML_NODE_TEXT : 3,
  36. // private override
  37. processResponse : function(response, node, callback){
  38. var xmlData = response.responseXML,
  39. root = xmlData.documentElement || xmlData;
  40. try{
  41. node.beginUpdate();
  42. node.appendChild(this.parseXml(root));
  43. node.endUpdate();
  44. this.runCallback(callback, scope || node, [node]);
  45. }catch(e){
  46. this.handleFailure(response);
  47. }
  48. },
  49. // private
  50. parseXml : function(node) {
  51. var nodes = [];
  52. Ext.each(node.childNodes, function(n){
  53. if(n.nodeType == this.XML_NODE_ELEMENT){
  54. var treeNode = this.createNode(n);
  55. if(n.childNodes.length > 0){
  56. var child = this.parseXml(n);
  57. if(typeof child == 'string'){
  58. treeNode.attributes.innerText = child;
  59. }else{
  60. treeNode.appendChild(child);
  61. }
  62. }
  63. nodes.push(treeNode);
  64. }
  65. else if(n.nodeType == this.XML_NODE_TEXT){
  66. var text = n.nodeValue.trim();
  67. if(text.length > 0){
  68. return nodes = text;
  69. }
  70. }
  71. }, this);
  72. return nodes;
  73. },
  74. // private override
  75. createNode : function(node){
  76. var attr = {
  77. tagName: node.tagName
  78. };
  79. Ext.each(node.attributes, function(a){
  80. attr[a.nodeName] = a.nodeValue;
  81. });
  82. this.processAttributes(attr);
  83. return Ext.ux.tree.XmlTreeLoader.superclass.createNode.call(this, attr);
  84. },
  85. /*
  86. * Template method intended to be overridden by subclasses that need to provide
  87. * custom attribute processing prior to the creation of each TreeNode. This method
  88. * will be passed a config object containing existing TreeNode attribute name/value
  89. * pairs which can be modified as needed directly (no need to return the object).
  90. */
  91. processAttributes: Ext.emptyFn
  92. });
  93. //backwards compat
  94. Ext.ux.XmlTreeLoader = Ext.ux.tree.XmlTreeLoader;