From 156638333cae9ce1c8713f3c257e92864686fdb6 Mon Sep 17 00:00:00 2001 From: Fabien Meghazi Date: Thu, 16 Jun 2011 16:37:11 +0200 Subject: [PATCH] [ADD] Added Dialog widget bzr revid: fme@openerp.com-20110616143711-9h3cmrg35l96tp7g --- addons/base/static/src/js/chrome.js | 60 +++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) diff --git a/addons/base/static/src/js/chrome.js b/addons/base/static/src/js/chrome.js index 9ce0efa8d9f..42a314f4316 100644 --- a/addons/base/static/src/js/chrome.js +++ b/addons/base/static/src/js/chrome.js @@ -737,6 +737,66 @@ openerp.base.BaseWidget = openerp.base.Controller.extend({ } }); +openerp.base.Dialog = openerp.base.BaseWidget.extend({ + dialog_title: "", + identifier_prefix: 'dialog', + init: function (session, options) { + this._super(null, session); + options = _.extend({ + modal: true, + title: this.dialog_title, + width: '700px', + min_width: 0, + max_width: '100%', + height: '500px', + min_height: 0, + max_height: '100%', + buttons: {} + }, options); + + options.width = this.get_width(options.width); + options.min_width = this.get_width(options.min_width); + options.max_width = this.get_width(options.max_width); + options.height = this.get_height(options.height); + options.min_height = this.get_height(options.min_height); + options.max_height = this.get_height(options.max_height); + + if (options.width > options.max_width) options.width = options.max_width; + if (options.width < options.min_width) options.width = options.min_width; + if (options.height > options.max_height) options.height = options.max_height; + if (options.height < options.min_height) options.height = options.min_height; + + for (var f in this) { + if (f.substr(0, 10) == 'on_button_') { + options.buttons[f.substr(10)] = this[f]; + } + } + this.options = options; + }, + 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) { + if (val == 'auto') { + return val; + } else if (val.slice(-1) == "%") { + return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10)); + } else { + return parseInt(val, 10); + } + }, + start: function () { + this.$dialog = $('
').dialog(this.options); + this._super(); + }, + stop: function () { + this.$dialog("destroy").remove(); + } +}); + openerp.base.CrashManager = openerp.base.Controller.extend({ init: function(session, element_id) { this._super(session, element_id);