summaryrefslogtreecommitdiff
path: root/addons/base/static/src/js/views.js
diff options
context:
space:
mode:
authorXavier Morel <xmo@openerp.com>2011-08-16 16:25:15 +0200
committerXavier Morel <xmo@openerp.com>2011-08-16 16:25:15 +0200
commitffae7cb4b3e7350d19b273feb100ba73cd022214 (patch)
tree15a06c6746e4d6f9d7042a269362ed72728eeceb /addons/base/static/src/js/views.js
parentd33c95fc4568516c22e12fdcce901d8250c9d218 (diff)
parent36a1a0f1c3f6fe471453d52955f97110220599a3 (diff)
[MERGE] from trunk
bzr revid: xmo@openerp.com-20110816142515-ohq33zvua5uq8cd3
Diffstat (limited to 'addons/base/static/src/js/views.js')
-rw-r--r--addons/base/static/src/js/views.js307
1 files changed, 119 insertions, 188 deletions
diff --git a/addons/base/static/src/js/views.js b/addons/base/static/src/js/views.js
index 9d299f23791..f21c6387d32 100644
--- a/addons/base/static/src/js/views.js
+++ b/addons/base/static/src/js/views.js
@@ -4,72 +4,83 @@
openerp.base.views = function(openerp) {
+/**
+ * Registry for all the client actions key: tag value: widget
+ */
openerp.base.client_actions = new openerp.base.Registry();
+
openerp.base.ActionManager = openerp.base.Widget.extend({
-// process all kind of actions
- init: function(parent, element_id) {
- this._super(parent, element_id);
- this.viewmanager = null;
- this.current_dialog = null;
- // Temporary linking view_manager to session.
- // Will use parent to find it when implementation will be done.
- this.session.action_manager = this;
+ identifier_prefix: "actionmanager",
+ init: function(parent) {
+ this._super(parent);
+ this.inner_viewmanager = null;
+ this.dialog = null;
+ this.dialog_viewmanager = null;
+ this.client_widget = null;
+ },
+ render: function() {
+ return "<div id='"+this.element_id+"'></div>";
+ },
+ dialog_stop: function () {
+ if (this.dialog) {
+ this.dialog_viewmanager.stop();
+ this.dialog_viewmanager = null;
+ this.dialog.stop();
+ this.dialog = null;
+ }
+ },
+ inner_stop: function () {
+ if (this.inner_viewmanager) {
+ this.inner_viewmanager.stop();
+ this.inner_viewmanager = null;
+ }
},
- do_action: function(action, on_closed) {
+ do_action: function(action, on_close) {
+ var type = action.type.replace(/\./g,'_');
+ var popup = action.target === 'new';
action.flags = _.extend({
- sidebar : action.target != 'new',
- search_view : action.target != 'new',
- new_window : false,
- views_switcher : action.target != 'new',
- action_buttons : action.target != 'new',
- pager : action.target != 'new'
+ views_switcher : !popup,
+ search_view : !popup,
+ action_buttons : !popup,
+ sidebar : !popup,
+ pager : !popup
}, action.flags || {});
- // instantiate the right controllers by understanding the action
- if (!(action.type in this)) {
- console.log("Action manager can't handle action of type " + action.type, action);
+ if (!(type in this)) {
+ this.log("Action manager can't handle action of type " + action.type, action);
return;
}
- this[action.type](action, on_closed);
- },
-
- 'ir.actions.act_window': function (action, on_closed) {
- if (!action.target && this.current_dialog) {
- action.flags.new_window = true;
- }
- if (action.target == 'new') {
- var dialog = this.current_dialog = new openerp.base.ActionDialog(this, {
- title: action.name,
- width: '50%'
- });
- if (on_closed) {
- dialog.close_callback = on_closed;
+ this[type](action, on_close);
+ },
+ ir_actions_act_window: function (action, on_close) {
+ if (action.target === 'new') {
+ if (this.dialog == null) {
+ this.dialog = new openerp.base.Dialog(this, { title: action.name, width: '80%' });
+ if(on_close)
+ this.dialog.on_close.add(on_close);
+ this.dialog.start();
+ } else {
+ this.dialog_viewmanager.stop();
}
- dialog.start(false);
- var viewmanager = dialog.viewmanager = new openerp.base.ViewManagerAction(this, dialog.element_id, action);
- viewmanager.start();
- dialog.open();
- } else if (action.flags.new_window) {
- action.flags.new_window = false;
+ this.dialog_viewmanager = new openerp.base.ViewManagerAction(this, action);
+ this.dialog_viewmanager.appendTo(this.dialog.$element);
+ this.dialog.open();
+ } else {
+ this.dialog_stop();
+ this.inner_stop();
+ this.inner_viewmanager = new openerp.base.ViewManagerAction(this, action);
+ this.inner_viewmanager.appendTo(this.$element);
+ }
+ /* new window code
this.rpc("/base/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);
- if (on_closed) {
- on_closed();
- }
+ var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + jQuery.param({ s_action : "" + key });
+ window.open(url,'_blank');
});
- } else {
- if (this.viewmanager) {
- this.viewmanager.stop();
- }
- this.viewmanager = new openerp.base.ViewManagerAction(this, this.element_id, action);
- this.viewmanager.start();
- }
+ */
},
- 'ir.actions.act_window_close': function (action, on_closed) {
- this.close_dialog();
+ ir_actions_act_window_close: function (action, on_closed) {
+ this.dialog_stop();
},
- 'ir.actions.server': function (action, on_closed) {
+ ir_actions_server: function (action, on_closed) {
var self = this;
this.rpc('/base/action/run', {
action_id: action.id,
@@ -78,47 +89,28 @@ openerp.base.ActionManager = openerp.base.Widget.extend({
self.do_action(action, on_closed)
});
},
- 'ir.actions.client': function (action) {
- var Handler = openerp.base.client_actions.get_object(action.tag);
- new Handler(this, this.element_id, action.params).start();
- },
- close_dialog: function () {
- if (this.current_dialog) {
- this.current_dialog.stop();
- this.current_dialog = null;
- }
- }
-});
-
-openerp.base.ActionDialog = openerp.base.Dialog.extend({
- identifier_prefix: 'action_dialog',
- on_close: function() {
- this._super(this, arguments);
- if (this.close_callback) {
- this.close_callback();
- }
- },
- stop: function() {
- this._super(this, arguments);
- if (this.viewmanager) {
- this.viewmanager.stop();
- }
+ ir_actions_client: function (action) {
+ this.client_widget = openerp.base.client_actions.get_object(action.tag);
+ new this.client_widget(this, this.element_id, action.params).start();
}
});
openerp.base.ViewManager = openerp.base.Widget.extend({
- init: function(parent, element_id, dataset, views) {
- this._super(parent, element_id);
+ identifier_prefix: "viewmanager",
+ init: function(parent, dataset, views) {
+ this._super(parent);
this.model = dataset.model;
this.dataset = dataset;
this.searchview = null;
this.active_view = null;
- this.views_src = _.map(views, function(x)
- {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
+ this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
this.views = {};
this.flags = this.flags || {};
this.registry = openerp.base.views;
},
+ render: function() {
+ return QWeb.render("ViewManager", {"prefix": this.element_id, views: this.views_src})
+ },
/**
* @returns {jQuery.Deferred} initial view loading promise
*/
@@ -126,28 +118,26 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
this._super();
var self = this;
this.dataset.start();
-
- this.$element.html(QWeb.render("ViewManager", {"prefix": this.element_id, views: this.views_src}));
this.$element.find('.oe_vm_switch button').click(function() {
self.on_mode_switch($(this).data('view-type'));
});
-
+ var views_ids = {};
_.each(this.views_src, function(view) {
self.views[view.view_type] = $.extend({}, view, {
controller : null,
options : _.extend({
- sidebar_id : self.element_id + '_sidebar_' + view.view_type
- }, self.flags)
+ sidebar_id : self.element_id + '_sidebar_' + view.view_type,
+ action : self.action,
+ action_views_ids : views_ids
+ }, self.flags, view.options || {})
});
+ views_ids[view.view_type] = view.view_id;
});
if (this.flags.views_switcher === false) {
this.$element.find('.oe_vm_switch').hide();
}
// switch to the first one in sequence
return this.on_mode_switch(this.views_src[0].view_type);
-
- },
- stop: function() {
},
/**
* Asks the view manager to switch visualization mode.
@@ -168,7 +158,8 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
if (view.embedded_view) {
controller.set_embedded_view(view.embedded_view);
}
- if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) {
+ controller.do_switch_view.add_last(this.on_mode_switch);
+ if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) {
// In case the search view is not instantiated: manually call ListView#search
var domains = !_(self.action.domain).isEmpty()
? [self.action.domain] : [],
@@ -217,11 +208,12 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
},
/**
* Event launched when a controller has been inited.
- *
+ *
* @param {String} view_type type of view
* @param {String} view the inited controller
*/
- on_controller_inited: function(view_type, view) {},
+ on_controller_inited: function(view_type, view) {
+ },
/**
* Sets up the current viewmanager's search view.
*
@@ -238,9 +230,8 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
this.searchview.hide();
}
this.searchview.on_search.add(function(domains, contexts, groupbys) {
- self.views[self.active_view].controller.do_search.call(
- self, domains.concat(self.domains()),
- contexts.concat(self.contexts()), groupbys);
+ var controller = self.views[self.active_view].controller;
+ controller.do_search.call(controller, domains, contexts, groupbys);
});
return this.searchview.start();
},
@@ -254,50 +245,22 @@ openerp.base.ViewManager = openerp.base.Widget.extend({
on_remove: function() {
},
on_edit: function() {
- },
- /**
- * Domains added on searches by the view manager, to override in subsequent
- * view manager in order to add new pieces of domains to searches
- *
- * @returns an empty list
- */
- domains: function () {
- return [];
- },
- /**
- * Contexts added on searches by the view manager.
- *
- * @returns an empty list
- */
- contexts: function () {
- return [];
- }
-});
-
-openerp.base.NullViewManager = openerp.base.generate_null_object_class(openerp.base.ViewManager, {
- init: function(parent) {
- this._super(parent);
- if(parent)
- this.session = parent.session;
- this.action = {flags: {}};
}
});
-// TODO Will move to action Manager
openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
- init: function(parent, element_id, action) {
+ init: function(parent, action) {
this.session = parent.session;
+ this.action = action;
var dataset;
if (!action.res_id) {
- dataset = new openerp.base.DataSetSearch(this, action.res_model, action.context || null);
+ dataset = new openerp.base.DataSetSearch(this, action.res_model, action.context, action.domain);
} else {
- dataset = new openerp.base.DataSetStatic(this, action.res_model, {}, [action.res_id]);
- if (action.context) {
- // TODO fme: should normalize all DataSets constructors to (session, model, context, ...)
- dataset.context = action.context;
- }
+ this.action.flags.search_view = false;
+ dataset = new openerp.base.DataSetStatic(this, action.res_model, action.context, [action.res_id]);
+ dataset.index = 0;
}
- this._super(parent, element_id, dataset, action.views);
+ this._super(parent, dataset, action.views);
this.action = action;
this.flags = this.action.flags || {};
if (action.res_model == 'board.board' && action.views.length == 1 && action.views) {
@@ -307,6 +270,7 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
},
start: function() {
var inital_view_loaded = this._super();
+
var search_defaults = {};
_.each(this.action.context, function (value, key) {
var match = /^search_default_(.*)$/.exec(key);
@@ -329,32 +293,6 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
}
}
},
- stop: function() {
- // should be replaced by automatic destruction implemented in Widget
- this._super();
- },
- /**
- * adds action domain to the search domains
- *
- * @returns the action's domain
- */
- domains: function () {
- if (!this.action.domain) {
- return [];
- }
- return [this.action.domain];
- },
- /**
- * adds action context to the search contexts
- *
- * @returns the action's context
- */
- contexts: function () {
- if (!this.action.context) {
- return [];
- }
- return [this.action.context];
- },
on_mode_switch: function (view_type) {
this._super(view_type);
this.shortcut_check(this.views[view_type]);
@@ -394,8 +332,6 @@ openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
$shortcut_toggle.addClass("oe-shortcut-remove");
}
});
-
-
}
});
@@ -491,7 +427,9 @@ openerp.base.View = openerp.base.Widget.extend({
_.defaults(this.options, {
// All possible views options should be defaulted here
sidebar_id: null,
- sidebar: true
+ sidebar: true,
+ action: null,
+ action_views_ids: {}
});
},
/**
@@ -503,17 +441,12 @@ openerp.base.View = openerp.base.Widget.extend({
* @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
* @param {Object} [action_data.context=null] additional action context, to add to the current context
* @param {openerp.base.DataSet} dataset a dataset object used to communicate with the server
- * @param {openerp.base.ActionManager} action_manager object able to actually execute the action, if any is fetched
* @param {Object} [record_id] the identifier of the object on which the action is to be applied
* @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
*/
- execute_action: function (action_data, dataset, action_manager, record_id, on_closed) {
+ execute_action: function (action_data, dataset, record_id, on_closed) {
var self = this;
- if (action_manager.current_dialog) {
- on_closed = action_manager.current_dialog.close_callback;
- }
var handler = function (r) {
- action_manager.close_dialog();
var action = r.result;
if (action && action.constructor == Object) {
action.context = action.context || {};
@@ -522,38 +455,36 @@ openerp.base.View = openerp.base.Widget.extend({
active_ids: [record_id || false],
active_model: dataset.model
});
- action.flags = {
- new_window: true
- };
- action_manager.do_action(action, on_closed);
+ self.do_action(action, on_closed);
} else if (on_closed) {
on_closed(action);
}
};
- if (!action_data.special) {
- var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
- switch(action_data.type) {
- case 'object':
- return dataset.call_button(action_data.name, [[record_id], context], handler);
- case 'action':
- return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
- default:
- return dataset.exec_workflow(record_id, action_data.name, handler);
- }
- } else {
- action_manager.close_dialog();
- }
+ var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
+
+ if (action_data.special) {
+ handler({result: {"type":"ir.actions.act_window_close"}});
+ } else if (action_data.type=="object") {
+ return dataset.call_button(action_data.name, [[record_id], context], handler);
+ } else if (action_data.type=="action") {
+ return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
+ } else {
+ return dataset.exec_workflow(record_id, action_data.name, handler);
+ }
},
/**
* Directly set a view to use instead of calling fields_view_get. This method must
* be called before start(). When an embedded view is set, underlying implementations
* of openerp.base.View must use the provided view instead of any other one.
- *
+ *
* @param embedded_view A view.
*/
set_embedded_view: function(embedded_view) {
this.embedded_view = embedded_view;
+ this.options.sidebar = false;
+ },
+ do_switch_view: function(view) {
},
set_common_sidebar_sections: function(sidebar) {
sidebar.add_section('customize', "Customize", [
@@ -598,16 +529,16 @@ openerp.base.View = openerp.base.Widget.extend({
}
},
on_sidebar_edit_workflow: function() {
- console.log('Todo');
+ this.log('Todo');
},
on_sidebar_customize_object: function() {
- console.log('Todo');
+ this.log('Todo');
},
on_sidebar_import: function() {
},
on_sidebar_export: function() {
var export_view = new openerp.base.DataExport(this, this.dataset);
- export_view.start(false);
+ export_view.start();
},
on_sidebar_translate: function() {
},