[ADD] web: special = save on form buttons

Add support for value 'save' to attribute 'special' for buttons in
form view. This is useful for form views in dialogs. When clicked,
it saves the form view and closes the dialog (the default 'Save'
button doesn't close the dialog). Without this, the only way to
achieve that was to define a dummy python method and call it with
<button type="object" name="dummy_method"/>.
This commit is contained in:
Simon Lejeune
2017-05-30 13:04:06 +02:00
committed by Aaron Bohy
parent 2742722d36
commit a0c16e9cd2
4 changed files with 45 additions and 5 deletions
@@ -547,7 +547,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
*
* @param {Object} action_data the action descriptor data
* @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
* @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
* @param {String} [action_data.special=null] special action handlers, closes the dialog if set
* @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
* @param {Object} [action_data.context=null] additional action context, to add to the current context
* @param {DataSet} dataset a dataset object used to communicate with the server
@@ -589,7 +589,7 @@ var ViewManager = Widget.extend(ControlPanelMixin, {
}
};
if (action_data.special === 'cancel') {
if (action_data.special) {
return handler({"type":"ir.actions.act_window_close"});
} else if (action_data.type === "object") {
var args = record_id ? [[record_id]] : [this.env.ids];
@@ -334,9 +334,9 @@ var FormController = BasicController.extend({
d.resolve();
});
def = d.promise();
} else if (attrs.special) {
} else if (attrs.special === 'cancel') {
def = this._callButtonAction(attrs, event.data.record);
} else {
} else if (!attrs.special || attrs.special === 'save') {
// save the record but don't switch to readonly mode
def = this.saveRecord(this.handle, {
stayInEdit: true,
@@ -1453,6 +1453,40 @@ QUnit.module('Views', {
form.$('button').eq(1).click();
assert.strictEqual(writeCount, 1, "should not have triggered a write");
assert.strictEqual(executeActionCount, 2, "should have triggered a execute action");
form.destroy();
});
QUnit.test('buttons with attr "special=save" save', function (assert) {
assert.expect(4);
var form = createView({
View: FormView,
model: 'partner',
data: this.data,
arch: '<form string="Partners">' +
'<field name="foo"/>' +
'<button string="Save" class="btn-primary" special="save"/>' +
'</form>',
res_id: 1,
intercepts: {
execute_action: function () {
assert.step('execute_action');
},
},
mockRPC: function (route, args) {
assert.step(args.method);
return this._super(route, args);
},
viewOptions: {
mode: 'edit',
},
});
form.$('input').val("tralala").trigger('input'); // make the record dirty
form.$('button').click(); // click on Save
assert.verifySteps(['read', 'write', 'execute_action']);
form.destroy();
});
+7 -1
View File
@@ -350,7 +350,13 @@ system. Available semantic components are:
``button``
call into the Odoo system, similar to :ref:`list view buttons
<reference/views/list/button>`
<reference/views/list/button>`. In addition, the following attribute can be
specified:
``special``
for form views opened in dialogs: ``save`` to save the record and close the
dialog, ``cancel`` to close the dialog without saving.
``field``
renders (and allow edition of, possibly) a single field of the current
record. Possible attributes are: