summaryrefslogtreecommitdiff
path: root/addons/web/static/src
diff options
context:
space:
mode:
authorChristophe Simonis <chs@openerp.com>2012-11-20 17:28:12 +0100
committerChristophe Simonis <chs@openerp.com>2012-11-20 17:28:12 +0100
commite7b2ec50fe8b719d6fae13737e8c34e54eb520ab (patch)
treebc7990858f27e24ed9ba897fcd316a72b242ef8e /addons/web/static/src
parent4aa5e761746376e57d14115e194ea3bcb968836f (diff)
parentbdca6b0925b7c9836842b2802efe8659bc23a88d (diff)
merge upstream
bzr revid: chs@openerp.com-20121120162812-wb04dwv62v25evtj
Diffstat (limited to 'addons/web/static/src')
-rw-r--r--addons/web/static/src/js/chrome.js116
-rw-r--r--addons/web/static/src/js/data_export.js1
-rw-r--r--addons/web/static/src/js/view_form.js7
-rw-r--r--addons/web/static/src/js/view_list.js2
-rw-r--r--addons/web/static/src/js/view_list_editable.js8
-rw-r--r--addons/web/static/src/js/views.js17
6 files changed, 82 insertions, 69 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 4197880182d..878e1bc41a5 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -66,50 +66,49 @@ instance.web.Dialog = instance.web.Widget.extend({
max_width: '95%',
height: 'auto',
min_height: 0,
- max_height: this.get_height('100%') - 200,
+ max_height: $(window.top).height() - 200,
autoOpen: false,
position: [false, 40],
- buttons: {},
+ buttons: null,
beforeClose: function () {
self.trigger("closing");
},
- resizeStop: this.on_resized
+ resizeStop: function() {
+ self.trigger("resized");
+ },
};
- for (var f in this) {
- if (f.substr(0, 10) == 'on_button_') {
- this.dialog_options.buttons[f.substr(10)] = this[f];
- }
- }
if (options) {
_.extend(this.dialog_options, options);
}
this.on("closing", this, this._closing);
+ this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix"><span class="oe_dialog_custom_buttons"/></div>');
},
- get_options: function(options) {
- var self = this,
- o = _.extend({}, this.dialog_options, options || {});
- _.each(['width', 'height'], function(unit) {
- o[unit] = self['get_' + unit](o[unit]);
- o['min_' + unit] = self['get_' + unit](o['min_' + unit] || 0);
- o['max_' + unit] = self['get_' + unit](o['max_' + unit] || 0);
- if (o[unit] !== 'auto' && o['min_' + unit] && o[unit] < o['min_' + unit]) o[unit] = o['min_' + unit];
- if (o[unit] !== 'auto' && o['max_' + unit] && o[unit] > o['max_' + unit]) o[unit] = o['max_' + unit];
+ _get_options: function(options) {
+ var self = this;
+ var o = _.extend({}, this.dialog_options, options || {});
+ var sizes = {
+ width: $(window.top).width(),
+ height: $(window.top).height(),
+ };
+ _.each(sizes, function(available_size, unit) {
+ o[unit] = self._get_size(o[unit], available_size);
+ o['min_' + unit] = self._get_size(o['min_' + unit] || 0, available_size);
+ o['max_' + unit] = self._get_size(o['max_' + unit] || 0, available_size);
+ if (o[unit] !== 'auto' && o['min_' + unit] && o[unit] < o['min_' + unit]) {
+ o[unit] = o['min_' + unit];
+ }
+ if (o[unit] !== 'auto' && o['max_' + unit] && o[unit] > o['max_' + unit]) {
+ o[unit] = o['max_' + unit];
+ }
});
- if (!o.title && this.dialog_title) {
- o.title = this.dialog_title;
- }
+ o.title = o.title || this.dialog_title;
return o;
},
- get_width: function(val) {
- return this.get_size(val.toString(), $(window.top).width());
- },
- get_height: function(val) {
- return this.get_size(val.toString(), $(window.top).height());
- },
- get_size: function(val, available_size) {
+ _get_size: function(val, available_size) {
+ val = val.toString();
if (val === 'auto') {
return val;
- } else if (val.slice(-1) == "%") {
+ } else if (val.slice(-1) === "%") {
return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
} else {
return parseInt(val, 10);
@@ -123,25 +122,32 @@ instance.web.Dialog = instance.web.Widget.extend({
}
},
open: function(options) {
- if (! this.dialog_inited)
- this.init_dialog();
- var o = this.get_options(options);
- this.add_buttons(o.buttons);
- delete(o.buttons);
- this.$buttons.appendTo($("body"));
+ var o = this._get_options(options);
+ if (o.buttons) {
+ this._add_buttons(o.buttons);
+ delete(o.buttons);
+ }
+ if (!this.dialog_inited) {
+ this.init_dialog(o);
+ }
instance.web.dialog(this.$el, o).dialog('open');
- this.$el.dialog("widget").find(".ui-dialog-buttonpane").remove();
- this.$buttons.appendTo(this.$el.dialog("widget"));
+ this.$el.dialog("widget").append(this.$buttons);
if (o.height === 'auto' && o.max_height) {
this.$el.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
}
return this;
},
- add_buttons: function(buttons) {
+ _add_buttons: function(buttons) {
var self = this;
- _.each(buttons, function(fn, but) {
- var $but = $(QWeb.render('WidgetButton', { widget : { string: but, node: { attrs: {} }}}));
- self.$buttons.append($but);
+ var $customButons = this.$buttons.find('.oe_dialog_custom_buttons').empty();
+ _.each(buttons, function(fn, text) {
+ // buttons can be object or array
+ if (!_.isFunction(fn)) {
+ text = fn.text;
+ fn = fn.click;
+ }
+ var $but = $(QWeb.render('WidgetButton', { widget : { string: text, node: { attrs: {} }}}));
+ $customButons.append($but);
$but.on('click', function(ev) {
fn.call(self.$el, ev);
});
@@ -149,10 +155,7 @@ instance.web.Dialog = instance.web.Widget.extend({
},
init_dialog: function(options) {
this.renderElement();
- var o = this.get_options(options);
- instance.web.dialog(this.$el, o);
- this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" />');
- this.$el.dialog("widget").append(this.$buttons);
+ instance.web.dialog(this.$el, options);
this.dialog_inited = true;
var res = this.start();
return res;
@@ -171,9 +174,8 @@ instance.web.Dialog = instance.web.Widget.extend({
this.__tmp_dialog_closing = undefined;
}
},
- on_resized: function() {
- },
destroy: function () {
+ this.$buttons.remove();
_.each(this.getChildren(), function(el) {
el.destroy();
});
@@ -182,7 +184,7 @@ instance.web.Dialog = instance.web.Widget.extend({
this.close();
this.__tmp_dialog_destroying = undefined;
}
- if (this.dialog_inited && !this.isDestroyed()) {
+ if (this.dialog_inited && !this.isDestroyed() && this.$el.is(":data(dialog)")) {
this.$el.dialog('destroy');
}
this._super();
@@ -565,13 +567,19 @@ instance.web.Login = instance.web.Widget.extend({
self.$el.find('.oe_login_manage_db').click(function() {
self.do_action("database_manager");
});
- var d;
- if (self.params.db) {
- if (self.params.login && self.params.password) {
- d = self.do_login(self.params.db, self.params.login, self.params.password);
- }
+ var d = $.when();
+ if ($.deparam.querystring().db) {
+ self.params.db = $.deparam.querystring().db;
+ }
+ // used by dbmanager.do_create via internal client action
+ if (self.params.db && self.params.login && self.params.password) {
+ d = self.do_login(self.params.db, self.params.login, self.params.password);
} else {
- d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed);
+ if (self.params.db) {
+ self.on_db_loaded([self.params.db])
+ } else {
+ d = self.rpc("/web/database/get_list", {}).done(self.on_db_loaded).fail(self.on_db_failed);
+ }
}
return d;
},
@@ -982,7 +990,7 @@ instance.web.Client = instance.web.Widget.extend({
start: function() {
var self = this;
return instance.session.session_bind(this.origin).then(function() {
- var $e = $(QWeb.render(self._template, {}));
+ var $e = $(QWeb.render(self._template, {widget: self}));
self.replaceElement($e);
$e.openerpClass();
self.bind_events();
diff --git a/addons/web/static/src/js/data_export.js b/addons/web/static/src/js/data_export.js
index 477d89c99b3..e38d21d1cd2 100644
--- a/addons/web/static/src/js/data_export.js
+++ b/addons/web/static/src/js/data_export.js
@@ -22,7 +22,6 @@ instance.web.DataExport = instance.web.Dialog.extend({
start: function() {
var self = this;
this._super.apply(this, arguments);
- this.open();
self.$el.removeClass('ui-dialog-content ui-widget-content');
self.$el.find('#add_field').click(function() {
if ($('#field-tree-structure tr.ui-selected')) {
diff --git a/addons/web/static/src/js/view_form.js b/addons/web/static/src/js/view_form.js
index dad622fb7f9..d7b3a6805d9 100644
--- a/addons/web/static/src/js/view_form.js
+++ b/addons/web/static/src/js/view_form.js
@@ -1009,8 +1009,8 @@ instance.web.FormView = instance.web.View.extend(instance.web.form.FieldManagerM
}
return true;
},
- sidebar_context: function () {
- return this.save().then(_.bind(function() {return this.get_fields_values();}, this));
+ sidebar_eval_context: function () {
+ return $.when(this.build_eval_context());
},
open_defaults_dialog: function () {
var self = this;
@@ -1215,7 +1215,7 @@ instance.web.form.FormRenderingEngine = instance.web.form.FormRenderingEngineInt
var doc = $.parseXML('<div class="oe_form">' + xml + '</div>');
$('button', doc).each(function() {
- $(this).attr('data-button-type', $(this).attr('type'));
+ $(this).attr('data-button-type', $(this).attr('type')).attr('type', 'button');
});
xml = instance.web.xml_to_str(doc);
return $(xml);
@@ -4628,6 +4628,7 @@ instance.web.form.SelectCreatePopup = instance.web.form.AbstractFormPopup.extend
'selectable': !self.options.disable_multiple_selection,
'import_enabled': false,
'$buttons': self.$buttonpane,
+ 'disable_editable_mode': true,
}, self.options.list_view_options || {}));
self.view_list.on('edit:before', self, function (e) {
e.cancel = true;
diff --git a/addons/web/static/src/js/view_list.js b/addons/web/static/src/js/view_list.js
index df74674a343..55e3c17b494 100644
--- a/addons/web/static/src/js/view_list.js
+++ b/addons/web/static/src/js/view_list.js
@@ -21,6 +21,8 @@ instance.web.ListView = instance.web.View.extend( /** @lends instance.web.ListVi
// whether the view rows can be reordered (via vertical drag & drop)
'reorderable': true,
'action_buttons': true,
+ //whether the editable property of the view has to be disabled
+ 'disable_editable_mode': false,
},
view_type: 'tree',
/**
diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js
index 1abe3caab39..db7e22e5f32 100644
--- a/addons/web/static/src/js/view_list_editable.js
+++ b/addons/web/static/src/js/view_list_editable.js
@@ -78,18 +78,20 @@ openerp.web.list_editable = function (instance) {
_.extend(this.dataset, dataset);
},
do_delete: function (ids) {
+ var nonfalse = _.compact(ids);
var _super = this._super.bind(this);
var next = this.editor.is_editing()
? this.cancel_edition(true)
: $.when();
return next.then(function () {
- return _super(ids);
+ return _super(nonfalse);
});
},
editable: function () {
- return this.fields_view.arch.attrs.editable
+ return !this.options.disable_editable_mode
+ && (this.fields_view.arch.attrs.editable
|| this._context_editable
- || this.options.editable;
+ || this.options.editable);
},
/**
* Replace do_search to handle editability process
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index 641821152b2..006f6768bdd 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -26,6 +26,7 @@ instance.web.ActionManager = instance.web.Widget.extend({
if (this.dialog) {
this.dialog.destroy();
}
+ this.dialog = null;
},
/**
* Add a new item to the breadcrumb
@@ -318,7 +319,6 @@ instance.web.ActionManager = instance.web.Widget.extend({
dialogClass: executor.klass,
});
this.dialog.on("closing", null, options.on_close);
- this.dialog.init_dialog();
this.dialog.dialog_title = executor.action.name;
if (widget instanceof instance.web.ViewManager) {
_.extend(widget.flags, {
@@ -1060,23 +1060,24 @@ instance.web.Sidebar = instance.web.Widget.extend({
},
on_item_action_clicked: function(item) {
var self = this;
- self.getParent().sidebar_context().done(function (context) {
+ self.getParent().sidebar_eval_context().done(function (sidebar_eval_context) {
var ids = self.getParent().get_selected_ids();
if (ids.length == 0) {
instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
return false;
}
- var additional_context = _.extend({
+ var active_ids_context = {
active_id: ids[0],
active_ids: ids,
active_model: self.getParent().dataset.model
- }, context);
+ };
self.rpc("/web/action/load", {
action_id: item.action.id,
- context: additional_context
+ context: active_ids_context,
+ eval_context: new instance.web.CompoundContext(sidebar_eval_context, active_ids_context),
}).done(function(result) {
- result.context = _.extend(result.context || {},
- additional_context);
+ console.log(result.context);
+ result.context = new instance.web.CompoundContext(result.context || {}, active_ids_context);
result.flags = result.flags || {};
result.flags.new_window = true;
self.do_action(result, {
@@ -1329,7 +1330,7 @@ instance.web.View = instance.web.Widget.extend({
on_sidebar_export: function() {
new instance.web.DataExport(this, this.dataset).open();
},
- sidebar_context: function () {
+ sidebar_eval_context: function () {
return $.when();
},
/**