[imp] simplified WebClient

bzr revid: nicolas.vanhoren@openerp.com-20120104181150-0zm2b3m6e89yb2zp
This commit is contained in:
niv-openerp 2012-01-04 19:11:50 +01:00
parent 5abc71cf20
commit deef3f37b5
2 changed files with 57 additions and 39 deletions

View File

@ -226,8 +226,20 @@ openerp.web.Loading = openerp.web.Widget.extend(/** @lends openerp.web.Loading#
this._super(parent);
this.count = 0;
this.blocked_ui = false;
this.session.on_rpc_request.add_first(this.on_rpc_event, 1);
this.session.on_rpc_response.add_last(this.on_rpc_event, -1);
var self = this;
this.request_call = function() {
self.on_rpc_event(1);
};
this.response_call = function() {
self.on_rpc_event(-1);
};
this.session.on_rpc_request.add_first(this.request_call);
this.session.on_rpc_response.add_last(this.response_call);
},
stop: function() {
this.session.on_rpc_request.remove(this.request_call);
this.session.on_rpc_response.remove(this.response_call);
this._super();
},
on_rpc_event : function(increment) {
var self = this;
@ -1056,31 +1068,12 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
});
}
self.crashmanager = new openerp.web.CrashManager();
self.notification = new openerp.web.Notification(self);
self.notification.appendTo(self.$element);
self.loading = new openerp.web.Loading(self);
self.loading.appendTo(self.$element);
if (!self.session.session_is_valid()) {
self.login = new openerp.web.Login(self);
self.login.appendTo(self.$element);
self.show_login();
}
});
this.session.ready.then(function() {
if (self.login) {
self.login.stop();
self.login = undefined;
}
self.$table = $(QWeb.render("Interface", {}));
self.$element.append(self.$table);
self.header = new openerp.web.Header(self);
self.header.on_logout.add(self.on_logout);
self.header.on_action.add(self.on_menu_action);
self.header.appendTo($("#oe_header"));
self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
self.menu.on_action.add(self.on_menu_action);
self.menu.start();
self.show_application();
self.header.do_update();
self.menu.do_reload();
@ -1095,6 +1088,40 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
}
});
},
show_login: function() {
var self = this;
this.destroy_content();
this.show_common();
self.login = new openerp.web.Login(self);
self.login.appendTo(self.$element);
},
show_application: function() {
var self = this;
this.destroy_content();
this.show_common();
self.$table = $(QWeb.render("Interface", {}));
self.$element.append(self.$table);
self.header = new openerp.web.Header(self);
self.header.on_logout.add(self.on_logout);
self.header.on_action.add(self.on_menu_action);
self.header.appendTo($("#oe_header"));
self.menu = new openerp.web.Menu(self, "oe_menu", "oe_secondary_menu");
self.menu.on_action.add(self.on_menu_action);
self.menu.start();
},
show_common: function() {
var self = this;
self.crashmanager = new openerp.web.CrashManager();
self.notification = new openerp.web.Notification(self);
self.notification.appendTo(self.$element);
self.loading = new openerp.web.Loading(self);
self.loading.appendTo(self.$element);
},
destroy_content: function() {
_.each(_.clone(this.widget_children), function(el) {
el.stop();
});
},
do_reload: function() {
return this.session.session_init().pipe(_.bind(function() {this.menu.do_reload();}, this));
},
@ -1111,22 +1138,7 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
this.header.do_update();
$(window).unbind('hashchange', this.on_hashchange);
this.do_push_state({});
if(this.action_manager) {
this.action_manager.stop();
this.action_manager = undefined;
}
if (this.menu) {
this.menu.stop();
this.menu = undefined;
}
if (this.header) {
this.header.stop();
this.header = undefined;
}
if (this.$table) {
this.$table.remove();
this.$table = undefined;
}
this.show_login();
window.location.reload();
},
bind_hashchange: function() {

View File

@ -160,6 +160,12 @@ openerp.web.callback = function(obj, method) {
position: "last"
});
};
callback.remove = function(f) {
callback.callback_chain = _.difference(callback.callback_chain, _.filter(callback.callback_chain, function(el) {
return el.callback === f;
}));
return callback;
};
return callback.add({
callback: method,