summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorChristophe Matthieu <chm@openerp.com>2012-11-05 14:08:32 +0100
committerChristophe Matthieu <chm@openerp.com>2012-11-05 14:08:32 +0100
commitc045cdd5028ea5e883a97c2b583282e4db11b1bc (patch)
tree68266f64936dd6a9635469721fe6802894c44a9d /addons/web/static/src/js
parente79b8e29120f319b1e3b0655088971059f203d02 (diff)
parent6f57449dcd48714ff9df5ff37dfbc0882610020e (diff)
[MERGE] merge from trunk
bzr revid: chm@openerp.com-20121105130832-klztvfcz8s88oe0j
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/chrome.js13
-rw-r--r--addons/web/static/src/js/data.js14
-rw-r--r--addons/web/static/src/js/view_form.js115
-rw-r--r--addons/web/static/src/js/view_list.js1
-rw-r--r--addons/web/static/src/js/view_list_editable.js20
-rw-r--r--addons/web/static/src/js/views.js6
6 files changed, 82 insertions, 87 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 6cf35a14e92..08ef8c4f9bf 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -504,13 +504,13 @@ instance.web.Login = instance.web.Widget.extend({
template: "Login",
remember_credentials: true,
- init: function(parent, params) {
+ init: function(parent, action) {
this._super(parent);
this.has_local_storage = typeof(localStorage) != 'undefined';
this.db_list = null;
this.selected_db = null;
this.selected_login = null;
- this.params = params || {};
+ this.params = action.params || {};
if (this.params.login_successful) {
this.on('login_successful', this, this.params.login_successful);
@@ -616,8 +616,9 @@ instance.web.client_actions.add("login", "instance.web.Login");
* Client action to reload the whole interface.
* If params has an entry 'menu_id', it opens the given menu entry.
*/
-instance.web.Reload = function(parent, params) {
- var menu_id = (params && params.menu_id) || false;
+instance.web.Reload = function(parent, action) {
+ var params = action.params || {};
+ var menu_id = params.menu_id || false;
var l = window.location;
var sobj = $.deparam(l.search.substr(1));
@@ -638,7 +639,7 @@ instance.web.client_actions.add("reload", "instance.web.Reload");
* Client action to go back in breadcrumb history.
* If can't go back in history stack, will go back to home.
*/
-instance.web.HistoryBack = function(parent, params) {
+instance.web.HistoryBack = function(parent) {
if (!parent.history_back()) {
window.location = '/' + (window.location.search || '');
}
@@ -649,7 +650,7 @@ instance.web.client_actions.add("history_back", "instance.web.HistoryBack");
* Client action to go back home.
*/
instance.web.Home = instance.web.Widget.extend({
- init: function(parent, params) {
+ init: function(parent) {
window.location = '/' + (window.location.search || '');
}
});
diff --git a/addons/web/static/src/js/data.js b/addons/web/static/src/js/data.js
index e279ade6fb3..63c90f53758 100644
--- a/addons/web/static/src/js/data.js
+++ b/addons/web/static/src/js/data.js
@@ -471,7 +471,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
default_get: function(fields, options) {
options = options || {};
return this._model.call('default_get',
- [fields], {context: this._model.context(options.context)});
+ [fields], {context: this.get_context(options.context)});
},
/**
* Creates a new record in db
@@ -480,7 +480,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @returns {$.Deferred}
*/
create: function(data) {
- return this._model.call('create', [data], {context: this._model.context()});
+ return this._model.call('create', [data], {context: this.get_context()});
},
/**
* Saves the provided data in an existing db record
@@ -493,7 +493,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
*/
write: function (id, data, options) {
options = options || {};
- return this._model.call('write', [[id], data], {context: this._model.context(options.context)}).then(this.trigger('dataset_changed', id, data, options));
+ return this._model.call('write', [[id], data], {context: this.get_context(options.context)}).then(this.trigger('dataset_changed', id, data, options));
},
/**
* Deletes an existing record from the database
@@ -501,7 +501,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @param {Number|String} ids identifier of the record to delete
*/
unlink: function(ids) {
- return this._model.call('unlink', [ids], {context: this._model.context()}).then(this.trigger('dataset_changed', ids));
+ return this._model.call('unlink', [ids], {context: this.get_context()}).then(this.trigger('dataset_changed', ids));
},
/**
* Calls an arbitrary RPC method
@@ -532,7 +532,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @returns {$.Deferred}
*/
name_get: function(ids) {
- return this._model.call('name_get', [ids], {context: this._model.context()});
+ return this._model.call('name_get', [ids], {context: this.get_context()});
},
/**
*
@@ -556,7 +556,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
* @param name
*/
name_create: function(name) {
- return this._model.call('name_create', [name], {context: this._model.context()});
+ return this._model.call('name_create', [name], {context: this.get_context()});
},
exec_workflow: function (id, signal) {
return this._model.exec_workflow(id, signal);
@@ -606,7 +606,7 @@ instance.web.DataSet = instance.web.CallbackEnabled.extend({
return instance.session.rpc('/web/dataset/resequence', {
model: this.model,
ids: ids,
- context: this._model.context(options.context),
+ context: this.get_context(options.context),
}).pipe(function (results) {
return results;
});
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index 7385f2bc2c0..9dd6e34c161 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -427,7 +427,7 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
var onchange = _.str.trim(on_change);
var call = onchange.match(/^\s?(.*?)\((.*?)\)\s?$/);
if (!call) {
- return null;
+ throw new Error("Wrong on change format: " + onchange);
}
var method = call[1];
@@ -494,71 +494,59 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
var self = this;
return this.on_change_mutex.exec(function() {
try {
- var response = {}, can_process_onchange = $.Deferred();
+ var def;
processed = processed || [];
processed.push(widget.name);
var on_change = widget.node.attrs.on_change;
if (on_change) {
var change_spec = self.parse_on_change(on_change, widget);
- if (change_spec) {
- var ajax = {
- url: '/web/dataset/onchange',
- async: false
- };
- can_process_onchange = self.rpc(ajax, {
- model: self.dataset.model,
- method: change_spec.method,
- args: [(self.datarecord.id == null ? [] : [self.datarecord.id])].concat(change_spec.args),
- context_id: change_spec.context_index == undefined ? null : change_spec.context_index + 1
- }).then(function(r) {
- _.extend(response, r);
- });
- } else {
- console.warn("Wrong on_change format", on_change);
- }
- }
- // fail if onchange failed
- if (can_process_onchange.isRejected()) {
- return can_process_onchange;
+ def = self.rpc('/web/dataset/onchange', {
+ model: self.dataset.model,
+ method: change_spec.method,
+ args: [(self.datarecord.id == null ? [] : [self.datarecord.id])].concat(change_spec.args),
+ context_id: change_spec.context_index == undefined ? null : change_spec.context_index + 1
+ });
+ } else {
+ def = $.when({});
}
-
- if (widget.field['change_default']) {
- var fieldname = widget.name, value_;
- if (response.value && (fieldname in response.value)) {
- // Use value from onchange if onchange executed
- value_ = response.value[fieldname];
- } else {
- // otherwise get form value for field
- value_ = self.fields[fieldname].get_value();
- }
- var condition = fieldname + '=' + value_;
-
- if (value_) {
- can_process_onchange = self.rpc({
- url: '/web/dataset/call',
- async: false
- }, {
- model: 'ir.values',
- method: 'get_defaults',
- args: [self.model, condition]
- }).then(function (results) {
- if (!results.length) { return; }
- if (!response.value) {
- response.value = {};
- }
- for(var i=0; i<results.length; ++i) {
- // [whatever, key, value]
- var triplet = results[i];
- response.value[triplet[1]] = triplet[2];
- }
- });
+ return def.pipe(function(response) {
+ if (widget.field['change_default']) {
+ var fieldname = widget.name
+ var value_;
+ if (response.value && (fieldname in response.value)) {
+ // Use value from onchange if onchange executed
+ value_ = response.value[fieldname];
+ } else {
+ // otherwise get form value for field
+ value_ = self.fields[fieldname].get_value();
+ }
+ var condition = fieldname + '=' + value_;
+
+ if (value_) {
+ return self.rpc('/web/dataset/call', {
+ model: 'ir.values',
+ method: 'get_defaults',
+ args: [self.model, condition]
+ }).pipe(function (results) {
+ if (!results.length) {
+ return response;
+ }
+ if (!response.value) {
+ response.value = {};
+ }
+ for(var i=0; i<results.length; ++i) {
+ // [whatever, key, value]
+ var triplet = results[i];
+ response.value[triplet[1]] = triplet[2];
+ }
+ return response;
+ });
+ }
}
- }
- if (can_process_onchange.isRejected()) {
- return can_process_onchange;
- }
-
- return self.on_processed_onchange(response, processed);
+ return response;
+ }).pipe(function(response) {
+ return self.on_processed_onchange(response, processed);
+ });
} catch(e) {
console.error(e);
instance.webclient.crashmanager.show_message(e);
@@ -2967,7 +2955,7 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
self.uned_def = $.Deferred();
var ed_delay = 200;
var ed_duration = 15000;
- var anyoneLoosesFocus = function() {
+ var anyoneLoosesFocus = function (e) {
var used = false;
if (self.floating) {
if (self.last_search.length > 0) {
@@ -2991,7 +2979,10 @@ instance.web.form.FieldMany2One = instance.web.form.AbstractField.extend(instanc
self.ed_def = $.Deferred();
self.ed_def.then(function() {
self.show_error_displayer();
+ ignore_blur = false;
+ self.trigger('focused');
});
+ ignore_blur = true;
setTimeout(function() {
self.ed_def.resolve();
self.uned_def.reject();
@@ -3321,7 +3312,7 @@ instance.web.form.FieldOne2Many = instance.web.form.AbstractField.extend({
e.cancel = true;
});
_(controller.columns).find(function (column) {
- if (!column instanceof instance.web.list.Handle) {
+ if (!(column instanceof instance.web.list.Handle)) {
return false;
}
column.modifiers.invisible = true;
@@ -4674,7 +4665,7 @@ instance.web.form.FieldBinary = instance.web.form.AbstractField.extend(instance.
this.binary_value = false;
this.useFileAPI = !!window.FileReader;
if (!this.useFileAPI) {
- this.fileupload_id = _.uniqueId('oe_attachmentupload');
+ this.fileupload_id = _.uniqueId('oe_fileupload');
$(window).on(this.fileupload_id, function() {
var args = [].slice.call(arguments).slice(1);
self.on_file_uploaded.apply(self, args);
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index 5546105e901..fd74fd8922b 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -1100,7 +1100,6 @@ instance.web.ListView.List = instance.web.Class.extend( /** @lends instance.web.
}, this);
if (!this.$current) { return; }
this.$current.remove();
- this.$current = null;
},
get_records: function () {
return this.records.map(function (record) {
diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js
index acc1d781976..021e5549c18 100644
--- a/addons/web/static/src/js/view_list_editable.js
+++ b/addons/web/static/src/js/view_list_editable.js
@@ -252,9 +252,10 @@ openerp.web.list_editable = function (instance) {
var position = $cell.position();
field.set_dimensions($cell.outerHeight(), $cell.outerWidth());
- field.$el.css({
- top: position.top,
- left: position.left,
+ field.$el.position({
+ my: 'left top',
+ at: 'left top',
+ of: $cell
});
},
/**
@@ -410,15 +411,15 @@ openerp.web.list_editable = function (instance) {
});
this.editor.$el.on('keyup keydown', function (e) {
- if (!self.editor.is_editing()) { return; }
+ if (!self.editor.is_editing()) { return true; }
var key = _($.ui.keyCode).chain()
.map(function (v, k) { return {name: k, code: v}; })
.find(function (o) { return o.code === e.which; })
.value();
- if (!key) { return; }
+ if (!key) { return true; }
var method = e.type + '_' + key.name;
- if (!(method in self)) { return; }
- self[method](e);
+ if (!(method in self)) { return true; }
+ return self[method](e);
});
},
/**
@@ -446,7 +447,10 @@ openerp.web.list_editable = function (instance) {
keyup_ENTER: function () {
return this._next();
},
- keyup_ESCAPE: function () {
+ keydown_ESCAPE: function (e) {
+ return false;
+ },
+ keyup_ESCAPE: function (e) {
return this.cancel_edition();
},
/**
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index ebc7c326724..a4fe86c516d 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -247,7 +247,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
action_menu_id: null,
});
if (_.isString(action) && instance.web.client_actions.contains(action)) {
- var action_client = { type: "ir.actions.client", tag: action };
+ var action_client = { type: "ir.actions.client", tag: action, params: {} };
return this.do_action(action_client, options);
} else if (_.isNumber(action) || _.isString(action)) {
var self = this;
@@ -346,14 +346,14 @@ instance.web.ActionManager = instance.web.Widget.extend({
if (!(ClientWidget.prototype instanceof instance.web.Widget)) {
var next;
- if (next = ClientWidget(this, action.params)) {
+ if (next = ClientWidget(this, action)) {
return this.do_action(next, options);
}
return $.when();
}
return this.ir_actions_common({
- widget: function () { return new ClientWidget(self, action.params); },
+ widget: function () { return new ClientWidget(self, action); },
action: action,
klass: 'oe_act_client',
post_process: function(widget) {