@@ -236,6 +236,48 @@ Ext.extend(FileMan.grid.Files, MODx.grid.Grid, {
236236 return true ;
237237 } ,
238238
239+ // Sort by handler
240+ sortByHandler : function ( act , btn , e ) {
241+ let field = '' ;
242+ switch ( act . name ) {
243+ case 'sortby_title' :
244+ field = 'title' ;
245+ break ;
246+ case 'sortby_name' :
247+ field = 'name' ;
248+ break ;
249+ case 'sortby_group' :
250+ field = 'group' ;
251+ break ;
252+ default :
253+ return false ;
254+ }
255+ var ids = this . _getSelectedIds ( ) ;
256+
257+ MODx . Ajax . request ( {
258+ url : this . config . url ,
259+ params : {
260+ action : 'File\\SortBy' ,
261+ field : field ,
262+ resource : FileMan . config . resource_id ,
263+ ids : Ext . util . JSON . encode ( ids )
264+ } ,
265+ listeners : {
266+ success : {
267+ fn : function ( r ) {
268+ this . refresh ( ) ;
269+ } , scope : this
270+ } ,
271+ failure : {
272+ fn : function ( r ) {
273+ } , scope : this
274+ }
275+ }
276+ } ) ;
277+
278+ return true ;
279+ } ,
280+
239281 // Remove file
240282 removeFile : function ( act , btn , e ) {
241283 var ids = this . _getSelectedIds ( ) ;
@@ -370,7 +412,7 @@ Ext.extend(FileMan.grid.Files, MODx.grid.Grid, {
370412 getTopBar : function ( config ) {
371413 var fields = [ ] ;
372414
373- if ( FileMan . config . resource_id )
415+ if ( FileMan . config . resource_id ) {
374416 fields . push ( {
375417 xtype : 'button' ,
376418 cls : 'primary-button' ,
@@ -385,76 +427,113 @@ Ext.extend(FileMan.grid.Files, MODx.grid.Grid, {
385427 scope : this ,
386428 handler : this . showUploadByUrlWindow
387429 } ) ;
430+ }
388431
389- fields . push ( {
390- xtype : 'splitbutton' ,
391- text : _ ( 'remove' ) ,
392- menu : [
393- {
394- name : 'open' ,
395- text : _ ( 'fileman_open' ) ,
396- handler : this . accessFile ,
397- scope : this
398- } ,
432+ let bulk_actions = [
433+ {
434+ name : 'open' ,
435+ text : _ ( 'fileman_open' ) ,
436+ handler : this . accessFile ,
437+ scope : this
438+ } ,
439+ {
440+ name : 'close' ,
441+ text : _ ( 'fileman_private' ) ,
442+ handler : this . accessFile ,
443+ scope : this
444+ } ,
445+ '-' ,
446+ {
447+ text : _ ( 'fileman_reset_downloads' ) ,
448+ handler : this . resetFileDownloads ,
449+ scope : this
450+ }
451+ ] ;
452+
453+ // sort actions
454+ if ( FileMan . config . resource_id ) {
455+ bulk_actions . push (
456+ '-' ,
399457 {
400- name : 'close ' ,
401- text : _ ( 'fileman_private ' ) ,
402- handler : this . accessFile ,
458+ name : 'sortby_title ' ,
459+ text : _ ( 'fileman_sortby_title ' ) ,
460+ handler : this . sortByHandler ,
403461 scope : this
404462 } ,
405- '-' ,
406463 {
407- text : _ ( 'fileman_reset_downloads' ) ,
408- handler : this . resetFileDownloads ,
464+ name : 'sortby_name' ,
465+ text : _ ( 'fileman_sortby_name' ) ,
466+ handler : this . sortByHandler ,
409467 scope : this
410468 } ,
411469 {
412- text : _ ( 'remove' ) ,
413- handler : this . removeFile ,
470+ name : 'sortby_group' ,
471+ text : _ ( 'fileman_sortby_group' ) ,
472+ handler : this . sortByHandler ,
414473 scope : this
415474 }
416- ] ,
417- text : _ ( 'bulk_actions' )
418- } , '->' , {
419- xtype : 'textfield' ,
420- name : 'user' ,
421- width : 200 ,
422- id : config . id + '-search-user-field' ,
423- emptyText : _ ( 'user' ) ,
424- listeners : {
425- render : {
426- fn : function ( tf ) {
427- tf . getEl ( ) . addKeyListener ( Ext . EventObject . ENTER ,
428- function ( ) {
429- this . _doSearch ( tf ) ;
430- } , this ) ;
431- } , scope : this
432- }
475+ ) ;
476+ }
477+
478+ // remove action
479+ bulk_actions . push (
480+ '-' ,
481+ {
482+ text : _ ( 'remove' ) ,
483+ handler : this . removeFile ,
484+ scope : this
433485 }
434- } , {
435- xtype : 'textfield' ,
436- name : 'query' ,
437- width : 200 ,
438- id : config . id + '-search-field' ,
439- emptyText : _ ( 'search' ) ,
440- listeners : {
441- render : {
442- fn : function ( tf ) {
443- tf . getEl ( ) . addKeyListener ( Ext . EventObject . ENTER ,
444- function ( ) {
445- this . _doSearch ( tf ) ;
446- } , this ) ;
447- } , scope : this
486+ ) ;
487+
488+ fields . push (
489+ {
490+ text : _ ( 'bulk_actions' ) ,
491+ menu : bulk_actions
492+ } ,
493+ '->' ,
494+ {
495+ xtype : 'textfield' ,
496+ name : 'user' ,
497+ width : 160 ,
498+ id : config . id + '-search-user-field' ,
499+ emptyText : _ ( 'user' ) ,
500+ listeners : {
501+ render : {
502+ fn : function ( tf ) {
503+ tf . getEl ( ) . addKeyListener ( Ext . EventObject . ENTER ,
504+ function ( ) {
505+ this . _doSearch ( tf ) ;
506+ } , this ) ;
507+ } , scope : this
508+ }
509+ }
510+ } ,
511+ {
512+ xtype : 'textfield' ,
513+ name : 'query' ,
514+ width : 160 ,
515+ id : config . id + '-search-field' ,
516+ emptyText : _ ( 'search' ) ,
517+ listeners : {
518+ render : {
519+ fn : function ( tf ) {
520+ tf . getEl ( ) . addKeyListener ( Ext . EventObject . ENTER ,
521+ function ( ) {
522+ this . _doSearch ( tf ) ;
523+ } , this ) ;
524+ } , scope : this
525+ }
526+ }
527+ } ,
528+ {
529+ xtype : 'button' ,
530+ id : config . id + '-search-clear' ,
531+ text : '<i class="icon icon-times"></i>' ,
532+ listeners : {
533+ click : { fn : this . _clearSearch , scope : this }
448534 }
449535 }
450- } , {
451- xtype : 'button' ,
452- id : config . id + '-search-clear' ,
453- text : '<i class="icon icon-times"></i>' ,
454- listeners : {
455- click : { fn : this . _clearSearch , scope : this }
456- }
457- } ) ;
536+ ) ;
458537
459538 return fields ;
460539 } ,
0 commit comments