diff --git a/src/screen.js b/src/screen.js index 7626e26..67e22e0 100644 --- a/src/screen.js +++ b/src/screen.js @@ -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)); }, diff --git a/src/tab.js b/src/tab.js index a928d4b..1bd5616 100644 --- a/src/tab.js +++ b/src/tab.js @@ -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('
  • ', { + 'class': 'ui-menu-item action_button' + }).append( + jQuery('').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() { diff --git a/src/view.js b/src/view.js index ce40004..9b9c7e3 100644 --- a/src/view.js +++ b/src/view.js @@ -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;