mirror of
https://github.com/pgadmin-org/pgadmin4.git
synced 2025-02-25 18:55:31 -06:00
Resolved a bug with the menu enable/disble logic.
Also, do not generate list disabled menu in the context menu
This commit is contained in:
parent
605f9aba32
commit
dee3185bae
web/pgadmin/browser
@ -18,7 +18,7 @@ function(_, pgAdmin, $) {
|
||||
};
|
||||
|
||||
_.extend(pgAdmin.Browser.MenuItem.prototype, {
|
||||
generate: function() {
|
||||
generate: function(node) {
|
||||
var url = $('<a></a>', {
|
||||
'id': this.name,
|
||||
'href': this.url,
|
||||
@ -35,15 +35,17 @@ function(_, pgAdmin, $) {
|
||||
url.append($('<span></span>').text(' ' + this.label));
|
||||
|
||||
return $('<li/>')
|
||||
.addClass('menu-item')
|
||||
.addClass('menu-item' + (this.disabled(node) ? ' disabled' : ''))
|
||||
.append(url);
|
||||
},
|
||||
disabled: function(o) {
|
||||
if (_.isFunction(this.enable)) return !this.enable.apply(this.module, [this.data]);
|
||||
disabled: function(node) {
|
||||
if (this.enable == undefined)
|
||||
return false;
|
||||
|
||||
if (_.isBoolean(this.enable)) return !this.enable;
|
||||
if (_.isFunction(this.enable)) return !this.enable.apply(this.module, [node, this.data]);
|
||||
if (this.module && _.isBoolean(this.module[this.enable])) return !this.module[this.enable];
|
||||
if (this.module && _.isFunction(this.module[this.enable])) return !this.enable.apply(this.module, [this.data]);
|
||||
if (_.isFunction(o[this.enable])) return !this.enable.apply(o, [this.data]);
|
||||
if (this.module && _.isFunction(this.module[this.enable])) return !(this.module[this.enable]).apply(this.module, [node, this.data]);
|
||||
|
||||
return false;
|
||||
}
|
||||
|
@ -243,7 +243,7 @@ OWNER TO helpdesk;\n';
|
||||
function(v, k) {
|
||||
// Remove disabled class in any case first.
|
||||
e = j.find('#' + k).closest('.menu-item').removeClass('disabled');
|
||||
if (v.disabled(obj)) {
|
||||
if (v.disabled(d)) {
|
||||
// Make this menu disabled
|
||||
e.addClass('disabled');
|
||||
}
|
||||
@ -260,9 +260,9 @@ OWNER TO helpdesk;\n';
|
||||
function(o) { return o.priority; }),
|
||||
function(m) {
|
||||
if (m.category && m.category == 'create') {
|
||||
create_items.push(m.generate());
|
||||
create_items.push(m.generate(d));
|
||||
} else {
|
||||
obj_mnu.append(m.generate());
|
||||
obj_mnu.append(m.generate(d));
|
||||
}
|
||||
});
|
||||
// Create menus goes seperately
|
||||
@ -389,25 +389,27 @@ OWNER TO helpdesk;\n';
|
||||
_.each(
|
||||
_.sortBy(menus, function(m) { return m.priority; }),
|
||||
function(m) {
|
||||
if (m.category == 'create')
|
||||
if (m.category == 'create' && !m.disabled(d))
|
||||
createMenu[m.module.type + '_' + m.callback] = { name: m.label };
|
||||
});
|
||||
|
||||
menu["create"] = { "name": "{{ _('Create') }}" }
|
||||
menu["create"]["items"] = createMenu
|
||||
if (createMenu.length) {
|
||||
menu["create"] = { "name": "{{ _('Create') }}" };
|
||||
menu["create"]["items"] = createMenu;
|
||||
}
|
||||
|
||||
_.each(
|
||||
_.sortBy(menus, function(m) { return m.priority; }),
|
||||
function(m) {
|
||||
if (m.category != 'create')
|
||||
menu[m.module.type + '_' + m.callback] = { name: m.label };
|
||||
});
|
||||
_.each(
|
||||
_.sortBy(menus, function(m) { return m.priority; }),
|
||||
function(m) {
|
||||
if (m.category != 'create' && !m.disabled(d))
|
||||
menu[m.module.type + '_' + m.callback] = { name: m.label };
|
||||
});
|
||||
|
||||
return {
|
||||
return menu.length ? {
|
||||
autoHide: true,
|
||||
items: menu,
|
||||
callback: cb
|
||||
};
|
||||
} : undefined;
|
||||
}
|
||||
});
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user