summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorAntonin Bourguignon <abo@openerp.com>2013-01-30 17:59:18 +0100
committerAntonin Bourguignon <abo@openerp.com>2013-01-30 17:59:18 +0100
commite096bb8dc06cba79fc2744c04f0c5665b2f1ea5d (patch)
treef795c3e18d8d2e171872532157326798654e6e67 /addons/web/static/src
parent75ce079a814f8795d43171965a842aa19a51b2f3 (diff)
parentbd3d0384fd49ecdf70ca4001e629d0e05d6f5191 (diff)
[MERGE] trunk
bzr revid: abo@openerp.com-20130129165545-9me851oxnexd8znk bzr revid: abo@openerp.com-20130130165918-i2b0saer1tfmcvzj
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/css/base.css2
-rw-r--r--addons/web/static/src/css/base.sass2
-rw-r--r--addons/web/static/src/js/chrome.js63
-rw-r--r--addons/web/static/src/js/corelib.js2
-rw-r--r--addons/web/static/src/js/formats.js10
-rw-r--r--addons/web/static/src/js/pyeval.js5
-rw-r--r--addons/web/static/src/js/search.js96
-rw-r--r--addons/web/static/src/js/test_support.js2
-rw-r--r--addons/web/static/src/js/view_form.js21
-rw-r--r--addons/web/static/src/xml/base.xml4
10 files changed, 128 insertions, 79 deletions
diff --git a/addons/web/static/src/css/base.css b/addons/web/static/src/css/base.css
index 638f446c5ba..6cfee50d6a4 100644
--- a/addons/web/static/src/css/base.css
+++ b/addons/web/static/src/css/base.css
@@ -1242,8 +1242,6 @@
.openerp .oe_secondary_submenu {
padding: 2px 0 8px 0;
margin: 0;
- width: 220px;
- display: inline-block;
}
.openerp .oe_secondary_submenu li {
position: relative;
diff --git a/addons/web/static/src/css/base.sass b/addons/web/static/src/css/base.sass
index 42ade77ccbb..b4665808caf 100644
--- a/addons/web/static/src/css/base.sass
+++ b/addons/web/static/src/css/base.sass
@@ -1009,8 +1009,6 @@ $sheet-padding: 16px
.oe_secondary_submenu
padding: 2px 0 8px 0
margin: 0
- width: 220px
- display: inline-block
li
position: relative
margin: 0
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 1c3723d3e4e..1407df4d33f 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -247,19 +247,17 @@ instance.web.CrashManager = instance.web.Class.extend({
if (!this.active) {
return;
}
- // yes, exception handling is shitty
- if (error.code === 300 && error.data && error.data.type == "client_exception" && error.data.debug.match("SessionExpiredException")) {
- this.show_warning({type: "Session Expired", data: { fault_code: "Your OpenERP session expired. Please refresh the current web page." }});
+ var handler = instance.web.crash_manager_registry.get_object(error.data.name, true);
+ if (handler) {
+ new (handler)(this, error).display();
+ return;
+ };
+ if (error.data.name === "openerp.addons.web.session SessionExpiredException") {
+ this.show_warning({type: "Session Expired", data: { message: "Your OpenERP session expired. Please refresh the current web page." }});
return;
}
- if (error.data.fault_code) {
- var split = ("" + error.data.fault_code).split('\n')[0].split(' -- ');
- if (split.length > 1) {
- error.type = split.shift();
- error.data.fault_code = error.data.fault_code.substr(error.type.length + 4);
- }
- }
- if (error.code === 200 && error.type) {
+ if (error.data.exception_type === "except_osv" || error.data.exception_type === "warning"
+ || error.data.exception_type === "access_error") {
this.show_warning(error);
} else {
this.show_error(error);
@@ -269,8 +267,11 @@ instance.web.CrashManager = instance.web.Class.extend({
if (!this.active) {
return;
}
+ if (error.data.exception_type === "except_osv") {
+ error = _.extend({}, error, {data: _.extend({}, error.data, {message: error.data.arguments[0] + "\n\n" + error.data.arguments[1]})});
+ }
instance.web.dialog($('<div>' + QWeb.render('CrashManager.warning', {error: error}) + '</div>'), {
- title: "OpenERP " + _.str.capitalize(error.type),
+ title: "OpenERP " + (_.str.capitalize(error.type) || "Warning"),
buttons: [
{text: _t("Ok"), click: function() { $(this).dialog("close"); }}
]
@@ -303,6 +304,29 @@ instance.web.CrashManager = instance.web.Class.extend({
},
});
+/**
+ An interface to implement to handle exceptions. Register implementation in instance.web.crash_manager_registry.
+*/
+instance.web.ExceptionHandler = {
+ /**
+ @param parent The parent.
+ @param error The error object as returned by the JSON-RPC implementation.
+ */
+ init: function(parent, error) {},
+ /**
+ Called to inform to display the widget, if necessary. A typical way would be to implement
+ this interface in a class extending instance.web.Dialog and simply display the dialog in this
+ method.
+ */
+ display: function() {},
+};
+
+/**
+ The registry to handle exceptions. It associate a fully qualified python exception name with a class implementing
+ instance.web.ExceptionHandler.
+*/
+instance.web.crash_manager_registry = new instance.web.Registry();
+
instance.web.Loading = instance.web.Widget.extend({
template: _t("Loading"),
init: function(parent) {
@@ -481,6 +505,7 @@ instance.web.DatabaseManager = instance.web.Widget.extend({
self.do_action("reload");
},
},
+ _push_me: false,
};
self.do_action(client_action);
});
@@ -649,7 +674,7 @@ instance.web.Login = instance.web.Widget.extend({
}
},
on_db_failed: function (error, event) {
- if (error.data.fault_code === 'AccessDenied') {
+ if (error.data.name === 'openerp.exceptions.AccessDenied') {
event.preventDefault();
}
},
@@ -868,7 +893,7 @@ instance.web.Menu = instance.web.Widget.extend({
this.needaction_data = data;
_.each(this.needaction_data, function (item, menu_id) {
var $item = self.$secondary_menus.find('a[data-menu="' + menu_id + '"]');
- $item.remove('oe_menu_counter');
+ $item.find('.oe_menu_counter').remove();
if (item.needaction_counter && item.needaction_counter > 0) {
$item.append(QWeb.render("Menu.needaction_counter", { widget : item }));
}
@@ -1395,13 +1420,9 @@ instance.web.WebClient = instance.web.Client.extend({
});
},
set_content_full_screen: function(fullscreen) {
- if (fullscreen) {
- $(".oe_webclient", this.$el).addClass("oe_content_full_screen");
- $("body").css({'overflow-y':'hidden'});
- } else {
- $(".oe_webclient", this.$el).removeClass("oe_content_full_screen");
- $("body").css({'overflow-y':'scroll'});
- }
+ $(document.body).css('overflow-y', fullscreen ? 'hidden' : 'scroll');
+ this.$('.oe_webclient').toggleClass(
+ 'oe_content_full_screen', fullscreen);
},
has_uncommitted_changes: function() {
var $e = $.Event('clear_uncommitted_changes');
diff --git a/addons/web/static/src/js/corelib.js b/addons/web/static/src/js/corelib.js
index 5bbd5316521..edd23e14522 100644
--- a/addons/web/static/src/js/corelib.js
+++ b/addons/web/static/src/js/corelib.js
@@ -991,7 +991,7 @@ instance.web.JsonRPC = instance.web.Class.extend(instance.web.PropertiesMixin, {
self.trigger('response', response);
if (!response.error) {
deferred.resolve(response["result"], textStatus, jqXHR);
- } else if (response.error.data.type === "session_invalid") {
+ } else if (response.error.code === 100) {
self.uid = false;
} else {
deferred.reject(response.error, $.Event());
diff --git a/addons/web/static/src/js/formats.js b/addons/web/static/src/js/formats.js
index 9432b02826f..851b60af229 100644
--- a/addons/web/static/src/js/formats.js
+++ b/addons/web/static/src/js/formats.js
@@ -166,9 +166,13 @@ instance.web.format_value = function (value, descriptor, value_if_empty) {
value = Math.abs(value);
pattern = '-' + pattern;
}
- return _.str.sprintf(pattern,
- Math.floor(value),
- Math.round((value % 1) * 60));
+ var hour = Math.floor(value);
+ var min = Math.round((value % 1) * 60);
+ if (min == 60){
+ min = 0;
+ hour = hour + 1;
+ }
+ return _.str.sprintf(pattern, hour, min);
case 'many2one':
// name_get value format
return value[1] ? value[1].split("\n")[0] : value[1];
diff --git a/addons/web/static/src/js/pyeval.js b/addons/web/static/src/js/pyeval.js
index 2c1b5ec9d7d..554c4aa7db0 100644
--- a/addons/web/static/src/js/pyeval.js
+++ b/addons/web/static/src/js/pyeval.js
@@ -689,15 +689,14 @@ openerp.web.pyeval = function (instance) {
};
instance.web.pyeval.context = function () {
- return {
- uid: py.float.fromJSON(instance.session.uid),
+ return _.extend({
datetime: datetime,
context_today: context_today,
time: time,
relativedelta: relativedelta,
current_date: py.PY_call(
time.strftime, [py.str.fromJSON('%Y-%m-%d')]),
- };
+ }, instance.session.user_context);
};
/**
diff --git a/addons/web/static/src/js/search.js b/addons/web/static/src/js/search.js
index 50e768bac59..12acf4039f4 100644
--- a/addons/web/static/src/js/search.js
+++ b/addons/web/static/src/js/search.js
@@ -127,41 +127,26 @@ my.InputView = instance.web.Widget.extend({
events: {
focus: function () { this.trigger('focused', this); },
blur: function () { this.$el.text(''); this.trigger('blurred', this); },
- keydown: 'onKeydown'
+ keydown: 'onKeydown',
+ paste: 'onPaste',
},
getSelection: function () {
// get Text node
- var root = this.$el[0].childNodes[0];
+ var root = this.el.childNodes[0];
if (!root || !root.textContent) {
// if input does not have a child node, or the child node is an
// empty string, then the selection can only be (0, 0)
return {start: 0, end: 0};
}
- if (window.getSelection) {
- var domRange = window.getSelection().getRangeAt(0);
- assert(domRange.startContainer === root,
- "selection should be in the input view");
- assert(domRange.endContainer === root,
- "selection should be in the input view");
- return {
- start: domRange.startOffset,
- end: domRange.endOffset
- }
- } else if (document.selection) {
- var ieRange = document.selection.createRange();
- var rangeParent = ieRange.parentElement();
- assert(rangeParent === root,
- "selection should be in the input view");
- var offsetRange = document.body.createTextRange();
- offsetRange = offsetRange.moveToElementText(rangeParent);
- offsetRange.setEndPoint("EndToStart", ieRange);
- var start = offsetRange.text.length;
- return {
- start: start,
- end: start + ieRange.text.length
- }
+ var range = window.getSelection().getRangeAt(0);
+ assert(range.startContainer === root,
+ "selection should be in the input view");
+ assert(range.endContainer === root,
+ "selection should be in the input view");
+ return {
+ start: range.startOffset,
+ end: range.endOffset
}
- throw new Error("Could not get caret position");
},
onKeydown: function (e) {
var sel;
@@ -199,6 +184,50 @@ my.InputView = instance.web.Widget.extend({
}
break;
}
+ },
+ setCursorAtEnd: function () {
+ var sel = window.getSelection();
+ sel.removeAllRanges();
+ var range = document.createRange();
+ // in theory, range.selectNodeContents should work here. In practice,
+ // MSIE9 has issues from time to time, instead of selecting the inner
+ // text node it would select the reference node instead (e.g. in demo
+ // data, company news, copy across the "Company News" link + the title,
+ // from about half the link to half the text, paste in search box then
+ // hit the left arrow key, getSelection would blow up).
+ //
+ // Explicitly selecting only the inner text node (only child node at
+ // this point, though maybe we should assert that) avoiids the issue
+ range.selectNode(this.el.childNodes[0]);
+ range.collapse(false);
+ sel.addRange(range);
+ },
+ onPaste: function () {
+ // In MSIE and Webkit, it is possible to get various representations of
+ // the clipboard data at this point e.g.
+ // window.clipboardData.getData('Text') and
+ // event.clipboardData.getData('text/plain') to ensure we have a plain
+ // text representation of the object (and probably ensure the object is
+ // pastable as well, so nobody puts an image in the search view)
+ // (nb: since it's not possible to alter the content of the clipboard
+ // — at least in Webkit — to ensure only textual content is available,
+ // using this would require 1. getting the text data; 2. manually
+ // inserting the text data into the content; and 3. cancelling the
+ // paste event)
+ //
+ // But Firefox doesn't support the clipboard API (as of FF18)
+ // although it correctly triggers the paste event (Opera does not even
+ // do that) => implement lowest-denominator system where onPaste
+ // triggers a followup "cleanup" pass after the data has been pasted
+ setTimeout(function () {
+ // Read text content (ignore pasted HTML)
+ var data = this.$el.text();
+ // paste raw text back in
+ this.$el.empty().text(data);
+ // Set the cursor at the end of the text, so the cursor is not lost
+ // in some kind of error-spawning limbo.
+ this.setCursorAtEnd();
+ }.bind(this), 0);
}
});
my.FacetView = instance.web.Widget.extend({
@@ -1572,6 +1601,7 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({
append_filter: function (filter) {
var self = this;
var key = this.key_for(filter);
+ var warning = _t("This filter is global and will be removed for everybody if you continue.");
var $filter;
if (key in this.$filters) {
@@ -1589,6 +1619,9 @@ instance.web.search.CustomFilters = instance.web.search.Input.extend({
$('<a class="oe_searchview_custom_delete">x</a>')
.click(function (e) {
e.stopPropagation();
+ if (!(filter.user_id || confirm(warning))) {
+ return;
+ }
self.model.call('unlink', [id]).done(function () {
$filter.remove();
delete self.$filters[key];
@@ -1711,10 +1744,12 @@ instance.web.search.Advanced = instance.web.search.Input.extend({
});
return $.when(
this._super(),
- new instance.web.Model(this.view.model).call('fields_get').done(function(data) {
- self.fields = _.extend({
- id: { string: 'ID', type: 'id' }
- }, data);
+ new instance.web.Model(this.view.model).call('fields_get', {
+ context: this.view.dataset.context
+ }).done(function(data) {
+ self.fields = _.extend({
+ id: { string: 'ID', type: 'id' }
+ }, data);
})).done(function () {
self.append_proposition();
});
@@ -1781,6 +1816,7 @@ instance.web.search.ExtendedSearchProposition = instance.web.Widget.extend(/** @
this._super(parent);
this.fields = _(fields).chain()
.map(function(val, key) { return _.extend({}, val, {'name': key}); })
+ .filter(function (field) { return !field.deprecated; })
.sortBy(function(field) {return field.string;})
.value();
this.attrs = {_: _, fields: this.fields, selected: null};
diff --git a/addons/web/static/src/js/test_support.js b/addons/web/static/src/js/test_support.js
index 90173f89845..82c1d6fa26e 100644
--- a/addons/web/static/src/js/test_support.js
+++ b/addons/web/static/src/js/test_support.js
@@ -72,7 +72,7 @@ openerp.test_support = {
}
return;
}
- fn(e.data.fault_code);
+ fn(e.data.name);
})
}
};
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 01d4bf6dd33..4880b3882ff 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -573,19 +573,14 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
]
});
}
- if (result.domain) {
- function edit_domain(node) {
- if (typeof node !== "object") {
- return;
- }
- var new_domain = result.domain[node.attrs.name];
- if (new_domain) {
- node.attrs.domain = new_domain;
- }
- _(node.children).each(edit_domain);
- }
- edit_domain(this.fields_view.arch);
- }
+
+ var fields = this.fields;
+ _(result.domain).each(function (domain, fieldname) {
+ var field = fields[fieldname];
+ if (!field) { return; }
+ field.node.attrs.domain = domain;
+ });
+
return $.Deferred().resolve();
} catch(e) {
console.error(e);
diff --git a/addons/web/static/src/xml/base.xml b/addons/web/static/src/xml/base.xml
index 6d707bb4627..7604814fe1d 100644
--- a/addons/web/static/src/xml/base.xml
+++ b/addons/web/static/src/xml/base.xml
@@ -40,7 +40,7 @@
<td>
<p>
<t t-js="d">
- var message = d.message ? d.message : d.error.data.fault_code;
+ var message = d.message ? d.message : d.error.data.message;
d.html_error = context.engine.tools.html_escape(message)
.replace(/\n/g, '<br/>');
</t>
@@ -1414,8 +1414,6 @@
this.removeAttr('t-if');
</t>
- <t t-jquery="tfoot &gt; tr:last-child" t-operation="replace"/>
-
<t t-jquery="td.oe-actions">
this.removeAttr('t-if');
</t>