Browse Source

Merge pull request #3990 from manassolanki/listview-sorting

sorted the select field options in permission manager as per translated string
version-14
Rushabh Mehta 7 years ago
committed by GitHub
parent
commit
0214a3717a
5 changed files with 15 additions and 12 deletions
  1. +2
    -2
      frappe/core/page/permission_manager/permission_manager.js
  2. +5
    -2
      frappe/core/page/permission_manager/permission_manager.py
  3. +1
    -1
      frappe/public/js/frappe/dom.js
  4. +1
    -1
      frappe/public/js/frappe/ui/page.js
  5. +6
    -6
      frappe/tests/test_domainification.py

+ 2
- 2
frappe/core/page/permission_manager/permission_manager.js View File

@@ -46,13 +46,13 @@ frappe.PermissionEngine = Class.extend({
var me = this; var me = this;
this.doctype_select this.doctype_select
= this.wrapper.page.add_select(__("Document Types"), = 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() { .change(function() {
frappe.set_route("permission-manager", $(this).val()); frappe.set_route("permission-manager", $(this).val());
}); });
this.role_select this.role_select
= this.wrapper.page.add_select(__("Roles"), = this.wrapper.page.add_select(__("Roles"),
[__("Select Role")+"..."].concat(this.options.roles.sort()))
[__("Select Role")+"..."].concat(this.options.roles))
.change(function() { .change(function() {
me.refresh(); me.refresh();
}); });


+ 5
- 2
frappe/core/page/permission_manager/permission_manager.py View File

@@ -35,9 +35,12 @@ def get_roles_and_doctypes():
"restrict_to_domain": ("in", active_domains) "restrict_to_domain": ("in", active_domains)
}, fields=["name"]) }, 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 { 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() @frappe.whitelist()


+ 1
- 1
frappe/public/js/frappe/dom.js View File

@@ -224,7 +224,7 @@ frappe.get_modal = function(title, content) {
(function($) { (function($) {
$.fn.add_options = function(options_list) { $.fn.add_options = function(options_list) {
// create options // 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]; var v = options_list[i];
if (is_null(v)) { if (is_null(v)) {
var value = null; var value = null;


+ 1
- 1
frappe/public/js/frappe/ui/page.js View File

@@ -369,7 +369,7 @@ frappe.ui.Page = Class.extend({
.appendTo(this.page_form); .appendTo(this.page_form);
}, },
add_select: function(label, options) { 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); return field.$wrapper.find("select").empty().add_options(options);
}, },
add_data: function(label) { add_data: function(label) {


+ 6
- 6
frappe/tests/test_domainification.py View File

@@ -92,8 +92,8 @@ class TestDomainification(unittest.TestCase):


# doctype should be hidden in desktop icon, role permissions # doctype should be hidden in desktop icon, role permissions
results = get_roles_and_doctypes() results = get_roles_and_doctypes()
self.assertTrue("Test Domainification" in results.get("doctypes"))
self.assertTrue("_Test Role" in results.get("roles"))
self.assertTrue("Test Domainification" in [d.get("value") for d in results.get("doctypes")])
self.assertTrue("_Test Role" in [d.get("value") for d in results.get("roles")])


self.add_active_domain("_Test Domain 2") self.add_active_domain("_Test Domain 2")
test_doctype.restrict_to_domain = "_Test Domain 2" test_doctype.restrict_to_domain = "_Test Domain 2"
@@ -103,14 +103,14 @@ class TestDomainification(unittest.TestCase):
test_role.save() test_role.save()


results = get_roles_and_doctypes() results = get_roles_and_doctypes()
self.assertTrue("Test Domainification" in results.get("doctypes"))
self.assertTrue("_Test Role" in results.get("roles"))
self.assertTrue("Test Domainification" in [d.get("value") for d in results.get("doctypes")])
self.assertTrue("_Test Role" in [d.get("value") for d in results.get("roles")])


self.remove_from_active_domains("_Test Domain 2") self.remove_from_active_domains("_Test Domain 2")
results = get_roles_and_doctypes() results = get_roles_and_doctypes()


self.assertTrue("Test Domainification" not in results.get("doctypes"))
self.assertTrue("_Test Role" not in results.get("roles"))
self.assertTrue("Test Domainification" not in [d.get("value") for d in results.get("doctypes")])
self.assertTrue("_Test Role" not in [d.get("value") for d in results.get("roles")])


def test_desktop_icon_for_domainification(self): def test_desktop_icon_for_domainification(self):
""" desktop icon should be hidden if doctype's restrict to domain is not in active domains """ """ desktop icon should be hidden if doctype's restrict to domain is not in active domains """


Loading…
Cancel
Save