diff options
| author | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
|---|---|---|
| committer | stephanchrst <stephanchrst@gmail.com> | 2022-05-10 21:51:50 +0700 |
| commit | 3751379f1e9a4c215fb6eb898b4ccc67659b9ace (patch) | |
| tree | a44932296ef4a9b71d5f010906253d8c53727726 /addons/website/static/src/js/widgets | |
| parent | 0a15094050bfde69a06d6eff798e9a8ddf2b8c21 (diff) | |
initial commit 2
Diffstat (limited to 'addons/website/static/src/js/widgets')
| -rw-r--r-- | addons/website/static/src/js/widgets/ace.js | 92 | ||||
| -rw-r--r-- | addons/website/static/src/js/widgets/media.js | 14 |
2 files changed, 106 insertions, 0 deletions
diff --git a/addons/website/static/src/js/widgets/ace.js b/addons/website/static/src/js/widgets/ace.js new file mode 100644 index 00000000..177a4db3 --- /dev/null +++ b/addons/website/static/src/js/widgets/ace.js @@ -0,0 +1,92 @@ +odoo.define("website.ace", function (require) { +"use strict"; + +var AceEditor = require('web_editor.ace'); + +/** + * Extends the default view editor so that the URL hash is updated with view ID + */ +var WebsiteAceEditor = AceEditor.extend({ + hash: '#advanced-view-editor', + + //-------------------------------------------------------------------------- + // Public + //-------------------------------------------------------------------------- + + /** + * @override + */ + do_hide: function () { + this._super.apply(this, arguments); + window.location.hash = ""; + }, + + //-------------------------------------------------------------------------- + // Private + //-------------------------------------------------------------------------- + + /** + * @override + */ + _displayResource: function () { + this._super.apply(this, arguments); + this._updateHash(); + }, + /** + * @override + */ + _saveResources: function () { + return this._super.apply(this, arguments).then((function () { + var defs = []; + if (this.currentType === 'xml') { + // When saving a view, the view ID might change. Thus, the + // active ID in the URL will be incorrect. After the save + // reload, that URL ID won't be found and JS will crash. + // We need to find the new ID (either because the view became + // specific or because its parent was edited too and the view + // got copy/unlink). + var selectedView = _.findWhere(this.views, {id: this._getSelectedResource()}); + var context; + this.trigger_up('context_get', { + callback: function (ctx) { + context = ctx; + }, + }); + defs.push(this._rpc({ + model: 'ir.ui.view', + method: 'search_read', + fields: ['id'], + domain: [['key', '=', selectedView.key], ['website_id', '=', context.website_id]], + }).then((function (view) { + if (view[0]) { + this._updateHash(view[0].id); + } + }).bind(this))); + } + return Promise.all(defs).then((function () { + window.location.reload(); + return new Promise(function () {}); + })); + }).bind(this)); + }, + /** + * @override + */ + _resetResource: function () { + return this._super.apply(this, arguments).then((function () { + window.location.reload(); + return new Promise(function () {}); + }).bind(this)); + }, + /** + * Adds the current resource ID in the URL. + * + * @private + */ + _updateHash: function (resID) { + window.location.hash = this.hash + "?res=" + (resID || this._getSelectedResource()); + }, +}); + +return WebsiteAceEditor; +}); diff --git a/addons/website/static/src/js/widgets/media.js b/addons/website/static/src/js/widgets/media.js new file mode 100644 index 00000000..900f5306 --- /dev/null +++ b/addons/website/static/src/js/widgets/media.js @@ -0,0 +1,14 @@ +odoo.define('website.widgets.media', function (require) { +'use strict'; + +const {ImageWidget} = require('wysiwyg.widgets.media'); + +ImageWidget.include({ + _getAttachmentsDomain() { + const domain = this._super(...arguments); + domain.push('|', ['url', '=', false], '!', ['url', '=like', '/web/image/website.%']); + domain.push(['key', '=', false]); + return domain; + } +}); +}); |
