summaryrefslogtreecommitdiff
path: root/addons
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2017-07-27 10:30:40 +0200
committerGéry Debongnie <ged@odoo.com>2017-07-27 11:34:05 +0200
commitecdcc65a9080fee876ca9cd82ab6385988557205 (patch)
treea4ea3c7d7b1e6b96967d44a6f2982994435bf7c2 /addons
parent72ed3a153a1f4c718fee33ac8550298e8a29f6cd (diff)
[FIX] pad: force writing url, even if it did not change
Before this commit, the pad widget did not force the view to save the current value, since it did not change (pad values are just the url for the pad). However, this is a problem for the server, since it uses the fact that the web client forces a save to update the description field in the model (get the data from the pad server and add it to the database). This was not a big deal when looking at the pad (the pad widget fetches its data each time), but it is a problem that the database is not synchronized with the current data.
Diffstat (limited to 'addons')
-rw-r--r--addons/pad/static/src/js/pad.js24
-rw-r--r--addons/pad/static/tests/pad_tests.js12
2 files changed, 33 insertions, 3 deletions
diff --git a/addons/pad/static/src/js/pad.js b/addons/pad/static/src/js/pad.js
index b59f3f0bc04..4068ff24ead 100644
--- a/addons/pad/static/src/js/pad.js
+++ b/addons/pad/static/src/js/pad.js
@@ -39,6 +39,25 @@ var FieldPad = AbstractField.extend({
this.$(".oe_configured").addClass('hidden');
return;
}
+ if (this.mode === 'edit' && _.str.startsWith(this.value, 'http')) {
+ this.url = this.value;
+ // please close your eyes and look elsewhere...
+ // Since the pad value (the url) will not change during the edition
+ // process, we have a problem: the description field will not be
+ // properly updated. We need to explicitely write the value each
+ // time someone edit the record in order to force the server to read
+ // the updated value of the pad and put it in the description field.
+ //
+ // However, the basic model optimizes away the changes if they are
+ // not really different from the current value. So, we need to
+ // either add special configuration options to the basic model, or
+ // to trick him into accepting the same value as being different...
+ // Guess what we decided...
+ var url = {};
+ url.toJSON = _.constant(this.url);
+ this._setValue(url);
+ }
+
return this._super.apply(this, arguments);
},
@@ -75,11 +94,11 @@ var FieldPad = AbstractField.extend({
* @private
*/
_renderEdit: function () {
- if (_.str.startsWith(this.value, 'http')) {
+ if (this.url) {
// here, we have a valid url, so we can simply display an iframe
// with the correct src attribute
var userName = encodeURIComponent(this.getSession().userName);
- var url = this.value + '?showChat=false&userName=' + userName;
+ var url = this.url + '?showChat=false&userName=' + userName;
var content = '<iframe width="100%" height="100%" frameborder="0" src="' + url + '"></iframe>';
this.$('.oe_pad_content').html(content);
} else if (this.value) {
@@ -111,6 +130,7 @@ var FieldPad = AbstractField.extend({
// We need to write the url of the pad to trigger
// the write function which updates the actual value
// of the field to the value of the pad content
+ self.url = result.url;
self._setValue(result.url, {doNotSetDirty: true});
});
}
diff --git a/addons/pad/static/tests/pad_tests.js b/addons/pad/static/tests/pad_tests.js
index 2aa8f7fe1db..5d18e55c1e0 100644
--- a/addons/pad/static/tests/pad_tests.js
+++ b/addons/pad/static/tests/pad_tests.js
@@ -112,7 +112,7 @@ QUnit.module('pad widget', {
});
QUnit.test('pad widget works, with existing data', function (assert) {
- assert.expect(2);
+ assert.expect(3);
var contentDef = $.Deferred();
@@ -129,10 +129,17 @@ QUnit.module('pad widget', {
'</form>',
res_id: 2,
mockRPC: function (route, args) {
+ if (_.str.startsWith(route, 'http')) {
+ return $.when(true);
+ }
var result = this._super.apply(this, arguments);
if (args.method === 'pad_get_content') {
return contentDef.then(_.constant(result));
}
+ if (args.method === 'write') {
+ assert.ok('description' in args.args[1],
+ "should always send the description value");
+ }
return result;
},
session: {
@@ -144,6 +151,9 @@ QUnit.module('pad widget', {
contentDef.resolve();
assert.strictEqual(form.$('.oe_pad_content').text(), "we should rewrite this server in haskell",
"should display proper value");
+
+ form.$buttons.find('.o_form_button_edit').click();
+ form.$buttons.find('.o_form_button_save').click();
form.destroy();
delete FieldPad.prototype.isPadConfigured;
});