[IMP] Cleaned dialog class to be closer to the Widget design

bzr revid: nicolas.vanhoren@openerp.com-20120802143650-czejc71u5atle2rs
This commit is contained in:
niv-openerp
2012-08-02 16:36:50 +02:00
parent c2ad177f93
commit d9aaf5c2d1
+33 -25
View File
@@ -57,7 +57,7 @@ instance.web.Dialog = instance.web.Widget.extend({
init: function (parent, options, content) {
var self = this;
this._super(parent);
this.setElement(content || this.make(this.tagName));
this.content_to_set = content;
this.dialog_options = {
modal: true,
destroy_on_close: true,
@@ -81,11 +81,6 @@ instance.web.Dialog = instance.web.Widget.extend({
if (options) {
_.extend(this.dialog_options, options);
}
if (this.dialog_options.autoOpen) {
this.open();
} else {
instance.web.dialog(this.$element, this.get_options());
}
},
get_options: function(options) {
var self = this,
@@ -114,31 +109,44 @@ instance.web.Dialog = instance.web.Widget.extend({
} else if (val.slice(-1) == "%") {
return Math.round(available_size / 100 * parseInt(val.slice(0, -1), 10));
} else {
return parseInt(val, 10);
return parseInt(val, 10);
}
},
renderElement: function() {
if (this.content_to_set) {
this.setElement(this.content_to_set);
} else if (this.template) {
this._super();
}
},
open: function(options) {
// TODO fme: bind window on resize
if (this.template) {
this.$element.html(this.renderElement());
}
if (! this.dialog_inited)
this.init_dialog();
var o = this.get_options(options);
instance.web.dialog(this.$element, o).dialog('open');
instance.web.dialog(this.$element, o).dialog('open');
if (o.height === 'auto' && o.max_height) {
this.$element.css({ 'max-height': o.max_height, 'overflow-y': 'auto' });
}
return this;
},
init_dialog: function(options) {
this.renderElement();
var o = this.get_options(options);
instance.web.dialog(this.$element, o);
var res = this.start();
this.dialog_inited = true;
return res;
},
close: function() {
this.$element.dialog('close');
},
on_close: function() {
if (this.__tmp_dialog_destroying)
return;
if (this.__tmp_dialog_destroying)
return;
if (this.dialog_options.destroy_on_close) {
this.__tmp_dialog_closing = true;
this.__tmp_dialog_closing = true;
this.destroy();
this.__tmp_dialog_closing = undefined;
this.__tmp_dialog_closing = undefined;
}
},
on_resized: function() {
@@ -148,10 +156,10 @@ instance.web.Dialog = instance.web.Widget.extend({
el.destroy();
});
if (! this.__tmp_dialog_closing) {
this.__tmp_dialog_destroying = true;
this.close();
this.__tmp_dialog_destroying = undefined;
}
this.__tmp_dialog_destroying = true;
this.close();
this.__tmp_dialog_destroying = undefined;
}
if (! this.isDestroyed()) {
this.$element.dialog('destroy');
}
@@ -261,11 +269,11 @@ instance.web.Loading = instance.web.Widget.extend({
this.count += increment;
if (this.count > 0) {
if (instance.connection.debug) {
this.$element.text(_.str.sprintf( _t("Loading (%d)"), this.count));
} else {
this.$element.text(_t("Loading"));
}
if (instance.connection.debug) {
this.$element.text(_.str.sprintf( _t("Loading (%d)"), this.count));
} else {
this.$element.text(_t("Loading"));
}
this.$element.show();
this.getParent().$element.addClass('oe_wait');
} else {