[ADD] Added Dialog widget

bzr revid: fme@openerp.com-20110616143711-9h3cmrg35l96tp7g
This commit is contained in:
Fabien Meghazi 2011-06-16 16:37:11 +02:00
parent ba4bd9f59e
commit 156638333c
1 changed files with 60 additions and 0 deletions

View File

@ -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 = $('<div id="' + this.element_id + '"></div>').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);