Add sort order field from Customize Form (#3284)
* Add sort order field from Customize Form - fixes support issue WN-SUP25048 * Handle case when meta_sort_field is undefined
This commit is contained in:
parent
44359d058d
commit
5c6483df97
1 changed files with 30 additions and 13 deletions
|
|
@ -91,16 +91,12 @@ frappe.ui.SortSelector = Class.extend({
|
|||
var me = this;
|
||||
var meta = frappe.get_meta(this.doctype);
|
||||
|
||||
var { meta_sort_field, meta_sort_order } = this.get_meta_sort_field();
|
||||
|
||||
if(!this.args.sort_by) {
|
||||
if(meta.sort_field) {
|
||||
if(meta.sort_field.indexOf(',')!==-1) {
|
||||
parts = meta.sort_field.split(',')[0].split(' ');
|
||||
this.args.sort_by = parts[0];
|
||||
this.args.sort_order = parts[1];
|
||||
} else {
|
||||
this.args.sort_by = meta.sort_field;
|
||||
this.args.sort_order = meta.sort_order.toLowerCase();
|
||||
}
|
||||
if(meta_sort_field) {
|
||||
this.args.sort_by = meta_sort_field;
|
||||
this.args.sort_order = meta_sort_order;
|
||||
} else {
|
||||
// default
|
||||
this.args.sort_by = 'modified';
|
||||
|
|
@ -115,7 +111,7 @@ frappe.ui.SortSelector = Class.extend({
|
|||
if(!this.args.options) {
|
||||
// default options
|
||||
var _options = [
|
||||
{'fieldname': 'modified'},
|
||||
{'fieldname': 'modified'}
|
||||
]
|
||||
|
||||
// title field
|
||||
|
|
@ -130,9 +126,15 @@ frappe.ui.SortSelector = Class.extend({
|
|||
}
|
||||
});
|
||||
|
||||
_options.push({'fieldname': 'name'});
|
||||
_options.push({'fieldname': 'creation'});
|
||||
_options.push({'fieldname': 'idx'});
|
||||
// meta sort field
|
||||
if(meta_sort_field) _options.push({ 'fieldname': meta_sort_field });
|
||||
|
||||
// more default options
|
||||
_options.push(
|
||||
{'fieldname': 'name'},
|
||||
{'fieldname': 'creation'},
|
||||
{'fieldname': 'idx'}
|
||||
)
|
||||
|
||||
// de-duplicate
|
||||
this.args.options = _options.uniqBy(function(obj) {
|
||||
|
|
@ -151,6 +153,21 @@ frappe.ui.SortSelector = Class.extend({
|
|||
this.sort_by = this.args.sort_by;
|
||||
this.sort_order = this.args.sort_order;
|
||||
},
|
||||
get_meta_sort_field: function() {
|
||||
var meta = frappe.get_meta(this.doctype);
|
||||
if(meta.sort_field && meta.sort_field.includes(',')) {
|
||||
var parts = meta.sort_field.split(',')[0].split(' ');
|
||||
return {
|
||||
meta_sort_field: parts[0],
|
||||
meta_sort_order: parts[1]
|
||||
}
|
||||
} else {
|
||||
return {
|
||||
meta_sort_field: meta.sort_field,
|
||||
meta_sort_order: meta.sort_order.toLowerCase()
|
||||
}
|
||||
}
|
||||
},
|
||||
get_label: function(fieldname) {
|
||||
if(fieldname==='idx') {
|
||||
return __("Most Used");
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue