summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorGéry Debongnie <ged@odoo.com>2016-06-16 13:44:21 +0200
committerGéry Debongnie <ged@odoo.com>2016-06-17 13:32:37 +0200
commit00120a9271b8c52c1ed3a392e0e66f3e8c9a6893 (patch)
tree2ed273420b423a0f0f4f11fbdd33934a4fc4988a /addons/web/static/src/js
parent2254abbde72862e7842614c33e261571eaebae64 (diff)
[REF] web: refactor and simplify web.core
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/action_manager.js3
-rw-r--r--addons/web/static/src/js/boot.js26
-rw-r--r--addons/web/static/src/js/compatibility.js23
-rw-r--r--addons/web/static/src/js/control_panel.js4
-rw-r--r--addons/web/static/src/js/framework/qweb.js2
-rw-r--r--addons/web/static/src/js/framework/translation.js33
-rw-r--r--addons/web/static/src/js/services/core.js (renamed from addons/web/static/src/js/framework/core.js)50
7 files changed, 66 insertions, 75 deletions
diff --git a/addons/web/static/src/js/action_manager.js b/addons/web/static/src/js/action_manager.js
index fa88f1cf943..b1f1bea8c99 100644
--- a/addons/web/static/src/js/action_manager.js
+++ b/addons/web/static/src/js/action_manager.js
@@ -1,6 +1,7 @@
odoo.define('web.ActionManager', function (require) {
"use strict";
+var Bus = require('web.Bus');
var ControlPanel = require('web.ControlPanel');
var core = require('web.core');
var crash_manager = require('web.crash_manager');
@@ -712,7 +713,7 @@ var ActionManager = Widget.extend({
if (this.dialog_widget.need_control_panel) {
// Set a fake bus to Dialogs needing a ControlPanel as they should not
// communicate with the main ControlPanel
- this.dialog_widget.set_cp_bus(new core.Bus());
+ this.dialog_widget.set_cp_bus(new Bus());
}
this.dialog_widget.setParent(this.dialog);
diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js
index f070730886d..842858926a9 100644
--- a/addons/web/static/src/js/boot.js
+++ b/addons/web/static/src/js/boot.js
@@ -267,30 +267,4 @@
};
$(log_when_loaded);
-
- // IE patch
- //-------------------------------------------------------------------------
- if (typeof(console) === "undefined") {
- // Even IE9 only exposes console object if debug window opened
- window.console = {};
- ('log error debug info warn assert clear dir dirxml trace group'
- + ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
- + ' exception').split(/\s+/).forEach(function(property) {
- console[property] = _.identity;
- });
- }
-
- /**
- Some hack to make placeholders work in ie9.
- */
- if (!('placeholder' in document.createElement('input'))) {
- document.addEventListener("DOMNodeInserted",function(event){
- var nodename = event.target.nodeName.toLowerCase();
- if ( nodename === "input" || nodename === "textarea" ) {
- $(event.target).placeholder();
- }
- });
- }
-
-
})();
diff --git a/addons/web/static/src/js/compatibility.js b/addons/web/static/src/js/compatibility.js
index fe3ef096d63..d6a97b76f0e 100644
--- a/addons/web/static/src/js/compatibility.js
+++ b/addons/web/static/src/js/compatibility.js
@@ -261,5 +261,28 @@ ListView.include({
},
});
+// IE patch
+//-------------------------------------------------------------------------
+if (typeof(console) === "undefined") {
+ // Even IE9 only exposes console object if debug window opened
+ window.console = {};
+ ('log error debug info warn assert clear dir dirxml trace group'
+ + ' groupCollapsed groupEnd time timeEnd profile profileEnd count'
+ + ' exception').split(/\s+/).forEach(function(property) {
+ console[property] = _.identity;
+ });
+}
+
+/**
+ Some hack to make placeholders work in ie9.
+*/
+if (!('placeholder' in document.createElement('input'))) {
+ document.addEventListener("DOMNodeInserted",function(event){
+ var nodename = event.target.nodeName.toLowerCase();
+ if ( nodename === "input" || nodename === "textarea" ) {
+ $(event.target).placeholder();
+ }
+ });
+}
});
diff --git a/addons/web/static/src/js/control_panel.js b/addons/web/static/src/js/control_panel.js
index 80744f243e9..42aac397d07 100644
--- a/addons/web/static/src/js/control_panel.js
+++ b/addons/web/static/src/js/control_panel.js
@@ -31,7 +31,7 @@ return ControlPanelMixin;
odoo.define('web.ControlPanel', function (require) {
"use strict";
-var core = require('web.core');
+var Bus = require('web.Bus');
var data = require('web.data');
var Widget = require('web.Widget');
@@ -47,7 +47,7 @@ var ControlPanel = Widget.extend({
this.template = template;
}
- this.bus = new core.Bus();
+ this.bus = new Bus();
this.bus.on("update", this, this.update);
},
/**
diff --git a/addons/web/static/src/js/framework/qweb.js b/addons/web/static/src/js/framework/qweb.js
index b29f0f06d65..2202460a18a 100644
--- a/addons/web/static/src/js/framework/qweb.js
+++ b/addons/web/static/src/js/framework/qweb.js
@@ -3,6 +3,8 @@ odoo.define('web.QWeb', function (require) {
var translation = require('web.translation');
+var _t = translation._t;
+
function QWeb(debug) {
var qweb = new QWeb2.Engine();
qweb.default_dict = {
diff --git a/addons/web/static/src/js/framework/translation.js b/addons/web/static/src/js/framework/translation.js
index 5d747869935..2b6e5a4cecc 100644
--- a/addons/web/static/src/js/framework/translation.js
+++ b/addons/web/static/src/js/framework/translation.js
@@ -74,10 +74,43 @@ var TranslationDataBase = Class.extend(/** @lends instance.TranslationDataBase#
});
var _t = new TranslationDataBase().build_translation_function();
+/**
+ * Lazy translation function, only performs the translation when actually
+ * printed (e.g. inserted into a template)
+ *
+ * Useful when defining translatable strings in code evaluated before the
+ * translation database is loaded, as class attributes or at the top-level of
+ * an OpenERP Web module
+ *
+ * @param {String} s string to translate
+ * @returns {Object} lazy translation object
+ */
var _lt = function (s) {
return {toString: function () { return _t(s); }};
};
+/** Setup jQuery timeago */
+/*
+ * Strings in timeago are "composed" with prefixes, words and suffixes. This
+ * makes their detection by our translating system impossible. Use all literal
+ * strings we're using with a translation mark here so the extractor can do its
+ * job.
+ */
+{
+ _t('less than a minute ago');
+ _t('about a minute ago');
+ _t('%d minutes ago');
+ _t('about an hour ago');
+ _t('%d hours ago');
+ _t('a day ago');
+ _t('%d days ago');
+ _t('about a month ago');
+ _t('%d months ago');
+ _t('about a year ago');
+ _t('%d years ago');
+}
+
+
return {
_t: _t,
_lt: _lt,
diff --git a/addons/web/static/src/js/framework/core.js b/addons/web/static/src/js/services/core.js
index 02a06408d9d..41e30c1bd52 100644
--- a/addons/web/static/src/js/framework/core.js
+++ b/addons/web/static/src/js/services/core.js
@@ -4,16 +4,12 @@ odoo.define('web.core', function (require) {
var Bus = require('web.Bus');
var Class = require('web.Class');
var mixins = require('web.mixins');
+var QWeb = require('web.QWeb');
var Registry = require('web.Registry');
var translation = require('web.translation');
-var QWeb = require('web.QWeb');
-
var debug = $.deparam($.param.querystring()).debug !== undefined;
-var _t = translation._t;
-var _lt = translation._lt;
-
var bus = new Bus ();
_.each('click,dblclick,keydown,keypress,keyup'.split(','), function(evtype) {
@@ -27,55 +23,17 @@ _.each('resize,scroll'.split(','), function(evtype) {
});
});
-
-/**
- * Lazy translation function, only performs the translation when actually
- * printed (e.g. inserted into a template)
- *
- * Useful when defining translatable strings in code evaluated before the
- * translation database is loaded, as class attributes or at the top-level of
- * an OpenERP Web module
- *
- * @param {String} s string to translate
- * @returns {Object} lazy translation object
- */
-var qweb = new QWeb(debug);
-
-
-
-/** Setup jQuery timeago */
-/*
- * Strings in timeago are "composed" with prefixes, words and suffixes. This
- * makes their detection by our translating system impossible. Use all literal
- * strings we're using with a translation mark here so the extractor can do its
- * job.
- */
-{
- _t('less than a minute ago');
- _t('about a minute ago');
- _t('%d minutes ago');
- _t('about an hour ago');
- _t('%d hours ago');
- _t('a day ago');
- _t('%d days ago');
- _t('about a month ago');
- _t('%d months ago');
- _t('about a year ago');
- _t('%d years ago');
-}
-
return {
debug: debug,
- qweb: qweb,
+ qweb: new QWeb(debug),
// core classes and functions
Class: Class,
- Bus: Bus,
mixins: mixins,
bus: bus,
main_bus: new Bus(),
- _t: _t,
- _lt: _lt,
+ _t: translation._t,
+ _lt: translation._lt,
// registries
action_registry : new Registry(),