Add buttons of the view in actions menu

This commit is contained in:
C?dric Krier 2014-02-13 19:53:33 +01:00
parent cfb1e85225
commit 605f64f560
3 changed files with 56 additions and 5 deletions

View file

@ -684,25 +684,39 @@
}
this.display();
},
get_buttons: function() {
var buttons = this.current_view.get_buttons();
this.current_view.selected_records().forEach(function(record) {
buttons = buttons.filter(function(button) {
var states = record.expr_eval(
button.attributes.states || {});
return !(states.invisible || states.readonly);
});
});
return buttons;
},
button: function(attributes) {
// TODO confirm
var record = this.current_record;
record.save().done(function() {
var context = record.get_context();
var ids = this.current_view.selected_records().map(
function(record) {
return record.id;
});
record.model.execute(attributes.name,
[[record.id]], context).then(
[ids], this.context).then(
function(action_id) {
if (action_id) {
Sao.Action.execute(action_id, {
model: this.model_name,
id: record.id,
ids: [record.id]
}, null, context);
}, null, this.context);
}
this.reload([record.id], true);
this.reload(ids, true);
}.bind(this),
function() {
this.reload([record.id], true);
this.reload(ids, true);
}.bind(this));
}.bind(this));
},

View file

@ -274,6 +274,21 @@
at: 'left bottom',
of: button
});
if (menu_action[0] == 'action') {
menu.find('.action_button').remove();
var buttons = screen.get_buttons();
buttons.forEach(function(button) {
var item = jQuery('<li/>', {
'class': 'ui-menu-item action_button'
}).append(
jQuery('<a/>').append(
button.attributes.string || ''));
menu.append(item);
item.click(function() {
screen.button(button.attributes);
});
});
}
// Bind hide after the processing of the current click
window.setTimeout(function() {
jQuery(document).one('click', function() {

View file

@ -14,6 +14,9 @@
},
get_fields: function() {
return Object.keys(this.fields);
},
get_buttons: function() {
return [];
}
});
@ -214,6 +217,15 @@
this.columns.push(column);
}.bind(this));
},
get_buttons: function() {
var buttons = [];
this.columns.forEach(function(column) {
if (column instanceof Sao.View.Tree.ButtonColumn) {
buttons.push(column);
}
});
return buttons;
},
display: function(selected, expanded) {
selected = selected || this.get_selected_paths();
expanded = expanded || [];
@ -1032,6 +1044,16 @@
this.state_widgets.push(group);
container.add(attributes, group);
},
get_buttons: function() {
var buttons = [];
for (var j in this.state_widgets) {
var widget = this.state_widgets[j];
if (widget instanceof Sao.common.Button) {
buttons.push(widget);
}
}
return buttons;
},
display: function() {
var record = this.screen.current_record;
var field;