[IMP] url handling by chs

bzr revid: al@openerp.com-20111213105908-740uk5jf0r64lsdb
This commit is contained in:
Antony Lesuisse
2011-12-13 11:59:08 +01:00
3 changed files with 106 additions and 96 deletions
+41 -63
View File
@@ -1011,13 +1011,12 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
this.session.on_session_valid.add_last(this.header.do_update);
this.session.on_session_invalid.add_last(this.header.do_update);
this.session.on_session_valid.add_last(this.on_logged);
this.session.on_session_invalid.add_last(this.on_logged_out);
this.menu = new openerp.web.Menu(this, "oe_menu", "oe_secondary_menu");
this.menu.on_action.add(this.on_menu_action);
this.url_internal_hashchange = false;
this.url_external_hashchange = false;
jQuery(window).bind('hashchange', this.on_url_hashchange);
this._current_state = null;
},
start: function() {
@@ -1046,77 +1045,56 @@ openerp.web.WebClient = openerp.web.Widget.extend(/** @lends openerp.web.WebClie
if(this.action_manager)
this.action_manager.stop();
this.action_manager = new openerp.web.ActionManager(this);
this.action_manager.do_push_state.add(this.do_push_state);
this.action_manager.appendTo($("#oe_app"));
this.action_manager.do_url_set_hash.add_last(this.do_url_set_hash);
// if using saved actions, load the action and give it to action manager
var parameters = jQuery.deparam(jQuery.param.querystring());
if (parameters["s_action"] != undefined) {
var key = parseInt(parameters["s_action"], 10);
var self = this;
this.rpc("/web/session/get_session_action", {key:key}, function(action) {
self.action_manager.do_action(action);
});
} else if (openerp._modules_loaded) { // TODO: find better option than this
this.load_url_state()
if (openerp._modules_loaded) { // TODO: find better option than this
this.bind_hashchange();
} else {
this.session.on_modules_loaded.add({
callback: $.proxy(this, 'load_url_state'),
this.session.on_modules_loaded.add({ // XXX what about a $.Deferred ?
callback: $.proxy(this, 'bind_hashchange'),
unique: true,
position: 'last'
})
}
},
/**
* Loads state from URL if any, or checks if there is a home action and
* loads that, assuming we're at the index
*/
load_url_state: function () {
var self = this;
// TODO: add actual loading if there is url state to unpack, test on window.location.hash
// not logged in
if (!this.session.uid) { return; }
self.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
},
default_home: function () {
},
/**
* Bundles the execution of the home action
*
* @param {Number} action action id
* @param {openerp.web.DataSet} dataset action executor
*/
execute_home_action: function (action, dataset) {
var self = this;
this.rpc('/web/action/load', {
action_id: action,
context: dataset.get_context()
}, function (meh) {
var action = meh.result;
action.context = _.extend(action.context || {}, {
active_id: false,
active_ids: [false],
active_model: dataset.model
});
self.action_manager.do_action(action);
});
},
do_url_set_hash: function(url) {
if(!this.url_external_hashchange) {
this.url_internal_hashchange = true;
jQuery.bbq.pushState(url);
}
},
on_url_hashchange: function() {
if(this.url_internal_hashchange) {
this.url_internal_hashchange = false;
bind_hashchange: function() {
$(window).bind('hashchange', this.on_hashchange);
var state = $.bbq.getState(true);
if (! _.isEmpty(state)) {
$(window).trigger('hashchange');
} else {
var url = jQuery.deparam.fragment();
this.url_external_hashchange = true;
this.action_manager.on_url_hashchange(url);
this.url_external_hashchange = false;
this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
}
},
on_logged_out: function() {
$(window).unbind('hashchange', this.on_hashchange);
if(this.action_manager)
this.action_manager.stop();
this.action_manager = null;
},
on_hashchange: function(event) {
var state = event.getState(true);
if (!_.isEqual(this._current_state, state)) {
this.action_manager.do_load_state(state);
}
this._current_state = state;
},
do_push_state: function(state, overwrite) {
if (!overwrite) {
var hash = $.deparam.fragment(true);
state = _.extend({}, hash, state);
}
var url = '#' + $.param(state);
this._current_state = _.clone(state);
$.bbq.pushState(url);
},
on_menu_action: function(action) {
this.action_manager.do_action(action);
},
+1
View File
@@ -985,6 +985,7 @@ openerp.web.Widget = openerp.web.CallbackEnabled.extend(/** @lends openerp.web.W
}
return false;
},
rpc: function(url, data, success, error) {
var def = $.Deferred().then(success, error);
var self = this;
+64 -33
View File
@@ -46,35 +46,38 @@ session.web.ActionManager = session.web.Widget.extend({
this.client_widget = null;
}
},
url_update: function(action) {
var url = {};
if(action.id)
url.action_id = action.id;
// this.url = {
// "model": action.res_model,
// "domain": action.domain,
// };
// action.res_model
// action.domain
// action.context
// after
// action.views
// action.res_id
// mode
// menu
this.do_url_set_hash(url);
do_push_state: function(state, overwrite) {
},
do_url_set_hash: function(url) {
},
on_url_hashchange: function(url) {
var self = this;
if(url && url.action_id) {
self.rpc("/web/action/load", { action_id: url.action_id }, function(result) {
self.do_action(result.result);
});
do_load_state: function(state) {
if (state.action_id) {
this.null_action();
this.do_action(state.action_id);
}
else if (state.model && state.id) {
// TODO implement it
//this.null_action();
// action = {}
}
else if (state.client_action) {
this.null_action();
this.ir_actions_client(state.client_action);
}
if (this.inner_viewmanager) {
this.inner_viewmanager.do_load_state(state);
}
},
do_action: function(action, on_close) {
if (_.isNumber(action)) {
var self = this;
self.rpc("/web/action/load", { action_id: action }, function(result) {
self.do_action(result.result, on_close);
});
return;
}
if (!action.type) {
console.error("No type for action", action);
return;
@@ -123,15 +126,12 @@ session.web.ActionManager = session.web.Widget.extend({
this.dialog_stop();
this.content_stop();
this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
this.inner_viewmanager.do_push_state.add(this.do_push_state);
this.inner_viewmanager.appendTo(this.$element);
this.url_update(action);
if (action.id) {
this.do_push_state({action_id: action.id}, true);
}
}
/* new window code
this.rpc("/web/session/save_session_action", { the_action : action}, function(key) {
var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + jQuery.param({ s_action : "" + key });
window.open(url,'_blank');
});
*/
},
ir_actions_act_window_close: function (action, on_closed) {
if (!this.dialog && on_closed) {
@@ -152,6 +152,10 @@ session.web.ActionManager = session.web.Widget.extend({
this.content_stop();
var ClientWidget = session.web.client_actions.get_object(action.tag);
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
var client_action = {tag: action.tag};
if (action.params) _.extend(client_action, {params: action.params});
this.do_push_state({client_action: client_action}, true);
},
ir_actions_report_xml: function(action, on_closed) {
var self = this;
@@ -272,7 +276,7 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View
var container = $("#" + this.element_id + '_view_' + view_type);
view_promise = controller.appendTo(container);
this.views[view_type].controller = controller;
this.views[view_type].deferred.resolve();
this.views[view_type].deferred.resolve(view_type);
$.when(view_promise).then(function() {
self.on_controller_inited(view_type, controller);
if (self.searchview && view.controller.searchable !== false) {
@@ -308,6 +312,8 @@ session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.View
});
return view_promise;
},
/**
* Returns to the view preceding the caller view in this manager's
* navigation history (the navigation history is appended to via
@@ -458,6 +464,12 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
var main_view_loaded = this._super();
_.each(_.keys(this.views), function(view_type) {
$.when(self.views[view_type].deferred).done(function(view_type) {
self.views[view_type].controller.do_push_state.add(self.do_push_state);
});
});
var manager_ready = $.when(searchview_loaded, main_view_loaded);
this.$element.find('.oe_get_xml_view').click(function () {
@@ -531,8 +543,21 @@ session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepner
} else {
$search_prefix.remove();
}
self.do_push_state({view_type: self.active_view});
});
},
do_push_state: function(state, overwrite) {
},
do_load_state: function(state) {
var self = this;
$.when(this.on_mode_switch(state.view_type, true)).done(function() {
self.views[self.active_view].controller.do_load_state(state);
});
},
shortcut_check : function(view) {
var self = this;
var grandparent = this.widget_parent && this.widget_parent.widget_parent;
@@ -1098,6 +1123,12 @@ session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
},
sidebar_context: function () {
return $.Deferred().resolve({}).promise();
},
do_push_state: function(state, overwrite) {
},
do_load_state: function(state) {
}
});