diff options
| author | qsm-odoo <qsm@odoo.com> | 2017-06-07 17:45:15 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2017-08-16 10:59:39 +0200 |
| commit | 4f925af06fd3cebfcfb56eb947ab68c8a2ca4490 (patch) | |
| tree | b13bd049b6b3e7bbdfb537d19b53c95fc4025ea5 /addons/website/static/src/js/widgets/ace.js | |
| parent | f205bfcd4ddcf3f1d8676ee87ee0b29941bd6773 (diff) | |
[MOV] web_editor, website: reorganize files
Diffstat (limited to 'addons/website/static/src/js/widgets/ace.js')
| -rw-r--r-- | addons/website/static/src/js/widgets/ace.js | 96 |
1 files changed, 96 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 00000000000..2ce486fc1c8 --- /dev/null +++ b/addons/website/static/src/js/widgets/ace.js @@ -0,0 +1,96 @@ +odoo.define('website.ace', function (require) { +'use strict'; + +var Widget = require('web.Widget'); +var website = require('website.website'); +var mixins = require('web.mixins'); + +var ViewEditor = require('web_editor.ace'); + +var hash = "#advanced-view-editor"; + +var Ace = Widget.extend(mixins.ServiceProvider, { + events: { + "click a[data-action=ace]": function (e) { + e.preventDefault(); + this.launchAce(); + }, + }, + init: function () { + mixins.ServiceProvider.init.apply(this, arguments); + this._super.apply(this, arguments); + }, + start: function () { + if (window.location.hash.substr(0, hash.length) === hash) { + this.launchAce(); + } + return this._super.apply(this, arguments); + }, + launchAce: function () { + if (this.globalEditor) { + this.globalEditor.do_show(); + } else { + var currentHash = window.location.hash; + var indexOfView = currentHash.indexOf("?res="); + var initialResID = undefined; + if (indexOfView >= 0) { + initialResID = currentHash.substr(indexOfView + ("?res=".length)); + var parsedResID = parseInt(initialResID, 10); + if (parsedResID) { + initialResID = parsedResID; + } + } + + this.globalEditor = new ViewEditor(this, $(document.documentElement).data('view-xmlid'), { + initialResID: initialResID, + defaultBundlesRestriction: [ + "web.assets_frontend", + "website.assets_frontend", + ], + }); + this.globalEditor.appendTo(document.body); + + $("a[data-action=edit]").on("click", this.globalEditor.do_hide.bind(this.globalEditor)); + } + }, +}); + +/** + * Extend the default view editor so that the URL hash is updated with view id. + */ +ViewEditor = ViewEditor.extend({ + displayResource: function () { + this._super.apply(this, arguments); + this._updateHash(); + }, + saveResources: function () { + return this._super.apply(this, arguments).then((function () { + this._updateHash(); + window.location.reload(); + }).bind(this)); + }, + resetResource: function () { + return this._super.apply(this, arguments).then((function () { + window.location.reload(); + }).bind(this)); + }, + do_hide: function () { + this._super.apply(this, arguments); + window.location.hash = ""; + }, + _updateHash: function () { + window.location.hash = hash + "?res=" + this.selectedResource(); + }, +}); + +website.TopBar.include({ + start: function () { + this.ace = new Ace(); + return $.when( + this._super.apply(this, arguments), + this.ace.attachTo(this.$('#html_editor')) + ); + }, +}); + +}); |
