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.

98 lines
3.2 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. //
  8. // Extend the XmlTreeLoader to set some custom TreeNode attributes specific to our application:
  9. //
  10. Ext.app.BookLoader = Ext.extend(Ext.ux.tree.XmlTreeLoader, {
  11. processAttributes : function(attr){
  12. if(attr.first){ // is it an author node?
  13. // Set the node text that will show in the tree since our raw data does not include a text attribute:
  14. attr.text = attr.first + ' ' + attr.last;
  15. // Author icon, using the gender flag to choose a specific icon:
  16. attr.iconCls = 'author-' + attr.gender;
  17. // Override these values for our folder nodes because we are loading all data at once. If we were
  18. // loading each node asynchronously (the default) we would not want to do this:
  19. attr.loaded = true;
  20. attr.expanded = true;
  21. }
  22. else if(attr.title){ // is it a book node?
  23. // Set the node text that will show in the tree since our raw data does not include a text attribute:
  24. attr.text = attr.title + ' (' + attr.published + ')';
  25. // Book icon:
  26. attr.iconCls = 'book';
  27. // Tell the tree this is a leaf node. This could also be passed as an attribute in the original XML,
  28. // but this example demonstrates that you can control this even when you cannot dictate the format of
  29. // the incoming source XML:
  30. attr.leaf = true;
  31. }
  32. }
  33. });
  34. Ext.onReady(function(){
  35. var detailsText = '<i>Select a book to see more information...</i>';
  36. var tpl = new Ext.Template(
  37. '<h2 class="title">{title}</h2>',
  38. '<p><b>Published</b>: {published}</p>',
  39. '<p><b>Synopsis</b>: {innerText}</p>',
  40. '<p><a href="{url}" target="_blank">Purchase from Amazon</a></p>'
  41. );
  42. tpl.compile();
  43. new Ext.Panel({
  44. title: 'Reading List',
  45. renderTo: 'tree',
  46. layout: 'border',
  47. width: 500,
  48. height: 500,
  49. items: [{
  50. xtype: 'treepanel',
  51. id: 'tree-panel',
  52. region: 'center',
  53. margins: '2 2 0 2',
  54. autoScroll: true,
  55. rootVisible: false,
  56. root: new Ext.tree.AsyncTreeNode(),
  57. // Our custom TreeLoader:
  58. loader: new Ext.app.BookLoader({
  59. dataUrl:'xml-tree-data.xml'
  60. }),
  61. listeners: {
  62. 'render': function(tp){
  63. tp.getSelectionModel().on('selectionchange', function(tree, node){
  64. var el = Ext.getCmp('details-panel').body;
  65. if(node && node.leaf){
  66. tpl.overwrite(el, node.attributes);
  67. }else{
  68. el.update(detailsText);
  69. }
  70. })
  71. }
  72. }
  73. },{
  74. region: 'south',
  75. title: 'Book Details',
  76. id: 'details-panel',
  77. autoScroll: true,
  78. collapsible: true,
  79. split: true,
  80. margins: '0 2 2 2',
  81. cmargins: '2 2 2 2',
  82. height: 220,
  83. html: detailsText
  84. }]
  85. });
  86. });