diff --git a/src/screen.js b/src/screen.js index 67e22e074e..051eeffba7 100644 --- a/src/screen.js +++ b/src/screen.js @@ -339,7 +339,9 @@ if (index < group.length - 1) { record = group[index + 1]; break; - } else if (group.parent) { + } else if (group.parent && + (record.group.model_name == + group.parent.group.model_name)) { record = group.parent; group = group.parent.group; } else { @@ -366,7 +368,9 @@ if (index > 0) { record = group[index - 1]; break; - } else if (group.parent) { + } else if (group.parent && + (record.group.model_name == + group.parent.group.model_name)) { record = group.parent; group = group.parent.group; } else { @@ -697,24 +701,54 @@ }, button: function(attributes) { // TODO confirm + var process_action = function(action) { + this.reload(ids, true); + if (typeof action == 'string') { + var access = Sao.common.MODELACCESS.get(this.model_name); + if (action == 'new') { + if (access.create) { + this.new_(); + } + } else if (action == 'delete') { + if (access['delete']) { + this.remove(!this.parent, false, !this.parent); + } + } else if (action == 'remove') { + if (access.write && access.read && this.parent) { + this.remove(false, true, false); + } + } else if (action == 'copy') { + if (access.create) { + this.copy(); + } + } else if (action == 'next') { + this.display_next(); + } else if (action == 'previous') { + this.display_previous(); + } else if (action == 'close') { + Sao.Tab.close_current(); + } else if (action.startsWith('switch')) { + var view_type = action.split(' ')[1]; + this.switch_view(view_type); + } + } + else if (action) { + Sao.Action.execute(action, { + model: this.model_name, + id: record.id, + ids: ids + }, null, this.context); + } + }; + var record = this.current_record; + var ids = this.current_view.selected_records().map( + function(record) { + return record.id; + }); record.save().done(function() { - var ids = this.current_view.selected_records().map( - function(record) { - return record.id; - }); record.model.execute(attributes.name, - [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, this.context); - } - this.reload(ids, true); - }.bind(this), + [ids], this.context).then(process_action.bind(this), function() { this.reload(ids, true); }.bind(this)); diff --git a/src/tab.js b/src/tab.js index 1bd5616e71..867a127487 100644 --- a/src/tab.js +++ b/src/tab.js @@ -139,6 +139,11 @@ } return jQuery.when(); }; + Sao.Tab.tabs.close_current = function() { + var tabs = jQuery('#tabs > div'); + var tab = Sao.Tab.tabs[tabs.tabs('option', 'active')]; + tab.close(); + }; Sao.Tab.create = function(attributes) { if (attributes.context === undefined) { diff --git a/src/wizard.js b/src/wizard.js index db55d6b6f4..25e59abf43 100644 --- a/src/wizard.js +++ b/src/wizard.js @@ -103,7 +103,7 @@ // TODO }, end: function() { - Sao.rpc({ + return Sao.rpc({ 'method': 'wizard.' + this.action + '.delete', 'params': [this.session_id, this.session.context] }, this.session); @@ -202,15 +202,15 @@ // TODO set size this.dialog.dialog('open'); }, - destroy: function() { + destroy: function(action) { Sao.Wizard.Dialog._super.destroy.call(this); this.dialog.dialog('destroy'); // TODO other dialogs - // TODO reload under screen + // TODO reload under screen and action }, end: function() { - Sao.Wizard.Dialog._super.end.call(this); - this.destroy(); + Sao.Wizard.Dialog._super.end.call(this).then( + this.destroy.bind(this)); }, show: function() { this.dialog.dialog('open');