diff options
| author | Jiten (OpenERP) <jra@tinyerp.com> | 2012-11-20 18:22:07 +0530 |
|---|---|---|
| committer | Jiten (OpenERP) <jra@tinyerp.com> | 2012-11-20 18:22:07 +0530 |
| commit | c1da45fade8c6505302a46d54c4a6a2d5fc04714 (patch) | |
| tree | 0410c69479255420226dfaf81e8790bddc822f45 /addons/web/static/src | |
| parent | e17c6b40d9ae463c1e3bbbd9836365284176615a (diff) | |
| parent | ade1a5df8713d6375bc7196261ed8b28f820fd42 (diff) | |
[Merged] Merged trunk.
bzr revid: jra@tinyerp.com-20121120125207-gjcwghoi0fjm88q4
Diffstat (limited to 'addons/web/static/src')
| -rw-r--r-- | addons/web/static/src/js/chrome.js | 103 | ||||
| -rw-r--r-- | addons/web/static/src/js/data_export.js | 1 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_form.js | 6 | ||||
| -rw-r--r-- | addons/web/static/src/js/view_list_editable.js | 3 | ||||
| -rw-r--r-- | addons/web/static/src/js/views.js | 16 |
5 files changed, 70 insertions, 59 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js index 0db21f2397f..cb19ea61e58 100644 --- a/addons/web/static/src/js/chrome.js +++ b/addons/web/static/src/js/chrome.js @@ -66,50 +66,48 @@ 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); }, - 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]); + 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,11 +121,14 @@ 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); + var o = this._get_options(options); + if (!this.dialog_inited) { + this.init_dialog(o); + } + if (o.buttons) { + this._add_buttons(o.buttons); + delete(o.buttons); + } this.$buttons.appendTo($("body")); instance.web.dialog(this.$el, o).dialog('open'); this.$el.dialog("widget").find(".ui-dialog-buttonpane").remove(); @@ -137,10 +138,15 @@ instance.web.Dialog = instance.web.Widget.extend({ } 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: {} }}})); + _.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: {} }}})); self.$buttons.append($but); $but.on('click', function(ev) { fn.call(self.$el, ev); @@ -149,8 +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); + instance.web.dialog(this.$el, options); this.$buttons = $('<div class="ui-dialog-buttonpane ui-widget-content ui-helper-clearfix" />'); this.$el.dialog("widget").append(this.$buttons); this.dialog_inited = true; @@ -171,8 +176,6 @@ instance.web.Dialog = instance.web.Widget.extend({ this.__tmp_dialog_closing = undefined; } }, - on_resized: function() { - }, destroy: function () { _.each(this.getChildren(), function(el) { el.destroy(); @@ -665,13 +668,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; }, @@ -1081,7 +1090,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 291fae5e0d8..043fd97d8fe 100644 --- a/addons/web/static/src/js/view_form.js +++ b/addons/web/static/src/js/view_form.js @@ -1025,8 +1025,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; @@ -1231,7 +1231,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); diff --git a/addons/web/static/src/js/view_list_editable.js b/addons/web/static/src/js/view_list_editable.js index 1abe3caab39..ec0bf2774fe 100644 --- a/addons/web/static/src/js/view_list_editable.js +++ b/addons/web/static/src/js/view_list_editable.js @@ -78,12 +78,13 @@ 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 () { diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js index 641821152b2..42d64c7d2f7 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 @@ -1060,23 +1061,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 +1331,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(); }, /** |
