[TESTS] add some
bzr revid: xmo@openerp.com-20120705070854-tsyl27v3hdh7sbds
This commit is contained in:
parent
b289447826
commit
09bf459bbc
|
@ -125,12 +125,13 @@ openerp.web.list_editable = function (instance) {
|
|||
}
|
||||
var $recordRow = this.groups.getRowFor(record);
|
||||
var cells = this.getCellsFor($recordRow);
|
||||
|
||||
return this.ensureSaved().pipe(function () {
|
||||
return self.withEvent('edit', {
|
||||
record: record.attributes,
|
||||
cancel: false
|
||||
}, self.editor.edit,
|
||||
[record.attributes, function (field_name, field) {
|
||||
}, function () {
|
||||
return self.editor.edit(record.attributes, function (field_name, field) {
|
||||
var cell = cells[field_name];
|
||||
if (!cell || field.get('effective_readonly')) {
|
||||
// Readonly fields can just remain the list's, form's
|
||||
|
@ -147,10 +148,11 @@ openerp.web.list_editable = function (instance) {
|
|||
width: $cell.outerWidth(),
|
||||
minHeight: $cell.outerHeight()
|
||||
});
|
||||
}],
|
||||
[record.attributes]);
|
||||
}).then(function () {
|
||||
$recordRow.addClass('oe_edition')
|
||||
}).pipe(function () {
|
||||
$recordRow.addClass('oe_edition');
|
||||
return record.attributes;
|
||||
});
|
||||
});
|
||||
});
|
||||
},
|
||||
getCellsFor: function ($row) {
|
||||
|
@ -165,12 +167,12 @@ openerp.web.list_editable = function (instance) {
|
|||
*/
|
||||
saveEdition: function () {
|
||||
var self = this;
|
||||
// TODO: save:after should be invoked after reload
|
||||
return this.withEvent('save', {
|
||||
editor: this.editor,
|
||||
form: this.editor.form,
|
||||
cancel: false
|
||||
}, this.editor.save).pipe(function (attrs) {
|
||||
}, function () {
|
||||
return this.editor.save().pipe(function (attrs) {
|
||||
var created = false;
|
||||
var record = self.records.get(attrs.id);
|
||||
if (!record) {
|
||||
|
@ -180,12 +182,14 @@ openerp.web.list_editable = function (instance) {
|
|||
return !r.get('id');
|
||||
}).set('id', attrs.id);
|
||||
}
|
||||
// onwrite callback could be altering & reloading the record
|
||||
// which has *just* been saved, so first perform all onwrites
|
||||
// then do a final reload of the record
|
||||
// onwrite callback could be altering & reloading the
|
||||
// record which has *just* been saved, so first perform all
|
||||
// onwrites then do a final reload of the record
|
||||
return self.handleOnWrite(record)
|
||||
.pipe(function () { return self.reload_record(record); })
|
||||
.pipe(function () { return { created: created, record: record };
|
||||
.pipe(function () {
|
||||
return self.reload_record(record); })
|
||||
.pipe(function () {
|
||||
return { created: created, record: record }; });
|
||||
});
|
||||
});
|
||||
},
|
||||
|
@ -198,7 +202,8 @@ openerp.web.list_editable = function (instance) {
|
|||
editor: this.editor,
|
||||
form: this.editor.form,
|
||||
cancel: false
|
||||
}, this.editor.cancel).then(function (attrs) {
|
||||
}, function () {
|
||||
return this.editor.cancel().pipe(function (attrs) {
|
||||
if (attrs.id) {
|
||||
return self.reload_record(self.records.get(attrs.id));
|
||||
}
|
||||
|
@ -209,6 +214,7 @@ openerp.web.list_editable = function (instance) {
|
|||
self.records.remove(to_delete);
|
||||
}
|
||||
});
|
||||
});
|
||||
},
|
||||
/**
|
||||
* Executes an action on the view's editor bracketed by a cancellable
|
||||
|
@ -227,7 +233,7 @@ openerp.web.list_editable = function (instance) {
|
|||
* @param {Array} [trigger_params] supplementary arguments provided to the ``:after`` sub-event, before anything fetched by the ``action`` function
|
||||
* @return {jQuery.Deferred}
|
||||
*/
|
||||
withEvent: function (event_name, event, action, args, trigger_params) {
|
||||
withEvent: function (event_name, event, action) {
|
||||
var self = this;
|
||||
event = event || {};
|
||||
this.trigger(event_name + ':before', event);
|
||||
|
@ -236,9 +242,8 @@ openerp.web.list_editable = function (instance) {
|
|||
message: _.str.sprintf("Event %s:before cancelled",
|
||||
event_name)});
|
||||
}
|
||||
return $.when(action.apply(this.editor, args || [])).then(function () {
|
||||
return $.when(action.call(this)).then(function () {
|
||||
self.trigger.apply(self, [event_name + ':after']
|
||||
.concat(trigger_params || [])
|
||||
.concat(_.toArray(arguments)));
|
||||
});
|
||||
},
|
||||
|
|
|
@ -185,4 +185,54 @@ $(document).ready(function () {
|
|||
ok(e.isEditing(), "should have kept editing");
|
||||
})
|
||||
});
|
||||
|
||||
module('list-edition-events', {
|
||||
setup: function () {
|
||||
baseSetup();
|
||||
_.extend(instance.connection.responses, {
|
||||
'/web/listview/load': function () {
|
||||
return {result: {
|
||||
type: 'tree',
|
||||
fields: {
|
||||
a: {type: 'char', string: "A"},
|
||||
b: {type: 'char', string: "B"},
|
||||
c: {type: 'char', string: "C"}
|
||||
},
|
||||
arch: {
|
||||
tag: 'tree',
|
||||
attrs: {},
|
||||
children: [
|
||||
{tag: 'field', attrs: {name: 'a'}},
|
||||
{tag: 'field', attrs: {name: 'b'}},
|
||||
{tag: 'field', attrs: {name: 'c'}}
|
||||
]
|
||||
}
|
||||
}};
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
asyncTest('edition events', function () {
|
||||
var ds = new instance.web.DataSetStatic(null, 'demo', null, [1]);
|
||||
var o = {
|
||||
counter: 0,
|
||||
onEvent: function (e) { this.counter++; }
|
||||
};
|
||||
var l = new instance.web.ListView(null, ds);
|
||||
l.set_editable(true);
|
||||
l.on('edit:before edit:after', o, o.onEvent);
|
||||
l.appendTo($fix)
|
||||
.always(start)
|
||||
.pipe(function () {
|
||||
ok(l.options.editable, "should be editable");
|
||||
equal(o.counter, 0, "should have seen no event yet");
|
||||
return l.startEdition();
|
||||
})
|
||||
.pipe(function () {
|
||||
ok(l.editor.isEditing(), "should be editing");
|
||||
equal(o.counter, 2, "should have seen two edition events");
|
||||
})
|
||||
.fail(function (e) { ok(false, e && e.message); });
|
||||
});
|
||||
// TODO: test cancelling edition events
|
||||
});
|
||||
|
|
Loading…
Reference in New Issue