summaryrefslogtreecommitdiff
path: root/addons/web/static/src/js
diff options
context:
space:
mode:
authorAntony Lesuisse <al@openerp.com>2011-12-13 11:59:08 +0100
committerAntony Lesuisse <al@openerp.com>2011-12-13 11:59:08 +0100
commitd34a0d0e1762a73e1ac3fdcf3634c1b7cd669b15 (patch)
tree95cc7a6d3a3af8c7929c68582e666b09bbc5d1b5 /addons/web/static/src/js
parent1976fdb93d7f8e331b0dbfaae10b10a7731210a0 (diff)
parent68914b311ba4a4e748c8c33342c3efed19a7efab (diff)
[IMP] url handling by chs
bzr revid: al@openerp.com-20111213105908-740uk5jf0r64lsdb
Diffstat (limited to 'addons/web/static/src/js')
-rw-r--r--addons/web/static/src/js/chrome.js98
-rw-r--r--addons/web/static/src/js/core.js1
-rw-r--r--addons/web/static/src/js/views.js99
3 files changed, 104 insertions, 94 deletions
diff --git a/addons/web/static/src/js/chrome.js b/addons/web/static/src/js/chrome.js
index 42f21996081..2dbd0867a81 100644
--- a/addons/web/static/src/js/chrome.js
+++ b/addons/web/static/src/js/chrome.js
@@ -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 () {
+
+ bind_hashchange: function() {
+ $(window).bind('hashchange', this.on_hashchange);
+
+ var state = $.bbq.getState(true);
+ if (! _.isEmpty(state)) {
+ $(window).trigger('hashchange');
+ } else {
+ this.action_manager.do_action({type: 'ir.actions.client', tag: 'default_home'});
+ }
},
- /**
- * 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);
- });
+
+ on_logged_out: function() {
+ $(window).unbind('hashchange', this.on_hashchange);
+ if(this.action_manager)
+ this.action_manager.stop();
+ this.action_manager = null;
},
- do_url_set_hash: function(url) {
- if(!this.url_external_hashchange) {
- this.url_internal_hashchange = true;
- jQuery.bbq.pushState(url);
+
+ 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;
},
- on_url_hashchange: function() {
- if(this.url_internal_hashchange) {
- this.url_internal_hashchange = false;
- } else {
- var url = jQuery.deparam.fragment();
- this.url_external_hashchange = true;
- this.action_manager.on_url_hashchange(url);
- this.url_external_hashchange = false;
+
+ 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);
},
diff --git a/addons/web/static/src/js/core.js b/addons/web/static/src/js/core.js
index 37bd19fddd9..95d1043c3ca 100644
--- a/addons/web/static/src/js/core.js
+++ b/addons/web/static/src/js/core.js
@@ -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;
diff --git a/addons/web/static/src/js/views.js b/addons/web/static/src/js/views.js
index ac1451cd55f..d9b72041e13 100644
--- a/addons/web/static/src/js/views.js
+++ b/addons/web/static/src/js/views.js
@@ -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_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_push_state: function(state, overwrite) {
+ },
+
+ 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) {
}
});