Pass the tree item object to the menu objects, which could be used by

the disabled function to make it enable/disable based on the current
selected item.
pull/3/head
Ashesh Vashi 2016-01-04 17:22:01 +05:30
parent b309b1ffb8
commit 84843f8c37
2 changed files with 11 additions and 12 deletions

View File

@ -18,7 +18,7 @@ function(_, pgAdmin, $) {
};
_.extend(pgAdmin.Browser.MenuItem.prototype, {
generate: function(node) {
generate: function(node, item) {
var url = $('<a></a>', {
'id': this.name,
'href': this.url,
@ -35,17 +35,17 @@ function(_, pgAdmin, $) {
url.append($('<span></span>').text(' ' + this.label));
return $('<li/>')
.addClass('menu-item' + (this.disabled(node) ? ' disabled' : ''))
.addClass('menu-item' + (this.disabled(node, item) ? ' disabled' : ''))
.append(url);
},
disabled: function(node) {
disabled: function(node, item) {
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 (_.isFunction(this.enable)) return !this.enable.apply(this.module, [node, item, 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.module[this.enable]).apply(this.module, [node, this.data]);
if (this.module && _.isFunction(this.module[this.enable])) return !(this.module[this.enable]).apply(this.module, [node, item, this.data]);
return false;
}

View File

@ -248,7 +248,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(d)) {
if (v.disabled(d, item)) {
// Make this menu disabled
e.addClass('disabled');
}
@ -265,9 +265,9 @@ OWNER TO helpdesk;\n';
function(o) { return o.priority; }),
function(m) {
if (m.category && m.category == 'create') {
create_items.push(m.generate(d));
create_items.push(m.generate(d, item));
} else {
obj_mnu.append(m.generate(d));
obj_mnu.append(m.generate(d, item));
}
});
// Create menus goes seperately
@ -393,8 +393,7 @@ OWNER TO helpdesk;\n';
}
if (cb) {
var args = {item: item};
cb.apply(o.module, [_.extend(args, o.data)]);
cb.apply(o.module, [o.data, item]);
} else {
pgAdmin.Browser.report_error(
S('Developer Warning: Callback - "%s" not found!').
@ -406,7 +405,7 @@ OWNER TO helpdesk;\n';
_.each(
_.sortBy(menus, function(m) { return m.priority; }),
function(m) {
if (m.category == 'create' && !m.disabled(d)) {
if (m.category == 'create' && !m.disabled(d, item)) {
createMenu[m.module.type + '_' + m.name] = { name: m.label, icon: m.icon || m.module.type };
}
});
@ -419,7 +418,7 @@ OWNER TO helpdesk;\n';
_.each(
_.sortBy(menus, function(m) { return m.priority; }),
function(m) {
if (m.category != 'create' && !m.disabled(d)) {
if (m.category != 'create' && !m.disabled(d, item)) {
menu[m.module.type + '_' + m.name] = { name: m.label, icon: m.icon };
}
});