diff options
| author | qsm-odoo <qsm@odoo.com> | 2016-05-18 18:02:51 +0200 |
|---|---|---|
| committer | qsm-odoo <qsm@odoo.com> | 2016-07-04 17:23:59 +0200 |
| commit | 62fb1bb92493b00bd45ed3f4eced5ca8b23f81d6 (patch) | |
| tree | 911fcb10158fa89ddd75ff2aac195f79236f3e59 /addons/web_editor/static/src/js/editor.js | |
| parent | c1ab17337bdc816222be372aff314fcf5de8ba92 (diff) | |
[REF] web_editor: code refactoring and simplification
* Remove dead code + optimization
* Use Dialog API from web module
* Reorganize files
* Correct buggy $() function for snippet option class
* Add comments
* Fix the snippet parent navigation :
If a page contained a three level snippet structure (i.e A contains
B contains C), when editing the following bug occured :
If B or C was selected first, parenting buttons were correctly set.
But if selecting A then C, clicking on the parent lead to going back
on A instead of going on B.
* Fix snippet thumbnail layout
* Better isolate ui css from themes
* MediaDialog image list : prevent displaying empty attachments
* ...
Diffstat (limited to 'addons/web_editor/static/src/js/editor.js')
| -rw-r--r-- | addons/web_editor/static/src/js/editor.js | 52 |
1 files changed, 21 insertions, 31 deletions
diff --git a/addons/web_editor/static/src/js/editor.js b/addons/web_editor/static/src/js/editor.js index 9e842bed4bc..9dd08c3abd5 100644 --- a/addons/web_editor/static/src/js/editor.js +++ b/addons/web_editor/static/src/js/editor.js @@ -2,6 +2,7 @@ odoo.define('web_editor.editor', function (require) { "use strict"; var ajax = require('web.ajax'); +var Dialog = require('web.Dialog'); var Widget = require('web.Widget'); var core = require('web.core'); var base = require('web_editor.base'); @@ -19,23 +20,22 @@ editor.editable = !!$('html').data('editable'); ajax.loadXML('/web_editor/static/src/xml/editor.xml', qweb); - $(document).on('click', '.note-editable', function (ev) { - ev.preventDefault(); - }); +$(document).on('click', '.note-editable', function (ev) { + ev.preventDefault(); +}); - $(document).on('submit', '.note-editable form .btn', function (ev) { - // Disable form submition in editable mode - ev.preventDefault(); - }); +$(document).on('submit', '.note-editable form .btn', function (ev) { + ev.preventDefault(); // Disable form submition in editable mode +}); - $(document).on('hide.bs.dropdown', '.dropdown', function (ev) { - // Prevent dropdown closing when a contenteditable children is focused - if (ev.originalEvent - && $(ev.target).has(ev.originalEvent.target).length - && $(ev.originalEvent.target).is('[contenteditable]')) { - ev.preventDefault(); - } - }); +$(document).on('hide.bs.dropdown', '.dropdown', function (ev) { + // Prevent dropdown closing when a contenteditable children is focused + if (ev.originalEvent + && $(ev.target).has(ev.originalEvent.target).length + && $(ev.originalEvent.target).is('[contenteditable]')) { + ev.preventDefault(); + } +}); ////////////////////////////////////////////////////////////////////////////////////////////////////////// @@ -76,8 +76,6 @@ editor.Class = Widget.extend({ return res; }, start: function () { - var self = this; - $('.dropdown-toggle').dropdown(); this.display_placeholder(); @@ -89,11 +87,12 @@ editor.Class = Widget.extend({ window.onbeforeunload = function (event) { if (rte.history.getEditableHasUndo().length && !flag) { flag = true; - setTimeout(function () {flag=false;},0); + _.defer(function () { flag=false; }); return _t('This document is not saved!'); } }; - return this._super(); + + return this._super.apply(this, arguments); }, display_placeholder: function () { var $area = $("#wrapwrap").find("[data-oe-model] .oe_structure.oe_empty, [data-oe-model].oe_structure.oe_empty, [data-oe-type=html]") @@ -135,18 +134,10 @@ editor.Class = Widget.extend({ if (!rte.history.getEditableHasUndo().length) { return d.resolve(); } - var $dialog = $(qweb.render('web_editor.discard')).appendTo(document.body); - $dialog.on('click', '.btn-danger', function () { - d.resolve(); - }).on('hidden.bs.modal', function () { - d.reject(); - }).on('keydown.dismiss.bs.modal', function (event) { - event.stopImmediatePropagation(); - }); - d.always(function () { - $dialog.remove(); + var confirm = Dialog.confirm(null, _t("If you discard the current edition, all unsaved changes will be lost. You can cancel to return to the edition mode."), { + confirm_callback: d.resolve.bind(d) }); - $dialog.modal('show'); + confirm.on("closed", d, d.reject); }).then(function () { window.onbeforeunload = null; editor.reload(); @@ -155,5 +146,4 @@ editor.Class = Widget.extend({ }); return editor; - }); |
