modx.panel.filetree.js 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  1. /**
  2. * Light container with all available media sources trees
  3. *
  4. * @class MODx.panel.FileTree
  5. * @extends Ext.Container
  6. * @param {Object} config
  7. * @xtype modx-panel-filetree
  8. */
  9. MODx.panel.FileTree = function(config) {
  10. config = config || {};
  11. Ext.applyIf(config, {
  12. _treePrefix: 'source-tree-'
  13. ,autoHeight: true
  14. ,defaults: {
  15. autoHeight: true
  16. ,border: false
  17. }
  18. });
  19. MODx.panel.FileTree.superclass.constructor.call(this, config);
  20. this.on('render', this.getSourceList, this);
  21. };
  22. Ext.extend(MODx.panel.FileTree, Ext.Container, {
  23. /**
  24. * Query the media sources list
  25. */
  26. getSourceList: function() {
  27. MODx.Ajax.request({
  28. url: MODx.config.connector_url
  29. ,params: {
  30. action: 'source/getList'
  31. ,limit: 0
  32. }
  33. ,listeners: {
  34. success: {
  35. fn: function(data) {
  36. this.onSourceListReceived(data.results);
  37. }
  38. ,scope:this
  39. }
  40. ,failure: {
  41. fn: function(data) {
  42. // Check if this really is an error
  43. if (data.total > 0 && data.results != undefined) {
  44. this.onSourceListReceived(data.results);
  45. }
  46. return false;
  47. }
  48. ,scope: this
  49. }
  50. }
  51. })
  52. }
  53. /**
  54. * Iterate over the given media sources list to add their trees
  55. *
  56. * @param {Array} sources
  57. */
  58. ,onSourceListReceived: function(sources) {
  59. for (var k = 0; k < sources.length; k++) {
  60. var source = sources[k]
  61. ,exists = this.getComponent(this._treePrefix + source.id);
  62. if (!exists) {
  63. var tree = this.loadTree(source);
  64. }
  65. this.add(tree);
  66. tree = exists = void 0;
  67. }
  68. this.doLayout();
  69. }
  70. /**
  71. * Load the tree configuration for the given media source
  72. *
  73. * @param {Object} source
  74. * @returns {Object}
  75. */
  76. ,loadTree: function(source) {
  77. return MODx.load({
  78. xtype: 'modx-tree-directory'
  79. ,itemId: this._treePrefix + source.id
  80. ,stateId: this._treePrefix + source.id
  81. ,id: this._treePrefix + source.id
  82. ,cls: source.cls || ''
  83. ,rootName: source.name
  84. ,rootQtip: source.description || ''
  85. ,hideSourceCombo: true
  86. ,source: source.id
  87. ,rootIconCls: source.iconCls || ''
  88. ,tbar: false
  89. ,tbarCfg: {
  90. hidden: true
  91. }
  92. });
  93. }
  94. });
  95. Ext.reg('modx-panel-filetree', MODx.panel.FileTree);