Skip to content

Commit 5723f92

Browse files
committed
Added sort by processor
1 parent 6cd49ef commit 5723f92

6 files changed

Lines changed: 250 additions & 84 deletions

File tree

assets/components/fileman/js/mgr/widgets/files.grid.js

Lines changed: 137 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -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
},

core/components/fileman/lexicon/en/default.inc.php

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,12 @@
1010
$_lang['fileman_open'] = 'Open access';
1111
$_lang['fileman_private'] = 'Close access';
1212
$_lang['fileman_update'] = 'Edit';
13-
$_lang['fileman_reset_downloads'] = 'reset downloads';
13+
$_lang['fileman_reset_downloads'] = 'Reset downloads';
14+
$_lang['fileman_sortby_title'] = 'Sort by Title';
15+
$_lang['fileman_sortby_name'] = 'Sort by Name';
16+
$_lang['fileman_sortby_group'] = 'Sort by Group';
1417

15-
$_lang['fileman_btn_upload'] = '<i class="icon icon-upload"></i> Upload from drive';
18+
$_lang['fileman_btn_upload'] = '<i class="icon icon-upload"></i> Upload';
1619

1720
$_lang['fileman_window_upload_by_url_title'] = '<i class="icon icon-link"></i> Upload by link';
1821
$_lang['fileman_btn_upload_by_url'] = '<i class="icon icon-link"></i> Upload by link';

core/components/fileman/lexicon/ru/default.inc.php

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,12 @@
1111
$_lang['fileman_private'] = 'Закрыть доступ';
1212
$_lang['fileman_update'] = 'Редактировать';
1313
$_lang['fileman_reset_downloads'] = 'Сбросить счетчик загрузок';
14+
$_lang['fileman_sortby_title'] = 'Сортировать по Заголовоку';
15+
$_lang['fileman_sortby_name'] = 'Сортировать по Названию файла';
16+
$_lang['fileman_sortby_group'] = 'Сортировать по Группе';
1417

15-
$_lang['fileman_btn_upload'] = '<i class="icon icon-upload"></i> Загрузить с диска';
18+
19+
$_lang['fileman_btn_upload'] = '<i class="icon icon-upload"></i> Загрузить';
1620

1721
$_lang['fileman_window_upload_by_url_title'] = '<i class="icon icon-link"></i> Загрузить по ссылке';
1822
$_lang['fileman_btn_upload_by_url'] = '<i class="icon icon-link"></i> Загрузить по ссылке';

core/components/fileman/schema/fileman.mysql.schema.xml

Lines changed: 26 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -2,36 +2,39 @@
22
<model package="FileMan\Model" baseClass="xPDO\Om\xPDOObject" platform="mysql" defaultEngine="InnoDB" version="3.0">
33
<object class="File" table="fileman_files" extends="xPDO\Om\xPDOSimpleObject">
44
<field key="fid" dbtype="varchar" precision="40" phptype="string" null="false" default=""/>
5-
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
6-
<field key="internal_name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
5+
<field key="name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
6+
<field key="internal_name" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
77
<field key="extension" dbtype="varchar" precision="50" phptype="string" null="false" default=""/>
8-
<field key="path" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
8+
<field key="path" dbtype="varchar" precision="100" phptype="string" null="false" default=""/>
99
<field key="title" dbtype="varchar" precision="1023" phptype="string" null="false" default=""/>
1010
<field key="description" dbtype="text" phptype="string" null="false" default="" />
1111
<field key="group" dbtype="varchar" precision="255" phptype="string" null="false" default=""/>
12-
<field key="size" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
13-
<field key="hash" dbtype="varchar" precision="50" phptype="string" null="false" default=""/>
12+
<field key="size" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
13+
<field key="hash" dbtype="varchar" precision="50" phptype="string" null="false" default=""/>
1414

15-
<field key="private" dbtype="tinyint" precision="1" phptype="boolean" attributes="unsigned" null="false" default="0"/>
16-
<field key="download" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
15+
<field key="private" dbtype="tinyint" precision="1" phptype="boolean" attributes="unsigned" null="false" default="0"/>
16+
<field key="download" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
1717

18-
<field key="resource_id" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
19-
<field key="user_id" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
20-
<field key="sort_order" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
18+
<field key="resource_id" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
19+
<field key="user_id" dbtype="int" precision="10" phptype="integer" null="false" default="0"/>
20+
<field key="sort_order" dbtype="int" precision="10" phptype="integer" attributes="unsigned" null="false" default="0"/>
2121

22-
<index alias="fid" name="fid" primary="false" unique="false" type="BTREE">
23-
<column key="fid" length="" collation="A" null="false"/>
24-
</index>
25-
<index alias="name" name="name" primary="false" unique="false" type="BTREE">
26-
<column key="name" length="" collation="A" null="false"/>
27-
</index>
28-
<index alias="resource_id" name="resource_id" primary="false" unique="false" type="BTREE">
29-
<column key="resource_id" length="" collation="A" null="false"/>
30-
</index>
31-
<index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
32-
<column key="user_id" length="" collation="A" null="false"/>
33-
</index>
22+
<index alias="fid" name="fid" primary="false" unique="false" type="BTREE">
23+
<column key="fid" length="" collation="A" null="false"/>
24+
</index>
25+
<index alias="name" name="name" primary="false" unique="false" type="BTREE">
26+
<column key="name" length="" collation="A" null="false"/>
27+
</index>
28+
<index alias="resource_id" name="resource_id" primary="false" unique="false" type="BTREE">
29+
<column key="resource_id" length="" collation="A" null="false"/>
30+
</index>
31+
<index alias="user_id" name="user_id" primary="false" unique="false" type="BTREE">
32+
<column key="user_id" length="" collation="A" null="false"/>
33+
</index>
34+
<index alias="sort_order" name="sort_order" primary="false" unique="false" type="BTREE">
35+
<column key="sort_order" length="" collation="A" null="false"/>
36+
</index>
3437

35-
<aggregate alias="Resource" class="MODX\Revolution\modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign"/>
38+
<aggregate alias="Resource" class="MODX\Revolution\modResource" local="resource_id" foreign="id" cardinality="one" owner="foreign"/>
3639
</object>
3740
</model>

core/components/fileman/src/Model/mysql/File.php

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -225,6 +225,22 @@ class File extends \FileMan\Model\File
225225
),
226226
),
227227
),
228+
'sort_order' =>
229+
array (
230+
'alias' => 'sort_order',
231+
'primary' => false,
232+
'unique' => false,
233+
'type' => 'BTREE',
234+
'columns' =>
235+
array (
236+
'sort_order' =>
237+
array (
238+
'length' => '',
239+
'collation' => 'A',
240+
'null' => false,
241+
),
242+
),
243+
),
228244
),
229245
'aggregates' =>
230246
array (

0 commit comments

Comments
 (0)