browser.js 7.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256
  1. /**
  2. * This is an attempt to extract the MODx.Browser.Window as a whole "component/page"
  3. *
  4. * @param {Object} config
  5. *
  6. * @extends Ext.Container
  7. * @xtype modx-media-view
  8. */
  9. MODx.Media = function(config) {
  10. config = config || {};
  11. this.ident = config.ident || Ext.id();
  12. // DataView
  13. this.view = MODx.load({
  14. xtype: 'modx-browser-view'
  15. ,source: config.source || MODx.config.default_media_source
  16. ,allowedFileTypes: config.allowedFileTypes || ''
  17. ,wctx: config.wctx || 'web'
  18. ,openTo: config.openTo || ''
  19. ,ident: this.ident
  20. ,id: this.ident+'-view'
  21. });
  22. // Hide the "new window" toolbar button
  23. MODx.browserOpen = true;
  24. // Tree navigation
  25. this.tree = MODx.load({
  26. xtype: 'modx-tree-directory'
  27. ,onUpload: function() {
  28. this.view.run();
  29. }
  30. ,scope: this
  31. ,source: config.source || MODx.config.default_media_source
  32. ,hideFiles: config.hideFiles || false
  33. ,openTo: config.openTo || ''
  34. ,ident: this.ident
  35. ,rootId: config.rootId || '/'
  36. ,rootName: _('files')
  37. ,rootVisible: config.rootVisible == undefined || !Ext.isEmpty(config.rootId)
  38. ,id: this.ident+'-tree'
  39. ,hideSourceCombo: config.hideSourceCombo || false
  40. ,useDefaultToolbar: false
  41. ,listeners: {
  42. afterUpload: {
  43. fn: function() {
  44. this.view.run();
  45. }
  46. ,scope: this
  47. }
  48. ,changeSource: {
  49. fn: function(s) {
  50. this.config.source = s;
  51. this.view.config.source = s;
  52. this.view.baseParams.source = s;
  53. this.view.dir = '/';
  54. this.view.run();
  55. }
  56. ,scope: this
  57. }
  58. ,nodeclick: {
  59. fn: function(n, e) {
  60. n.select();
  61. e.preventDefault();
  62. e.stopPropagation();
  63. return false;
  64. }
  65. ,scope: this
  66. }
  67. ,afterrender: {
  68. fn: function(tree) {
  69. tree.root.expand();
  70. }
  71. ,scope: this
  72. }
  73. }
  74. });
  75. this.tree.on('click', function(node, e) {
  76. this.load(node.id);
  77. }, this);
  78. Ext.applyIf(config, {
  79. cls: 'modx-browser container'
  80. ,layout: 'border'
  81. ,width: '98%'
  82. ,height: '95%'
  83. ,items: [{
  84. region: 'west'
  85. ,width: 250
  86. ,items: this.tree
  87. ,id: this.ident+'-browser-tree'
  88. ,cls: 'modx-browser-tree shadowbox'
  89. ,autoScroll: true
  90. ,split: true
  91. },{
  92. region: 'center'
  93. ,layout: 'fit'
  94. ,items: this.view
  95. ,id: this.ident+'-browser-view'
  96. ,cls: 'modx-browser-view-ct'
  97. ,autoScroll: true
  98. ,border: false
  99. ,tbar: this.getToolbar()
  100. },{
  101. region: 'east'
  102. ,width: 250
  103. ,id: this.ident+'-img-detail-panel'
  104. ,cls: 'modx-browser-details-ct'
  105. ,split: true
  106. //,collapsed: true
  107. }]
  108. });
  109. MODx.Media.superclass.constructor.call(this, config);
  110. this.config = config;
  111. };
  112. Ext.extend(MODx.Media, Ext.Container, {
  113. returnEl: null
  114. /**
  115. * Filter the DataView results
  116. */
  117. ,filter : function() {
  118. var filter = Ext.getCmp(this.ident+'filter');
  119. this.view.store.filter('name', filter.getValue(), true);
  120. this.view.select(0);
  121. }
  122. ,setReturn: function(el) {
  123. this.returnEl = el;
  124. }
  125. /**
  126. * Load the given directory in the DataView
  127. *
  128. * @param {String} dir
  129. */
  130. ,load: function(dir) {
  131. dir = dir || (Ext.isEmpty(this.config.openTo) ? '' : this.config.openTo);
  132. this.view.run({
  133. dir: dir
  134. ,source: this.config.source
  135. ,allowedFileTypes: this.config.allowedFileTypes || ''
  136. ,wctx: this.config.wctx || 'web'
  137. });
  138. this.sortStore();
  139. }
  140. /**
  141. * Sort the DataView results
  142. */
  143. ,sortStore: function(){
  144. var v = Ext.getCmp(this.ident+'sortSelect').getValue();
  145. this.view.store.sort(v, v == 'name' ? 'asc' : 'desc');
  146. this.view.select(0);
  147. }
  148. /**
  149. * Switch viewmode
  150. */
  151. ,changeViewmode: function() {
  152. var v = Ext.getCmp(this.ident+'viewSelect').getValue();
  153. this.view.setTemplate(v);
  154. this.view.select(0);
  155. }
  156. /**
  157. * Remove any filter applied to the DataView
  158. */
  159. ,reset: function() {
  160. if (this.rendered) {
  161. Ext.getCmp(this.ident+'filter').reset();
  162. this.view.getEl().dom.scrollTop = 0;
  163. }
  164. this.view.store.clearFilter();
  165. this.view.select(0);
  166. }
  167. /**
  168. * Get the tree toolbar configuration
  169. *
  170. * @returns {Array}
  171. */
  172. ,getToolbar: function() {
  173. return [{
  174. text: _('filter')+':'
  175. ,xtype: 'label'
  176. },{
  177. xtype: 'textfield'
  178. ,id: this.ident+'filter'
  179. ,selectOnFocus: true
  180. ,width: 200
  181. ,listeners: {
  182. render: {
  183. fn: function(){
  184. Ext.getCmp(this.ident+'filter').getEl().on('keyup', function() {
  185. this.filter();
  186. }, this, {buffer: 500});
  187. }
  188. ,scope: this
  189. }
  190. }
  191. },{
  192. text: _('sort_by')+':'
  193. ,xtype: 'label'
  194. },{
  195. id: this.ident+'sortSelect'
  196. ,xtype: 'combo'
  197. ,typeAhead: true
  198. ,triggerAction: 'all'
  199. ,width: 100
  200. ,editable: false
  201. ,mode: 'local'
  202. ,displayField: 'desc'
  203. ,valueField: 'name'
  204. ,lazyInit: false
  205. ,value: MODx.config.modx_browser_default_sort || 'name'
  206. ,store: new Ext.data.SimpleStore({
  207. fields: ['name', 'desc'],
  208. data : [
  209. ['name', _('name')]
  210. ,['size', _('file_size')]
  211. ,['lastmod', _('last_modified')]
  212. ]
  213. })
  214. ,listeners: {
  215. select: {
  216. fn: this.sortStore
  217. ,scope: this
  218. }
  219. }
  220. }, '-', {
  221. text: _('files_viewmode')+':'
  222. ,xtype: 'label'
  223. }, '-', {
  224. id: this.ident+'viewSelect'
  225. ,xtype: 'combo'
  226. ,typeAhead: false
  227. ,triggerAction: 'all'
  228. ,width: 100
  229. ,editable: false
  230. ,mode: 'local'
  231. ,displayField: 'desc'
  232. ,valueField: 'type'
  233. ,lazyInit: false
  234. ,value: MODx.config.modx_browser_default_viewmode || 'grid'
  235. ,store: new Ext.data.SimpleStore({
  236. fields: ['type', 'desc'],
  237. data : [['grid', _('files_viewmode_grid')],['list', _('files_viewmode_list')]]
  238. })
  239. ,listeners: {
  240. 'select': {fn:this.changeViewmode, scope:this}
  241. }
  242. }];
  243. }
  244. });
  245. Ext.reg('modx-media-view', MODx.Media);