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 = ''; 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', { '', 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; });