summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorRaphael Collet <rco@openerp.com>2012-05-03 09:35:50 +0200
committerRaphael Collet <rco@openerp.com>2012-05-03 09:35:50 +0200
commitb8e8ec6f7f36aba5ba7f7ef0e4972cca044140db (patch)
tree9f50858cee72ed77f402947304269fc84ce34551 /addons/web/static/src
parent4a4ebf4941c500b57bd8a7ee22943dc70a764c96 (diff)
parent253cfdd59d32f3329684ec69b05a7423784d78a4 (diff)
[MERGE] from trunk
bzr revid: rco@openerp.com-20120503073550-ub1yafqmoovwlhic
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/css/base.css94
-rw-r--r--addons/web/static/src/css/base.sass86
-rw-r--r--addons/web/static/src/img/list_empty_arrow.pngbin0 -> 2308 bytes
-rw-r--r--addons/web/static/src/img/user_menu_avatar.png (renamed from addons/web/static/src/img/topbar-avatar.png)bin846 -> 846 bytes
-rw-r--r--addons/web/static/src/js/boot.js12
-rw-r--r--addons/web/static/src/js/chrome.js8
-rw-r--r--addons/web/static/src/js/corelib.js450
-rw-r--r--addons/web/static/src/js/coresetup.js447
-rw-r--r--addons/web/static/src/js/data.js845
-rw-r--r--addons/web/static/src/js/formats.js4
-rw-r--r--addons/web/static/src/js/search.js1
-rw-r--r--addons/web/static/src/js/test_support.js79
-rw-r--r--addons/web/static/src/js/view_editor.js5
-rw-r--r--addons/web/static/src/js/view_form.js493
-rw-r--r--addons/web/static/src/js/view_list.js67
-rw-r--r--addons/web/static/src/js/view_list_editable.js18
-rw-r--r--addons/web/static/src/js/views.js17
-rw-r--r--addons/web/static/src/xml/base.xml82
18 files changed, 1608 insertions, 1100 deletions
diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css
index fc384fd9fbf..fab545d09b8 100644
--- a/addons/web/static/src/css/base.css
+++ b/addons/web/static/src/css/base.css
@@ -21,16 +21,13 @@
color: #4c4c4c;
font-size: 13px;
background: white;
-}
-.openerp a {
- text-decoration: none;
-}
-
-.openerp {
/* http://www.quirksmode.org/dom/inputfile.html
* http://stackoverflow.com/questions/2855589/replace-input-type-file-by-an-image
*/
}
+.openerp a {
+ text-decoration: none;
+}
.openerp table {
padding: 0;
font-size: 13px;
@@ -1356,10 +1353,6 @@
padding: 2px;
height: 25px;
}
-.openerp .oe_form_autolayout .oe_form_group_cell .oe_form_button {
- width: 100%;
- white-space: nowrap;
-}
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_many2one,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_many2one input,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_char input,
@@ -1368,31 +1361,38 @@
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_email input,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_url,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_url input,
-.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_date input,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_float input,
.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_field_selection select,
-.openerp .oe_form_autolayout .oe_form_group_cell > .oe_datepicker_root {
+.openerp .oe_form_autolayout .oe_form_group_cell > div > .oe_datepicker_root,
+.openerp .oe_form_autolayout .oe_form_group_cell > div > .oe_datepicker_root > input.oe_datepicker_master {
width: 100%;
}
.openerp .oe_form_autolayout .oe_form_button.oe_button {
color: #4c4c4c;
- white-space: nowrap;
- min-width: 100%;
- width: 100%;
- height: 22px;
}
.openerp .oe_form_autolayout .oe_form_button.oe_button span {
position: relative;
vertical-align: top;
}
+.openerp .oe_form_autolayout .oe_form_group_cell > .oe_form_button.oe_button {
+ white-space: nowrap;
+ min-width: 100%;
+ width: 100%;
+}
.openerp .oe_form_autolayout .oe_form_group_cell.oe_form_group_nested {
padding: 0;
}
-.openerp .oe_form label {
- font-weight: bold;
-}
-.openerp .oe_form_label_help[for], .openerp .oe_form_label[for] {
+.openerp .oe_form .oe_form_label_help[for], .openerp .oe_form .oe_form_label[for] {
white-space: nowrap;
+ padding-right: 8px;
+}
+.openerp .oe_form .oe_form_label_help[for] span, .openerp .oe_form .oe_form_label[for] span {
+ font-size: 80%;
+ color: darkGreen;
+ vertical-align: top;
+ position: relative;
+ top: -4px;
+ padding: 0 2px;
}
.openerp .oe_form textarea {
resize: vertical;
@@ -1580,6 +1580,9 @@
border-bottom-color: transparent;
cursor: default;
}
+.openerp .oe_form_notebook_page {
+ padding: 0;
+}
.openerp .ui-tabs-hide {
display: none;
}
@@ -1620,6 +1623,32 @@
height: auto;
line-height: 16px;
}
+.openerp .oe_form .oe_form_title, .openerp .oe_form .oe_form_title input {
+ font-size: 20px;
+ font-weight: bold;
+}
+.openerp .oe_form .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell:nth-child(odd),
+.openerp .oe_form .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell_label {
+ border-right: 1px solid #dddddd;
+}
+.openerp .oe_form .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell:nth-child(odd) label,
+.openerp .oe_form .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell_label label {
+ display: block;
+ min-width: 120px;
+}
+.openerp .oe_form .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell,
+.openerp .oe_form .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell {
+ padding: 2px 2px 2px 8px !important;
+}
+.openerp .oe_listview_nocontent > img {
+ float: left;
+ margin-right: 1.5em;
+}
+.openerp .oe_listview_nocontent > div {
+ overflow: hidden;
+ padding: 6px;
+ font-size: 125%;
+}
.openerp .oe-listview-content {
width: 100%;
}
@@ -1777,23 +1806,24 @@
font-weight: bold;
}
.openerp .oe_layout_debugging .oe_form_group {
- border: 2px dashed red;
+ outline: 2px dashed green;
}
.openerp .oe_layout_debugging .oe_form_group_cell {
- border: 1px solid blue;
- padding-bottom: 1em;
+ outline: 1px solid blue;
}
-.openerp .oe_layout_debugging .oe_layout_debug_cell {
- color: white;
- background: #669966;
- font-size: 80%;
- text-align: center;
+.openerp .oe_layout_debugging .oe_form_group:hover, .openerp .oe_layout_debugging .oe_form_group_cell:hover {
+ outline-color: red;
}
-.openerp .oe_layout_debugging .oe_layout_debug_cell {
- display: block;
+.openerp .oe_layout_debugging .oe_form_group_row_incomplete > td:last-child:after {
+ content: "[Incomplete Row]";
+ background: red;
+ padding: 2px;
+ font-weight: bold;
+ color: white;
+ float: right;
}
-.openerp .oe_layout_debug_cell {
- display: none;
+.openerp .oe_layout_debugging .oe_form_group_row_incomplete.oe_form_group_row_newline > td:last-child:after {
+ content: "[newline]";
}
.openerp .oe_debug_view {
float: left;
diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass
index b2373c7782b..447bfc48abf 100644
--- a/addons/web/static/src/css/base.sass
+++ b/addons/web/static/src/css/base.sass
@@ -78,12 +78,10 @@ $colour4: #8a89ba
color: #4c4c4c
font-size: 13px
background: white
- a
- text-decoration: none
// }}}
-
-.openerp
// Tag reset {{{
+ a
+ text-decoration: none
table
padding: 0
font-size: 13px
@@ -1115,9 +1113,6 @@ $colour4: #8a89ba
line-height: 18px
padding: 2px
height: 25px
- .oe_form_button
- width: 100%
- white-space: nowrap
.oe_form_group_cell > .oe_form_field_many2one,
.oe_form_group_cell > .oe_form_field_many2one input,
.oe_form_group_cell > .oe_form_field_char input,
@@ -1126,29 +1121,35 @@ $colour4: #8a89ba
.oe_form_group_cell > .oe_form_field_email input,
.oe_form_group_cell > .oe_form_field_url,
.oe_form_group_cell > .oe_form_field_url input,
- .oe_form_group_cell > .oe_form_field_date input,
.oe_form_group_cell > .oe_form_field_float input,
.oe_form_group_cell > .oe_form_field_selection select,
- .oe_form_group_cell > .oe_datepicker_root
+ .oe_form_group_cell > div > .oe_datepicker_root,
+ .oe_form_group_cell > div > .oe_datepicker_root > input.oe_datepicker_master
width: 100%
.oe_form_button.oe_button
color: #4c4c4c
- white-space: nowrap
- min-width: 100%
- width: 100%
- height: 22px
span
position: relative
vertical-align: top
+ .oe_form_group_cell > .oe_form_button.oe_button
+ white-space: nowrap
+ min-width: 100%
+ width: 100%
.oe_form_group_cell.oe_form_group_nested
padding: 0
// }}}
// FormView.label {{{
.oe_form
- label
- font-weight: bold
- .oe_form_label_help[for], .oe_form_label[for]
- white-space: nowrap
+ .oe_form_label_help[for], .oe_form_label[for]
+ white-space: nowrap
+ padding-right: 8px
+ span
+ font-size: 80%
+ color: darkGreen
+ vertical-align: top
+ position: relative
+ top: -4px
+ padding: 0 2px
// }}}
// FormView.fields {{{
.oe_form
@@ -1321,6 +1322,8 @@ $colour4: #8a89ba
border: 1px solid #ddd
border-bottom-color: transparent
cursor: default
+ .oe_form_notebook_page
+ padding: 0
.ui-tabs-hide
display: none
@@ -1365,7 +1368,31 @@ $colour4: #8a89ba
line-height: 16px
// }}}
+ // FormView.classes for openerp views {{{
+ .oe_form
+ .oe_form_title, .oe_form_title input
+ font-size: 20px
+ font-weight: bold
+ .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell:nth-child(odd),
+ .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell_label
+ border-right: 1px solid #ddd
+ label
+ display: block
+ min-width: 120px
+ .oe_form_group_odd_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell,
+ .oe_form_group_label_border > tbody > tr.oe_form_group_row > td.oe_form_group_cell
+ padding: 2px 2px 2px 8px !important
+ // }}}
// ListView {{{
+ .oe_listview_nocontent
+ > img
+ float: left
+ margin-right: 1.5em
+ > div
+ // don't encroach on my arrow
+ overflow: hidden
+ padding: 6px
+ font-size: 125%
.oe-listview-content
width: 100%
thead, tfoot
@@ -1480,23 +1507,23 @@ $colour4: #8a89ba
.oe_tooltip_technical_title
font-weight: bold
// }}}
-
// Debugging stuff {{{
.oe_layout_debugging
.oe_form_group
- border: 2px dashed red
+ outline: 2px dashed green
.oe_form_group_cell
- border: 1px solid blue
- padding-bottom: 1em
- .oe_layout_debug_cell
+ outline: 1px solid blue
+ .oe_form_group:hover, .oe_form_group_cell:hover
+ outline-color: red
+ .oe_form_group_row_incomplete > td:last-child:after
+ content: "[Incomplete Row]"
+ background: red
+ padding: 2px
+ font-weight: bold
color: white
- background: #696
- font-size: 80%
- text-align: center
- .oe_layout_debug_cell
- display: block
- .oe_layout_debug_cell
- display: none
+ float: right
+ .oe_form_group_row_incomplete.oe_form_group_row_newline > td:last-child:after
+ content: "[newline]"
.oe_debug_view
float: left
@@ -1529,4 +1556,3 @@ $colour4: #8a89ba
// au BufWritePost,FileWritePost *.sass :!sass --style expanded --line-numbers <afile> > "%:p:r.css"
// vim:tabstop=4:shiftwidth=4:softtabstop=4:fdm=marker:
-
diff --git a/addons/web/static/src/img/list_empty_arrow.png b/addons/web/static/src/img/list_empty_arrow.png
new file mode 100644
index 00000000000..b0b1372adfd
--- /dev/null
+++ b/addons/web/static/src/img/list_empty_arrow.png
Binary files differ
diff --git a/addons/web/static/src/img/topbar-avatar.png b/addons/web/static/src/img/user_menu_avatar.png
index a2c70ea7d49..a2c70ea7d49 100644
--- a/addons/web/static/src/img/topbar-avatar.png
+++ b/addons/web/static/src/img/user_menu_avatar.png
Binary files differ
diff --git a/addons/web/static/src/js/boot.js b/addons/web/static/src/js/boot.js
index 1251975f41c..29d953aadd8 100644
--- a/addons/web/static/src/js/boot.js
+++ b/addons/web/static/src/js/boot.js
@@ -14,8 +14,8 @@
var openerp = this.openerp = {
// Per session namespace
// openerp.<module> will map to
- // openerp.sessions.sessionname.<module> using a closure
- sessions: {},
+ // openerp.instances.sessionname.<module> using a closure
+ instances: {},
/**
* OpenERP instance constructor
*
@@ -23,19 +23,19 @@
*/
init: function(modules) {
// By default only web will be loaded, the rest will be by loaded
- // by openerp.web.Connection on the first session_authenticate
+ // by openerp.web.Session on the first session_authenticate
modules = modules || ["web"];
var new_instance = {
// links to the global openerp
_openerp: openerp,
// this unique id will be replaced by hostname_databasename by
- // openerp.web.Connection on the first connection
- _session_id: "session" + session_counter++,
+ // openerp.web.Session on the first connection
+ _session_id: "instance" + session_counter++,
_modules: modules,
web: {},
web_mobile: {}
};
- openerp.sessions[new_instance._session_id] = new_instance;
+ openerp.instances[new_instance._session_id] = new_instance;
for(var i=0; i < modules.length; i++) {
openerp[modules[i]](new_instance);
}
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index f1d3faef367..f43da0431ff 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -638,6 +638,7 @@ instance.web.Menu = instance.web.Widget.extend({
}
},
on_menu_click: function(ev, id) {
+ // TODO If first level menu doesnt have action trigger first leaf
this.do_hide_more();
id = id || 0;
var $clicked_menu, manual = false;
@@ -984,13 +985,18 @@ instance.web.WebClient = instance.web.Widget.extend({
});
},
bind_hashchange: function() {
+ var self = this;
$(window).bind('hashchange', this.on_hashchange);
var state = $.bbq.getState(true);
if (! _.isEmpty(state)) {
$(window).trigger('hashchange');
} else {
- this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
+ self.menu.has_been_loaded.then(function() {
+ var first_menu_id = self.menu.$element.find("a:first").data("menu");
+ if(first_menu_id)
+ self.menu.on_menu_click(null,first_menu_id);
+ });
}
},
on_hashchange: function(event) {
diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js
index 5475f4ad53c..465ad2c921b 100644
--- a/addons/web/static/src/js/corelib.js
+++ b/addons/web/static/src/js/corelib.js
@@ -239,9 +239,7 @@ instance.web.ParentedMixin = {
};
/**
- * TODO al: move into the the mixin
- *
- * Backbone's events
+ * Backbone's events. Do not ever use it directly, use EventDispatcherMixin instead.
*
* (c) 2010-2012 Jeremy Ashkenas, DocumentCloud Inc.
* Backbone may be freely distributed under the MIT license.
@@ -253,8 +251,7 @@ instance.web.ParentedMixin = {
* events is done in EventDispatcherMixin.
*
*/
-instance.web.Events = instance.web.Class.extend({
-
+var Events = instance.web.Class.extend({
on : function(events, callback, context) {
var ev;
events = events.split(/\s+/);
@@ -323,12 +320,13 @@ instance.web.Events = instance.web.Class.extend({
return this;
}
});
+// end of Jeremy Ashkenas' code
instance.web.EventDispatcherMixin = _.extend({}, instance.web.ParentedMixin, {
__eventDispatcherMixin: true,
init: function() {
instance.web.ParentedMixin.init.call(this);
- this.__edispatcherEvents = new instance.web.Events();
+ this.__edispatcherEvents = new Events();
this.__edispatcherRegisteredEvents = [];
},
on: function(events, dest, func) {
@@ -373,7 +371,7 @@ instance.web.EventDispatcherMixin = _.extend({}, instance.web.ParentedMixin, {
}
});
-instance.web.GetterSetterMixin = _.extend({}, instance.web.EventDispatcherMixin, {
+instance.web.PropertiesMixin = _.extend({}, instance.web.EventDispatcherMixin, {
init: function() {
instance.web.EventDispatcherMixin.init.call(this);
this.__getterSetterInternalMap = {};
@@ -400,9 +398,9 @@ instance.web.GetterSetterMixin = _.extend({}, instance.web.EventDispatcherMixin,
}
});
-instance.web.CallbackEnabledMixin = _.extend({}, instance.web.GetterSetterMixin, {
+instance.web.CallbackEnabledMixin = _.extend({}, instance.web.PropertiesMixin, {
init: function() {
- instance.web.GetterSetterMixin.init.call(this);
+ instance.web.PropertiesMixin.init.call(this);
var self = this;
var callback_maker = function(obj, name, method) {
var callback = function() {
@@ -535,7 +533,7 @@ instance.web.WidgetMixin = _.extend({},instance.web.CallbackEnabledMixin, {
if(this.$element != null) {
this.$element.remove();
}
- instance.web.GetterSetterMixin.destroy.call(this);
+ instance.web.PropertiesMixin.destroy.call(this);
},
/**
* Renders the current widget and appends it to the given jQuery object or Widget.
@@ -758,7 +756,7 @@ instance.web.Registry = instance.web.Class.extend({
* registry was created.
*
* An object path is simply a dotted name from the instance root to the
- * object pointed to (e.g. ``"instance.web.Connection"`` for an OpenERP
+ * object pointed to (e.g. ``"instance.web.Session"`` for an OpenERP
* connection object).
*
* @constructs instance.web.Registry
@@ -867,9 +865,9 @@ instance.web.Registry = instance.web.Class.extend({
}
});
-instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instance.web.Connection# */{
+instance.web.JsonRPC = instance.web.CallbackEnabled.extend({
/**
- * @constructs instance.web.Connection
+ * @constructs instance.web.JsonRPC
* @extends instance.web.CallbackEnabled
*
* @param {String} [server] JSON-RPC endpoint hostname
@@ -879,32 +877,13 @@ instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instan
this._super();
this.server = null;
this.debug = ($.deparam($.param.querystring()).debug != undefined);
- // TODO: session store in cookie should be optional
- this.name = instance._session_id;
- this.qweb_mutex = new $.Mutex();
},
- session_bind: function(origin) {
+ setup: function(origin) {
var window_origin = location.protocol+"//"+location.host, self=this;
this.origin = origin ? _.str.rtrim(origin,'/') : window_origin;
this.prefix = this.origin;
this.server = this.origin; // keep chs happy
- instance.web.qweb.default_dict['_s'] = this.origin;
this.rpc_function = (this.origin == window_origin) ? this.rpc_json : this.rpc_jsonp;
- this.session_id = false;
- this.uid = false;
- this.username = false;
- this.user_context= {};
- this.db = false;
- this.openerp_entreprise = false;
- this.module_list = instance._modules.slice();
- this.module_loaded = {};
- _(this.module_list).each(function (mod) {
- self.module_loaded[mod] = true;
- });
- this.context = {};
- this.shortcuts = [];
- this.active_id = null;
- return this.session_init();
},
test_eval_get_context: function () {
var asJS = function (arg) {
@@ -1213,7 +1192,6 @@ instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instan
url = { url: url };
}
// Construct a JSON-RPC2 request, method is currently unused
- params.session_id = this.session_id;
if (this.debug)
params.debug = 1;
var payload = {
@@ -1361,410 +1339,6 @@ instance.web.Connection = instance.web.CallbackEnabled.extend( /** @lends instan
},
on_rpc_error: function(error) {
},
- /**
- * Init a session, reloads from cookie, if it exists
- */
- session_init: function () {
- var self = this;
- // TODO: session store in cookie should be optional
- this.session_id = this.get_cookie('session_id');
- return this.session_reload().pipe(function(result) {
- var modules = instance._modules.join(',');
- var deferred = self.rpc('/web/webclient/qweblist', {mods: modules}).pipe(self.do_load_qweb);
- if(self.session_is_valid()) {
- return deferred.pipe(function() { return self.load_modules(); });
- }
- return deferred;
- });
- },
- /**
- * (re)loads the content of a session: db name, username, user id, session
- * context and status of the support contract
- *
- * @returns {$.Deferred} deferred indicating the session is done reloading
- */
- session_reload: function () {
- var self = this;
- return this.rpc("/web/session/get_session_info", {}).then(function(result) {
- // If immediately follows a login (triggered by trying to restore
- // an invalid session or no session at all), refresh session data
- // (should not change, but just in case...)
- _.extend(self, {
- db: result.db,
- username: result.login,
- uid: result.uid,
- user_context: result.context,
- openerp_entreprise: result.openerp_entreprise
- });
- });
- },
- session_is_valid: function() {
- return !!this.uid;
- },
- /**
- * The session is validated either by login or by restoration of a previous session
- */
- session_authenticate: function(db, login, password, _volatile) {
- var self = this;
- var base_location = document.location.protocol + '//' + document.location.host;
- var params = { db: db, login: login, password: password, base_location: base_location };
- return this.rpc("/web/session/authenticate", params).pipe(function(result) {
- _.extend(self, {
- session_id: result.session_id,
- db: result.db,
- username: result.login,
- uid: result.uid,
- user_context: result.context,
- openerp_entreprise: result.openerp_entreprise
- });
- if (!_volatile) {
- self.set_cookie('session_id', self.session_id);
- }
- return self.load_modules();
- });
- },
- session_logout: function() {
- this.set_cookie('session_id', '');
- return this.rpc("/web/session/destroy", {});
- },
- on_session_valid: function() {
- },
- /**
- * Called when a rpc call fail due to an invalid session.
- * By default, it's a noop
- */
- on_session_invalid: function(retry_callback) {
- },
- /**
- * Fetches a cookie stored by an openerp session
- *
- * @private
- * @param name the cookie's name
- */
- get_cookie: function (name) {
- if (!this.name) { return null; }
- var nameEQ = this.name + '|' + name + '=';
- var cookies = document.cookie.split(';');
- for(var i=0; i<cookies.length; ++i) {
- var cookie = cookies[i].replace(/^\s*/, '');
- if(cookie.indexOf(nameEQ) === 0) {
- return JSON.parse(decodeURIComponent(cookie.substring(nameEQ.length)));
- }
- }
- return null;
- },
- /**
- * Create a new cookie with the provided name and value
- *
- * @private
- * @param name the cookie's name
- * @param value the cookie's value
- * @param ttl the cookie's time to live, 1 year by default, set to -1 to delete
- */
- set_cookie: function (name, value, ttl) {
- if (!this.name) { return; }
- ttl = ttl || 24*60*60*365;
- document.cookie = [
- this.name + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)),
- 'path=/',
- 'max-age=' + ttl,
- 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
- ].join(';');
- },
- /**
- * Load additional web addons of that instance and init them
- *
- * @param {Boolean} [no_session_valid_signal=false] prevents load_module from triggering ``on_session_valid``.
- */
- load_modules: function(no_session_valid_signal) {
- var self = this;
- return this.rpc('/web/session/modules', {}).pipe(function(result) {
- var lang = self.user_context.lang,
- all_modules = _.uniq(self.module_list.concat(result));
- var params = { mods: all_modules, lang: lang};
- var to_load = _.difference(result, self.module_list).join(',');
- self.module_list = all_modules;
-
- var loaded = $.Deferred().resolve().promise();
- if (to_load.length) {
- loaded = $.when(
- self.rpc('/web/webclient/csslist', {mods: to_load}, self.do_load_css),
- self.rpc('/web/webclient/qweblist', {mods: to_load}).pipe(self.do_load_qweb),
- self.rpc('/web/webclient/translations', params).pipe(function(trans) {
- instance.web._t.database.set_bundle(trans);
- var file_list = ["/web/static/lib/datejs/globalization/" + lang.replace("_", "-") + ".js"];
- return self.rpc('/web/webclient/jslist', {mods: to_load}).pipe(function(files) {
- return self.do_load_js(file_list.concat(files));
- }).then(function () {
- if (!Date.CultureInfo.pmDesignator) {
- // If no am/pm designator is specified but the openerp
- // datetime format uses %i, date.js won't be able to
- // correctly format a date. See bug#938497.
- Date.CultureInfo.amDesignator = 'AM';
- Date.CultureInfo.pmDesignator = 'PM';
- }
- });
- }))
- }
- return loaded.then(function() {
- self.on_modules_loaded();
- if (!no_session_valid_signal) {
- self.on_session_valid();
- }
- });
- });
- },
- do_load_css: function (files) {
- var self = this;
- _.each(files, function (file) {
- $('head').append($('<link>', {
- 'href': self.get_url(file),
- 'rel': 'stylesheet',
- 'type': 'text/css'
- }));
- });
- },
- do_load_js: function(files) {
- var self = this;
- var d = $.Deferred();
- if(files.length != 0) {
- var file = files.shift();
- var tag = document.createElement('script');
- tag.type = 'text/javascript';
- tag.src = self.get_url(file);
- tag.onload = tag.onreadystatechange = function() {
- if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
- return;
- tag.onload_done = true;
- self.do_load_js(files).then(function () {
- d.resolve();
- });
- };
- var head = document.head || document.getElementsByTagName('head')[0];
- head.appendChild(tag);
- } else {
- d.resolve();
- }
- return d;
- },
- do_load_qweb: function(files) {
- var self = this;
- _.each(files, function(file) {
- self.qweb_mutex.exec(function() {
- return self.rpc('/web/proxy/load', {path: file}).pipe(function(xml) {
- if (!xml) { return; }
- instance.web.qweb.add_template(_.str.trim(xml));
- });
- });
- });
- return self.qweb_mutex.def;
- },
- on_modules_loaded: function() {
- for(var j=0; j<this.module_list.length; j++) {
- var mod = this.module_list[j];
- if(this.module_loaded[mod])
- continue;
- instance[mod] = {};
- // init module mod
- if(instance._openerp[mod] != undefined) {
- instance._openerp[mod](instance);
- this.module_loaded[mod] = true;
- }
- }
- },
- get_url: function (file) {
- return this.prefix + file;
- },
- /**
- * Cooperative file download implementation, for ajaxy APIs.
- *
- * Requires that the server side implements an httprequest correctly
- * setting the `fileToken` cookie to the value provided as the `token`
- * parameter. The cookie *must* be set on the `/` path and *must not* be
- * `httpOnly`.
- *
- * It would probably also be a good idea for the response to use a
- * `Content-Disposition: attachment` header, especially if the MIME is a
- * "known" type (e.g. text/plain, or for some browsers application/json
- *
- * @param {Object} options
- * @param {String} [options.url] used to dynamically create a form
- * @param {Object} [options.data] data to add to the form submission. If can be used without a form, in which case a form is created from scratch. Otherwise, added to form data
- * @param {HTMLFormElement} [options.form] the form to submit in order to fetch the file
- * @param {Function} [options.success] callback in case of download success
- * @param {Function} [options.error] callback in case of request error, provided with the error body
- * @param {Function} [options.complete] called after both ``success`` and ``error` callbacks have executed
- */
- get_file: function (options) {
- // need to detect when the file is done downloading (not used
- // yet, but we'll need it to fix the UI e.g. with a throbber
- // while dump is being generated), iframe load event only fires
- // when the iframe content loads, so we need to go smarter:
- // http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
- var timer, token = new Date().getTime(),
- cookie_name = 'fileToken', cookie_length = cookie_name.length,
- CHECK_INTERVAL = 1000, id = _.uniqueId('get_file_frame'),
- remove_form = false;
-
- var $form, $form_data = $('<div>');
-
- var complete = function () {
- if (options.complete) { options.complete(); }
- clearTimeout(timer);
- $form_data.remove();
- $target.remove();
- if (remove_form && $form) { $form.remove(); }
- };
- var $target = $('<iframe style="display: none;">')
- .attr({id: id, name: id})
- .appendTo(document.body)
- .load(function () {
- try {
- if (options.error) {
- options.error(JSON.parse(
- this.contentDocument.body.childNodes[1].textContent
- ));
- }
- } finally {
- complete();
- }
- });
-
- if (options.form) {
- $form = $(options.form);
- } else {
- remove_form = true;
- $form = $('<form>', {
- action: options.url,
- method: 'POST'
- }).appendTo(document.body);
- }
-
- _(_.extend({}, options.data || {},
- {session_id: this.session_id, token: token}))
- .each(function (value, key) {
- var $input = $form.find('[name=' + key +']');
- if (!$input.length) {
- $input = $('<input type="hidden" name="' + key + '">')
- .appendTo($form_data);
- }
- $input.val(value)
- });
-
- $form
- .append($form_data)
- .attr('target', id)
- .get(0).submit();
-
- var waitLoop = function () {
- var cookies = document.cookie.split(';');
- // setup next check
- timer = setTimeout(waitLoop, CHECK_INTERVAL);
- for (var i=0; i<cookies.length; ++i) {
- var cookie = cookies[i].replace(/^\s*/, '');
- if (!cookie.indexOf(cookie_name === 0)) { continue; }
- var cookie_val = cookie.substring(cookie_length + 1);
- if (parseInt(cookie_val, 10) !== token) { continue; }
-
- // clear cookie
- document.cookie = _.str.sprintf("%s=;expires=%s;path=/",
- cookie_name, new Date().toGMTString());
- if (options.success) { options.success(); }
- complete();
- return;
- }
- };
- timer = setTimeout(waitLoop, CHECK_INTERVAL);
- },
- synchronized_mode: function(to_execute) {
- var synch = this.synch;
- this.synch = true;
- try {
- return to_execute();
- } finally {
- this.synch = synch;
- }
- }
-});
-
-instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{
- /**
- * @constructs instance.web.TranslationDataBase
- * @extends instance.web.Class
- */
- init: function() {
- this.db = {};
- this.parameters = {"direction": 'ltr',
- "date_format": '%m/%d/%Y',
- "time_format": '%H:%M:%S',
- "grouping": [],
- "decimal_point": ".",
- "thousands_sep": ","};
- },
- set_bundle: function(translation_bundle) {
- var self = this;
- this.db = {};
- var modules = _.keys(translation_bundle.modules);
- modules.sort();
- if (_.include(modules, "web")) {
- modules = ["web"].concat(_.without(modules, "web"));
- }
- _.each(modules, function(name) {
- self.add_module_translation(translation_bundle.modules[name]);
- });
- if (translation_bundle.lang_parameters) {
- this.parameters = translation_bundle.lang_parameters;
- this.parameters.grouping = py.eval(
- this.parameters.grouping);
- }
- },
- add_module_translation: function(mod) {
- var self = this;
- _.each(mod.messages, function(message) {
- self.db[message.id] = message.string;
- });
- },
- build_translation_function: function() {
- var self = this;
- var fcnt = function(str) {
- var tmp = self.get(str);
- return tmp === undefined ? str : tmp;
- };
- fcnt.database = this;
- return fcnt;
- },
- get: function(key) {
- if (this.db[key])
- return this.db[key];
- return undefined;
- }
-});
-
-/**
- * @deprecated use :class:`instance.web.Widget`
- */
-instance.web.OldWidget = instance.web.Widget.extend({
- init: function(parent, element_id) {
- this._super(parent);
- this.element_id = element_id;
- this.element_id = this.element_id || _.uniqueId('widget-');
- var tmp = document.getElementById(this.element_id);
- this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName));
- },
- renderElement: function() {
- var rendered = this.render();
- if (rendered) {
- var elem = $(rendered);
- this.$element.replaceWith(elem);
- this.$element = elem;
- }
- return this;
- },
- render: function (additional) {
- if (this.template)
- return instance.web.qweb.render(this.template, _.extend({widget: this}, additional || {}));
- return null;
- }
});
}
diff --git a/addons/web/static/src/js/coresetup.js b/addons/web/static/src/js/coresetup.js
index 86040302668..e633ea9cfec 100644
--- a/addons/web/static/src/js/coresetup.js
+++ b/addons/web/static/src/js/coresetup.js
@@ -11,6 +11,449 @@ if (!console.debug) {
openerp.web.coresetup = function(instance) {
+/**
+ * @deprecated use :class:`instance.web.Widget`
+ */
+instance.web.OldWidget = instance.web.Widget.extend({
+ init: function(parent, element_id) {
+ this._super(parent);
+ this.element_id = element_id;
+ this.element_id = this.element_id || _.uniqueId('widget-');
+ var tmp = document.getElementById(this.element_id);
+ this.$element = tmp ? $(tmp) : $(document.createElement(this.tagName));
+ },
+ renderElement: function() {
+ var rendered = this.render();
+ if (rendered) {
+ var elem = $(rendered);
+ this.$element.replaceWith(elem);
+ this.$element = elem;
+ }
+ return this;
+ },
+ render: function (additional) {
+ if (this.template)
+ return instance.web.qweb.render(this.template, _.extend({widget: this}, additional || {}));
+ return null;
+ }
+});
+
+/** Session openerp specific RPC class */
+instance.web.Session = instance.web.JsonRPC.extend( /** @lends instance.web.Session# */{
+ init: function() {
+ this._super.apply(this, arguments);
+ // TODO: session store in cookie should be optional
+ this.name = instance._session_id;
+ this.qweb_mutex = new $.Mutex();
+ },
+ rpc: function(url, params, success_callback, error_callback) {
+ params.session_id = this.session_id;
+ return this._super(url, params, success_callback, error_callback);
+ },
+ /**
+ * Setup a sessionm
+ */
+ session_bind: function(origin) {
+ var self = this;
+ this.setup(origin);
+ instance.web.qweb.default_dict['_s'] = this.origin;
+ this.session_id = false;
+ this.uid = false;
+ this.username = false;
+ this.user_context= {};
+ this.db = false;
+ this.openerp_entreprise = false;
+ this.module_list = instance._modules.slice();
+ this.module_loaded = {};
+ _(this.module_list).each(function (mod) {
+ self.module_loaded[mod] = true;
+ });
+ this.context = {};
+ this.shortcuts = [];
+ this.active_id = null;
+ return this.session_init();
+ },
+ /**
+ * Init a session, reloads from cookie, if it exists
+ */
+ session_init: function () {
+ var self = this;
+ // TODO: session store in cookie should be optional
+ this.session_id = this.get_cookie('session_id');
+ return this.session_reload().pipe(function(result) {
+ var modules = instance._modules.join(',');
+ var deferred = self.rpc('/web/webclient/qweblist', {mods: modules}).pipe(self.do_load_qweb);
+ if(self.session_is_valid()) {
+ return deferred.pipe(function() { return self.load_modules(); });
+ }
+ return deferred;
+ });
+ },
+ /**
+ * (re)loads the content of a session: db name, username, user id, session
+ * context and status of the support contract
+ *
+ * @returns {$.Deferred} deferred indicating the session is done reloading
+ */
+ session_reload: function () {
+ var self = this;
+ return this.rpc("/web/session/get_session_info", {}).then(function(result) {
+ // If immediately follows a login (triggered by trying to restore
+ // an invalid session or no session at all), refresh session data
+ // (should not change, but just in case...)
+ _.extend(self, {
+ session_id: result.session_id,
+ db: result.db,
+ username: result.login,
+ uid: result.uid,
+ user_context: result.context,
+ openerp_entreprise: result.openerp_entreprise
+ });
+ });
+ },
+ session_is_valid: function() {
+ return !!this.uid;
+ },
+ /**
+ * The session is validated either by login or by restoration of a previous session
+ */
+ session_authenticate: function(db, login, password, _volatile) {
+ var self = this;
+ var base_location = document.location.protocol + '//' + document.location.host;
+ var params = { db: db, login: login, password: password, base_location: base_location };
+ return this.rpc("/web/session/authenticate", params).pipe(function(result) {
+ _.extend(self, {
+ session_id: result.session_id,
+ db: result.db,
+ username: result.login,
+ uid: result.uid,
+ user_context: result.context,
+ openerp_entreprise: result.openerp_entreprise
+ });
+ if (!_volatile) {
+ self.set_cookie('session_id', self.session_id);
+ }
+ return self.load_modules();
+ });
+ },
+ session_logout: function() {
+ this.set_cookie('session_id', '');
+ return this.rpc("/web/session/destroy", {});
+ },
+ on_session_valid: function() {
+ },
+ /**
+ * Called when a rpc call fail due to an invalid session.
+ * By default, it's a noop
+ */
+ on_session_invalid: function(retry_callback) {
+ },
+ /**
+ * Fetches a cookie stored by an openerp session
+ *
+ * @private
+ * @param name the cookie's name
+ */
+ get_cookie: function (name) {
+ if (!this.name) { return null; }
+ var nameEQ = this.name + '|' + name + '=';
+ var cookies = document.cookie.split(';');
+ for(var i=0; i<cookies.length; ++i) {
+ var cookie = cookies[i].replace(/^\s*/, '');
+ if(cookie.indexOf(nameEQ) === 0) {
+ return JSON.parse(decodeURIComponent(cookie.substring(nameEQ.length)));
+ }
+ }
+ return null;
+ },
+ /**
+ * Create a new cookie with the provided name and value
+ *
+ * @private
+ * @param name the cookie's name
+ * @param value the cookie's value
+ * @param ttl the cookie's time to live, 1 year by default, set to -1 to delete
+ */
+ set_cookie: function (name, value, ttl) {
+ if (!this.name) { return; }
+ ttl = ttl || 24*60*60*365;
+ document.cookie = [
+ this.name + '|' + name + '=' + encodeURIComponent(JSON.stringify(value)),
+ 'path=/',
+ 'max-age=' + ttl,
+ 'expires=' + new Date(new Date().getTime() + ttl*1000).toGMTString()
+ ].join(';');
+ },
+ /**
+ * Load additional web addons of that instance and init them
+ *
+ * @param {Boolean} [no_session_valid_signal=false] prevents load_module from triggering ``on_session_valid``.
+ */
+ load_modules: function(no_session_valid_signal) {
+ var self = this;
+ return this.rpc('/web/session/modules', {}).pipe(function(result) {
+ var lang = self.user_context.lang,
+ all_modules = _.uniq(self.module_list.concat(result));
+ var params = { mods: all_modules, lang: lang};
+ var to_load = _.difference(result, self.module_list).join(',');
+ self.module_list = all_modules;
+
+ var loaded = $.Deferred().resolve().promise();
+ if (to_load.length) {
+ loaded = $.when(
+ self.rpc('/web/webclient/csslist', {mods: to_load}, self.do_load_css),
+ self.rpc('/web/webclient/qweblist', {mods: to_load}).pipe(self.do_load_qweb),
+ self.rpc('/web/webclient/translations', params).pipe(function(trans) {
+ instance.web._t.database.set_bundle(trans);
+ var file_list = ["/web/static/lib/datejs/globalization/" + lang.replace("_", "-") + ".js"];
+ return self.rpc('/web/webclient/jslist', {mods: to_load}).pipe(function(files) {
+ return self.do_load_js(file_list.concat(files));
+ }).then(function () {
+ if (!Date.CultureInfo.pmDesignator) {
+ // If no am/pm designator is specified but the openerp
+ // datetime format uses %i, date.js won't be able to
+ // correctly format a date. See bug#938497.
+ Date.CultureInfo.amDesignator = 'AM';
+ Date.CultureInfo.pmDesignator = 'PM';
+ }
+ });
+ }))
+ }
+ return loaded.then(function() {
+ self.on_modules_loaded();
+ if (!no_session_valid_signal) {
+ self.on_session_valid();
+ }
+ });
+ });
+ },
+ do_load_css: function (files) {
+ var self = this;
+ _.each(files, function (file) {
+ $('head').append($('<link>', {
+ 'href': self.get_url(file),
+ 'rel': 'stylesheet',
+ 'type': 'text/css'
+ }));
+ });
+ },
+ do_load_js: function(files) {
+ var self = this;
+ var d = $.Deferred();
+ if(files.length != 0) {
+ var file = files.shift();
+ var tag = document.createElement('script');
+ tag.type = 'text/javascript';
+ tag.src = self.get_url(file);
+ tag.onload = tag.onreadystatechange = function() {
+ if ( (tag.readyState && tag.readyState != "loaded" && tag.readyState != "complete") || tag.onload_done )
+ return;
+ tag.onload_done = true;
+ self.do_load_js(files).then(function () {
+ d.resolve();
+ });
+ };
+ var head = document.head || document.getElementsByTagName('head')[0];
+ head.appendChild(tag);
+ } else {
+ d.resolve();
+ }
+ return d;
+ },
+ do_load_qweb: function(files) {
+ var self = this;
+ _.each(files, function(file) {
+ self.qweb_mutex.exec(function() {
+ return self.rpc('/web/proxy/load', {path: file}).pipe(function(xml) {
+ if (!xml) { return; }
+ instance.web.qweb.add_template(_.str.trim(xml));
+ });
+ });
+ });
+ return self.qweb_mutex.def;
+ },
+ on_modules_loaded: function() {
+ for(var j=0; j<this.module_list.length; j++) {
+ var mod = this.module_list[j];
+ if(this.module_loaded[mod])
+ continue;
+ instance[mod] = {};
+ // init module mod
+ if(instance._openerp[mod] != undefined) {
+ instance._openerp[mod](instance);
+ this.module_loaded[mod] = true;
+ }
+ }
+ },
+ get_url: function (file) {
+ return this.prefix + file;
+ },
+ /**
+ * Cooperative file download implementation, for ajaxy APIs.
+ *
+ * Requires that the server side implements an httprequest correctly
+ * setting the `fileToken` cookie to the value provided as the `token`
+ * parameter. The cookie *must* be set on the `/` path and *must not* be
+ * `httpOnly`.
+ *
+ * It would probably also be a good idea for the response to use a
+ * `Content-Disposition: attachment` header, especially if the MIME is a
+ * "known" type (e.g. text/plain, or for some browsers application/json
+ *
+ * @param {Object} options
+ * @param {String} [options.url] used to dynamically create a form
+ * @param {Object} [options.data] data to add to the form submission. If can be used without a form, in which case a form is created from scratch. Otherwise, added to form data
+ * @param {HTMLFormElement} [options.form] the form to submit in order to fetch the file
+ * @param {Function} [options.success] callback in case of download success
+ * @param {Function} [options.error] callback in case of request error, provided with the error body
+ * @param {Function} [options.complete] called after both ``success`` and ``error` callbacks have executed
+ */
+ get_file: function (options) {
+ // need to detect when the file is done downloading (not used
+ // yet, but we'll need it to fix the UI e.g. with a throbber
+ // while dump is being generated), iframe load event only fires
+ // when the iframe content loads, so we need to go smarter:
+ // http://geekswithblogs.net/GruffCode/archive/2010/10/28/detecting-the-file-download-dialog-in-the-browser.aspx
+ var timer, token = new Date().getTime(),
+ cookie_name = 'fileToken', cookie_length = cookie_name.length,
+ CHECK_INTERVAL = 1000, id = _.uniqueId('get_file_frame'),
+ remove_form = false;
+
+ var $form, $form_data = $('<div>');
+
+ var complete = function () {
+ if (options.complete) { options.complete(); }
+ clearTimeout(timer);
+ $form_data.remove();
+ $target.remove();
+ if (remove_form && $form) { $form.remove(); }
+ };
+ var $target = $('<iframe style="display: none;">')
+ .attr({id: id, name: id})
+ .appendTo(document.body)
+ .load(function () {
+ try {
+ if (options.error) {
+ options.error(JSON.parse(
+ this.contentDocument.body.childNodes[1].textContent
+ ));
+ }
+ } finally {
+ complete();
+ }
+ });
+
+ if (options.form) {
+ $form = $(options.form);
+ } else {
+ remove_form = true;
+ $form = $('<form>', {
+ action: options.url,
+ method: 'POST'
+ }).appendTo(document.body);
+ }
+
+ _(_.extend({}, options.data || {},
+ {session_id: this.session_id, token: token}))
+ .each(function (value, key) {
+ var $input = $form.find('[name=' + key +']');
+ if (!$input.length) {
+ $input = $('<input type="hidden" name="' + key + '">')
+ .appendTo($form_data);
+ }
+ $input.val(value)
+ });
+
+ $form
+ .append($form_data)
+ .attr('target', id)
+ .get(0).submit();
+
+ var waitLoop = function () {
+ var cookies = document.cookie.split(';');
+ // setup next check
+ timer = setTimeout(waitLoop, CHECK_INTERVAL);
+ for (var i=0; i<cookies.length; ++i) {
+ var cookie = cookies[i].replace(/^\s*/, '');
+ if (!cookie.indexOf(cookie_name === 0)) { continue; }
+ var cookie_val = cookie.substring(cookie_length + 1);
+ if (parseInt(cookie_val, 10) !== token) { continue; }
+
+ // clear cookie
+ document.cookie = _.str.sprintf("%s=;expires=%s;path=/",
+ cookie_name, new Date().toGMTString());
+ if (options.success) { options.success(); }
+ complete();
+ return;
+ }
+ };
+ timer = setTimeout(waitLoop, CHECK_INTERVAL);
+ },
+ synchronized_mode: function(to_execute) {
+ var synch = this.synch;
+ this.synch = true;
+ try {
+ return to_execute();
+ } finally {
+ this.synch = synch;
+ }
+ }
+});
+
+/** OpenERP Translations */
+instance.web.TranslationDataBase = instance.web.Class.extend(/** @lends instance.web.TranslationDataBase# */{
+ /**
+ * @constructs instance.web.TranslationDataBase
+ * @extends instance.web.Class
+ */
+ init: function() {
+ this.db = {};
+ this.parameters = {"direction": 'ltr',
+ "date_format": '%m/%d/%Y',
+ "time_format": '%H:%M:%S',
+ "grouping": [],
+ "decimal_point": ".",
+ "thousands_sep": ","};
+ },
+ set_bundle: function(translation_bundle) {
+ var self = this;
+ this.db = {};
+ var modules = _.keys(translation_bundle.modules);
+ modules.sort();
+ if (_.include(modules, "web")) {
+ modules = ["web"].concat(_.without(modules, "web"));
+ }
+ _.each(modules, function(name) {
+ self.add_module_translation(translation_bundle.modules[name]);
+ });
+ if (translation_bundle.lang_parameters) {
+ this.parameters = translation_bundle.lang_parameters;
+ this.parameters.grouping = py.eval(
+ this.parameters.grouping);
+ }
+ },
+ add_module_translation: function(mod) {
+ var self = this;
+ _.each(mod.messages, function(message) {
+ self.db[message.id] = message.string;
+ });
+ },
+ build_translation_function: function() {
+ var self = this;
+ var fcnt = function(str) {
+ var tmp = self.get(str);
+ return tmp === undefined ? str : tmp;
+ };
+ fcnt.database = this;
+ return fcnt;
+ },
+ get: function(key) {
+ if (this.db[key])
+ return this.db[key];
+ return undefined;
+ }
+});
+
/** Configure default qweb */
instance.web._t = new instance.web.TranslationDataBase().build_translation_function();
/**
@@ -98,8 +541,8 @@ $.Mutex = (function() {
return Mutex;
})();
-/** Setup default connection */
-instance.connection = new instance.web.Connection();
+/** Setup default session */
+instance.connection = new instance.web.Session();
instance.web.qweb.default_dict['__debug__'] = instance.connection.debug;
$.async_when = function() {
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js
index 4f18a4c53d9..2dc66aaa135 100644
--- a/addons/web/static/src/js/data.js
+++ b/addons/web/static/src/js/data.js
@@ -18,205 +18,496 @@ instance.web.serialize_sort = function (criterion) {
}).join(', ');
};
-instance.web.DataGroup = instance.web.OldWidget.extend( /** @lends instance.web.DataGroup# */{
+instance.web.Query = instance.web.Class.extend({
+ init: function (model, fields) {
+ this._model = model;
+ this._fields = fields;
+ this._filter = [];
+ this._context = {};
+ this._limit = false;
+ this._offset = 0;
+ this._order_by = [];
+ },
+ clone: function (to_set) {
+ to_set = to_set || {};
+ var q = new instance.web.Query(this._model, this._fields);
+ q._context = this._context;
+ q._filter = this._filter;
+ q._limit = this._limit;
+ q._offset = this._offset;
+ q._order_by = this._order_by;
+
+ for(var key in to_set) {
+ if (!to_set.hasOwnProperty(key)) { continue; }
+ switch(key) {
+ case 'filter':
+ q._filter = new instance.web.CompoundDomain(
+ q._filter, to_set.filter);
+ break;
+ case 'context':
+ q._context = new instance.web.CompoundContext(
+ q._context, to_set.context);
+ break;
+ case 'limit':
+ case 'offset':
+ case 'order_by':
+ q['_' + key] = to_set[key];
+ }
+ }
+ return q;
+ },
+ _execute: function () {
+ var self = this;
+ return instance.connection.rpc('/web/dataset/search_read', {
+ model: this._model.name,
+ fields: this._fields || false,
+ domain: this._model.domain(this._filter),
+ context: this._model.context(this._context),
+ offset: this._offset,
+ limit: this._limit,
+ sort: instance.web.serialize_sort(this._order_by)
+ }).pipe(function (results) {
+ self._count = results.length;
+ return results.records;
+ }, null);
+ },
/**
- * Management interface between views and grouped collections of OpenERP
- * records.
+ * Fetches the first record matching the query, or null
*
- * The root DataGroup is instantiated with the relevant information
- * (a session, a model, a domain, a context and a group_by sequence), the
- * domain and context may be empty. It is then interacted with via
- * :js:func:`~instance.web.DataGroup.list`, which is used to read the
- * content of the current grouping level.
+ * @returns {jQuery.Deferred<Object|null>}
+ */
+ first: function () {
+ var self = this;
+ return this.clone({limit: 1})._execute().pipe(function (records) {
+ delete self._count;
+ if (records.length) { return records[0]; }
+ return null;
+ });
+ },
+ /**
+ * Fetches all records matching the query
*
- * @constructs instance.web.DataGroup
- * @extends instance.web.OldWidget
+ * @returns {jQuery.Deferred<Array<>>}
+ */
+ all: function () {
+ return this._execute();
+ },
+ /**
+ * Fetches the number of records matching the query in the database
*
- * @param {instance.web.OldWidget} parent widget
- * @param {String} model name of the model managed by this DataGroup
- * @param {Array} domain search domain for this DataGroup
- * @param {Object} context context of the DataGroup's searches
- * @param {Array} group_by sequence of fields by which to group
- * @param {Number} [level=0] nesting level of the group
+ * @returns {jQuery.Deferred<Number>}
*/
- init: function(parent, model, domain, context, group_by, level) {
- this._super(parent, null);
- if (group_by) {
- if (group_by.length || context['group_by_no_leaf']) {
- return new instance.web.ContainerDataGroup( this, model, domain, context, group_by, level);
- } else {
- return new instance.web.GrouplessDataGroup( this, model, domain, context, level);
- }
+ count: function () {
+ if (this._count != undefined) { return $.when(this._count); }
+ return this._model.call(
+ 'search_count', [this._filter], {
+ context: this._model.context(this._context)});
+ },
+ /**
+ * Performs a groups read according to the provided grouping criterion
+ *
+ * @param {String|Array<String>} grouping
+ * @returns {jQuery.Deferred<Array<openerp.web.data.Group>> | null}
+ */
+ group_by: function (grouping) {
+ if (grouping === undefined) {
+ return null;
}
- this.model = model;
- this.context = context;
- this.domain = domain;
+ if (!(grouping instanceof Array)) {
+ grouping = _.toArray(arguments);
+ }
+ if (_.isEmpty(grouping)) { return null; }
- this.level = level || 0;
+ var self = this;
+ return this._model.call('read_group', {
+ groupby: grouping,
+ fields: _.uniq(grouping.concat(this._fields || [])),
+ domain: this._model.domain(this._filter),
+ context: this._model.context(this._context),
+ offset: this._offset,
+ limit: this._limit,
+ orderby: instance.web.serialize_sort(this._order_by) || false
+ }).pipe(function (results) {
+ return _(results).map(function (result) {
+ return new instance.web.data.Group(
+ self._model.name, grouping[0], result);
+ });
+ });
},
- cls: 'DataGroup'
-});
-instance.web.ContainerDataGroup = instance.web.DataGroup.extend( /** @lends instance.web.ContainerDataGroup# */ {
/**
+ * Creates a new query with the union of the current query's context and
+ * the new context.
*
- * @constructs instance.web.ContainerDataGroup
- * @extends instance.web.DataGroup
+ * @param context context data to add to the query
+ * @returns {openerp.web.Query}
+ */
+ context: function (context) {
+ if (!context) { return this; }
+ return this.clone({context: context});
+ },
+ /**
+ * Creates a new query with the union of the current query's filter and
+ * the new domain.
+ *
+ * @param domain domain data to AND with the current query filter
+ * @returns {openerp.web.Query}
+ */
+ filter: function (domain) {
+ if (!domain) { return this; }
+ return this.clone({filter: domain});
+ },
+ /**
+ * Creates a new query with the provided limit replacing the current
+ * query's own limit
+ *
+ * @param {Number} limit maximum number of records the query should retrieve
+ * @returns {openerp.web.Query}
+ */
+ limit: function (limit) {
+ return this.clone({limit: limit});
+ },
+ /**
+ * Creates a new query with the provided offset replacing the current
+ * query's own offset
+ *
+ * @param {Number} offset number of records the query should skip before starting its retrieval
+ * @returns {openerp.web.Query}
+ */
+ offset: function (offset) {
+ return this.clone({offset: offset});
+ },
+ /**
+ * Creates a new query with the provided ordering parameters replacing
+ * those of the current query
*
- * @param session
- * @param model
- * @param domain
- * @param context
- * @param group_by
- * @param level
+ * @param {String...} fields ordering clauses
+ * @returns {openerp.web.Query}
*/
- init: function (parent, model, domain, context, group_by, level) {
- this._super(parent, model, domain, context, null, level);
+ order_by: function (fields) {
+ if (fields === undefined) { return this; }
+ if (!(fields instanceof Array)) {
+ fields = _.toArray(arguments);
+ }
+ if (_.isEmpty(fields)) { return this; }
+ return this.clone({order_by: fields});
+ }
+});
- this.group_by = group_by;
+instance.web.Model = instance.web.Class.extend(/** @lends openerp.web.Model# */{
+ /**
+ * @constructs instance.web.Model
+ * @extends instance.web.Class
+ *
+ * @param {String} model_name name of the OpenERP model this object is bound to
+ * @param {Object} [context]
+ * @param {Array} [domain]
+ */
+ init: function (model_name, context, domain) {
+ this.name = model_name;
+ this._context = context || {};
+ this._domain = domain || [];
+ },
+ /**
+ * @deprecated does not allow to specify kwargs, directly use call() instead
+ */
+ get_func: function (method_name) {
+ var self = this;
+ return function () {
+ return self.call(method_name, _.toArray(arguments));
+ };
},
/**
- * The format returned by ``read_group`` is absolutely dreadful:
+ * Call a method (over RPC) on the bound OpenERP model.
*
- * * A ``__context`` key provides future grouping levels
- * * A ``__domain`` key provides the domain for the next search
- * * The current grouping value is provided through the name of the
- * current grouping name e.g. if currently grouping on ``user_id``, then
- * the ``user_id`` value for this group will be provided through the
- * ``user_id`` key.
- * * Similarly, the number of items in the group (not necessarily direct)
- * is provided via ``${current_field}_count``
- * * Other aggregate fields are just dumped there
+ * @param {String} method name of the method to call
+ * @param {Array} [args] positional arguments
+ * @param {Object} [kwargs] keyword arguments
+ * @returns {jQuery.Deferred<>} call result
+ */
+ call: function (method, args, kwargs) {
+ args = args || [];
+ kwargs = kwargs || {};
+ if (!_.isArray(args)) {
+ // call(method, kwargs)
+ kwargs = args;
+ args = [];
+ }
+ return instance.connection.rpc('/web/dataset/call_kw', {
+ model: this.name,
+ method: method,
+ args: args,
+ kwargs: kwargs
+ });
+ },
+ /**
+ * Fetches a Query instance bound to this model, for searching
*
- * This function slightly improves the grouping records by:
+ * @param {Array<String>} [fields] fields to ultimately fetch during the search
+ * @returns {openerp.web.Query}
+ */
+ query: function (fields) {
+ return new instance.web.Query(this, fields);
+ },
+ /**
+ * Executes a signal on the designated workflow, on the bound OpenERP model
*
- * * Adding a ``grouped_on`` property providing the current grouping field
- * * Adding a ``value`` and a ``length`` properties which replace the
- * ``$current_field`` and ``${current_field}_count`` ones
- * * Moving aggregate values into an ``aggregates`` property object
+ * @param {Number} id workflow identifier
+ * @param {String} signal signal to trigger on the workflow
+ */
+ exec_workflow: function (id, signal) {
+ return instance.connection.rpc('/web/dataset/exec_workflow', {
+ model: this.name,
+ id: id,
+ signal: signal
+ });
+ },
+ /**
+ * Fetches the model's domain, combined with the provided domain if any
*
- * Context and domain keys remain as-is, they should not be used externally
- * but in case they're needed...
+ * @param {Array} [domain] to combine with the model's internal domain
+ * @returns The model's internal domain, or the AND-ed union of the model's internal domain and the provided domain
+ */
+ domain: function (domain) {
+ if (!domain) { return this._domain; }
+ return new instance.web.CompoundDomain(
+ this._domain, domain);
+ },
+ /**
+ * Fetches the combination of the user's context and the domain context,
+ * combined with the provided context if any
*
- * @param {Object} group ``read_group`` record
+ * @param {Object} [context] to combine with the model's internal context
+ * @returns The union of the user's context and the model's internal context, as well as the provided context if any. In that order.
*/
- transform_group: function (group) {
- var field_name = this.group_by[0];
- // In cases where group_by_no_leaf and no group_by, the result of
- // read_group has aggregate fields but no __context or __domain.
- // Create default (empty) values for those so that things don't break
- var fixed_group = _.extend(
- {__context: {group_by: []}, __domain: []},
- group);
-
- var aggregates = {};
- _(fixed_group).each(function (value, key) {
- if (key.indexOf('__') === 0
- || key === field_name
- || key === field_name + '_count') {
- return;
- }
- aggregates[key] = value || 0;
+ context: function (context) {
+ return new instance.web.CompoundContext(
+ instance.connection.user_context, this._context, context || {});
+ },
+ /**
+ * Button action caller, needs to perform cleanup if an action is returned
+ * from the button (parsing of context and domain, and fixup of the views
+ * collection for act_window actions)
+ *
+ * FIXME: remove when evaluator integrated
+ */
+ call_button: function (method, args) {
+ return instance.connection.rpc('/web/dataset/call_button', {
+ model: this.name,
+ method: method,
+ domain_id: null,
+ context_id: args.length - 1,
+ args: args || []
});
+ },
+});
- var group_size = fixed_group[field_name + '_count'] || fixed_group.__count || 0;
- var leaf_group = fixed_group.__context.group_by.length === 0;
- return {
- __context: fixed_group.__context,
- __domain: fixed_group.__domain,
-
- grouped_on: field_name,
- // if terminal group (or no group) and group_by_no_leaf => use group.__count
- length: group_size,
- value: fixed_group[field_name],
- // A group is openable if it's not a leaf in group_by_no_leaf mode
- openable: !(leaf_group && this.context['group_by_no_leaf']),
+instance.web.Traverser = instance.web.Class.extend(/** @lends openerp.web.Traverser# */{
+ /**
+ * @constructs instance.web.Traverser
+ * @extends instance.web.Class
+ *
+ * @param {instance.web.Model} model instance this traverser is bound to
+ */
+ init: function (model) {
+ this._model = model;
+ this._index = 0;
+ },
- aggregates: aggregates
- };
+ /**
+ * Gets and sets the current index
+ *
+ * @param {Number} [idx]
+ * @returns {Number} current index
+ */
+ index: function (idx) {
+ if (idx) { this._index = idx; }
+ return this._index;
+ },
+ /**
+ * Returns the model this traverser is currently bound to
+ *
+ * @returns {openerp.web.Model}
+ */
+ model: function () {
+ return this._model;
+ },
+ /**
+ * Fetches the size of the backing model's match
+ *
+ * @returns {Deferred<Number>} deferred count
+ */
+ size: function () {
+ return this._model.query().count();
},
- fetch: function (fields) {
- // internal method
- var d = new $.Deferred();
- var self = this;
- this.rpc('/web/group/read', {
- model: this.model,
- context: this.context,
- domain: this.domain,
- fields: _.uniq(this.group_by.concat(fields)),
- group_by_fields: this.group_by,
- sort: instance.web.serialize_sort(this.sort)
- }, function () { }).then(function (response) {
- var data_groups = _(response).map(
- _.bind(self.transform_group, self));
- self.groups = data_groups;
- d.resolveWith(self, [data_groups]);
- }, function () {
- d.rejectWith.apply(d, [self, arguments]);
- });
- return d.promise();
- },
- /**
- * The items of a list have the following properties:
- *
- * ``length``
- * the number of records contained in the group (and all of its
- * sub-groups). This does *not* provide the size of the "next level"
- * of the group, unless the group is terminal (no more groups within
- * it).
- * ``grouped_on``
- * the name of the field this level was grouped on, this is mostly
- * used for display purposes, in order to know the name of the current
- * level of grouping. The ``grouped_on`` should be the same for all
- * objects of the list.
- * ``value``
- * the value which led to this group (this is the value all contained
- * records have for the current ``grouped_on`` field name).
- * ``aggregates``
- * a mapping of other aggregation fields provided by ``read_group``
- *
- * @param {Array} fields the list of fields to aggregate in each group, can be empty
- * @param {Function} ifGroups function executed if any group is found (DataGroup.group_by is non-null and non-empty), called with a (potentially empty) list of groups as parameters.
- * @param {Function} ifRecords function executed if there is no grouping left to perform, called with a DataSet instance as parameter
+ /**
+ * Record at the current index for the collection, fails if there is no
+ * record at the current index.
+ *
+ * @returns {Deferred<>}
*/
- list: function (fields, ifGroups, ifRecords) {
+ current: function (fields) {
+ return this._model.query(fields).first().pipe(function (record) {
+ if (record == null) {
+ return $.Deferred()
+ .reject('No record at index' + this._index)
+ .promise();
+ }
+ return record;
+ });
+ },
+ next: function (fields) {
var self = this;
- this.fetch(fields).then(function (group_records) {
- ifGroups(_(group_records).map(function (group) {
- var child_context = _.extend({}, self.context, group.__context);
- return _.extend(
- new instance.web.DataGroup(
- self, self.model, group.__domain,
- child_context, child_context.group_by,
- self.level + 1),
- group, {sort: self.sort});
- }));
+ this._index++;
+ return this.size().pipe(function (s) {
+ if (self._index >= s) {
+ self._index = 0;
+ }
+ return self.current(fields);
});
+ },
+ previous: function (fields) {
+ var self = this;
+ this._index--;
+ if (this._index < 0) {
+ return this.size().pipe(function (s) {
+ self._index = s-1;
+ return self.current(fields);
+ });
+ }
+ return this.current(fields);
}
+
});
-instance.web.GrouplessDataGroup = instance.web.DataGroup.extend( /** @lends instance.web.GrouplessDataGroup# */ {
+
+/**
+ * Utility objects, should never need to be instantiated from outside of this
+ * module
+ *
+ * @namespace
+ */
+instance.web.data = {
+ Group: instance.web.Class.extend(/** @lends openerp.web.data.Group# */{
+ /**
+ * @constructs instance.web.data.Group
+ * @extends instance.web.Class
+ */
+ init: function (model, grouping_field, read_group_group) {
+ // In cases where group_by_no_leaf and no group_by, the result of
+ // read_group has aggregate fields but no __context or __domain.
+ // Create default (empty) values for those so that things don't break
+ var fixed_group = _.extend(
+ {__context: {group_by: []}, __domain: []},
+ read_group_group);
+
+ var aggregates = {};
+ _(fixed_group).each(function (value, key) {
+ if (key.indexOf('__') === 0
+ || key === grouping_field
+ || key === grouping_field + '_count') {
+ return;
+ }
+ aggregates[key] = value || 0;
+ });
+
+ this.model = new instance.web.Model(
+ model, fixed_group.__context, fixed_group.__domain);
+
+ var group_size = fixed_group[grouping_field + '_count'] || fixed_group.__count || 0;
+ var leaf_group = fixed_group.__context.group_by.length === 0;
+ this.attributes = {
+ grouped_on: grouping_field,
+ // if terminal group (or no group) and group_by_no_leaf => use group.__count
+ length: group_size,
+ value: fixed_group[grouping_field],
+ // A group is open-able if it's not a leaf in group_by_no_leaf mode
+ has_children: !(leaf_group && fixed_group.__context['group_by_no_leaf']),
+
+ aggregates: aggregates
+ };
+ },
+ get: function (key) {
+ return this.attributes[key];
+ },
+ subgroups: function () {
+ return this.model.query().group_by(this.model.context().group_by);
+ },
+ query: function () {
+ return this.model.query.apply(this.model, arguments);
+ }
+ })
+};
+
+instance.web.DataGroup = instance.web.OldWidget.extend( /** @lends openerp.web.DataGroup# */{
/**
+ * Management interface between views and grouped collections of OpenERP
+ * records.
*
- * @constructs instance.web.GrouplessDataGroup
- * @extends instance.web.DataGroup
+ * The root DataGroup is instantiated with the relevant information
+ * (a session, a model, a domain, a context and a group_by sequence), the
+ * domain and context may be empty. It is then interacted with via
+ * :js:func:`~instance.web.DataGroup.list`, which is used to read the
+ * content of the current grouping level.
+ *
+ * @constructs instance.web.DataGroup
+ * @extends instance.web.OldWidget
*
- * @param session
- * @param model
- * @param domain
- * @param context
- * @param level
+ * @param {instance.web.OldWidget} parent widget
+ * @param {String} model name of the model managed by this DataGroup
+ * @param {Array} domain search domain for this DataGroup
+ * @param {Object} context context of the DataGroup's searches
+ * @param {Array} group_by sequence of fields by which to group
+ * @param {Number} [level=0] nesting level of the group
*/
- init: function (parent, model, domain, context, level) {
- this._super(parent, model, domain, context, null, level);
+ init: function(parent, model, domain, context, group_by, level) {
+ this._super(parent, null);
+ this.model = new instance.web.Model(model, context, domain);
+ this.group_by = group_by;
+ this.context = context;
+ this.domain = domain;
+
+ this.level = level || 0;
},
list: function (fields, ifGroups, ifRecords) {
- ifRecords(_.extend(
- new instance.web.DataSetSearch(this, this.model),
- {domain: this.domain, context: this.context, _sort: this.sort}));
+ var self = this;
+ $.when(this.model.query(fields)
+ .order_by(this.sort)
+ .group_by(this.group_by)).then(function (groups) {
+ if (!groups) {
+ ifRecords(_.extend(
+ new instance.web.DataSetSearch(
+ self, self.model.name,
+ self.model.context(),
+ self.model.domain()),
+ {_sort: self.sort}));
+ return;
+ }
+ ifGroups(_(groups).map(function (group) {
+ var child_context = _.extend(
+ {}, self.model.context(), group.model.context());
+ return _.extend(
+ new instance.web.DataGroup(
+ self, self.model.name, group.model.domain(),
+ child_context, group.model._context.group_by,
+ self.level + 1),
+ {
+ __context: child_context,
+ __domain: group.model.domain(),
+ grouped_on: group.get('grouped_on'),
+ length: group.get('length'),
+ value: group.get('value'),
+ openable: group.get('has_children'),
+ aggregates: group.get('aggregates')
+ }, {sort: self.sort});
+ }));
+ });
}
});
-instance.web.StaticDataGroup = instance.web.GrouplessDataGroup.extend( /** @lends instance.web.StaticDataGroup# */ {
+instance.web.ContainerDataGroup = instance.web.DataGroup.extend({ });
+instance.web.GrouplessDataGroup = instance.web.DataGroup.extend({ });
+
+instance.web.StaticDataGroup = instance.web.GrouplessDataGroup.extend( /** @lends openerp.web.StaticDataGroup# */ {
/**
* A specialization of groupless data groups, relying on a single static
* dataset as its records provider.
@@ -233,7 +524,7 @@ instance.web.StaticDataGroup = instance.web.GrouplessDataGroup.extend( /** @lend
}
});
-instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.DataSet# */{
+instance.web.DataSet = instance.web.OldWidget.extend( /** @lends openerp.web.DataSet# */{
/**
* DateaManagement interface between views and the collection of selected
* OpenERP records (represents the view's state?)
@@ -249,6 +540,7 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
this.context = context || {};
this.index = null;
this._sort = [];
+ this._model = new instance.web.Model(model, context);
},
previous: function () {
this.index -= 1;
@@ -296,13 +588,11 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
read_ids: function (ids, fields, options) {
- var options = options || {};
- return this.rpc('/web/dataset/get', {
- model: this.model,
- ids: ids,
- fields: fields,
- context: this.get_context(options.context)
- });
+ options = options || {};
+ // TODO: reorder results to match ids list
+ return this._model.call('read',
+ [ids, fields || false],
+ {context: this._model.context(options.context)});
},
/**
* Read a slice of the records represented by this DataSet, based on its
@@ -315,7 +605,14 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
read_slice: function (fields, options) {
- return null;
+ var self = this;
+ options = options || {};
+ return this._model.query(fields)
+ .limit(options.limit || false)
+ .offset(options.offset || 0)
+ .all().then(function (records) {
+ self.ids = _(records).pluck('id');
+ });
},
/**
* Reads the current dataset record (from its index)
@@ -325,18 +622,11 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
read_index: function (fields, options) {
- var def = $.Deferred();
- if (_.isEmpty(this.ids)) {
- def.reject();
- } else {
- fields = fields || false;
- this.read_ids([this.ids[this.index]], fields, options).then(function(records) {
- def.resolve(records[0]);
- }, function() {
- def.reject.apply(def, arguments);
- });
- }
- return def.promise();
+ options = options || {};
+ return this.read_ids([this.ids[this.index]], fields, options).pipe(function (records) {
+ if (_.isEmpty(records)) { return $.Deferred().reject().promise(); }
+ return records[0];
+ });
},
/**
* Reads default values for the current model
@@ -346,12 +636,9 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
default_get: function(fields, options) {
- var options = options || {};
- return this.rpc('/web/dataset/default_get', {
- model: this.model,
- fields: fields,
- context: this.get_context(options.context)
- });
+ options = options || {};
+ return this._model.call('default_get',
+ [fields], {context: this._model.context(options.context)});
},
/**
* Creates a new record in db
@@ -362,11 +649,10 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
create: function(data, callback, error_callback) {
- return this.rpc('/web/dataset/create', {
- model: this.model,
- data: data,
- context: this.get_context()
- }, callback, error_callback);
+ return this._model.call('create',
+ [data], {context: this._model.context()})
+ .pipe(function (r) { return {result: r}; })
+ .then(callback, error_callback);
},
/**
* Saves the provided data in an existing db record
@@ -379,12 +665,10 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
*/
write: function (id, data, options, callback, error_callback) {
options = options || {};
- return this.rpc('/web/dataset/save', {
- model: this.model,
- id: id,
- data: data,
- context: this.get_context(options.context)
- }, callback, error_callback);
+ return this._model.call('write',
+ [[id], data], {context: this._model.context(options.context)})
+ .pipe(function (r) { return {result: r}})
+ .then(callback, error_callback);
},
/**
* Deletes an existing record from the database
@@ -394,9 +678,9 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @param {Function} error_callback function called in case of deletion error
*/
unlink: function(ids, callback, error_callback) {
- var self = this;
- return this.call_and_eval("unlink", [ids, this.get_context()], null, 1,
- callback, error_callback);
+ return this._model.call('unlink',
+ [ids], {context: this._model.context()})
+ .then(callback, error_callback);
},
/**
* Calls an arbitrary RPC method
@@ -408,11 +692,7 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
call: function (method, args, callback, error_callback) {
- return this.rpc('/web/dataset/call', {
- model: this.model,
- method: method,
- args: args || []
- }, callback, error_callback);
+ return this._model.call(method, args).then(callback, error_callback);
},
/**
* Calls an arbitrary method, with more crazy
@@ -431,9 +711,7 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
method: method,
domain_id: domain_index == undefined ? null : domain_index,
context_id: context_index == undefined ? null : context_index,
- args: args || [],
- // FIXME: API which does not suck for aborting requests in-flight
- aborter: this
+ args: args || []
}, callback, error_callback);
},
/**
@@ -446,13 +724,8 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
call_button: function (method, args, callback, error_callback) {
- return this.rpc('/web/dataset/call_button', {
- model: this.model,
- method: method,
- domain_id: null,
- context_id: args.length - 1,
- args: args || []
- }, callback, error_callback);
+ return this._model.call_button(method, args)
+ .then(callback, error_callback);
},
/**
* Fetches the "readable name" for records, based on intrinsic rules
@@ -462,7 +735,9 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
name_get: function(ids, callback) {
- return this.call_and_eval('name_get', [ids, this.get_context()], null, 1, callback);
+ return this._model.call('name_get',
+ [ids], {context: this._model.context()})
+ .then(callback);
},
/**
*
@@ -474,29 +749,30 @@ instance.web.DataSet = instance.web.OldWidget.extend( /** @lends instance.web.D
* @returns {$.Deferred}
*/
name_search: function (name, domain, operator, limit, callback) {
- return this.call_and_eval('name_search',
- [name || '', domain || false, operator || 'ilike', this.get_context(), limit || 0],
- 1, 3, callback);
+ return this._model.call('name_search', {
+ name: name || '',
+ args: domain || false,
+ operator: operator || 'ilike',
+ context: this._model.context(),
+ limit: limit || 0
+ }).then(callback);
},
/**
* @param name
* @param callback
*/
name_create: function(name, callback) {
- return this.call_and_eval('name_create', [name, this.get_context()], null, 1, callback);
+ return this._model.call('name_create',
+ [name], {context: this._model.context()})
+ .then(callback);
},
exec_workflow: function (id, signal, callback) {
- return this.rpc('/web/dataset/exec_workflow', {
- model: this.model,
- id: id,
- signal: signal
- }, callback);
+ return this._model.exec_workflow(id, signal)
+ .pipe(function (result) { return { result: result }; })
+ .then(callback);
},
get_context: function(request_context) {
- if (request_context) {
- return new instance.web.CompoundContext(this.context, request_context);
- }
- return this.context;
+ return this._model.context(request_context);
},
/**
* Reads or changes sort criteria on the dataset.
@@ -560,7 +836,7 @@ instance.web.DataSetStatic = instance.web.DataSet.extend({
this.set_ids(_.without.apply(null, [this.ids].concat(ids)));
}
});
-instance.web.DataSetSearch = instance.web.DataSet.extend(/** @lends instance.web.DataSetSearch */{
+instance.web.DataSetSearch = instance.web.DataSet.extend(/** @lends openerp.web.DataSetSearch */{
/**
* @constructs instance.web.DataSetSearch
* @extends instance.web.DataSet
@@ -573,11 +849,9 @@ instance.web.DataSetSearch = instance.web.DataSet.extend(/** @lends instance.we
init: function(parent, model, context, domain) {
this._super(parent, model, context);
this.domain = domain || [];
- this.offset = 0;
- this._length;
- // subset records[offset:offset+limit]
- // is it necessary ?
+ this._length = null;
this.ids = [];
+ this._model = new instance.web.Model(model, context, domain);
},
/**
* Read a slice of the records represented by this DataSet, based on its
@@ -594,32 +868,29 @@ instance.web.DataSetSearch = instance.web.DataSet.extend(/** @lends instance.we
read_slice: function (fields, options) {
options = options || {};
var self = this;
- var offset = options.offset || 0;
- return this.rpc('/web/dataset/search_read', {
- model: this.model,
- fields: fields || false,
- domain: this.get_domain(options.domain),
- context: this.get_context(options.context),
- sort: this.sort(),
- offset: offset,
- limit: options.limit || false
- }).pipe(function (result) {
- self.ids = result.ids;
- self.offset = offset;
- self._length = result.length;
- return result.records;
+ var q = this._model.query(fields || false)
+ .filter(options.domain)
+ .context(options.context)
+ .offset(options.offset || 0)
+ .limit(options.limit || false);
+ q = q.order_by.apply(q, this._sort);
+
+ return q.all().then(function (records) {
+ // FIXME: not sure about that one, *could* have discarded count
+ q.count().then(function (count) { self._length = count; });
+ self.ids = _(records).pluck('id');
});
},
get_domain: function (other_domain) {
- if (other_domain) {
- return new instance.web.CompoundDomain(this.domain, other_domain);
- }
- return this.domain;
+ this._model.domain(other_domain);
},
unlink: function(ids, callback, error_callback) {
var self = this;
return this._super(ids, function(result) {
- self.ids = _.without.apply(_, [self.ids].concat(ids));
+ self.ids = _(self.ids).difference(ids);
+ if (self._length) {
+ self._length -= 1;
+ }
if (this.index !== null) {
self.index = self.index <= self.ids.length - 1 ?
self.index : (self.ids.length > 0 ? self.ids.length -1 : 0);
@@ -848,34 +1119,6 @@ instance.web.ProxyDataSet = instance.web.DataSetSearch.extend({
on_unlink: function(ids) {}
});
-instance.web.Model = instance.web.CallbackEnabled.extend({
- init: function(model_name) {
- this._super();
- this.model_name = model_name;
- },
- rpc: function() {
- var c = instance.connection;
- return c.rpc.apply(c, arguments);
- },
- /*
- * deprecated because it does not allow to specify kwargs, directly use call() instead
- */
- get_func: function(method_name) {
- var self = this;
- return function() {
- return self.call(method_name, _.toArray(arguments), {});
- };
- },
- call: function (method, args, kwargs) {
- return this.rpc('/web/dataset/call_kw', {
- model: this.model_name,
- method: method,
- args: args,
- kwargs: kwargs
- });
- }
-});
-
instance.web.CompoundContext = instance.web.Class.extend({
init: function () {
this.__ref = "compound_context";
@@ -921,6 +1164,46 @@ instance.web.CompoundDomain = instance.web.Class.extend({
return this.__eval_context;
}
});
+
+instance.web.DropMisordered = instance.web.Class.extend(/** @lends openerp.web.DropMisordered# */{
+ /**
+ * @constructs instance.web.DropMisordered
+ * @extends instance.web.Class
+ *
+ * @param {Boolean} [failMisordered=false] whether mis-ordered responses should be failed or just ignored
+ */
+ init: function (failMisordered) {
+ // local sequence number, for requests sent
+ this.lsn = 0;
+ // remote sequence number, seqnum of last received request
+ this.rsn = -1;
+ this.failMisordered = failMisordered || false;
+ },
+ /**
+ * Adds a deferred (usually an async request) to the sequencer
+ *
+ * @param {$.Deferred} deferred to ensure add
+ * @returns {$.Deferred}
+ */
+ add: function (deferred) {
+ var res = $.Deferred();
+
+ var self = this, seq = this.lsn++;
+ deferred.then(function () {
+ if (seq > self.rsn) {
+ self.rsn = seq;
+ res.resolve.apply(res, arguments);
+ } else if (self.failMisordered) {
+ res.reject();
+ }
+ }, function () {
+ res.reject.apply(res, arguments);
+ });
+
+ return res.promise();
+ }
+});
+
};
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js
index 107a923b625..640ba4d5a93 100644
--- a/addons/web/static/src/js/formats.js
+++ b/addons/web/static/src/js/formats.js
@@ -111,7 +111,7 @@ instance.web.format_value = function (value, descriptor, value_if_empty) {
return value_if_empty === undefined ? '' : value_if_empty;
}
var l10n = _t.database.parameters;
- switch (descriptor.widget || descriptor.type) {
+ switch (descriptor.type || (descriptor.field && descriptor.field.type)) {
case 'id':
return value.toString();
case 'integer':
@@ -171,7 +171,7 @@ instance.web.parse_value = function (value, descriptor, value_if_empty) {
case "":
return value_if_empty === undefined ? false : value_if_empty;
}
- switch (descriptor.widget || descriptor.type) {
+ switch (descriptor.type || (descriptor.field && descriptor.field.type)) {
case 'integer':
var tmp;
do {
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 18ac6b78de5..c2df866b5c6 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -1403,7 +1403,6 @@ instance.web.search.ExtendedSearchProposition = instance.web.OldWidget.extend(/*
var type = field.type;
var obj = instance.web.search.custom_filters.get_object(type);
if(obj === null) {
- console.log('Unknow field type ' + e.key);
obj = instance.web.search.custom_filters.get_object("char");
}
this.value = new (obj) (this);
diff --git a/addons/web/static/src/js/test_support.js b/addons/web/static/src/js/test_support.js
new file mode 100644
index 00000000000..d46366326b7
--- /dev/null
+++ b/addons/web/static/src/js/test_support.js
@@ -0,0 +1,79 @@
+openerp.test_support = {
+ setup_connection: function (connection) {
+ var origin = location.protocol+"//"+location.host;
+ _.extend(connection, {
+ origin: origin,
+ prefix: origin,
+ server: origin, // keep chs happy
+ //openerp.web.qweb.default_dict['_s'] = this.origin;
+ rpc_function: connection.rpc_json,
+ session_id: false,
+ uid: false,
+ username: false,
+ user_context: {},
+ db: false,
+ openerp_entreprise: false,
+// this.module_list = openerp._modules.slice();
+// this.module_loaded = {};
+// _(this.module_list).each(function (mod) {
+// self.module_loaded[mod] = true;
+// });
+ context: {},
+ shortcuts: [],
+ active_id: null
+ });
+ return connection.session_reload();
+ },
+ module: function (title, tested_core, nonliterals) {
+ var conf = QUnit.config.openerp = {};
+ QUnit.module(title, {
+ setup: function () {
+ QUnit.stop();
+ var oe = conf.openerp = window.openerp.init();
+ window.openerp.web[tested_core](oe);
+ var done = openerp.test_support.setup_connection(oe.connection);
+ if (nonliterals) {
+ done = done.pipe(function () {
+ return oe.connection.rpc('/tests/add_nonliterals', {
+ domains: nonliterals.domains || [],
+ contexts: nonliterals.contexts || []
+ }).then(function (r) {
+ oe.domains = r.domains;
+ oe.contexts = r.contexts;
+ });
+ });
+ }
+ done.always(QUnit.start)
+ .then(function () {
+ conf.openerp = oe;
+ }, function (e) {
+ QUnit.test(title, function () {
+ console.error(e);
+ QUnit.ok(false, 'Could not obtain a session:' + e.debug);
+ });
+ });
+ }
+ });
+ },
+ test: function (title, fn) {
+ var conf = QUnit.config.openerp;
+ QUnit.test(title, function () {
+ QUnit.stop();
+ fn(conf.openerp);
+ });
+ },
+ expect: function (promise, fn) {
+ promise.always(QUnit.start)
+ .done(function () { QUnit.ok(false, 'RPC requests should not succeed'); })
+ .fail(function (e) {
+ if (e.code !== 200) {
+ QUnit.equal(e.code, 200, 'Testing connector should raise RPC faults');
+ if (typeof console !== 'undefined' && console.error) {
+ console.error(e.data.debug);
+ }
+ return;
+ }
+ fn(e.data.fault_code);
+ })
+ }
+};
diff --git a/addons/web/static/src/js/view_editor.js b/addons/web/static/src/js/view_editor.js
index 59d1fed9345..6a14c0ef7f9 100644
--- a/addons/web/static/src/js/view_editor.js
+++ b/addons/web/static/src/js/view_editor.js
@@ -873,7 +873,8 @@ instance.web.ViewEditor = instance.web.OldWidget.extend({
'widget' : {'name':'widget', 'string': 'widget', 'type': 'selection'},
'colors' : {'name':'colors', 'string': 'Colors', 'type': 'char'},
'editable' : {'name':'editable', 'string': 'Editable', 'type': 'selection', 'selection': [["",""],["top","Top"],["bottom", "Bottom"]]},
- 'groups' : {'name':'groups', 'string': 'Groups', 'type': 'selection_multi'}
+ 'groups' : {'name':'groups', 'string': 'Groups', 'type': 'selection_multi'},
+ 'fonts' : {'name':'fonts', 'string': 'fonts', 'type': 'char'},
};
var arch_val = self.get_object_by_id(this.one_object.clicked_tr_id,this.one_object['main_object'], []);
this.edit_node_dialog.$element.append('<table id="rec_table" style="width:400px" class="oe_forms"></table>');
@@ -1149,7 +1150,7 @@ var _PROPERTIES = {
'board': ['style'],
'column' : [],
'action' : ['name', 'string', 'colspan', 'groups'],
- 'tree' : ['string', 'colors', 'editable', 'link', 'limit', 'min_rows'],
+ 'tree' : ['string', 'colors', 'editable', 'link', 'limit', 'min_rows', 'fonts'],
'graph' : ['string', 'type'],
'calendar' : ['string', 'date_start', 'date_stop', 'date_delay', 'day_length', 'color', 'mode']
};
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 3cda7bf1b4c..09dd69074d8 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -6,8 +6,34 @@ var QWeb = instance.web.qweb;
/** @namespace */
instance.web.form = {};
+/**
+ * Interface implemented by the form view or any other object
+ * able to provide the features necessary for the fields to work.
+ *
+ * Properties:
+ * - display_invalid_fields : if true, all fields where is_valid() return true should
+ * be displayed as invalid.
+ * Events:
+ * - view_content_has_changed : when the values of the fields have changed. When
+ * this event is triggered all fields should reprocess their modifiers.
+ */
+instance.web.form.FieldManagerMixin = {
+ /**
+ * Must return the asked field as in fields_get.
+ */
+ get_field: function(field_name) {},
+ /**
+ * Called by the field when the translate button is clicked.
+ */
+ open_translate_dialog: function(field) {},
+ /**
+ * Returns true when the view is in create mode.
+ */
+ is_create_mode: function() {},
+};
+
instance.web.views.add('form', 'instance.web.FormView');
-instance.web.FormView = instance.web.View.extend({
+instance.web.FormView = instance.web.View.extend(_.extend({}, instance.web.form.FieldManagerMixin, {
/**
* Indicates that this view is not searchable, and thus that no search
* view should be displayed (if there is one active).
@@ -24,7 +50,6 @@ instance.web.FormView = instance.web.View.extend({
* @param {instance.web.DataSet} dataset the dataset this view will work with
* @param {String} view_id the identifier of the OpenERP view object
* @param {Object} options
- * - sidebar : [true|false]
* - resize_textareas : [true|false|max_height]
*
* @property {instance.web.Registry} registry=instance.web.form.widgets widgets registry for this form view instance
@@ -53,7 +78,6 @@ instance.web.FormView = instance.web.View.extend({
this.mutating_mutex = new $.Mutex();
this.on_change_mutex = new $.Mutex();
this.reload_mutex = new $.Mutex();
- this.mode = null;
this.rendering_engine = new instance.web.form.FormRenderingEngineReadonly(this);
this.qweb = null; // A QWeb instance will be created if the view is a QWeb template
},
@@ -90,13 +114,12 @@ instance.web.FormView = instance.web.View.extend({
} else {
this.$element.find('.oe_form_buttons').replaceWith(this.$buttons);
}
- this.$buttons
- .on('click','button.oe_form_button_save',this.on_button_save)
- .on('click','button.oe_form_button_cancel',this.on_button_cancel)
- .on('click','button.oe_form_button_edit',this.on_button_edit)
- .on('click','button.oe_form_button_create',this.on_button_create)
- .on('click','button.oe_form_button_duplicate',this.on_button_duplicate)
- .on('click','button.oe_form_button_delete',this.on_button_delete);
+ this.$buttons.on('click','.oe_form_button_create',this.on_button_create);
+ this.$buttons.on('click','.oe_form_button_edit',this.on_button_edit);
+ this.$buttons.on('click','.oe_form_button_duplicate',this.on_button_duplicate);
+ this.$buttons.on('click','.oe_form_button_delete',this.on_button_delete);
+ this.$buttons.on('click','.oe_form_button_save',this.on_button_save);
+ this.$buttons.on('click','.oe_form_button_cancel',this.on_button_cancel);
this.$pager = $(QWeb.render("FormView.pager", {'widget':self}));
if (this.options.$pager) {
@@ -109,7 +132,7 @@ instance.web.FormView = instance.web.View.extend({
self.on_pager_action(action);
});
- if (!this.sidebar && this.options.sidebar) {
+ if (!this.sidebar && this.options.$sidebar) {
this.sidebar = new instance.web.Sidebar(this);
this.sidebar.appendTo(this.$sidebar);
if(this.fields_view.toolbar) {
@@ -247,7 +270,7 @@ instance.web.FormView = instance.web.View.extend({
}
_(this.fields).each(function (field, f) {
- field.reset();
+ field._dirty_flag = false;
var result = field.set_value(self.datarecord[f] || false);
set_values.push(result);
});
@@ -258,7 +281,7 @@ instance.web.FormView = instance.web.View.extend({
_.each(self.fields_order, function(field_name) {
if (record[field_name] !== undefined) {
var field = self.fields[field_name];
- field.dirty = true;
+ field._dirty_flag = true;
self.do_onchange(field);
}
});
@@ -281,9 +304,6 @@ instance.web.FormView = instance.web.View.extend({
},
on_form_changed: function() {
this.trigger("view_content_has_changed");
- _.each(this.get_widgets(), function(w) {
- w.update_dom();
- });
},
do_notify_change: function() {
this.$element.addClass('oe_form_dirty');
@@ -469,7 +489,7 @@ instance.web.FormView = instance.web.View.extend({
var value_ = result.value[f];
if (field.get_value() != value_) {
field.set_value(value_);
- field.dirty = true;
+ field._dirty_flag = true;
if (!_.contains(processed, field.name)) {
this.do_onchange(field, processed);
}
@@ -503,9 +523,8 @@ instance.web.FormView = instance.web.View.extend({
}
},
switch_mode: function() {
- var mode = this.get("mode");
var self = this;
- if(mode=="view") {
+ if(this.get("mode") == "view") {
self.$buttons.find('.oe_form_buttons_edit').hide();
self.$buttons.find('.oe_form_buttons_view').show();
_.each(this.fields,function(field){
@@ -518,7 +537,6 @@ instance.web.FormView = instance.web.View.extend({
field.set({"force_readonly": false});
});
}
- self.mode = mode;
},
on_button_save: function() {
var self = this;
@@ -526,10 +544,11 @@ instance.web.FormView = instance.web.View.extend({
self.set({mode: "view"});
});
},
- on_button_cancel: function() {
+ on_button_cancel: function(event) {
if (this.can_be_discarded()) {
this.set({mode: "view"});
}
+ return false;
},
on_button_new: function() {
var self = this;
@@ -611,11 +630,10 @@ instance.web.FormView = instance.web.View.extend({
f = self.fields[f];
if (!f.is_valid()) {
form_invalid = true;
- f.update_dom(true);
if (!first_invalid_field) {
first_invalid_field = f;
}
- } else if (f.name !== 'id' && !f.get("readonly") && (!self.datarecord.id || f.is_dirty())) {
+ } else if (f.name !== 'id' && !f.get("readonly") && (!self.datarecord.id || f._dirty_flag)) {
// Special case 'id' field, do not save this field
// on 'create' : save all non readonly fields
// on 'edit' : save non readonly modified fields
@@ -623,20 +641,23 @@ instance.web.FormView = instance.web.View.extend({
}
}
if (form_invalid) {
+ self.set({'display_invalid_fields': true});
first_invalid_field.focus();
self.on_invalid();
return $.Deferred().reject();
} else {
+ self.set({'display_invalid_fields': false});
var save_deferral;
if (!self.datarecord.id) {
//console.log("FormView(", self, ") : About to create", values);
save_deferral = self.dataset.create(values).pipe(function(r) {
return self.on_created(r, undefined, prepend_on_create);
}, null);
- } else if (_.isEmpty(values)) {
+ } else if (_.isEmpty(values) && ! self.force_dirty) {
//console.log("FormView(", self, ") : Nothing to save");
save_deferral = $.Deferred().resolve({}).promise();
} else {
+ self.force_dirty = false;
//console.log("FormView(", self, ") : About to save", values);
save_deferral = self.dataset.write(self.datarecord.id, values, {}).pipe(function(r) {
return self.on_saved(r);
@@ -725,7 +746,7 @@ instance.web.FormView = instance.web.View.extend({
},
get_widgets: function() {
return _.filter(this.getChildren(), function(obj) {
- return obj instanceof instance.web.form.Widget;
+ return obj instanceof instance.web.form.FormWidget;
});
},
get_fields_values: function(blacklist) {
@@ -754,7 +775,7 @@ instance.web.FormView = instance.web.View.extend({
},
is_dirty: function() {
return _.any(this.fields, function (value_) {
- return value_.is_dirty();
+ return value_._dirty_flag;
});
},
is_interactible_record: function() {
@@ -854,9 +875,12 @@ instance.web.FormView = instance.web.View.extend({
this.translatable_fields.push(field);
}
field.on('changed_value', this, function() {
- this.do_onchange(field);
- this.on_form_changed(true);
- this.do_notify_change();
+ field._dirty_flag = true;
+ if (field.is_syntax_valid()) {
+ this.do_onchange(field);
+ this.on_form_changed(true);
+ this.do_notify_change();
+ }
});
},
get_field: function(field_name) {
@@ -865,23 +889,23 @@ instance.web.FormView = instance.web.View.extend({
is_create_mode: function() {
return !this.datarecord.id;
},
-});
+}));
/**
* Interface to be implemented by rendering engines for the form view.
*/
-instance.web.form.FormRenderingEngineInterface = {
+instance.web.form.FormRenderingEngineInterface = instance.web.Class.extend({
set_fields_view: function(fields_view) {},
set_fields_registry: function(fields_registry) {},
render_to: function($element) {},
-};
+});
/**
* Default rendering engine for the form view.
*
* It is necessary to set the view using set_view() before usage.
*/
-instance.web.form.FormRenderingEngine = instance.web.Class.extend({
+instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInterface.extend({
init: function(view) {
this.view = view;
},
@@ -952,10 +976,10 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
},
toggle_layout_debugging: function() {
if (!this.$target.has('.oe_layout_debug_cell:first').length) {
+ this.$target.find('[title]').removeAttr('title');
this.$target.find('.oe_form_group_cell').each(function() {
- var text = 'W:' + ($(this).attr('width') || '') + ' - C:' + $(this).attr('colspan'),
- $span = $('<span class="oe_layout_debug_cell"/>').text(text);
- $span.prependTo($(this));
+ var text = 'W:' + ($(this).attr('width') || '') + ' - C:' + $(this).attr('colspan');
+ $(this).attr('title', text);
});
}
this.$target.toggleClass('oe_layout_debugging');
@@ -988,13 +1012,18 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
return $tag;
}
},
- process_sheet: function() {
- this.process_form.apply(this, arguments);
+ process_sheet: function($sheet, layout) {
+ var $new_sheet = this.render_element('FormRenderingSheet', layout, $sheet.getAttributes());
+ this.handle_common_properties($new_sheet, $sheet);
+ var $dst = (layout === 'auto') ? $new_sheet.find('group:first') : $new_sheet.find('.oe_form_sheet');
+ $sheet.children().appendTo($dst);
+ $sheet.before($new_sheet).remove();
+ this.process($new_sheet, layout);
},
process_form: function($form, layout) {
var $new_form = this.render_element('FormRenderingForm', layout, $form.getAttributes());
+ this.handle_common_properties($new_form, $form);
var $dst = (layout === 'auto') ? $new_form.find('group:first') : $new_form;
- $new_form.attr("modifiers", $form.attr("modifiers"));
$form.children().appendTo($dst);
if ($form[0] === this.$form[0]) {
// If root element, replace it
@@ -1002,7 +1031,7 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
} else {
$form.before($new_form).remove();
}
- this.process($new_form);
+ this.process($new_form, layout);
},
preprocess_field: function($field) {
var self = this;
@@ -1065,10 +1094,18 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
var children = [];
$group.children().each(function(a,b,c) {
- var $child = $(this),
- colspan = parseInt($child.attr('colspan') || 1, 10),
- tagName = $child[0].tagName.toLowerCase();
- if (tagName === 'newline') {
+ var $child = $(this);
+ var colspan = parseInt($child.attr('colspan') || 1, 10);
+ var tagName = $child[0].tagName.toLowerCase();
+ var $td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
+ var newline = tagName === 'newline';
+ if ($tr && row_cols > 0 && (newline || row_cols < colspan)) {
+ $tr.addClass('oe_form_group_row_incomplete');
+ if (newline) {
+ $tr.addClass('oe_form_group_row_newline');
+ }
+ }
+ if (newline) {
$tr = null;
return;
}
@@ -1078,7 +1115,6 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
}
row_cols -= colspan;
- $td = $('<td/>').addClass('oe_form_group_cell').attr('colspan', colspan);
// invisibility transfer
var field_modifiers = JSON.parse($child.attr('modifiers') || '{}');
var invisible = field_modifiers.invisible;
@@ -1112,21 +1148,36 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
break;
case 'label':
if ($child.attr('for')) {
- $td.attr('width', '1%');
+ $td.attr('width', '1%').addClass('oe_form_group_cell_label');
row_cols--;
total--;
}
break;
default:
- to_compute.push($td);
+ var width = _.str.trim($child.attr('width') || ''),
+ iwidth = parseInt(width, 10);
+ if (iwidth) {
+ if (width.substr(-1) === '%') {
+ total -= iwidth;
+ width = iwidth + '%';
+ }
+ $td.attr('width', width);
+ $child.removeAttr('width');
+ row_cols--;
+ } else {
+ to_compute.push($td);
+ }
+
}
});
var unit = Math.floor(total / row_cols);
- _.each(to_compute, function($td, i) {
- var width = parseInt($td.attr('colspan'), 10) * unit;
- $td.attr('width', ((i == to_compute.length - 1) ? total : width) + '%');
- total -= width;
- });
+ if (!$(this).is('.oe_form_group_row_incomplete')) {
+ _.each(to_compute, function($td, i) {
+ var width = parseInt($td.attr('colspan'), 10) * unit;
+ $td.attr('width', ((i == to_compute.length - 1) ? total : width) + '%');
+ total -= width;
+ });
+ }
});
_.each(children, function(el) {
self.process($(el));
@@ -1195,6 +1246,7 @@ instance.web.form.FormRenderingEngine = instance.web.Class.extend({
if (modifiers.invisible !== undefined)
new instance.web.form.InvisibilityChanger(this.view, this.view, modifiers.invisible, $new_element);
$new_element.addClass($node.attr("class") || "");
+ $new_element.attr('style', $node.attr('style'));
},
});
@@ -1214,7 +1266,6 @@ instance.web.form.FormDialog = instance.web.Dialog.extend({
start: function() {
this._super();
this.form = new instance.web.FormView(this, this.dataset, this.view_id, {
- sidebar: false,
pager: false
});
this.form.appendTo(this.$element);
@@ -1307,7 +1358,7 @@ instance.web.form.compute_domain = function(expr, fields) {
};
/**
- * Must be applied over an class already possessing the GetterSetterMixin.
+ * Must be applied over an class already possessing the PropertiesMixin.
*
* Apply the result of the "invisible" domain to this.$element.
*/
@@ -1335,19 +1386,19 @@ instance.web.form.InvisibilityChangerMixin = {
},
};
-instance.web.form.InvisibilityChanger = instance.web.Class.extend(_.extend({}, instance.web.GetterSetterMixin, instance.web.form.InvisibilityChangerMixin, {
+instance.web.form.InvisibilityChanger = instance.web.Class.extend(_.extend({}, instance.web.PropertiesMixin, instance.web.form.InvisibilityChangerMixin, {
init: function(parent, field_manager, invisible_domain, $element) {
this.setParent(parent);
- instance.web.GetterSetterMixin.init.call(this);
+ instance.web.PropertiesMixin.init.call(this);
instance.web.form.InvisibilityChangerMixin.init.call(this, field_manager, invisible_domain);
this.$element = $element;
this.start();
},
}));
-instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.form.InvisibilityChangerMixin, {
+instance.web.form.FormWidget = instance.web.Widget.extend(_.extend({}, instance.web.form.InvisibilityChangerMixin, {
/**
- * @constructs instance.web.form.Widget
+ * @constructs instance.web.form.FormWidget
* @extends instance.web.Widget
*
* @param view
@@ -1366,10 +1417,6 @@ instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.
this._super();
this.$element.addClass(this.node.attrs["class"] || "");
},
- start: function() {
- this._super();
- instance.web.form.InvisibilityChangerMixin.start.call(this);
- },
destroy: function() {
$.fn.tipsy.clear();
this._super.apply(this, arguments);
@@ -1385,8 +1432,6 @@ instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.
}
this.set(to_set);
},
- update_dom: function() {
- },
do_attach_tooltip: function(widget, trigger, options) {
widget = widget || this;
trigger = trigger || this.$element;
@@ -1408,7 +1453,7 @@ instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.
opacity: 0.85,
trigger: 'hover'
}, options || {});
- trigger.tipsy(options);
+ $(trigger).tipsy(options);
},
_build_view_fields_values: function(blacklist) {
var a_dataset = this.view.dataset;
@@ -1459,7 +1504,7 @@ instance.web.form.Widget = instance.web.Widget.extend(_.extend({}, instance.web.
}
}));
-instance.web.form.WidgetButton = instance.web.form.Widget.extend({
+instance.web.form.WidgetButton = instance.web.form.FormWidget.extend({
template: 'WidgetButton',
init: function(view, node) {
this._super(view, node);
@@ -1469,6 +1514,7 @@ instance.web.form.WidgetButton = instance.web.form.Widget.extend({
// TODO fme: provide enter key binding to widgets
this.view.default_focus_button = this;
}
+ this.view.on('view_content_has_changed', this, this.check_disable);
},
start: function() {
this._super.apply(this, arguments);
@@ -1515,6 +1561,7 @@ instance.web.form.WidgetButton = instance.web.form.Widget.extend({
}
};
if (!this.node.attrs.special) {
+ this.view.force_dirty = true;
return this.view.recursive_save().pipe(exec_action);
} else {
return exec_action();
@@ -1535,10 +1582,6 @@ instance.web.form.WidgetButton = instance.web.form.Widget.extend({
self.view.reload();
});
},
- update_dom: function() {
- this._super.apply(this, arguments);
- this.check_disable();
- },
check_disable: function() {
var disabled = (this.force_disabled || !this.view.is_interactible_record());
this.$element.prop('disabled', disabled);
@@ -1547,31 +1590,6 @@ instance.web.form.WidgetButton = instance.web.form.Widget.extend({
});
/**
- * Interface implemented by the form view or any other object
- * able to provide the features necessary for the fields to work.
- *
- * Properties:
- * - ...
- * Events:
- * - view_content_has_changed : when the values of the fields have changed. When
- * this event is triggered all fields should reprocess their modifiers.
- */
-instance.web.form.FieldManagerInterface = {
- /**
- * Must return the asked field as in fields_get.
- */
- get_field: function(field_name) {},
- /**
- * Called by the field when the translate button is clicked.
- */
- open_translate_dialog: function(field) {},
- /**
- * Returns true when the view is in create mode.
- */
- is_create_mode: function() {},
-};
-
-/**
* Interface to be implemented by fields.
*
* Properties:
@@ -1579,13 +1597,13 @@ instance.web.form.FieldManagerInterface = {
* - force_readonly: boolean, When it is true, the field should always appear
* in read only mode, no matter what the value of the "readonly" property can be.
* Events:
- * - changed_value: called to trigger a on_change in the view
+ * - changed_value: triggered to inform the view to check on_changes
*
*/
-instance.web.form.FieldInterface = {
+instance.web.form.FieldMixin = {
/**
* Constructor takes 2 arguments:
- * - field_manager: Implements FieldManagerInterface
+ * - field_manager: Implements FieldManagerMixin
* - node: the "<field>" node in json form
*/
init: function(field_manager, node) {},
@@ -1628,21 +1646,38 @@ instance.web.form.FieldInterface = {
* Inform the current object of the id it should use to match a html <label> that exists somewhere in the
* view.
*/
- set_input_id: function(id) {}
+ set_input_id: function(id) {},
+ /**
+ * Returns true if is_syntax_valid() returns true and the value is semantically
+ * valid too according to the semantic restrictions applied to the field.
+ */
+ is_valid: function() {},
+ /**
+ * Returns true if the field holds a value which is syntaxically correct, ignoring
+ * the potential semantic restrictions applied to the field.
+ */
+ is_syntax_valid: function() {},
+ /**
+ * Must set the focus on the field.
+ */
+ focus: function() {},
};
/**
- * Abstract class for classes implementing FieldInterface.
+ * Abstract class for classes implementing FieldMixin.
*
* Properties:
* - effective_readonly: when it is true, the widget is displayed as readonly. Vary depending
* the values of the "readonly" property and the "force_readonly" property on the field manager.
+ * - value: useful property to hold the value of the field. By default, set_value() and get_value()
+ * set and retrieve the value property. Changing the value property also triggers automatically
+ * a 'changed_value' event that inform the view to trigger on_changes.
*
*/
-instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends instance.web.form.AbstractField# */{
+instance.web.form.AbstractField = instance.web.form.FormWidget.extend(_.extend({}, instance.web.form.FieldMixin, {
/**
* @constructs instance.web.form.AbstractField
- * @extends instance.web.form.Widget
+ * @extends instance.web.form.FormWidget
*
* @param field_manager
* @param node
@@ -1654,7 +1689,6 @@ instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends ins
this.set({'value': false});
this.field = this.field_manager.get_field(this.name);
this.set({required: this.modifiers['required'] === true});
- this.dirty = false;
// some events to make the property "effective_readonly" sync automatically with "readonly" and
// "force_readonly"
@@ -1668,34 +1702,37 @@ instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends ins
this.on("change:value", this, function() {
if (! this._inhibit_on_change)
- this._on_ui_change();
+ this.trigger('changed_value');
+ this._check_css_flags();
});
},
- start: function() {
- this._super.apply(this, arguments);
+ renderElement: function() {
+ this._super();
if (this.field.translate) {
this.$element.addClass('oe_form_field_translatable');
- this.$element.find('.oe_field_translate').click(this.on_translate);
+ this.$element.find('.oe_field_translate').click(_.bind(function() {
+ this.field_manager.open_translate_dialog(this);
+ }, this));
}
if (instance.connection.debug) {
- this.do_attach_tooltip(this, this.$element);
+ this.do_attach_tooltip(this, this.view.$element.find('label[for=' + this.id_for_label + ']')[0] || this.$element);
}
if (!this.disable_utility_classes) {
- var set_required = function() {
- this.$element.toggleClass('oe_form_required', this.get("required"));
- };
- this.on("change:required", this, set_required);
- _.bind(set_required, this)();
+ this.off("change:required", this, this._set_required);
+ this.on("change:required", this, this._set_required);
+ this._set_required();
}
},
+ /**
+ * Private. Do not use.
+ */
+ _set_required: function() {
+ this.$element.toggleClass('oe_form_required', this.get("required"));
+ },
set_value: function(value_) {
this._inhibit_on_change = true;
this.set({'value': value_});
this._inhibit_on_change = false;
- this.update_dom();
- },
- on_translate: function() {
- this.field_manager.open_translate_dialog(this);
},
get_value: function() {
return this.get('value');
@@ -1706,41 +1743,36 @@ instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends ins
is_syntax_valid: function() {
return true;
},
+ /**
+ * Method useful to implement to ease validity testing. Must return true if the current
+ * value is similar to false in OpenERP.
+ */
is_false: function() {
return this.get('value') === false;
},
- is_dirty: function() {
- return this.dirty && !this.get("effective_readonly");
- },
- update_dom: function(show_invalid) {
- this._super.apply(this, arguments);
+ _check_css_flags: function(show_invalid) {
if (this.field.translate) {
this.$element.find('.oe_field_translate').toggle(!this.field_manager.is_create_mode());
}
if (!this.disable_utility_classes) {
- if (show_invalid) {
+ if (this.field_manager.get('display_invalid_fields')) {
this.$element.toggleClass('oe_form_invalid', !this.is_valid());
}
}
},
- _on_ui_change: function() {
- this.dirty = true;
- if (this.is_syntax_valid()) {
- this.trigger('changed_value');
- } else {
- this.update_dom(true);
- }
+ focus: function() {
},
- focus: function($element) {
- if ($element) {
- setTimeout(function() {
- $element.focus();
- }, 50);
- }
- },
- reset: function() {
- this.dirty = false;
+ /**
+ * Utility method to focus an element, but only after a small amount of time.
+ */
+ delay_focus: function($elem) {
+ setTimeout(function() {
+ $elem.focus();
+ }, 50);
},
+ /**
+ * Utility method to get the widget options defined in the field xml description.
+ */
get_definition_options: function() {
if (!this.definition_options) {
var str = this.node.attrs.options || '{}';
@@ -1751,7 +1783,7 @@ instance.web.form.AbstractField = instance.web.form.Widget.extend(/** @lends ins
set_input_id: function(id) {
this.id_for_label = id;
},
-});
+}));
/**
* A mixin to apply on any field that has to completely re-render when its readonly state
@@ -1792,8 +1824,8 @@ instance.web.form.ReinitializeFieldMixin = {
instance.web.form.FieldChar = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: 'FieldChar',
- init: function (view, node) {
- this._super(view, node);
+ init: function (field_manager, node) {
+ this._super(field_manager, node);
this.password = this.node.attrs.password === 'True' || this.node.attrs.password === '1';
},
initialize_content: function() {
@@ -1831,8 +1863,8 @@ instance.web.form.FieldChar = instance.web.form.AbstractField.extend(_.extend({}
is_false: function() {
return this.get('value') === '';
},
- focus: function($element) {
- this._super($element || this.$element.find('input:first'));
+ focus: function() {
+ this.delay_focus(this.$element.find('input:first'));
}
}));
@@ -1896,8 +1928,8 @@ instance.web.form.FieldUrl = instance.web.form.FieldChar.extend({
instance.web.form.FieldFloat = instance.web.form.FieldChar.extend({
is_field_number: true,
- init: function (view, node) {
- this._super(view, node);
+ init: function (field_manager, node) {
+ this._super(field_manager, node);
this.set({'value': 0});
if (this.node.attrs.digits) {
this.digits = py.eval(node.attrs.digits);
@@ -2039,8 +2071,9 @@ instance.web.form.FieldDatetime = instance.web.form.AbstractField.extend(_.exten
is_false: function() {
return this.get('value') === '';
},
- focus: function($element) {
- this._super($element || (this.datewidget && this.datewidget.$input));
+ focus: function() {
+ if (this.datewidget && this.datewidget.$input)
+ this.delay_focus(this.datewidget.$input);
}
}));
@@ -2053,13 +2086,13 @@ instance.web.form.FieldDate = instance.web.form.FieldDatetime.extend({
instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: 'FieldText',
initialize_content: function() {
- this.$textarea = undefined;
+ this.$textarea = this.$element.find('textarea');
if (!this.get("effective_readonly")) {
- this.$textarea = this.$element.find('textarea');
this.$textarea.change(_.bind(function() {
this.set({'value': instance.web.parse_value(this.$textarea.val(), this)});
}, this));
- this.resized = false;
+ } else {
+ this.$textarea.attr('disabled', 'disabled');
}
},
set_value: function(value_) {
@@ -2068,14 +2101,9 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({}
},
render_value: function() {
var show_value = instance.web.format_value(this.get('value'), this, '');
- if (!this.get("effective_readonly")) {
- this.$textarea.val(show_value);
- if (!this.resized && this.view.options.resize_textareas) {
- this.do_resize(this.view.options.resize_textareas);
- this.resized = true;
- }
- } else {
- this.$element.text(show_value);
+ this.$textarea.val(show_value);
+ if (show_value && this.view.options.resize_textareas) {
+ this.do_resize(this.view.options.resize_textareas);
}
},
is_syntax_valid: function() {
@@ -2093,7 +2121,7 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({}
return this.get('value') === '';
},
focus: function($element) {
- this._super($element || this.$textarea);
+ this.delay_focus(this.$textarea);
},
do_resize: function(max_height) {
max_height = parseInt(max_height, 10);
@@ -2115,9 +2143,6 @@ instance.web.form.FieldText = instance.web.form.AbstractField.extend(_.extend({}
$div.remove();
$input.height(new_height);
},
- reset: function() {
- this.resized = false;
- }
}));
instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
@@ -2138,8 +2163,8 @@ instance.web.form.FieldBoolean = instance.web.form.AbstractField.extend({
this._super.apply(this, arguments);
this.$checkbox[0].checked = value_;
},
- focus: function($element) {
- this._super($element || this.$checkbox);
+ focus: function() {
+ this.delay_focus(this.$checkbox);
}
});
@@ -2169,9 +2194,9 @@ instance.web.form.FieldTextXml = instance.web.form.AbstractField.extend({
instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: 'FieldSelection',
- init: function(view, node) {
+ init: function(field_manager, node) {
var self = this;
- this._super(view, node);
+ this._super(field_manager, node);
this.values = _.clone(this.field.selection);
_.each(this.values, function(v, i) {
if (v[0] === false && v[1] === '') {
@@ -2232,8 +2257,8 @@ instance.web.form.FieldSelection = instance.web.form.AbstractField.extend(_.exte
var value_ = this.values[this.$element.find('select')[0].selectedIndex];
return !! value_;
},
- focus: function($element) {
- this._super($element || this.$element.find('select:first'));
+ focus: function() {
+ this.delay_focus(this.$element.find('select:first'));
}
}));
@@ -2281,14 +2306,15 @@ instance.web.form.dialog = function(content, options) {
instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: "FieldMany2One",
- init: function(view, node) {
- this._super(view, node);
+ init: function(field_manager, node) {
+ this._super(field_manager, node);
this.limit = 7;
this.set({'value': false});
this.display_value = {};
this.last_search = [];
this.floating = false;
this.inhibit_on_change = false;
+ this.orderer = new instance.web.DropMisordered();
},
start: function() {
this._super();
@@ -2437,14 +2463,10 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten
var search_val = request.term;
var self = this;
- if (this.abort_last) {
- this.abort_last();
- delete this.abort_last;
- }
- var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
+ var dataset = new instance.web.DataSet(this, this.field.relation, self.build_context());
- dataset.name_search(search_val, self.build_domain(), 'ilike',
- this.limit + 1, function(data) {
+ this.orderer.add(dataset.name_search(
+ search_val, self.build_domain(), 'ilike', this.limit + 1)).then(function(data) {
self.last_search = data;
// possible selections for the m2o
var values = _.map(data, function(x) {
@@ -2483,7 +2505,6 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten
response(values);
});
- this.abort_last = dataset.abort_last;
},
_quick_create: function(name) {
var self = this;
@@ -2491,15 +2512,15 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten
self._search_create_popup("form", undefined, {"default_name": name});
};
if (self.get_definition_options().quick_create === undefined || self.get_definition_options().quick_create) {
- var dataset = new instance.web.DataSetStatic(this, this.field.relation, self.build_context());
- dataset.name_create(name, function(data) {
- self.display_value = {};
- self.display_value["" + data[0]] = data[1];
- self.set({value: data[0]});
- }).fail(function(error, event) {
- event.preventDefault();
- slow_create();
- });
+ new instance.web.DataSet(this, this.field.relation, self.build_context())
+ .name_create(name, function(data) {
+ self.display_value = {};
+ self.display_value["" + data[0]] = data[1];
+ self.set({value: data[0]});
+ }).fail(function(error, event) {
+ event.preventDefault();
+ slow_create();
+ });
} else
slow_create();
},
@@ -2577,8 +2598,8 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(_.exten
is_false: function() {
return ! this.get("value");
},
- focus: function ($element) {
- this._super($element || this.$input);
+ focus: function () {
+ this.delay_focus(this.$input);
}
}));
@@ -2630,8 +2651,8 @@ var commands = {
instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
multi_selection: false,
disable_utility_classes: true,
- init: function(view, node) {
- this._super(view, node);
+ init: function(field_manager, node) {
+ this._super(field_manager, node);
lazy_build_o2m_kanban_view();
this.is_loaded = $.Deferred();
this.initial_is_loaded = this.is_loaded;
@@ -2670,7 +2691,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
trigger_on_change: function() {
var tmp = this.doing_on_change;
this.doing_on_change = true;
- this._on_ui_change();
+ this.trigger('changed_value');
this.doing_on_change = tmp;
},
load_views: function() {
@@ -2683,7 +2704,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
var view = {
view_id: false,
view_type: mode == "tree" ? "list" : mode,
- options: { sidebar : false }
+ options: {}
};
if (self.field.views && self.field.views[mode]) {
view.embedded_view = self.field.views[mode];
@@ -2705,7 +2726,9 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
});
this.views = views;
- this.viewmanager = new instance.web.ViewManager(this, this.dataset, views, {});
+ this.viewmanager = new instance.web.ViewManager(this, this.dataset, views, {
+ $sidebar: false,
+ });
this.viewmanager.template = 'One2Many.viewmanager';
this.viewmanager.registry = instance.web.views.extend({
list: 'instance.web.form.One2ManyListView',
@@ -2893,10 +2916,6 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
}
return true;
},
- is_dirty: function() {
- this.save_any_view();
- return this._super();
- }
});
instance.web.form.One2ManyDataSet = instance.web.BufferedDataSet.extend({
@@ -2975,7 +2994,7 @@ instance.web.form.One2ManyFormView = instance.web.FormView.extend({
on_loaded: function(data) {
this._super(data);
var self = this;
- this.$form_header.find('button.oe_form_button_create').click(function() {
+ this.$buttons.find('button.oe_form_button_create').click(function() {
self.do_save().then(self.on_button_new);
});
},
@@ -3023,8 +3042,8 @@ instance.web.form.One2ManyKanbanView = instance.web_kanban.KanbanView.extend({
instance.web.form.FieldMany2Many = instance.web.form.AbstractField.extend({
multi_selection: false,
disable_utility_classes: true,
- init: function(view, node) {
- this._super(view, node);
+ init: function(field_manager, node) {
+ this._super(field_manager, node);
this.is_loaded = $.Deferred();
this.initial_is_loaded = this.is_loaded;
this.is_setted = $.Deferred();
@@ -3421,7 +3440,7 @@ instance.web.form.FormOpenPopup = instance.web.OldWidget.extend(/** @lends insta
setup_form_view: function() {
var self = this;
var FormClass = instance.web.views.get_object('form');
- var options = _.clone(self.options.form_view_options);
+ var options = _.clone(self.options.form_view_options) || {};
options.initial_mode = this.options.readonly ? "view" : "edit";
this.view_form = new FormClass(this, this.dataset, false, options);
if (this.options.alternative_form_view) {
@@ -3463,25 +3482,8 @@ instance.web.form.FormOpenDataset = instance.web.ProxyDataSet.extend({
instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
template: 'FieldReference',
- init: function(view, node) {
- this._super(view, node);
- this.fields_view = {
- fields: {
- selection: {
- selection: view.fields_view.fields[this.name].selection
- },
- m2o: {
- relation: null
- }
- }
- };
- this.get_fields_values = view.get_fields_values;
- this.get_selected_ids = view.get_selected_ids;
- this.do_onchange = this.on_form_changed = this.do_notify_change = this.on_nop;
- this.dataset = this.view.dataset;
- this.view_id = 'reference_' + _.uniqueId();
- this.fields = {};
- this.fields_order = [];
+ init: function(field_manager, node) {
+ this._super(field_manager, node);
this.reference_ready = true;
},
on_nop: function() {
@@ -3506,20 +3508,20 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte
},
initialize_content: function() {
this.selection = new instance.web.form.FieldSelection(this, { attrs: {
- name: 'selection',
- widget: 'selection'
+ name: 'selection'
}});
- this.selection.set({readonly: this.get('effective_readonly')});
+ this.selection.view = this.view;
+ this.selection.set({force_readonly: this.get('effective_readonly')});
this.selection.on("change:value", this, this.on_selection_changed);
this.selection.$element = $(".oe_form_view_reference_selection", this.$element);
this.selection.renderElement();
this.selection.start();
this.m2o = new instance.web.form.FieldMany2One(this, { attrs: {
- name: 'm2o',
- widget: 'many2one'
+ name: 'm2o'
}});
- this.m2o.set({"readonly": this.get("effective_readonly")});
+ this.m2o.view = this.view;
+ this.m2o.set({force_readonly: this.get("effective_readonly")});
this.m2o.on("change:value", this, this.data_changed);
this.m2o.$element = $(".oe_form_view_reference_m2o", this.$element);
this.m2o.renderElement();
@@ -3528,9 +3530,6 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte
is_false: function() {
return typeof(this.get_value()) !== 'string';
},
- is_dirty: function() {
- return this.selection.is_dirty() || this.m2o.is_dirty();
- },
set_value: function(value_) {
this._super(value_);
this.render_value();
@@ -3542,13 +3541,12 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte
vals = this.get('value').split(',');
}
sel_val = vals[0] || false;
- m2o_val = vals[1] ? parseInt(vals[1], 10) : false;
+ m2o_val = vals[1] ? parseInt(vals[1], 10) : vals[1];
if (!this.get("effective_readonly")) {
this.selection.set_value(sel_val);
}
this.m2o.field.relation = sel_val;
this.m2o.set_value(m2o_val);
- this.m2o.$element.toggle(sel_val !== false);
this.reference_ready = true;
},
data_changed: function() {
@@ -3560,11 +3558,25 @@ instance.web.form.FieldReference = instance.web.form.AbstractField.extend(_.exte
this.set({'value': false});
}
},
+ get_field: function(name) {
+ if (name === "selection") {
+ return {
+ selection: this.view.fields_view.fields[this.name].selection,
+ type: "selection",
+ };
+ } else if (name === "m2o") {
+ return {
+ relation: null,
+ type: "many2one",
+ };
+ }
+ throw Exception("Should not happen");
+ },
}));
instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(_.extend({}, instance.web.form.ReinitializeFieldMixin, {
- init: function(view, node) {
- this._super(view, node);
+ init: function(field_manager, node) {
+ this._super(field_manager, node);
this.iframe = this.element_id + '_iframe';
this.binary_value = false;
},
@@ -3795,7 +3807,10 @@ instance.web.form.FieldStatus = instance.web.form.AbstractField.extend({
});
/**
- * Registry of form widgets, called by :js:`instance.web.FormView`
+ * Registry of form fields, called by :js:`instance.web.FormView`.
+ *
+ * All referenced classes must implement FieldMixin. Those represent the classes whose instances
+ * will substitute to the <field> tags as defined in OpenERP's views.
*/
instance.web.form.widgets = new instance.web.Registry({
'char' : 'instance.web.form.FieldChar',
@@ -3821,6 +3836,12 @@ instance.web.form.widgets = new instance.web.Registry({
'statusbar': 'instance.web.form.FieldStatus'
});
+/**
+ * Registry of widgets usable in the form view that can substitute to any possible
+ * tags defined in OpenERP's form views.
+ *
+ * Every referenced class should extend FormWidget.
+ */
instance.web.form.tags = new instance.web.Registry({
'button' : 'instance.web.form.WidgetButton',
});
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index d149ef28840..1fa3ca4fcee 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -56,6 +56,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
this.view_id = view_id;
this.previous_colspan = null;
this.colors = null;
+ this.fonts = null;
this.columns = [];
@@ -140,29 +141,53 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
return this.reload_view(null, null, true);
},
/**
- * Returns the color for the provided record in the current view (from the
- * ``@colors`` attribute)
+ * Returns the style for the provided record in the current view (from the
+ * ``@colors`` and ``@fonts`` attributes)
*
* @param {Record} record record for the current row
- * @returns {String} CSS color declaration
+ * @returns {String} CSS style declaration
*/
- color_for: function (record) {
- if (!this.colors) { return ''; }
+ style_for: function (record) {
+ var style= '';
+
var context = _.extend({}, record.attributes, {
uid: this.session.uid,
current_date: new Date().toString('yyyy-MM-dd')
// TODO: time, datetime, relativedelta
});
+
+ if (this.fonts) {
+ for(var i=0, len=this.fonts.length; i<len; ++i) {
+ var pair = this.fonts[i],
+ font = pair[0],
+ expression = pair[1];
+ if (py.evaluate(expression, context).toJSON()) {
+ switch(font) {
+ case 'bold':
+ style += 'font-weight: bold;';
+ break;
+ case 'italic':
+ style += 'font-style: italic;';
+ break;
+ case 'underline':
+ style += 'text-decoration: underline;';
+ break;
+ }
+ }
+ }
+ }
+
+ if (!this.colors) { return style; }
for(var i=0, len=this.colors.length; i<len; ++i) {
var pair = this.colors[i],
color = pair[0],
expression = pair[1];
if (py.evaluate(expression, context).toJSON()) {
- return 'color: ' + color + ';';
+ return style += 'color: ' + color + ';';
}
// TODO: handle evaluation errors
}
- return '';
+ return style;
},
/**
* Called after loading the list view's description, sets up such things
@@ -203,6 +228,16 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
}).value();
}
+ if (this.fields_view.arch.attrs.fonts) {
+ this.fonts = _(this.fields_view.arch.attrs.fonts.split(';')).chain().compact()
+ .map(function(font_pair) {
+ var pair = font_pair.split(':'),
+ font = pair[0],
+ expr = pair[1];
+ return [font, py.parse(py.tokenize(expr)), expr];
+ }).value();
+ }
+
this.setup_columns(this.fields_view.fields, grouped);
this.$element.html(QWeb.render(this._template, this));
@@ -301,7 +336,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
}
// Sidebar
- if (!this.sidebar && this.options.sidebar && this.options.$sidebar) {
+ if (!this.sidebar && this.options.$sidebar) {
this.sidebar = new instance.web.Sidebar(this);
this.sidebar.appendTo(this.options.$sidebar);
this.sidebar.add_toolbar(this.fields_view.toolbar);
@@ -464,7 +499,7 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
view_id: this.view_id,
view_type: "tree",
context: this.dataset.get_context(context),
- toolbar: this.options.sidebar
+ toolbar: !!this.options.$sidebar
}, callback);
}
},
@@ -770,6 +805,17 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
.attr('colspan', this.previous_colspan);
this.previous_colspan = null;
}
+ },
+ no_result: function () {
+ if (this.groups.group_by
+ || !this.options.action
+ || !this.options.action.help) {
+ return;
+ }
+ this.$element.children('table').replaceWith(
+ $('<div class="oe_listview_nocontent">')
+ .append($('<img>', { src: '/web/static/src/img/list_empty_arrow.png' }))
+ .append($('<div>').html(this.options.action.help)));
}
});
instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web.ListView.List# */{
@@ -1367,6 +1413,9 @@ instance.web.ListView.Groups = instance.web.Class.extend( /** @lends instance.we
self.records.add(records, {silent: true});
list.render();
d.resolve(list);
+ if (_.isEmpty(records)) {
+ view.no_result();
+ }
});});
return d.promise();
},
diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js
index ac19e3f341d..ff76f333ea9 100644
--- a/addons/web/static/src/js/view_list_editable.js
+++ b/addons/web/static/src/js/view_list_editable.js
@@ -372,11 +372,12 @@ openerp.web.list_editable = function (instance) {
init: function() {
this._super.apply(this, arguments);
this.rendering_engine = new instance.web.ListEditableRenderingEngine(this);
+ this.options.initial_mode = "edit";
},
renderElement: function() {}
});
- instance.web.ListEditableRenderingEngine = instance.web.Class.extend({
+ instance.web.ListEditableRenderingEngine = instance.web.form.FormRenderingEngineInterface.extend({
init: function(view) {
this.view = view;
},
@@ -406,18 +407,21 @@ openerp.web.list_editable = function (instance) {
if (modifiers.tree_invisible === true)
$td.hide();
var tag_name = el.tagName.toLowerCase();
- var key = tag_name;
+ var w;
if (tag_name === "field") {
var name = $(el).attr("name");
- key = $(el).attr('widget') || self.fvg.fields[name].type;
+ var key = $(el).attr('widget') || self.fvg.fields[name].type;
+ var obj = self.view.fields_registry.get_object(key);
+ w = new (obj)(self.view, instance.web.xml_to_json(el));
+ self.view.register_field(w, $(el).attr("name"));
+ } else {
+ var obj = self.tags_registry.get_object(tag_name);
+ w = new (obj)(self.view, instance.web.xml_to_json(el));
}
- var obj = self.view.fields_registry.get_object(key);
- var w = new (obj)(self.view, instance.web.xml_to_json(el));
- self.view.register_field(w, $(el).attr("name"));
w.appendTo($td);
$td.appendTo($element);
});
- $("<td><button class='oe-edit-row-save' type='button'></button></td>").appendTo($element);
+ $("<td><button class='oe-edit-row-save' type='button'>Save</button></td>").appendTo($element);
},
});
};
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 3e4d2056c93..798c5bb1493 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -140,13 +140,13 @@ instance.web.ActionManager = instance.web.Widget.extend({
this.dialog_viewmanager.appendTo(this.dialog.$element);
this.dialog.open();
} else {
+ this.dialog_stop();
+ this.content_stop();
if(action.menu_id) {
return this.getParent().do_action(action, function () {
instance.webclient.menu.open_menu(action.menu_id);
});
}
- this.dialog_stop();
- this.content_stop();
this.inner_action = action;
this.inner_viewmanager = new instance.web.ViewManagerAction(this, action);
this.inner_viewmanager.appendTo(this.$element);
@@ -245,7 +245,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
controller : null,
options : _.extend({
$buttons : self.$element.find('.oe_view_manager_buttons'),
- $sidebar : self.$element.find('.oe_view_manager_sidebar'),
+ $sidebar : self.flags.sidebar ? self.$element.find('.oe_view_manager_sidebar') : undefined,
$pager : self.$element.find('.oe_view_manager_pager'),
action : self.action,
action_views_ids : views_ids
@@ -283,7 +283,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
// Lazy loading of views
var controllerclass = this.registry.get_object(view_type);
var options = _.clone(view.options);
- if (view_type === "form") {
+ if (view_type === "form" && this.action) {
switch (this.action.target) {
case 'new':
case 'inline':
@@ -353,6 +353,7 @@ instance.web.ViewManager = instance.web.Widget.extend({
* @returns {$.Deferred} switching end signal
*/
on_prev_view: function (options) {
+ options = options || {};
var current_view = this.views_history.pop();
var previous_view = this.views_history[this.views_history.length - 1] || options['default'];
if (options.created && current_view === 'form' && previous_view === 'list') {
@@ -390,8 +391,8 @@ instance.web.ViewManager = instance.web.Widget.extend({
contexts: [action_context].concat(contexts || []),
group_by_seq: groupbys || []
}, function (results) {
- self.dataset.context = results.context;
- self.dataset.domain = results.domain;
+ self.dataset._model = new instance.web.Model(
+ self.dataset.model, results.context, results.domain);
var groupby = results.group_by.length
? results.group_by
: action_context.group_by;
@@ -1055,7 +1056,7 @@ instance.web.View = instance.web.Widget.extend({
"model": this.dataset.model,
"view_id": this.view_id,
"view_type": this.view_type,
- toolbar: this.options.sidebar,
+ toolbar: !!this.options.$sidebar,
context: context
}).pipe(this.on_loaded);
}
@@ -1072,7 +1073,6 @@ instance.web.View = instance.web.Widget.extend({
// All possible views options should be defaulted here
$sidebar: null,
sidebar_id: null,
- sidebar: true,
action: null,
action_views_ids: {}
});
@@ -1163,7 +1163,6 @@ instance.web.View = instance.web.Widget.extend({
*/
set_embedded_view: function(embedded_view) {
this.embedded_view = embedded_view;
- this.options.sidebar = false;
},
do_show: function () {
this.$element.show();
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index f365abf8856..84179ea0042 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -324,7 +324,7 @@
</ul>
</t>
<t t-name="Menu.secondary.link">
- <a href="#"
+ <a t-attf-href="#menu_id=#{menu.id}&amp;action_id=#{menu.action ? menu.action.split(',')[1] : ''}"
t-att-class="menu.children.length ? 'oe_menu_toggler' : 'oe_menu_leaf'"
t-att-data-menu="menu.id"
t-att-data-action-model="menu.action ? menu.action.split(',')[0] : ''"
@@ -342,7 +342,7 @@
<ul class="oe_user_menu oe_topbar_item">
<li class="oe_dropdown">
<a href="#" class="oe_dropdown_toggle">
- <img class="oe_topbar_avatar" t-att-data-default-src="_s + '/web/static/src/img/topbar-avatar.png'"/>
+ <img class="oe_topbar_avatar" t-att-data-default-src="_s + '/web/static/src/img/user_menu_avatar.png'"/>
<span class="oe_topbar_name"/>
</a>
<ul class="oe_dropdown_options">
@@ -670,7 +670,7 @@
</t>
<tr t-name="ListView.row" t-att-class="row_parity"
t-att-data-id="record.get('id')"
- t-att-style="view.color_for(record)">
+ t-att-style="view.style_for(record)">
<t t-foreach="columns" t-as="column">
<td t-if="column.meta">
@@ -715,8 +715,8 @@
<button type="button" class="oe_button oe_form_button_delete">Delete</button>
</span>
<span class="oe_form_buttons_edit">
- <button type="button" class="oe_button oe_form_button_save">Save</button>
- <button type="button" class="oe_button oe_form_button_cancel">Cancel</button>
+ <button type="button" class="oe_button oe_form_button_save">Save</button> or
+ <a href="#" class="oe_form_button_cancel">Discard</a>
</span>
</t>
</div>
@@ -790,10 +790,12 @@
<t t-name="FormRenderingForm">
<div class="oe_form_sheetbg">
<div t-attf-class="oe_form_sheet oe_form_sheet_width #{classnames}">
- <group col="4"/>
+ <group t-if="layout === 'auto'" col="4"/>
</div>
</div>
</t>
+<t t-name="FormRenderingSheet" t-extend="FormRenderingForm">
+</t>
<t t-name="FormRenderingGroup">
<t t-set="table">
<table border="0" cellpadding="0" cellspacing="0" width="100%" t-att-class="classnames"/>
@@ -835,7 +837,6 @@
t-attf-class="#{classnames} oe_form_label#{help ? '_help' : ''} oe_align_#{align}">
<t t-esc="string"/>
<span t-if="help">?</span>
- :
</label>
</t>
@@ -847,7 +848,7 @@
<div class="oe_tooltip_string" t-if="widget.string">
<t t-esc="widget.node.attrs.string"/> <t t-if="debug and widget.nolabel">(nolabel)</t>
</div>
- <p t-if="widget.help" class="oe_tooltip_help"><t t-esc="widget.help"/></p>
+ <p t-if="widget.node.attrs.help or (widget.field and widget.field.help)" class="oe_tooltip_help"><t t-esc="widget.node.attrs.help || widget.field.help"/></p>
<ul t-if="debug" class="oe_tooltip_technical">
<li data-item="field" t-if="widget.name">
<span class="oe_tooltip_technical_title">Field:</span>
@@ -917,8 +918,7 @@
</div>
</t>
<t t-if="widget.get('effective_readonly')">
- <div t-attf-class="oe_form_field_char #{widget.is_field_number ? 'oe-number' : ''}">
- </div>
+ <span t-attf-class="oe_form_field_char #{widget.is_field_number ? 'oe-number' : ''}"/>
</t>
</t>
<t t-name="FieldEmail">
@@ -941,9 +941,9 @@
</table>
</t>
<t t-if="widget.get('effective_readonly')">
- <div>
+ <span>
<a href="#" class="oe_form_uri"/>
- </div>
+ </span>
</t>
</t>
<t t-name="FieldUrl">
@@ -966,29 +966,29 @@
</table>
</t>
<t t-if="widget.get('effective_readonly')">
- <div>
+ <span>
<a href="#" class="oe_form_uri"/>
- </div>
+ </span>
</t>
</t>
<t t-name="FieldText">
- <t t-if="!widget.get('effective_readonly')">
- <div class="oe_form_field_text">
- <textarea rows="6"
- t-att-name="widget.name"
- class="field_text"
- t-att-tabindex="widget.node.attrs.tabindex"
- t-att-autofocus="widget.node.attrs.autofocus"
- ></textarea><img class="oe_field_translate oe_input_icon" t-if="widget.field.translate" t-att-src='_s + "/web/static/src/img/icons/terp-translate.png"' width="16" height="16" border="0"/>
- </div>
- </t>
+ <div class="oe_form_field_text">
+ <textarea rows="6"
+ t-att-name="widget.name"
+ class="field_text"
+ t-att-tabindex="widget.node.attrs.tabindex"
+ t-att-autofocus="widget.node.attrs.autofocus"
+ ></textarea>
+ <img class="oe_field_translate oe_input_icon" t-if="widget.field.translate"
+ t-att-src='_s + "/web/static/src/img/icons/terp-translate.png"' width="16" height="16" border="0"/>
+ </div>
</t>
<t t-name="web.datetimepicker">
<div class="oe_datepicker_root oe_form_field_datetime">
<input type="text" class="oe_datepicker_container" disabled="disabled" style="display: none;"/>
<input type="text"
t-att-name="widget.name"
- t-attf-class="oe_datepicker_master field_#{widget.type_of_date}"
+ t-attf-class="oe_datepicker_master field_#{widget.type_of_date} oe_form_field_#{widget.type_of_date}"
/><img class="oe_input_icon oe_datepicker_trigger" t-att-src='_s + "/web/static/src/img/ui/field_calendar.png"'
title="Select date" width="16" height="16" border="0"/>
</div>
@@ -1008,8 +1008,7 @@
</div>
</t>
<t t-if="widget.get('effective_readonly')">
- <div class="field_selection">
- </div>
+ <span class="field_selection"/>
</t>
</t>
<t t-name="FieldMany2One">
@@ -1034,25 +1033,20 @@
</table>
</t>
<t t-if="widget.get('effective_readonly')">
- <div>
+ <span>
<a href="#" class="oe_form_uri"/>
- </div>
+ </span>
</t>
</t>
<t t-name="FieldReference">
- <t t-if="!widget.get('effective_readonly')">
- <table class="oe_form_field_reference oe_frame oe_forms" border="0" cellpadding="0" cellspacing="0">
- <tr>
- <td t-attf-class="oe_form_frame_cell oe_form_selection oe_form_view_reference_selection">
- </td>
- <td t-attf-class="oe_form_frame_cell oe_form_many2one oe_form_view_reference_m2o" nowrap="true" style="display: none">
- </td>
- </tr>
- </table>
- </t>
- <t t-if="widget.get('effective_readonly')">
- <a href="#" class="oe_form_uri"/>
- </t>
+ <table class="oe_form_field_reference oe_frame oe_forms" border="0" cellpadding="0" cellspacing="0">
+ <tr>
+ <td t-attf-class="oe_form_frame_cell oe_form_selection oe_form_view_reference_selection">
+ </td>
+ <td t-attf-class="oe_form_frame_cell oe_form_many2one oe_form_view_reference_m2o" nowrap="true" style="display: none">
+ </td>
+ </tr>
+ </table>
</t>
<t t-name="FieldBoolean">
<span class="oe_form_field_boolean">
@@ -1197,9 +1191,9 @@
</table>
</t>
<t t-if="widget.get('effective_readonly')">
- <div>
+ <span>
<a href="javascript:void(0)" class="oe_form_uri"/>
- </div>
+ </span>
</t>
</t>
<t t-name="WidgetButton">