sorted the select in permission manager as per translated string

This commit is contained in:
Manas Solanki 2017-08-24 15:21:15 +05:30
parent fc22c31ab0
commit 899fe860d1
4 changed files with 9 additions and 6 deletions

View file

@ -46,13 +46,13 @@ frappe.PermissionEngine = Class.extend({
var me = this;
this.doctype_select
= this.wrapper.page.add_select(__("Document Types"),
[{value: "", label: __("Select Document Type")+"..."}].concat(this.options.doctypes.sort()))
[{value: "", label: __("Select Document Type")+"..."}].concat(this.options.doctypes))
.change(function() {
frappe.set_route("permission-manager", $(this).val());
});
this.role_select
= this.wrapper.page.add_select(__("Roles"),
[__("Select Role")+"..."].concat(this.options.roles.sort()))
[__("Select Role")+"..."].concat(this.options.roles))
.change(function() {
me.refresh();
});

View file

@ -35,9 +35,12 @@ def get_roles_and_doctypes():
"restrict_to_domain": ("in", active_domains)
}, fields=["name"])
doctypes_list = [ {"label":_(d.get("name")), "value":d.get("name")} for d in doctypes]
roles_list = [ {"label":_(d.get("name")), "value":d.get("name")} for d in roles]
return {
"doctypes": [d.get("name") for d in doctypes],
"roles": [d.get("name") for d in roles]
"doctypes": sorted(doctypes_list, key=lambda d: d['label']),
"roles": sorted(roles_list, key=lambda d: d['label'])
}
@frappe.whitelist()

View file

@ -224,7 +224,7 @@ frappe.get_modal = function(title, content) {
(function($) {
$.fn.add_options = function(options_list) {
// create options
for(var i=0; i<options_list.length; i++) {
for(var i=0, j=options_list.length; i<j; i++) {
var v = options_list[i];
if (is_null(v)) {
var value = null;

View file

@ -369,7 +369,7 @@ frappe.ui.Page = Class.extend({
.appendTo(this.page_form);
},
add_select: function(label, options) {
var field = this.add_field({label:label, fieldtype:"Select"})
var field = this.add_field({label:label, fieldtype:"Select"});
return field.$wrapper.find("select").empty().add_options(options);
},
add_data: function(label) {