2011-03-30 14:00:48 +00:00
|
|
|
/*---------------------------------------------------------
|
|
|
|
* OpenERP base library
|
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2011-03-30 14:35:56 +00:00
|
|
|
openerp.base.views = function(openerp) {
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-07-01 11:57:26 +00:00
|
|
|
openerp.base.client_actions = new openerp.base.Registry();
|
2011-07-28 14:49:12 +00:00
|
|
|
openerp.base.ActionManager = openerp.base.Widget.extend({
|
2011-03-30 23:57:43 +00:00
|
|
|
// process all kind of actions
|
2011-07-18 15:08:33 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
2011-03-30 14:00:48 +00:00
|
|
|
this.viewmanager = null;
|
2011-07-12 12:47:14 +00:00
|
|
|
this.current_dialog = null;
|
2011-04-12 14:07:01 +00:00
|
|
|
// Temporary linking view_manager to session.
|
2011-07-22 15:59:48 +00:00
|
|
|
// Will use parent to find it when implementation will be done.
|
2011-07-18 15:08:33 +00:00
|
|
|
this.session.action_manager = this;
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-06-28 10:30:49 +00:00
|
|
|
do_action: function(action, on_closed) {
|
2011-05-11 13:36:55 +00:00
|
|
|
action.flags = _.extend({
|
2011-05-24 09:46:49 +00:00
|
|
|
sidebar : action.target != 'new',
|
2011-07-12 09:11:10 +00:00
|
|
|
search_view : action.target != 'new',
|
2011-05-11 13:36:55 +00:00
|
|
|
new_window : false,
|
2011-07-12 09:11:10 +00:00
|
|
|
views_switcher : action.target != 'new',
|
|
|
|
action_buttons : action.target != 'new',
|
|
|
|
pager : action.target != 'new'
|
2011-05-11 13:36:55 +00:00
|
|
|
}, action.flags || {});
|
2011-03-30 14:00:48 +00:00
|
|
|
// instantiate the right controllers by understanding the action
|
2011-06-30 13:01:33 +00:00
|
|
|
if (!(action.type in this)) {
|
|
|
|
console.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) {
|
2011-07-14 10:22:43 +00:00
|
|
|
if (!action.target && this.current_dialog) {
|
2011-06-30 13:01:33 +00:00
|
|
|
action.flags.new_window = true;
|
2011-03-30 14:00:48 +00:00
|
|
|
}
|
2011-06-30 13:01:33 +00:00
|
|
|
if (action.target == 'new') {
|
2011-07-26 12:36:26 +00:00
|
|
|
var dialog = this.current_dialog = new openerp.base.ActionDialog(this, {
|
2011-06-30 13:01:33 +00:00
|
|
|
title: action.name,
|
2011-07-14 10:22:43 +00:00
|
|
|
width: '50%'
|
2011-06-30 13:01:33 +00:00
|
|
|
});
|
2011-07-14 10:22:43 +00:00
|
|
|
if (on_closed) {
|
|
|
|
dialog.close_callback = on_closed;
|
|
|
|
}
|
|
|
|
dialog.start(false);
|
2011-07-26 12:36:26 +00:00
|
|
|
var viewmanager = dialog.viewmanager = new openerp.base.ViewManagerAction(this, dialog.element_id, action);
|
2011-06-30 13:01:33 +00:00
|
|
|
viewmanager.start();
|
2011-07-14 10:22:43 +00:00
|
|
|
dialog.open();
|
2011-06-30 13:01:33 +00:00
|
|
|
} else if (action.flags.new_window) {
|
|
|
|
action.flags.new_window = false;
|
|
|
|
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);
|
2011-07-26 12:36:26 +00:00
|
|
|
if (on_closed) {
|
|
|
|
on_closed();
|
2011-04-12 15:09:55 +00:00
|
|
|
}
|
2011-06-30 13:01:33 +00:00
|
|
|
});
|
|
|
|
} else {
|
|
|
|
if (this.viewmanager) {
|
|
|
|
this.viewmanager.stop();
|
|
|
|
}
|
2011-07-26 12:36:26 +00:00
|
|
|
this.viewmanager = new openerp.base.ViewManagerAction(this, this.element_id, action);
|
2011-06-30 13:01:33 +00:00
|
|
|
this.viewmanager.start();
|
|
|
|
}
|
|
|
|
},
|
|
|
|
'ir.actions.act_window_close': function (action, on_closed) {
|
2011-07-14 14:30:29 +00:00
|
|
|
this.close_dialog();
|
2011-06-30 13:01:33 +00:00
|
|
|
},
|
|
|
|
'ir.actions.server': function (action, on_closed) {
|
|
|
|
var self = this;
|
|
|
|
this.rpc('/base/action/run', {
|
|
|
|
action_id: action.id,
|
|
|
|
context: {active_id: 66, active_ids: [66], active_model: 'ir.ui.menu'}
|
|
|
|
}).then(function (action) {
|
|
|
|
self.do_action(action, on_closed)
|
|
|
|
});
|
2011-07-01 11:57:26 +00:00
|
|
|
},
|
|
|
|
'ir.actions.client': function (action) {
|
|
|
|
var Handler = openerp.base.client_actions.get_object(action.tag);
|
2011-08-03 14:42:44 +00:00
|
|
|
new Handler(this, this.element_id, action.params).start();
|
2011-07-14 14:30:29 +00:00
|
|
|
},
|
|
|
|
close_dialog: function () {
|
|
|
|
if (this.current_dialog) {
|
|
|
|
this.current_dialog.stop();
|
|
|
|
this.current_dialog = null;
|
|
|
|
}
|
2011-08-12 12:35:59 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
|
|
|
|
2011-07-19 10:27:07 +00:00
|
|
|
openerp.base.ActionDialog = openerp.base.Dialog.extend({
|
|
|
|
identifier_prefix: 'action_dialog',
|
2011-07-27 15:05:42 +00:00
|
|
|
on_close: function() {
|
2011-07-19 10:27:07 +00:00
|
|
|
this._super(this, arguments);
|
|
|
|
if (this.close_callback) {
|
|
|
|
this.close_callback();
|
|
|
|
}
|
2011-07-27 15:05:42 +00:00
|
|
|
},
|
|
|
|
stop: function() {
|
|
|
|
this._super(this, arguments);
|
2011-07-19 10:27:07 +00:00
|
|
|
if (this.viewmanager) {
|
|
|
|
this.viewmanager.stop();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-28 14:49:12 +00:00
|
|
|
openerp.base.ViewManager = openerp.base.Widget.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id, dataset, views) {
|
|
|
|
this._super(parent, element_id);
|
2011-04-06 21:10:37 +00:00
|
|
|
this.model = dataset.model;
|
|
|
|
this.dataset = dataset;
|
2011-03-30 14:00:48 +00:00
|
|
|
this.searchview = null;
|
2011-03-31 12:25:22 +00:00
|
|
|
this.active_view = null;
|
2011-06-16 14:25:30 +00:00
|
|
|
this.views_src = _.map(views, function(x)
|
|
|
|
{return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
|
2011-03-30 14:00:48 +00:00
|
|
|
this.views = {};
|
2011-05-17 09:26:27 +00:00
|
|
|
this.flags = this.flags || {};
|
2011-06-16 16:37:09 +00:00
|
|
|
this.registry = openerp.base.views;
|
2011-04-05 10:24:40 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @returns {jQuery.Deferred} initial view loading promise
|
|
|
|
*/
|
2011-04-06 00:51:36 +00:00
|
|
|
start: function() {
|
2011-07-29 14:01:06 +00:00
|
|
|
this._super();
|
2011-04-05 10:24:40 +00:00
|
|
|
var self = this;
|
|
|
|
this.dataset.start();
|
2011-08-12 12:35:59 +00:00
|
|
|
|
2011-04-06 00:51:36 +00:00
|
|
|
this.$element.html(QWeb.render("ViewManager", {"prefix": this.element_id, views: this.views_src}));
|
2011-04-05 10:10:08 +00:00
|
|
|
this.$element.find('.oe_vm_switch button').click(function() {
|
|
|
|
self.on_mode_switch($(this).data('view-type'));
|
|
|
|
});
|
2011-08-12 12:35:59 +00:00
|
|
|
|
2011-04-06 00:51:36 +00:00
|
|
|
_.each(this.views_src, function(view) {
|
2011-07-26 21:00:05 +00:00
|
|
|
self.views[view.view_type] = $.extend({}, view, {
|
|
|
|
controller : null,
|
|
|
|
options : _.extend({
|
|
|
|
sidebar_id : self.element_id + '_sidebar_' + view.view_type
|
|
|
|
}, self.flags)
|
|
|
|
});
|
2011-04-05 10:10:08 +00:00
|
|
|
});
|
2011-05-17 09:26:27 +00:00
|
|
|
if (this.flags.views_switcher === false) {
|
|
|
|
this.$element.find('.oe_vm_switch').hide();
|
|
|
|
}
|
2011-04-06 00:51:36 +00:00
|
|
|
// switch to the first one in sequence
|
2011-06-16 14:25:30 +00:00
|
|
|
return this.on_mode_switch(this.views_src[0].view_type);
|
2011-08-12 07:12:48 +00:00
|
|
|
|
2011-04-06 00:51:36 +00:00
|
|
|
},
|
|
|
|
stop: function() {
|
2011-04-05 10:10:08 +00:00
|
|
|
},
|
2011-04-01 11:50:05 +00:00
|
|
|
/**
|
|
|
|
* Asks the view manager to switch visualization mode.
|
|
|
|
*
|
|
|
|
* @param {String} view_type type of view to display
|
|
|
|
* @returns {jQuery.Deferred} new view loading promise
|
|
|
|
*/
|
2011-03-30 14:00:48 +00:00
|
|
|
on_mode_switch: function(view_type) {
|
2011-06-22 13:43:20 +00:00
|
|
|
var self = this,
|
|
|
|
view_promise;
|
2011-03-31 12:25:22 +00:00
|
|
|
this.active_view = view_type;
|
2011-03-31 13:20:58 +00:00
|
|
|
var view = this.views[view_type];
|
2011-08-12 07:12:48 +00:00
|
|
|
this.shortcut_check(view.view_id,view_type);
|
2011-03-31 13:20:58 +00:00
|
|
|
if (!view.controller) {
|
|
|
|
// Lazy loading of views
|
2011-06-16 16:37:09 +00:00
|
|
|
var controllerclass = this.registry.get_object(view_type);
|
2011-07-26 21:00:05 +00:00
|
|
|
var controller = new controllerclass(this, this.element_id + '_view_' + view_type,
|
2011-06-16 14:25:30 +00:00
|
|
|
this.dataset, view.view_id, view.options);
|
2011-06-06 07:04:51 +00:00
|
|
|
if (view.embedded_view) {
|
|
|
|
controller.set_embedded_view(view.embedded_view);
|
|
|
|
}
|
2011-08-12 12:35:59 +00:00
|
|
|
if (view_type === 'list' && this.flags.search_view === false && this.action && this.action['auto_search']) {
|
2011-06-28 14:21:24 +00:00
|
|
|
// In case the search view is not instantiated: manually call ListView#search
|
2011-06-28 07:57:55 +00:00
|
|
|
var domains = !_(self.action.domain).isEmpty()
|
|
|
|
? [self.action.domain] : [],
|
|
|
|
contexts = !_(self.action.context).isEmpty()
|
|
|
|
? [self.action.context] : [];
|
2011-06-22 13:43:20 +00:00
|
|
|
controller.on_loaded.add({
|
|
|
|
callback: function () {
|
2011-06-28 07:57:55 +00:00
|
|
|
controller.do_search(domains, contexts, []);
|
2011-06-22 13:43:20 +00:00
|
|
|
},
|
|
|
|
position: 'last',
|
|
|
|
unique: true
|
|
|
|
});
|
|
|
|
}
|
2011-04-01 11:50:05 +00:00
|
|
|
view_promise = controller.start();
|
2011-05-31 15:28:07 +00:00
|
|
|
$.when(view_promise).then(function() {
|
2011-06-01 08:23:58 +00:00
|
|
|
self.on_controller_inited(view_type, controller);
|
2011-05-31 15:28:07 +00:00
|
|
|
});
|
2011-03-31 13:20:58 +00:00
|
|
|
this.views[view_type].controller = controller;
|
|
|
|
}
|
2011-04-01 09:06:53 +00:00
|
|
|
|
2011-06-22 13:43:20 +00:00
|
|
|
|
2011-05-17 09:26:27 +00:00
|
|
|
if (this.searchview) {
|
2011-04-05 10:24:40 +00:00
|
|
|
if (view.controller.searchable === false) {
|
|
|
|
this.searchview.hide();
|
|
|
|
} else {
|
|
|
|
this.searchview.show();
|
|
|
|
}
|
2011-04-01 10:45:00 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 09:06:53 +00:00
|
|
|
this.$element
|
2011-04-01 09:11:17 +00:00
|
|
|
.find('.views-switchers button').removeAttr('disabled')
|
|
|
|
.filter('[data-view-type="' + view_type + '"]')
|
2011-04-04 11:25:35 +00:00
|
|
|
.attr('disabled', true);
|
2011-04-01 09:06:53 +00:00
|
|
|
|
2011-06-28 06:09:34 +00:00
|
|
|
for (var view_name in this.views) {
|
|
|
|
if (!this.views.hasOwnProperty(view_name)) { continue; }
|
|
|
|
if (this.views[view_name].controller) {
|
|
|
|
if (view_name === view_type) {
|
|
|
|
$.when(view_promise).then(this.views[view_name].controller.do_show);
|
2011-04-04 15:34:26 +00:00
|
|
|
} else {
|
2011-06-28 06:09:34 +00:00
|
|
|
this.views[view_name].controller.do_hide();
|
2011-04-04 15:34:26 +00:00
|
|
|
}
|
2011-03-31 13:20:58 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
}
|
2011-04-01 11:50:05 +00:00
|
|
|
return view_promise;
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-05-31 15:28:07 +00:00
|
|
|
/**
|
|
|
|
* Event launched when a controller has been inited.
|
2011-07-07 10:01:04 +00:00
|
|
|
*
|
2011-05-31 15:28:07 +00:00
|
|
|
* @param {String} view_type type of view
|
2011-06-01 08:23:58 +00:00
|
|
|
* @param {String} view the inited controller
|
2011-05-31 15:28:07 +00:00
|
|
|
*/
|
2011-06-01 08:23:58 +00:00
|
|
|
on_controller_inited: function(view_type, view) {},
|
2011-04-06 21:10:37 +00:00
|
|
|
/**
|
|
|
|
* Sets up the current viewmanager's search view.
|
|
|
|
*
|
|
|
|
* @param view_id the view to use or false for a default one
|
|
|
|
* @returns {jQuery.Deferred} search view startup deferred
|
|
|
|
*/
|
|
|
|
setup_search_view: function(view_id, search_defaults) {
|
|
|
|
var self = this;
|
|
|
|
if (this.searchview) {
|
|
|
|
this.searchview.stop();
|
|
|
|
}
|
2011-07-18 12:54:22 +00:00
|
|
|
this.searchview = new openerp.base.SearchView(this, this.element_id + "_search", this.dataset, view_id, search_defaults);
|
2011-05-17 09:26:27 +00:00
|
|
|
if (this.flags.search_view === false) {
|
|
|
|
this.searchview.hide();
|
|
|
|
}
|
2011-04-12 07:23:56 +00:00
|
|
|
this.searchview.on_search.add(function(domains, contexts, groupbys) {
|
|
|
|
self.views[self.active_view].controller.do_search.call(
|
2011-04-12 07:27:50 +00:00
|
|
|
self, domains.concat(self.domains()),
|
|
|
|
contexts.concat(self.contexts()), groupbys);
|
2011-04-06 21:10:37 +00:00
|
|
|
});
|
|
|
|
return this.searchview.start();
|
|
|
|
},
|
2011-03-30 14:00:48 +00:00
|
|
|
/**
|
2011-04-06 00:51:36 +00:00
|
|
|
* Called when one of the view want to execute an action
|
2011-03-30 14:00:48 +00:00
|
|
|
*/
|
2011-04-06 00:51:36 +00:00
|
|
|
on_action: function(action) {
|
|
|
|
},
|
|
|
|
on_create: function() {
|
|
|
|
},
|
|
|
|
on_remove: function() {
|
|
|
|
},
|
|
|
|
on_edit: function() {
|
2011-04-12 07:23:56 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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 [];
|
2011-04-12 07:27:50 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Contexts added on searches by the view manager.
|
|
|
|
*
|
|
|
|
* @returns an empty list
|
|
|
|
*/
|
|
|
|
contexts: function () {
|
|
|
|
return [];
|
2011-08-12 07:12:48 +00:00
|
|
|
},
|
2011-08-12 12:35:59 +00:00
|
|
|
shortcut_check : function(view_id,view_type){
|
|
|
|
main_view = this.session.action_manager.viewmanager.views_src[0];
|
|
|
|
if (view_type == "tree" || main_view.view_id == view_id && main_view.view_type == view_type &&
|
|
|
|
this.element_id == "oe_app"){
|
|
|
|
$('#shortcut_add_remove').show();
|
2011-08-12 07:12:48 +00:00
|
|
|
var img = "shortcut-add";
|
2011-08-12 12:35:59 +00:00
|
|
|
for(var list_shortcut=0; list_shortcut<this.session.sc_list.length; list_shortcut++){
|
2011-08-12 07:12:48 +00:00
|
|
|
if (this.session.sc_list[list_shortcut]['res_id'] == this.session.active_id)
|
2011-08-12 12:35:59 +00:00
|
|
|
{img = "shortcut-remove"}
|
|
|
|
}
|
2011-08-12 07:12:48 +00:00
|
|
|
$('#shortcut_add_remove').addClass(img);
|
2011-08-12 12:35:59 +00:00
|
|
|
}
|
|
|
|
else{
|
|
|
|
$('#shortcut_add_remove').hide();
|
2011-08-12 07:12:48 +00:00
|
|
|
}
|
|
|
|
this.shortcut_add_remove();
|
2011-08-12 12:35:59 +00:00
|
|
|
},
|
|
|
|
shortcut_add_remove: function(){
|
2011-08-12 07:12:48 +00:00
|
|
|
var self = this;
|
|
|
|
var shortcut_selector =$('#shortcut_add_remove');
|
|
|
|
var dataset_shortcut = new openerp.base.DataSet(this, 'ir.ui.view_sc');
|
|
|
|
shortcut_selector.click(function(ev,id){
|
2011-08-12 12:35:59 +00:00
|
|
|
if(shortcut_selector.hasClass("shortcut-remove")){
|
|
|
|
var unlink_id = $("li[id="+self.session.active_id+"]").attr('shortcut-id');
|
|
|
|
dataset_shortcut.unlink([parseInt(unlink_id)]);
|
|
|
|
shortcut_selector.removeClass("shortcut-remove");
|
|
|
|
shortcut_selector.addClass("shortcut-add"); }
|
|
|
|
else {
|
|
|
|
var data = {'user_id': self.uid, 'res_id': self.session.active_id, 'resource': 'ir.ui.menu', 'name': self.action.name};
|
|
|
|
dataset_shortcut.create(data);
|
|
|
|
shortcut_selector.removeClass("shortcut-add");
|
|
|
|
shortcut_selector.addClass("shortcut-remove"); }
|
2011-08-12 07:12:48 +00:00
|
|
|
});
|
2011-08-12 12:35:59 +00:00
|
|
|
|
|
|
|
|
2011-04-06 00:51:36 +00:00
|
|
|
}
|
2011-08-12 12:35:59 +00:00
|
|
|
|
2011-04-06 00:51:36 +00:00
|
|
|
});
|
|
|
|
|
2011-05-24 11:30:13 +00:00
|
|
|
openerp.base.NullViewManager = openerp.base.generate_null_object_class(openerp.base.ViewManager, {
|
2011-07-20 10:39:41 +00:00
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
|
|
|
if(parent)
|
|
|
|
this.session = parent.session;
|
2011-05-24 11:30:13 +00:00
|
|
|
this.action = {flags: {}};
|
2011-05-24 09:37:37 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-22 12:15:42 +00:00
|
|
|
// TODO Will move to action Manager
|
2011-04-06 00:51:36 +00:00
|
|
|
openerp.base.ViewManagerAction = openerp.base.ViewManager.extend({
|
2011-07-18 12:54:22 +00:00
|
|
|
init: function(parent, element_id, action) {
|
|
|
|
this.session = parent.session;
|
2011-04-26 14:13:34 +00:00
|
|
|
var dataset;
|
2011-06-28 10:01:10 +00:00
|
|
|
if (!action.res_id) {
|
2011-07-18 12:54:22 +00:00
|
|
|
dataset = new openerp.base.DataSetSearch(this, action.res_model, action.context || null);
|
2011-04-26 14:13:34 +00:00
|
|
|
} else {
|
2011-07-18 12:54:22 +00:00
|
|
|
dataset = new openerp.base.DataSetStatic(this, action.res_model, {}, [action.res_id]);
|
2011-06-28 10:01:10 +00:00
|
|
|
if (action.context) {
|
|
|
|
// TODO fme: should normalize all DataSets constructors to (session, model, context, ...)
|
|
|
|
dataset.context = action.context;
|
|
|
|
}
|
2011-04-26 14:13:34 +00:00
|
|
|
}
|
2011-07-18 12:54:22 +00:00
|
|
|
this._super(parent, element_id, dataset, action.views);
|
2011-04-06 00:51:36 +00:00
|
|
|
this.action = action;
|
2011-05-17 09:26:27 +00:00
|
|
|
this.flags = this.action.flags || {};
|
2011-05-18 12:52:51 +00:00
|
|
|
if (action.res_model == 'board.board' && action.views.length == 1 && action.views) {
|
|
|
|
// Not elegant but allows to avoid flickering of SearchView#do_hide
|
2011-05-24 09:50:24 +00:00
|
|
|
this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false;
|
2011-05-18 12:52:51 +00:00
|
|
|
}
|
2011-04-06 00:51:36 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var inital_view_loaded = this._super();
|
2011-04-06 21:10:37 +00:00
|
|
|
var search_defaults = {};
|
|
|
|
_.each(this.action.context, function (value, key) {
|
|
|
|
var match = /^search_default_(.*)$/.exec(key);
|
|
|
|
if (match) {
|
|
|
|
search_defaults[match[1]] = value;
|
|
|
|
}
|
|
|
|
});
|
2011-04-12 07:50:37 +00:00
|
|
|
|
2011-06-22 13:43:20 +00:00
|
|
|
if (this.flags.search_view !== false) {
|
|
|
|
// init search view
|
|
|
|
var searchview_id = this.action.search_view_id && this.action.search_view_id[0];
|
2011-04-12 07:50:37 +00:00
|
|
|
|
2011-06-22 13:43:20 +00:00
|
|
|
var searchview_loaded = this.setup_search_view(
|
|
|
|
searchview_id || false, search_defaults);
|
2011-08-12 12:35:59 +00:00
|
|
|
|
2011-06-22 13:43:20 +00:00
|
|
|
// schedule auto_search
|
|
|
|
if (searchview_loaded != null && this.action['auto_search']) {
|
|
|
|
$.when(searchview_loaded, inital_view_loaded)
|
|
|
|
.then(this.searchview.do_search);
|
|
|
|
}
|
2011-04-06 00:51:36 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
stop: function() {
|
2011-07-28 14:49:12 +00:00
|
|
|
// should be replaced by automatic destruction implemented in Widget
|
2011-04-06 00:51:36 +00:00
|
|
|
this._super();
|
2011-04-12 07:23:56 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* adds action domain to the search domains
|
|
|
|
*
|
|
|
|
* @returns the action's domain
|
|
|
|
*/
|
|
|
|
domains: function () {
|
2011-04-12 07:45:29 +00:00
|
|
|
if (!this.action.domain) {
|
|
|
|
return [];
|
|
|
|
}
|
2011-04-12 07:23:56 +00:00
|
|
|
return [this.action.domain];
|
2011-04-12 07:27:50 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* adds action context to the search contexts
|
|
|
|
*
|
|
|
|
* @returns the action's context
|
|
|
|
*/
|
|
|
|
contexts: function () {
|
2011-04-12 07:45:29 +00:00
|
|
|
if (!this.action.context) {
|
|
|
|
return [];
|
|
|
|
}
|
2011-04-12 07:27:50 +00:00
|
|
|
return [this.action.context];
|
2011-08-12 12:35:59 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
|
|
|
|
2011-07-28 14:49:12 +00:00
|
|
|
openerp.base.Sidebar = openerp.base.Widget.extend({
|
2011-07-26 21:00:05 +00:00
|
|
|
init: function(parent, element_id) {
|
|
|
|
this._super(parent, element_id);
|
|
|
|
this.items = {};
|
2011-07-28 15:15:45 +00:00
|
|
|
this.sections = {};
|
2011-04-04 16:08:13 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
start: function() {
|
2011-04-04 13:47:05 +00:00
|
|
|
var self = this;
|
2011-07-26 21:00:05 +00:00
|
|
|
this._super(this, arguments);
|
|
|
|
this.$element.html(QWeb.render('Sidebar'));
|
2011-04-12 11:14:56 +00:00
|
|
|
this.$element.find(".toggle-sidebar").click(function(e) {
|
2011-07-26 21:00:05 +00:00
|
|
|
self.do_toggle();
|
2011-04-12 11:14:56 +00:00
|
|
|
});
|
2011-04-04 16:08:13 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
add_toolbar: function(toolbar) {
|
2011-04-04 13:47:05 +00:00
|
|
|
var self = this;
|
2011-07-26 21:00:05 +00:00
|
|
|
_.each([['print', "Reports"], ['action', "Actions"], ['relate', "Links"]], function(type) {
|
|
|
|
var items = toolbar[type[0]];
|
|
|
|
if (items.length) {
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
items[i] = {
|
|
|
|
label: items[i]['name'],
|
|
|
|
action: items[i],
|
|
|
|
classname: 'oe_sidebar_' + type[0]
|
|
|
|
}
|
|
|
|
}
|
2011-07-28 15:15:45 +00:00
|
|
|
self.add_section(type[0], type[1], items);
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
2011-04-04 13:47:05 +00:00
|
|
|
});
|
|
|
|
},
|
2011-07-28 15:15:45 +00:00
|
|
|
add_section: function(code, name, items) {
|
2011-07-26 21:00:05 +00:00
|
|
|
// For each section, we pass a name/label and optionally an array of items.
|
|
|
|
// If no items are passed, then the section will be created as a custom section
|
|
|
|
// returning back an element_id to be used by a custom controller.
|
|
|
|
// Else, the section is a standard section with items displayed as links.
|
|
|
|
// An item is a dictonary : {
|
|
|
|
// label: label to be displayed for the link,
|
|
|
|
// action: action to be launch when the link is clicked,
|
|
|
|
// callback: a function to be executed when the link is clicked,
|
2011-07-28 15:15:45 +00:00
|
|
|
// classname: optional dom class name for the line,
|
|
|
|
// title: optional title for the link
|
2011-07-26 21:00:05 +00:00
|
|
|
// }
|
|
|
|
// Note: The item should have one action or/and a callback
|
|
|
|
var self = this,
|
2011-07-28 15:15:45 +00:00
|
|
|
section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
|
2011-07-26 21:00:05 +00:00
|
|
|
if (items) {
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
items[i].element_id = _.uniqueId(section_id + '_item_');
|
|
|
|
this.items[items[i].element_id] = items[i];
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var $section = $(QWeb.render("Sidebar.section", {
|
|
|
|
section_id: section_id,
|
|
|
|
name: name,
|
2011-07-28 15:15:45 +00:00
|
|
|
classname: 'oe_sidebar_' + code,
|
2011-07-26 21:00:05 +00:00
|
|
|
items: items
|
|
|
|
}));
|
|
|
|
if (items) {
|
|
|
|
$section.find('a.oe_sidebar_action_a').click(function() {
|
|
|
|
var item = self.items[$(this).attr('id')];
|
|
|
|
if (item.callback) {
|
|
|
|
item.callback();
|
|
|
|
}
|
|
|
|
if (item.action) {
|
|
|
|
item.action.flags = item.action.flags || {};
|
|
|
|
item.action.flags.new_window = true;
|
|
|
|
self.do_action(item.action);
|
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
|
|
|
}
|
|
|
|
$section.appendTo(this.$element.find('div.sidebar-actions'));
|
2011-07-28 15:15:45 +00:00
|
|
|
this.sections[code] = $section;
|
2011-07-26 21:00:05 +00:00
|
|
|
return section_id;
|
2011-06-20 14:47:46 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
do_fold: function() {
|
|
|
|
this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
|
2011-06-20 14:47:46 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
do_unfold: function() {
|
|
|
|
this.$element.addClass('open-sidebar').removeClass('closed-sidebar');
|
2011-06-20 14:47:46 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
do_toggle: function() {
|
|
|
|
this.$element.toggleClass('open-sidebar closed-sidebar');
|
2011-06-20 14:47:46 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-07-28 14:49:12 +00:00
|
|
|
openerp.base.View = openerp.base.Widget.extend({
|
2011-07-26 21:00:05 +00:00
|
|
|
set_default_options: function(options) {
|
|
|
|
this.options = options || {};
|
|
|
|
_.defaults(this.options, {
|
|
|
|
// All possible views options should be defaulted here
|
|
|
|
sidebar_id: null,
|
|
|
|
sidebar: true
|
|
|
|
});
|
|
|
|
},
|
2011-05-11 14:49:10 +00:00
|
|
|
/**
|
|
|
|
* Fetches and executes the action identified by ``action_data``.
|
|
|
|
*
|
|
|
|
* @param {Object} action_data the action descriptor data
|
|
|
|
* @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
|
|
|
|
* @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
|
|
|
|
* @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
|
2011-05-27 07:44:42 +00:00
|
|
|
* @param {Object} [record_id] the identifier of the object on which the action is to be applied
|
2011-07-13 14:25:02 +00:00
|
|
|
* @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
|
2011-05-11 14:49:10 +00:00
|
|
|
*/
|
2011-07-13 14:25:02 +00:00
|
|
|
execute_action: function (action_data, dataset, action_manager, record_id, on_closed) {
|
2011-06-28 12:43:55 +00:00
|
|
|
var self = this;
|
2011-07-13 14:25:02 +00:00
|
|
|
if (action_manager.current_dialog) {
|
|
|
|
on_closed = action_manager.current_dialog.close_callback;
|
|
|
|
}
|
2011-05-11 14:49:10 +00:00
|
|
|
var handler = function (r) {
|
2011-07-13 14:25:02 +00:00
|
|
|
action_manager.close_dialog();
|
2011-06-21 14:38:04 +00:00
|
|
|
var action = r.result;
|
|
|
|
if (action && action.constructor == Object) {
|
|
|
|
action.context = action.context || {};
|
2011-06-28 06:09:34 +00:00
|
|
|
_.extend(action.context, {
|
2011-06-28 16:35:07 +00:00
|
|
|
active_id: record_id || false,
|
|
|
|
active_ids: [record_id || false],
|
2011-06-28 06:09:34 +00:00
|
|
|
active_model: dataset.model
|
2011-06-28 10:01:10 +00:00
|
|
|
});
|
2011-06-21 14:38:04 +00:00
|
|
|
action.flags = {
|
2011-07-07 14:16:41 +00:00
|
|
|
new_window: true
|
2011-06-21 12:11:16 +00:00
|
|
|
};
|
2011-06-28 10:30:49 +00:00
|
|
|
action_manager.do_action(action, on_closed);
|
2011-07-13 14:25:02 +00:00
|
|
|
} else if (on_closed) {
|
|
|
|
on_closed(action);
|
2011-05-11 14:49:10 +00:00
|
|
|
}
|
|
|
|
};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-07-13 14:25:02 +00:00
|
|
|
if (!action_data.special) {
|
2011-07-01 11:59:12 +00:00
|
|
|
var context = new openerp.base.CompoundContext(dataset.get_context(), action_data.context || {});
|
2011-05-11 14:49:10 +00:00
|
|
|
switch(action_data.type) {
|
|
|
|
case 'object':
|
2011-06-28 16:35:07 +00:00
|
|
|
return dataset.call_button(action_data.name, [[record_id], context], handler);
|
2011-05-11 14:49:10 +00:00
|
|
|
case 'action':
|
2011-06-21 14:38:04 +00:00
|
|
|
return this.rpc('/base/action/load', { action_id: parseInt(action_data.name, 10), context: context }, handler);
|
2011-05-11 14:49:10 +00:00
|
|
|
default:
|
|
|
|
return dataset.exec_workflow(record_id, action_data.name, handler);
|
|
|
|
}
|
2011-07-13 14:25:02 +00:00
|
|
|
} else {
|
|
|
|
action_manager.close_dialog();
|
2011-05-11 14:49:10 +00:00
|
|
|
}
|
2011-06-06 07:52:43 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* 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.
|
2011-07-07 10:01:04 +00:00
|
|
|
*
|
2011-06-06 07:52:43 +00:00
|
|
|
* @param embedded_view A view.
|
|
|
|
*/
|
|
|
|
set_embedded_view: function(embedded_view) {
|
|
|
|
this.embedded_view = embedded_view;
|
2011-07-28 15:15:45 +00:00
|
|
|
},
|
|
|
|
set_common_sidebar_sections: function(sidebar) {
|
|
|
|
sidebar.add_section('customize', "Customize", [
|
|
|
|
{
|
|
|
|
label: "Manage Views",
|
|
|
|
callback: this.on_sidebar_manage_view,
|
|
|
|
title: "Manage views of the current object"
|
|
|
|
}, {
|
|
|
|
label: "Edit Workflow",
|
|
|
|
callback: this.on_sidebar_edit_workflow,
|
|
|
|
title: "Manage views of the current object",
|
|
|
|
classname: 'oe_hide oe_sidebar_edit_workflow'
|
|
|
|
}, {
|
|
|
|
label: "Customize Object",
|
|
|
|
callback: this.on_sidebar_customize_object,
|
|
|
|
title: "Manage views of the current object"
|
|
|
|
}
|
|
|
|
]);
|
2011-07-28 16:18:53 +00:00
|
|
|
sidebar.add_section('other', "Other Options", [
|
|
|
|
{
|
|
|
|
label: "Import",
|
|
|
|
callback: this.on_sidebar_import
|
|
|
|
}, {
|
|
|
|
label: "Export",
|
|
|
|
callback: this.on_sidebar_export
|
|
|
|
}, {
|
|
|
|
label: "Translate",
|
|
|
|
callback: this.on_sidebar_translate,
|
|
|
|
classname: 'oe_hide oe_sidebar_translate'
|
|
|
|
}, {
|
|
|
|
label: "View Log",
|
|
|
|
callback: this.on_sidebar_view_log,
|
|
|
|
classname: 'oe_hide oe_sidebar_view_log'
|
|
|
|
}
|
|
|
|
]);
|
2011-07-28 15:15:45 +00:00
|
|
|
},
|
|
|
|
on_sidebar_manage_view: function() {
|
2011-08-03 08:42:50 +00:00
|
|
|
if (this.fields_view && this.fields_view.arch) {
|
|
|
|
$('<xmp>' + openerp.base.json_node_to_xml(this.fields_view.arch, true) + '</xmp>').dialog({ width: '95%', height: 600});
|
|
|
|
} else {
|
|
|
|
this.notification.warn("Manage Views", "Could not find current view declaration");
|
|
|
|
}
|
2011-07-28 15:15:45 +00:00
|
|
|
},
|
|
|
|
on_sidebar_edit_workflow: function() {
|
|
|
|
console.log('Todo');
|
|
|
|
},
|
|
|
|
on_sidebar_customize_object: function() {
|
|
|
|
console.log('Todo');
|
2011-07-28 16:18:53 +00:00
|
|
|
},
|
|
|
|
on_sidebar_import: function() {
|
|
|
|
},
|
|
|
|
on_sidebar_export: function() {
|
|
|
|
var export_view = new openerp.base.DataExport(this, this.dataset);
|
|
|
|
export_view.start(false);
|
|
|
|
},
|
|
|
|
on_sidebar_translate: function() {
|
|
|
|
},
|
|
|
|
on_sidebar_view_log: function() {
|
2011-04-01 09:40:30 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
|
|
|
|
2011-03-31 15:25:31 +00:00
|
|
|
/**
|
2011-05-11 14:49:10 +00:00
|
|
|
* Registry for all the main views
|
2011-03-31 15:25:31 +00:00
|
|
|
*/
|
2011-05-11 14:49:10 +00:00
|
|
|
openerp.base.views = new openerp.base.Registry();
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-06-22 11:11:29 +00:00
|
|
|
openerp.base.json_node_to_xml = function(node, single_quote, indent) {
|
|
|
|
// For debugging purpose, this function will convert a json node back to xml
|
|
|
|
// Maybe usefull for xml view editor
|
|
|
|
if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
|
|
|
|
throw("Node a json node");
|
|
|
|
}
|
|
|
|
indent = indent || 0;
|
2011-06-28 06:09:34 +00:00
|
|
|
var sindent = new Array(indent + 1).join('\t'),
|
2011-06-22 11:11:29 +00:00
|
|
|
r = sindent + '<' + node.tag;
|
|
|
|
for (var attr in node.attrs) {
|
|
|
|
var vattr = node.attrs[attr];
|
|
|
|
if (typeof(vattr) !== 'string') {
|
|
|
|
// domains, ...
|
|
|
|
vattr = JSON.stringify(vattr);
|
|
|
|
}
|
|
|
|
vattr = vattr.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
|
|
|
|
if (single_quote) {
|
|
|
|
vattr = vattr.replace(/"/g, "'");
|
|
|
|
}
|
|
|
|
r += ' ' + attr + '="' + vattr + '"';
|
|
|
|
}
|
|
|
|
if (node.children.length) {
|
|
|
|
r += '>\n';
|
|
|
|
var childs = [];
|
|
|
|
for (var i = 0, ii = node.children.length; i < ii; i++) {
|
|
|
|
childs.push(openerp.base.json_node_to_xml(node.children[i], single_quote, indent + 1));
|
|
|
|
}
|
|
|
|
r += childs.join('\n');
|
|
|
|
r += '\n' + sindent + '</' + node.tag + '>';
|
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
return r + '/>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:00:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|