2011-03-30 14:00:48 +00:00
|
|
|
/*---------------------------------------------------------
|
2011-09-05 11:03:09 +00:00
|
|
|
* OpenERP web library
|
2011-03-30 14:00:48 +00:00
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
openerp.web.views = function(session) {
|
2011-12-13 11:35:21 +00:00
|
|
|
var QWeb = session.web.qweb,
|
|
|
|
_t = session.web._t;
|
2011-08-24 15:13:57 +00:00
|
|
|
|
2011-08-10 00:38:57 +00:00
|
|
|
/**
|
|
|
|
* Registry for all the client actions key: tag value: widget
|
|
|
|
*/
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.client_actions = new session.web.Registry();
|
2011-08-10 00:38:57 +00:00
|
|
|
|
2011-09-14 21:54:03 +00:00
|
|
|
/**
|
|
|
|
* Registry for all the main views
|
|
|
|
*/
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.views = new session.web.Registry();
|
2011-09-14 21:54:03 +00:00
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.ActionManager = session.web.Widget.extend({
|
2011-08-10 00:38:57 +00:00
|
|
|
identifier_prefix: "actionmanager",
|
|
|
|
init: function(parent) {
|
|
|
|
this._super(parent);
|
2011-12-14 18:04:42 +00:00
|
|
|
this.inner_action = null;
|
2011-08-10 00:38:57 +00:00
|
|
|
this.inner_viewmanager = null;
|
|
|
|
this.dialog = null;
|
|
|
|
this.dialog_viewmanager = null;
|
|
|
|
this.client_widget = null;
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-08-10 00:38:57 +00:00
|
|
|
render: function() {
|
2011-12-22 10:27:41 +00:00
|
|
|
return '<div id="' + this.element_id + '" style="height: 100%;"></div>';
|
2011-08-10 00:38:57 +00:00
|
|
|
},
|
2011-08-10 01:34:48 +00:00
|
|
|
dialog_stop: function () {
|
2011-08-10 00:38:57 +00:00
|
|
|
if (this.dialog) {
|
|
|
|
this.dialog_viewmanager.stop();
|
2011-08-10 01:34:48 +00:00
|
|
|
this.dialog_viewmanager = null;
|
2011-08-10 00:38:57 +00:00
|
|
|
this.dialog.stop();
|
|
|
|
this.dialog = null;
|
|
|
|
}
|
|
|
|
},
|
2011-08-19 14:39:47 +00:00
|
|
|
content_stop: function () {
|
2011-08-10 01:34:48 +00:00
|
|
|
if (this.inner_viewmanager) {
|
|
|
|
this.inner_viewmanager.stop();
|
|
|
|
this.inner_viewmanager = null;
|
|
|
|
}
|
2011-08-19 14:39:47 +00:00
|
|
|
if (this.client_widget) {
|
|
|
|
this.client_widget.stop();
|
|
|
|
this.client_widget = null;
|
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-12-14 16:09:58 +00:00
|
|
|
do_push_state: function(state) {
|
2011-12-14 18:04:42 +00:00
|
|
|
if (this.widget_parent && this.widget_parent.do_push_state) {
|
2011-12-21 14:18:26 +00:00
|
|
|
if (this.inner_action) {
|
|
|
|
if (this.inner_action.id) {
|
|
|
|
state['action_id'] = this.inner_action.id;
|
|
|
|
} else {
|
|
|
|
state['model'] = this.inner_action.res_model;
|
|
|
|
}
|
2011-12-14 16:09:58 +00:00
|
|
|
}
|
|
|
|
this.widget_parent.do_push_state(state);
|
|
|
|
}
|
2011-12-12 14:20:12 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
do_load_state: function(state) {
|
2011-12-15 14:29:39 +00:00
|
|
|
var self = this,
|
|
|
|
action_loaded;
|
2011-12-12 16:44:55 +00:00
|
|
|
if (state.action_id) {
|
2011-12-15 14:29:39 +00:00
|
|
|
var run_action = (!this.inner_viewmanager) || this.inner_viewmanager.action.id !== state.action_id;
|
|
|
|
if (run_action) {
|
|
|
|
this.null_action();
|
|
|
|
action_loaded = this.do_action(state.action_id);
|
|
|
|
}
|
2011-12-13 10:41:00 +00:00
|
|
|
}
|
|
|
|
else if (state.model && state.id) {
|
2011-12-21 14:18:26 +00:00
|
|
|
// TODO handle context & domain ?
|
|
|
|
this.null_action();
|
2011-12-22 15:34:49 +00:00
|
|
|
var action = {
|
2011-12-21 14:18:26 +00:00
|
|
|
res_model: state.model,
|
|
|
|
res_id: state.id,
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
views: [[false, 'page'], [false, 'form']]
|
|
|
|
};
|
|
|
|
action_loaded = this.do_action(action);
|
2011-12-12 16:44:55 +00:00
|
|
|
}
|
|
|
|
else if (state.client_action) {
|
2011-12-13 10:41:00 +00:00
|
|
|
this.null_action();
|
|
|
|
this.ir_actions_client(state.client_action);
|
2011-12-09 16:31:14 +00:00
|
|
|
}
|
|
|
|
|
2011-12-15 14:29:39 +00:00
|
|
|
$.when(action_loaded || null).then(function() {
|
|
|
|
if (self.inner_viewmanager) {
|
|
|
|
self.inner_viewmanager.do_load_state(state);
|
|
|
|
}
|
|
|
|
});
|
2011-08-18 22:57:21 +00:00
|
|
|
},
|
2011-08-10 23:02:13 +00:00
|
|
|
do_action: function(action, on_close) {
|
2011-12-09 16:31:14 +00:00
|
|
|
if (_.isNumber(action)) {
|
|
|
|
var self = this;
|
2011-12-15 14:29:39 +00:00
|
|
|
return self.rpc("/web/action/load", { action_id: action }, function(result) {
|
2011-12-09 16:31:14 +00:00
|
|
|
self.do_action(result.result, on_close);
|
|
|
|
});
|
|
|
|
}
|
2011-12-07 16:13:53 +00:00
|
|
|
if (!action.type) {
|
|
|
|
console.error("No type for action", action);
|
|
|
|
return;
|
|
|
|
}
|
2011-08-10 00:38:57 +00:00
|
|
|
var type = action.type.replace(/\./g,'_');
|
|
|
|
var popup = action.target === 'new';
|
2011-05-11 13:36:55 +00:00
|
|
|
action.flags = _.extend({
|
2011-08-10 00:38:57 +00:00
|
|
|
views_switcher : !popup,
|
|
|
|
search_view : !popup,
|
|
|
|
action_buttons : !popup,
|
|
|
|
sidebar : !popup,
|
2012-01-09 10:58:32 +00:00
|
|
|
pager : !popup,
|
|
|
|
display_title : !popup
|
2011-05-11 13:36:55 +00:00
|
|
|
}, action.flags || {});
|
2011-08-09 22:31:15 +00:00
|
|
|
if (!(type in this)) {
|
2011-12-07 16:13:53 +00:00
|
|
|
console.error("Action manager can't handle action of type " + action.type, action);
|
2011-06-30 13:01:33 +00:00
|
|
|
return;
|
|
|
|
}
|
2011-09-30 16:15:06 +00:00
|
|
|
return this[type](action, on_close);
|
2011-06-30 13:01:33 +00:00
|
|
|
},
|
2011-12-07 10:50:08 +00:00
|
|
|
null_action: function() {
|
|
|
|
this.dialog_stop();
|
|
|
|
this.content_stop();
|
|
|
|
},
|
2011-08-10 23:02:13 +00:00
|
|
|
ir_actions_act_window: function (action, on_close) {
|
2011-12-13 14:26:08 +00:00
|
|
|
var self = this;
|
2011-11-28 14:47:26 +00:00
|
|
|
if (_(['base.module.upgrade', 'base.setup.installer'])
|
|
|
|
.contains(action.res_model)) {
|
|
|
|
var old_close = on_close;
|
|
|
|
on_close = function () {
|
|
|
|
session.webclient.do_reload();
|
|
|
|
if (old_close) { old_close(); }
|
|
|
|
};
|
|
|
|
}
|
2011-08-11 14:59:04 +00:00
|
|
|
if (action.target === 'new') {
|
2011-08-10 00:38:57 +00:00
|
|
|
if (this.dialog == null) {
|
2012-01-10 10:02:49 +00:00
|
|
|
this.dialog = new session.web.Dialog(this, { width: '80%' });
|
2011-08-10 23:02:13 +00:00
|
|
|
if(on_close)
|
|
|
|
this.dialog.on_close.add(on_close);
|
2011-08-10 12:05:48 +00:00
|
|
|
this.dialog.start();
|
2011-08-10 00:38:57 +00:00
|
|
|
} else {
|
|
|
|
this.dialog_viewmanager.stop();
|
2011-07-14 10:22:43 +00:00
|
|
|
}
|
2012-01-10 10:02:49 +00:00
|
|
|
this.dialog.dialog_title = action.name;
|
2011-10-24 22:54:31 +00:00
|
|
|
this.dialog_viewmanager = new session.web.ViewManagerAction(this, action);
|
2011-08-10 23:02:13 +00:00
|
|
|
this.dialog_viewmanager.appendTo(this.dialog.$element);
|
|
|
|
this.dialog.open();
|
2011-08-10 00:38:57 +00:00
|
|
|
} else {
|
2011-12-21 11:49:04 +00:00
|
|
|
if(action.menu_id) {
|
2011-12-22 15:34:49 +00:00
|
|
|
return this.widget_parent.do_action(action, function () {
|
|
|
|
session.webclient.menu.open_menu(action.menu_id);
|
|
|
|
});
|
2011-12-21 11:49:04 +00:00
|
|
|
}
|
2011-08-10 01:34:48 +00:00
|
|
|
this.dialog_stop();
|
2011-08-19 14:39:47 +00:00
|
|
|
this.content_stop();
|
2011-12-13 14:26:08 +00:00
|
|
|
this.inner_action = action;
|
2011-10-24 22:54:31 +00:00
|
|
|
this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
|
2011-08-10 00:38:57 +00:00
|
|
|
this.inner_viewmanager.appendTo(this.$element);
|
|
|
|
}
|
2011-07-13 14:25:02 +00:00
|
|
|
},
|
2011-08-09 22:31:15 +00:00
|
|
|
ir_actions_act_window_close: function (action, on_closed) {
|
2011-10-05 10:17:14 +00:00
|
|
|
if (!this.dialog && on_closed) {
|
|
|
|
on_closed();
|
|
|
|
}
|
2011-08-11 01:52:32 +00:00
|
|
|
this.dialog_stop();
|
2011-06-30 13:01:33 +00:00
|
|
|
},
|
2011-08-09 22:31:15 +00:00
|
|
|
ir_actions_server: function (action, on_closed) {
|
2011-06-30 13:01:33 +00:00
|
|
|
var self = this;
|
2011-09-05 11:03:09 +00:00
|
|
|
this.rpc('/web/action/run', {
|
2011-06-30 13:01:33 +00:00
|
|
|
action_id: action.id,
|
2011-09-12 13:07:27 +00:00
|
|
|
context: action.context || {}
|
2011-06-30 13:01:33 +00:00
|
|
|
}).then(function (action) {
|
|
|
|
self.do_action(action, on_closed)
|
|
|
|
});
|
2011-07-01 11:57:26 +00:00
|
|
|
},
|
2011-08-09 22:31:15 +00:00
|
|
|
ir_actions_client: function (action) {
|
2011-08-19 14:39:47 +00:00
|
|
|
this.content_stop();
|
2011-12-14 17:03:56 +00:00
|
|
|
this.dialog_stop();
|
2011-10-24 22:54:31 +00:00
|
|
|
var ClientWidget = session.web.client_actions.get_object(action.tag);
|
2011-08-19 14:39:47 +00:00
|
|
|
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
|
2011-08-29 15:24:38 +00:00
|
|
|
},
|
2011-11-18 07:30:41 +00:00
|
|
|
ir_actions_report_xml: function(action, on_closed) {
|
2011-09-15 13:12:01 +00:00
|
|
|
var self = this;
|
2011-09-07 07:23:58 +00:00
|
|
|
$.blockUI();
|
2011-09-15 13:12:01 +00:00
|
|
|
self.rpc("/web/session/eval_domain_and_context", {
|
|
|
|
contexts: [action.context],
|
|
|
|
domains: []
|
|
|
|
}).then(function(res) {
|
|
|
|
action = _.clone(action);
|
|
|
|
action.context = res.context;
|
|
|
|
self.session.get_file({
|
|
|
|
url: '/web/report',
|
|
|
|
data: {action: JSON.stringify(action)},
|
2011-11-21 09:14:51 +00:00
|
|
|
complete: $.unblockUI,
|
|
|
|
success: function(){
|
|
|
|
if (!self.dialog && on_closed) {
|
|
|
|
on_closed();
|
|
|
|
}
|
|
|
|
self.dialog_stop();
|
|
|
|
}
|
|
|
|
})
|
2011-08-29 15:24:38 +00:00
|
|
|
});
|
2011-10-19 12:56:04 +00:00
|
|
|
},
|
|
|
|
ir_actions_act_url: function (action) {
|
|
|
|
window.open(action.url, action.target === 'self' ? '_self' : '_blank');
|
2011-12-12 10:39:05 +00:00
|
|
|
},
|
|
|
|
ir_ui_menu: function (action) {
|
|
|
|
this.widget_parent.do_action(action);
|
2011-07-19 10:27:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.ViewManager# */{
|
2011-08-10 01:34:48 +00:00
|
|
|
identifier_prefix: "viewmanager",
|
2011-09-12 10:53:25 +00:00
|
|
|
template: "ViewManager",
|
2011-09-12 12:06:04 +00:00
|
|
|
/**
|
2011-10-24 22:54:31 +00:00
|
|
|
* @constructs session.web.ViewManager
|
|
|
|
* @extends session.web.Widget
|
2011-09-12 12:06:04 +00:00
|
|
|
*
|
|
|
|
* @param parent
|
|
|
|
* @param dataset
|
|
|
|
* @param views
|
|
|
|
*/
|
2011-12-14 15:29:03 +00:00
|
|
|
init: function(parent, dataset, views, flags) {
|
2011-08-10 00:38:57 +00:00
|
|
|
this._super(parent);
|
2011-09-28 15:16:13 +00:00
|
|
|
this.model = dataset ? dataset.model : undefined;
|
2011-04-06 21:10:37 +00:00
|
|
|
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-12-16 11:20:54 +00:00
|
|
|
this.views_src = _.map(views, function(x) {
|
|
|
|
if (x instanceof Array) {
|
|
|
|
var View = session.web.views.get_object(x[1], true);
|
|
|
|
return {
|
|
|
|
view_id: x[0],
|
|
|
|
view_type: x[1],
|
|
|
|
label: View ? View.prototype.display_name : (void 'nope')
|
|
|
|
};
|
|
|
|
} else {
|
|
|
|
return x;
|
|
|
|
}
|
|
|
|
});
|
2011-03-30 14:00:48 +00:00
|
|
|
this.views = {};
|
2011-12-14 15:29:03 +00:00
|
|
|
this.flags = flags || {};
|
2011-10-24 22:54:31 +00:00
|
|
|
this.registry = session.web.views;
|
2011-12-07 10:45:03 +00:00
|
|
|
this.views_history = [];
|
2011-04-05 10:24:40 +00:00
|
|
|
},
|
2011-08-10 00:38:57 +00:00
|
|
|
render: function() {
|
2011-10-24 22:54:31 +00:00
|
|
|
return session.web.qweb.render(this.template, {
|
2011-09-14 09:13:19 +00:00
|
|
|
self: this,
|
|
|
|
prefix: this.element_id,
|
|
|
|
views: this.views_src});
|
2011-08-10 00:38:57 +00:00
|
|
|
},
|
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;
|
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-08 17:32:30 +00:00
|
|
|
var views_ids = {};
|
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, {
|
2011-12-06 14:04:52 +00:00
|
|
|
deferred : $.Deferred(),
|
2011-07-26 21:00:05 +00:00
|
|
|
controller : null,
|
|
|
|
options : _.extend({
|
2011-08-08 17:32:30 +00:00
|
|
|
sidebar_id : self.element_id + '_sidebar_' + view.view_type,
|
|
|
|
action : self.action,
|
|
|
|
action_views_ids : views_ids
|
2011-11-17 11:18:57 +00:00
|
|
|
}, self.flags, self.flags[view.view_type] || {}, view.options || {})
|
2011-07-26 21:00:05 +00:00
|
|
|
});
|
2011-08-08 17:32:30 +00:00
|
|
|
views_ids[view.view_type] = view.view_id;
|
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-12-12 09:41:52 +00:00
|
|
|
// If no default view defined, switch to the first one in sequence
|
|
|
|
var default_view = this.flags.default_view || this.views_src[0].view_type;
|
|
|
|
return this.on_mode_switch(default_view);
|
2011-04-06 00:51:36 +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
|
2011-12-07 10:45:03 +00:00
|
|
|
* @param {Boolean} [no_store=false] don't store the view being switched to on the switch stack
|
2011-04-01 11:50:05 +00:00
|
|
|
* @returns {jQuery.Deferred} new view loading promise
|
|
|
|
*/
|
2011-12-07 10:45:03 +00:00
|
|
|
on_mode_switch: function(view_type, no_store) {
|
2011-06-22 13:43:20 +00:00
|
|
|
var self = this,
|
2011-12-08 05:59:09 +00:00
|
|
|
view = this.views[view_type],
|
2011-06-22 13:43:20 +00:00
|
|
|
view_promise;
|
2011-12-08 05:59:09 +00:00
|
|
|
if(!view)
|
|
|
|
return $.Deferred().reject();
|
|
|
|
|
2011-12-07 10:45:03 +00:00
|
|
|
if (!no_store) {
|
|
|
|
this.views_history.push(view_type);
|
|
|
|
}
|
2011-03-31 12:25:22 +00:00
|
|
|
this.active_view = view_type;
|
2011-12-09 14:46:38 +00:00
|
|
|
|
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-09-14 14:30:28 +00:00
|
|
|
var controller = new controllerclass(this, 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-08 14:41:20 +00:00
|
|
|
controller.do_switch_view.add_last(this.on_mode_switch);
|
2011-12-07 10:45:03 +00:00
|
|
|
controller.do_prev_view.add_last(this.on_prev_view);
|
2011-09-14 14:30:28 +00:00
|
|
|
var container = $("#" + this.element_id + '_view_' + view_type);
|
|
|
|
view_promise = controller.appendTo(container);
|
2011-09-29 11:47:20 +00:00
|
|
|
this.views[view_type].controller = controller;
|
2011-12-12 16:44:55 +00:00
|
|
|
this.views[view_type].deferred.resolve(view_type);
|
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-09-29 11:47:20 +00:00
|
|
|
if (self.searchview && view.controller.searchable !== false) {
|
2011-12-07 09:03:54 +00:00
|
|
|
self.searchview.ready.then(self.searchview.do_search);
|
2011-09-29 11:47:20 +00:00
|
|
|
}
|
2011-05-31 15:28:07 +00:00
|
|
|
});
|
2011-09-29 08:09:17 +00:00
|
|
|
} else if (this.searchview && view.controller.searchable !== false) {
|
2011-12-07 09:03:54 +00:00
|
|
|
this.searchview.ready.then(this.searchview.do_search);
|
2011-03-31 13:20:58 +00:00
|
|
|
}
|
2011-04-01 09:06:53 +00:00
|
|
|
|
2011-09-28 15:32:54 +00:00
|
|
|
if (this.searchview) {
|
2011-09-29 14:49:15 +00:00
|
|
|
this.searchview[(view.controller.searchable === false || this.searchview.hidden) ? 'hide' : 'show']();
|
2011-04-01 10:45:00 +00:00
|
|
|
}
|
|
|
|
|
2011-04-01 09:06:53 +00:00
|
|
|
this.$element
|
2011-12-05 13:50:37 +00:00
|
|
|
.find('.oe_vm_switch button').removeAttr('disabled')
|
2011-04-01 09:11:17 +00:00
|
|
|
.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-10-25 14:37:38 +00:00
|
|
|
$.when(view_promise).then(function () {
|
2011-12-20 17:37:42 +00:00
|
|
|
_.each(_.keys(self.views), function(view_name) {
|
|
|
|
var controller = self.views[view_name].controller;
|
|
|
|
if (controller) {
|
|
|
|
if (view_name === view_type) {
|
|
|
|
controller.do_show();
|
|
|
|
} else {
|
|
|
|
controller.do_hide();
|
|
|
|
}
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-11-30 13:25:43 +00:00
|
|
|
self.$element.find('.oe_view_title_text:first').text(
|
2011-10-25 14:37:38 +00:00
|
|
|
self.display_title());
|
|
|
|
});
|
2011-04-01 11:50:05 +00:00
|
|
|
return view_promise;
|
2011-03-30 14:00:48 +00:00
|
|
|
},
|
2011-12-07 15:31:01 +00:00
|
|
|
/**
|
|
|
|
* Returns to the view preceding the caller view in this manager's
|
|
|
|
* navigation history (the navigation history is appended to via
|
|
|
|
* on_mode_switch)
|
|
|
|
*
|
|
|
|
* @param {Boolean} [created=false] returning from a creation
|
|
|
|
* @returns {$.Deferred} switching end signal
|
|
|
|
*/
|
|
|
|
on_prev_view: function (created) {
|
|
|
|
var current_view = this.views_history.pop();
|
2011-12-07 10:45:03 +00:00
|
|
|
var previous_view = this.views_history[this.views_history.length - 1];
|
2011-12-07 15:31:01 +00:00
|
|
|
if (created && current_view === 'form' && previous_view === 'list') {
|
2012-01-09 14:15:34 +00:00
|
|
|
// APR special case: "If creation mode from list (and only from a list),
|
|
|
|
// after saving, go to page view (don't come back in list)"
|
2011-12-07 15:31:01 +00:00
|
|
|
return this.on_mode_switch('page');
|
2012-01-09 14:15:34 +00:00
|
|
|
} else if (created && !previous_view && this.action && this.action.flags.default_view === 'form') {
|
|
|
|
// APR special case: "If creation from dashboard, we have no previous view
|
2011-12-07 15:31:01 +00:00
|
|
|
return this.on_mode_switch('page');
|
|
|
|
}
|
|
|
|
return this.on_mode_switch(previous_view, true);
|
2011-12-07 10:45:03 +00:00
|
|
|
},
|
2011-09-28 15:32:54 +00:00
|
|
|
/**
|
|
|
|
* Sets up the current viewmanager's search view.
|
|
|
|
*
|
|
|
|
* @param {Number|false} 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-10-24 22:54:31 +00:00
|
|
|
this.searchview = new session.web.SearchView(
|
2011-09-28 15:32:54 +00:00
|
|
|
this, this.dataset,
|
|
|
|
view_id, search_defaults, this.flags.search_view === false);
|
|
|
|
|
|
|
|
this.searchview.on_search.add(this.do_searchview_search);
|
|
|
|
return this.searchview.appendTo($("#" + this.element_id + "_search"));
|
|
|
|
},
|
|
|
|
do_searchview_search: function(domains, contexts, groupbys) {
|
2011-09-29 09:53:05 +00:00
|
|
|
var self = this,
|
2011-12-12 14:16:56 +00:00
|
|
|
controller = this.views[this.active_view].controller,
|
|
|
|
action_context = this.action.context || {};
|
2011-12-06 11:36:58 +00:00
|
|
|
this.rpc('/web/session/eval_domain_and_context', {
|
|
|
|
domains: [this.action.domain || []].concat(domains || []),
|
2011-12-12 14:16:56 +00:00
|
|
|
contexts: [action_context].concat(contexts || []),
|
2011-12-06 11:36:58 +00:00
|
|
|
group_by_seq: groupbys || []
|
|
|
|
}, function (results) {
|
|
|
|
self.dataset.context = results.context;
|
|
|
|
self.dataset.domain = results.domain;
|
2011-12-12 14:16:56 +00:00
|
|
|
var groupby = results.group_by.length
|
|
|
|
? results.group_by
|
|
|
|
: action_context.group_by;
|
|
|
|
controller.do_search(results.domain, results.context, groupby || []);
|
2011-12-06 11:36:58 +00:00
|
|
|
});
|
2011-09-28 15:32:54 +00:00
|
|
|
},
|
2011-05-31 15:28:07 +00:00
|
|
|
/**
|
|
|
|
* Event launched when a controller has been inited.
|
2011-09-06 13:05:25 +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-08-10 01:34:48 +00:00
|
|
|
on_controller_inited: function(view_type, view) {
|
|
|
|
},
|
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-09-14 12:13:05 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Called by children view after executing an action
|
|
|
|
*/
|
2011-12-14 18:04:42 +00:00
|
|
|
on_action_executed: function () {
|
|
|
|
},
|
2011-10-25 14:37:38 +00:00
|
|
|
display_title: function () {
|
|
|
|
var view = this.views[this.active_view];
|
|
|
|
if (view) {
|
|
|
|
// ick
|
|
|
|
return view.controller.fields_view.arch.attrs.string;
|
|
|
|
}
|
|
|
|
return '';
|
|
|
|
}
|
2011-04-06 00:51:36 +00:00
|
|
|
});
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{
|
2011-09-13 06:33:46 +00:00
|
|
|
template:"ViewManagerAction",
|
2011-09-13 06:32:38 +00:00
|
|
|
/**
|
2011-10-24 22:54:31 +00:00
|
|
|
* @constructs session.web.ViewManagerAction
|
|
|
|
* @extends session.web.ViewManager
|
2011-09-13 06:32:38 +00:00
|
|
|
*
|
2011-10-24 22:54:31 +00:00
|
|
|
* @param {session.web.ActionManager} parent parent object/widget
|
2011-09-13 06:32:38 +00:00
|
|
|
* @param {Object} action descriptor for the action this viewmanager needs to manage its views.
|
|
|
|
*/
|
2011-09-13 06:33:46 +00:00
|
|
|
init: function(parent, action) {
|
2011-09-13 06:47:45 +00:00
|
|
|
// dataset initialization will take the session from ``this``, so if we
|
|
|
|
// do not have it yet (and we don't, because we've not called our own
|
|
|
|
// ``_super()``) rpc requests will blow up.
|
2011-12-14 15:29:03 +00:00
|
|
|
var flags = action.flags || {};
|
2011-12-07 15:59:13 +00:00
|
|
|
if (action.res_model == 'board.board' && action.view_mode === 'form') {
|
|
|
|
// Special case for Dashboards
|
2011-12-14 15:29:03 +00:00
|
|
|
_.extend(flags, {
|
2011-12-07 15:59:13 +00:00
|
|
|
views_switcher : false,
|
|
|
|
display_title : false,
|
|
|
|
search_view : false,
|
|
|
|
pager : false,
|
|
|
|
sidebar : false,
|
|
|
|
action_buttons : false
|
|
|
|
});
|
2011-05-18 12:52:51 +00:00
|
|
|
}
|
2011-12-14 15:29:03 +00:00
|
|
|
this._super(parent, null, action.views, flags);
|
|
|
|
this.session = parent.session;
|
|
|
|
this.action = action;
|
|
|
|
var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain);
|
|
|
|
if (action.res_id) {
|
|
|
|
dataset.ids.push(action.res_id);
|
|
|
|
dataset.index = 0;
|
|
|
|
}
|
|
|
|
this.dataset = dataset;
|
2011-09-14 10:15:31 +00:00
|
|
|
|
|
|
|
// setup storage for session-wise menu hiding
|
|
|
|
if (this.session.hidden_menutips) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
this.session.hidden_menutips = {}
|
2011-04-06 00:51:36 +00:00
|
|
|
},
|
2011-09-13 06:32:38 +00:00
|
|
|
/**
|
|
|
|
* Initializes the ViewManagerAction: sets up the searchview (if the
|
|
|
|
* searchview is enabled in the manager's action flags), calls into the
|
|
|
|
* parent to initialize the primary view and (if the VMA has a searchview)
|
|
|
|
* launches an initial search after both views are done rendering.
|
|
|
|
*/
|
2011-04-06 00:51:36 +00:00
|
|
|
start: function() {
|
2011-09-28 10:44:58 +00:00
|
|
|
var self = this,
|
|
|
|
searchview_loaded,
|
|
|
|
search_defaults = {};
|
|
|
|
_.each(this.action.context, function (value, key) {
|
|
|
|
var match = /^search_default_(.*)$/.exec(key);
|
|
|
|
if (match) {
|
|
|
|
search_defaults[match[1]] = value;
|
|
|
|
}
|
|
|
|
});
|
|
|
|
// 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-09-28 10:44:58 +00:00
|
|
|
searchview_loaded = this.setup_search_view(searchview_id || false, search_defaults);
|
2011-08-19 05:53:54 +00:00
|
|
|
|
2011-09-13 06:32:38 +00:00
|
|
|
var main_view_loaded = this._super();
|
2011-09-06 13:05:25 +00:00
|
|
|
|
2011-09-13 06:38:30 +00:00
|
|
|
var manager_ready = $.when(searchview_loaded, main_view_loaded);
|
2011-09-14 10:08:33 +00:00
|
|
|
|
2011-12-13 11:35:21 +00:00
|
|
|
this.$element.find('.oe_debug_view').change(this.on_debug_changed);
|
|
|
|
|
2011-09-14 13:16:35 +00:00
|
|
|
if (this.action.help && !this.flags.low_profile) {
|
2011-10-24 22:54:31 +00:00
|
|
|
var Users = new session.web.DataSet(self, 'res.users'),
|
2011-11-30 13:11:54 +00:00
|
|
|
$tips = this.$element.find('.oe_view_manager_menu_tips');
|
|
|
|
$tips.delegate('blockquote button', 'click', function() {
|
2011-09-14 10:08:33 +00:00
|
|
|
var $this = $(this);
|
|
|
|
//noinspection FallthroughInSwitchStatementJS
|
2011-09-14 13:16:35 +00:00
|
|
|
switch ($this.attr('name')) {
|
2011-09-14 10:08:33 +00:00
|
|
|
case 'disable':
|
2011-09-14 13:16:35 +00:00
|
|
|
Users.write(self.session.uid, {menu_tips:false});
|
2011-09-14 10:08:33 +00:00
|
|
|
case 'hide':
|
|
|
|
$this.closest('blockquote').hide();
|
2011-09-14 10:15:31 +00:00
|
|
|
self.session.hidden_menutips[self.action.id] = true;
|
2011-09-14 10:08:33 +00:00
|
|
|
}
|
|
|
|
});
|
2011-09-14 10:15:31 +00:00
|
|
|
if (!(self.action.id in self.session.hidden_menutips)) {
|
2012-01-10 15:45:00 +00:00
|
|
|
Users.read_ids([this.session.uid], ['menu_tips']).then(function(users) {
|
2011-09-14 10:15:31 +00:00
|
|
|
var user = users[0];
|
|
|
|
if (!(user && user.id === self.session.uid)) {
|
|
|
|
return;
|
|
|
|
}
|
2011-11-30 13:11:54 +00:00
|
|
|
$tips.find('blockquote').toggle(user.menu_tips);
|
2011-09-14 10:15:31 +00:00
|
|
|
});
|
2011-06-22 13:43:20 +00:00
|
|
|
}
|
2011-04-06 00:51:36 +00:00
|
|
|
}
|
2011-09-14 10:08:33 +00:00
|
|
|
|
2011-11-09 11:50:09 +00:00
|
|
|
var $res_logs = this.$element.find('.oe-view-manager-logs:first');
|
|
|
|
$res_logs.delegate('a.oe-more-logs', 'click', function () {
|
|
|
|
$res_logs.removeClass('oe-folded');
|
|
|
|
return false;
|
|
|
|
}).delegate('a.oe-remove-everything', 'click', function () {
|
2011-12-30 10:53:41 +00:00
|
|
|
$res_logs.removeClass('oe-has-more').find('ul').empty();
|
|
|
|
$res_logs.css('display','none');
|
2011-11-09 11:35:35 +00:00
|
|
|
return false;
|
|
|
|
});
|
2011-12-22 15:54:50 +00:00
|
|
|
$res_logs.css('display','none');
|
2011-11-09 11:35:35 +00:00
|
|
|
|
2011-09-13 06:38:30 +00:00
|
|
|
return manager_ready;
|
2011-04-06 00:51:36 +00:00
|
|
|
},
|
2011-12-13 11:35:21 +00:00
|
|
|
on_debug_changed: function (evt) {
|
2012-01-10 11:23:28 +00:00
|
|
|
var self = this,
|
|
|
|
$sel = $(evt.currentTarget),
|
2011-12-13 11:35:21 +00:00
|
|
|
$option = $sel.find('option:selected'),
|
2012-01-10 11:23:28 +00:00
|
|
|
val = $sel.val(),
|
|
|
|
current_view = this.views[this.active_view].controller;
|
2011-12-13 11:35:21 +00:00
|
|
|
switch (val) {
|
|
|
|
case 'fvg':
|
2012-01-10 11:23:28 +00:00
|
|
|
var dialog = new session.web.Dialog(this, { title: "Fields View Get", width: '95%' }).open();
|
|
|
|
$('<pre>').text(session.web.json_node_to_xml(current_view.fields_view.arch, true)).appendTo(dialog.$element);
|
2011-12-13 11:35:21 +00:00
|
|
|
break;
|
2012-01-10 11:23:28 +00:00
|
|
|
case 'customize_object':
|
|
|
|
this.rpc('/web/dataset/search_read', {
|
|
|
|
model: 'ir.model',
|
|
|
|
fields: ['id'],
|
|
|
|
domain: [['model', '=', this.dataset.model]]
|
|
|
|
}, function (result) {
|
|
|
|
self.do_edit_resource('ir.model', result.ids[0], { name : "Customize Object" });
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'manage_views':
|
|
|
|
if (current_view.fields_view && current_view.fields_view.arch) {
|
|
|
|
var view_editor = new session.web.ViewEditor(current_view, current_view.$element, this.dataset, current_view.fields_view.arch);
|
|
|
|
view_editor.start();
|
|
|
|
} else {
|
|
|
|
this.do_warn("Manage Views", "Could not find current view declaration");
|
2011-12-13 11:35:21 +00:00
|
|
|
}
|
2012-01-10 11:23:28 +00:00
|
|
|
break;
|
|
|
|
case 'edit_workflow':
|
|
|
|
return this.do_action({
|
|
|
|
res_model : 'workflow',
|
|
|
|
domain : [['osv', '=', this.dataset.model]],
|
|
|
|
views: [[false, 'list'], [false, 'form'], [false, 'diagram']],
|
|
|
|
type : 'ir.actions.act_window',
|
|
|
|
view_type : 'list',
|
|
|
|
view_mode : 'list'
|
|
|
|
});
|
|
|
|
break;
|
|
|
|
case 'edit':
|
|
|
|
this.do_edit_resource($option.data('model'), $option.data('id'), { name : $option.text() });
|
2011-12-13 11:35:21 +00:00
|
|
|
break;
|
|
|
|
default:
|
|
|
|
if (val) {
|
|
|
|
console.log("No debug handler for ", val);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
evt.currentTarget.selectedIndex = 0;
|
|
|
|
},
|
2012-01-10 11:23:28 +00:00
|
|
|
do_edit_resource: function(model, id, action) {
|
|
|
|
var action = _.extend({
|
|
|
|
res_model : model,
|
|
|
|
res_id : id,
|
|
|
|
type : 'ir.actions.act_window',
|
|
|
|
view_type : 'form',
|
|
|
|
view_mode : 'form',
|
|
|
|
views : [[false, 'form']],
|
|
|
|
target : 'new',
|
|
|
|
flags : {
|
|
|
|
action_buttons : true,
|
|
|
|
form : {
|
|
|
|
resize_textareas : true
|
|
|
|
}
|
|
|
|
}
|
|
|
|
}, action || {});
|
|
|
|
this.do_action(action);
|
|
|
|
},
|
2011-12-07 10:45:03 +00:00
|
|
|
on_mode_switch: function (view_type, no_store) {
|
2011-09-14 09:13:19 +00:00
|
|
|
var self = this;
|
2011-12-09 14:46:38 +00:00
|
|
|
|
|
|
|
return $.when(this._super(view_type, no_store)).then(function () {
|
2011-12-09 13:48:09 +00:00
|
|
|
self.shortcut_check(self.views[view_type]);
|
2011-12-09 14:46:38 +00:00
|
|
|
|
2011-12-30 10:53:41 +00:00
|
|
|
self.$element.find('.oe-view-manager-logs:first').addClass('oe-folded').removeClass('oe-has-more').css('display','none').find('ul').empty();
|
2011-10-25 13:23:26 +00:00
|
|
|
|
2011-12-09 14:46:38 +00:00
|
|
|
var controller = self.views[self.active_view].controller,
|
|
|
|
fvg = controller.fields_view,
|
|
|
|
view_id = (fvg && fvg.view_id) || '--';
|
2011-12-13 11:35:21 +00:00
|
|
|
self.$element.find('.oe_debug_view').html(QWeb.render('ViewManagerDebug', {
|
|
|
|
view: controller,
|
|
|
|
view_manager: self
|
|
|
|
}));
|
2011-12-09 14:46:38 +00:00
|
|
|
if (!self.action.name && fvg) {
|
|
|
|
self.$element.find('.oe_view_title_text').text(fvg.arch.attrs.string || fvg.name);
|
|
|
|
}
|
|
|
|
|
|
|
|
var $title = self.$element.find('.oe_view_title_text'),
|
|
|
|
$search_prefix = $title.find('span.oe_searchable_view');
|
2011-12-21 10:46:16 +00:00
|
|
|
if (controller.searchable !== false && self.flags.search_view !== false) {
|
2011-12-09 14:46:38 +00:00
|
|
|
if (!$search_prefix.length) {
|
|
|
|
$title.prepend('<span class="oe_searchable_view">' + _t("Search: ") + '</span>');
|
2011-10-25 13:23:26 +00:00
|
|
|
}
|
2011-12-09 14:46:38 +00:00
|
|
|
} else {
|
|
|
|
$search_prefix.remove();
|
|
|
|
}
|
2011-09-14 09:13:19 +00:00
|
|
|
});
|
2011-08-16 12:35:10 +00:00
|
|
|
},
|
2011-12-14 16:09:58 +00:00
|
|
|
do_push_state: function(state) {
|
2011-12-14 18:04:42 +00:00
|
|
|
if (this.widget_parent && this.widget_parent.do_push_state) {
|
|
|
|
state["view_type"] = this.active_view;
|
2011-12-14 16:09:58 +00:00
|
|
|
this.widget_parent.do_push_state(state);
|
|
|
|
}
|
2011-12-12 14:20:12 +00:00
|
|
|
},
|
2011-12-12 16:44:55 +00:00
|
|
|
do_load_state: function(state) {
|
2011-12-15 14:29:39 +00:00
|
|
|
var self = this,
|
|
|
|
defs = [];
|
|
|
|
if (state.view_type && state.view_type !== this.active_view) {
|
2011-12-20 17:37:42 +00:00
|
|
|
defs.push(
|
|
|
|
this.views[this.active_view].deferred.pipe(function() {
|
|
|
|
return self.on_mode_switch(state.view_type, true);
|
|
|
|
})
|
|
|
|
);
|
2011-12-15 14:29:39 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
$.when(defs).then(function() {
|
2011-12-12 16:44:55 +00:00
|
|
|
self.views[self.active_view].controller.do_load_state(state);
|
|
|
|
});
|
2011-12-12 14:20:12 +00:00
|
|
|
},
|
2011-08-16 12:35:10 +00:00
|
|
|
shortcut_check : function(view) {
|
|
|
|
var self = this;
|
2011-08-16 14:12:36 +00:00
|
|
|
var grandparent = this.widget_parent && this.widget_parent.widget_parent;
|
2011-08-16 12:35:10 +00:00
|
|
|
// display shortcuts if on the first view for the action
|
|
|
|
var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
|
2011-12-20 16:49:03 +00:00
|
|
|
if (!this.action.name ||
|
2011-08-16 14:12:36 +00:00
|
|
|
!(view.view_type === this.views_src[0].view_type
|
2011-08-16 12:35:10 +00:00
|
|
|
&& view.view_id === this.views_src[0].view_id)) {
|
|
|
|
$shortcut_toggle.hide();
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
$shortcut_toggle.removeClass('oe-shortcut-remove').show();
|
2011-08-16 14:04:25 +00:00
|
|
|
if (_(this.session.shortcuts).detect(function (shortcut) {
|
2011-08-16 12:35:10 +00:00
|
|
|
return shortcut.res_id === self.session.active_id; })) {
|
|
|
|
$shortcut_toggle.addClass("oe-shortcut-remove");
|
|
|
|
}
|
|
|
|
this.shortcut_add_remove();
|
|
|
|
},
|
|
|
|
shortcut_add_remove: function() {
|
|
|
|
var self = this;
|
|
|
|
var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
|
2011-08-26 08:47:58 +00:00
|
|
|
$shortcut_toggle
|
|
|
|
.unbind("click")
|
|
|
|
.click(function() {
|
|
|
|
if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
|
|
|
|
$(self.session.shortcuts.binding).trigger('remove-current');
|
|
|
|
$shortcut_toggle.removeClass("oe-shortcut-remove");
|
|
|
|
} else {
|
|
|
|
$(self.session.shortcuts.binding).trigger('add', {
|
|
|
|
'user_id': self.session.uid,
|
|
|
|
'res_id': self.session.active_id,
|
|
|
|
'resource': 'ir.ui.menu',
|
|
|
|
'name': self.action.name
|
|
|
|
});
|
|
|
|
$shortcut_toggle.addClass("oe-shortcut-remove");
|
|
|
|
}
|
|
|
|
});
|
2011-09-14 12:13:05 +00:00
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Intercept do_action resolution from children views
|
|
|
|
*/
|
|
|
|
on_action_executed: function () {
|
2011-10-24 22:54:31 +00:00
|
|
|
return new session.web.DataSet(this, 'res.log')
|
2011-09-14 12:13:05 +00:00
|
|
|
.call('get', [], this.do_display_log);
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* @param {Array<Object>} log_records
|
|
|
|
*/
|
|
|
|
do_display_log: function (log_records) {
|
2011-12-30 10:53:41 +00:00
|
|
|
var self = this;
|
|
|
|
var cutoff = 3;
|
|
|
|
var $logs = this.$element.find('.oe-view-manager-logs:first').addClass('oe-folded').css('display', 'block');
|
|
|
|
var $logs_list = $logs.find('ul').empty();
|
2011-11-09 11:35:35 +00:00
|
|
|
$logs.toggleClass('oe-has-more', log_records.length > cutoff);
|
2011-11-09 11:04:57 +00:00
|
|
|
_(log_records.reverse()).each(function (record) {
|
2011-11-15 12:30:59 +00:00
|
|
|
$(_.str.sprintf('<li><a href="#">%s</a></li>', record.name))
|
2011-11-09 11:35:35 +00:00
|
|
|
.appendTo($logs_list)
|
2011-09-14 12:25:25 +00:00
|
|
|
.delegate('a', 'click', function (e) {
|
|
|
|
self.do_action({
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
res_model: record.res_model,
|
|
|
|
res_id: record.res_id,
|
|
|
|
// TODO: need to have an evaluated context here somehow
|
|
|
|
//context: record.context,
|
|
|
|
views: [[false, 'form']]
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
});
|
2011-09-14 12:13:05 +00:00
|
|
|
});
|
2011-10-25 14:37:38 +00:00
|
|
|
},
|
|
|
|
display_title: function () {
|
|
|
|
return this.action.name;
|
2011-04-08 10:37:36 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.Sidebar = session.web.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-08-26 12:44:18 +00:00
|
|
|
this._super(this);
|
2011-04-04 13:47:05 +00:00
|
|
|
var self = this;
|
2011-10-24 22:54:31 +00:00
|
|
|
this.$element.html(session.web.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-07-26 21:00:05 +00:00
|
|
|
},
|
2011-10-10 12:34:32 +00:00
|
|
|
add_default_sections: function() {
|
2011-12-07 14:55:14 +00:00
|
|
|
var self = this,
|
|
|
|
view = this.widget_parent,
|
|
|
|
view_manager = view.widget_parent,
|
|
|
|
action = view_manager.action;
|
2011-11-09 10:47:00 +00:00
|
|
|
if (this.session.uid === 1) {
|
|
|
|
this.add_section(_t('Customize'), 'customize');
|
2012-01-10 11:23:28 +00:00
|
|
|
this.add_items('customize', [{
|
|
|
|
label: _t("Translate"),
|
|
|
|
callback: view.on_sidebar_translate,
|
|
|
|
title: _t("Technical translation")
|
|
|
|
}]);
|
2011-11-09 10:47:00 +00:00
|
|
|
}
|
2011-10-10 12:34:32 +00:00
|
|
|
|
2011-10-12 10:18:02 +00:00
|
|
|
this.add_section(_t('Other Options'), 'other');
|
2011-11-09 10:47:00 +00:00
|
|
|
this.add_items('other', [
|
2011-10-10 12:34:32 +00:00
|
|
|
{
|
2011-10-12 10:18:02 +00:00
|
|
|
label: _t("Import"),
|
2011-12-07 14:55:14 +00:00
|
|
|
callback: view.on_sidebar_import
|
2011-10-10 12:34:32 +00:00
|
|
|
}, {
|
2011-10-12 10:18:02 +00:00
|
|
|
label: _t("Export"),
|
2011-12-07 14:55:14 +00:00
|
|
|
callback: view.on_sidebar_export
|
2011-10-10 12:34:32 +00:00
|
|
|
}, {
|
2011-10-12 10:18:02 +00:00
|
|
|
label: _t("View Log"),
|
2011-12-07 14:55:14 +00:00
|
|
|
callback: view.on_sidebar_view_log,
|
2011-10-10 12:34:32 +00:00
|
|
|
classname: 'oe_hide oe_sidebar_view_log'
|
|
|
|
}
|
|
|
|
]);
|
|
|
|
},
|
|
|
|
|
2011-07-26 21:00:05 +00:00
|
|
|
add_toolbar: function(toolbar) {
|
|
|
|
var self = this;
|
2011-10-12 10:18:02 +00:00
|
|
|
_.each([['print', _t("Reports")], ['action', _t("Actions")], ['relate', _t("Links")]], function(type) {
|
2011-07-26 21:00:05 +00:00
|
|
|
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-10-12 09:54:26 +00:00
|
|
|
self.add_section(type[1], type[0]);
|
|
|
|
self.add_items(type[0], items);
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
2011-04-04 13:47:05 +00:00
|
|
|
});
|
|
|
|
},
|
2011-11-09 10:47:00 +00:00
|
|
|
|
2011-10-12 09:54:26 +00:00
|
|
|
add_section: function(name, code) {
|
2011-11-15 12:30:59 +00:00
|
|
|
if(!code) code = _.str.underscored(name);
|
2011-10-12 09:54:26 +00:00
|
|
|
var $section = this.sections[code];
|
2011-10-10 12:34:32 +00:00
|
|
|
|
|
|
|
if(!$section) {
|
2011-11-09 10:34:50 +00:00
|
|
|
var section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
|
|
|
|
$section = $(session.web.qweb.render("Sidebar.section", {
|
2011-10-10 12:34:32 +00:00
|
|
|
section_id: section_id,
|
|
|
|
name: name,
|
2011-10-28 08:52:12 +00:00
|
|
|
classname: 'oe_sidebar_' + code
|
2011-10-10 12:34:32 +00:00
|
|
|
}));
|
|
|
|
$section.appendTo(this.$element.find('div.sidebar-actions'));
|
|
|
|
this.sections[code] = $section;
|
|
|
|
}
|
|
|
|
return $section;
|
|
|
|
},
|
|
|
|
|
2011-10-12 09:54:26 +00:00
|
|
|
add_items: function(section_code, items) {
|
2011-07-26 21:00:05 +00:00
|
|
|
// 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
|
2011-10-10 12:34:32 +00:00
|
|
|
//
|
|
|
|
|
2011-07-26 21:00:05 +00:00
|
|
|
var self = this,
|
2011-11-15 12:30:59 +00:00
|
|
|
$section = this.add_section(_.str.titleize(section_code.replace('_', ' ')), section_code),
|
2011-10-10 12:34:32 +00:00
|
|
|
section_id = $section.attr('id');
|
|
|
|
|
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];
|
|
|
|
}
|
2011-10-10 12:34:32 +00:00
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
var $items = $(session.web.qweb.render("Sidebar.section.items", {items: items}));
|
2011-10-10 12:34:32 +00:00
|
|
|
|
|
|
|
$items.find('a.oe_sidebar_action_a').click(function() {
|
2011-07-26 21:00:05 +00:00
|
|
|
var item = self.items[$(this).attr('id')];
|
|
|
|
if (item.callback) {
|
2011-10-10 12:34:32 +00:00
|
|
|
item.callback.apply(self, [item]);
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
|
|
|
if (item.action) {
|
2011-11-21 16:34:41 +00:00
|
|
|
self.on_item_action_clicked(item);
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
|
|
|
return false;
|
|
|
|
});
|
2011-11-14 11:02:39 +00:00
|
|
|
|
2011-10-10 12:34:32 +00:00
|
|
|
var $ul = $section.find('ul');
|
|
|
|
if(!$ul.length) {
|
|
|
|
$ul = $('<ul/>').appendTo($section);
|
|
|
|
}
|
|
|
|
$items.appendTo($ul);
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
|
|
|
},
|
2011-11-14 11:02:39 +00:00
|
|
|
on_item_action_clicked: function(item) {
|
|
|
|
var self = this;
|
2011-11-21 14:09:08 +00:00
|
|
|
self.widget_parent.sidebar_context().then(function (context) {
|
2011-11-21 16:34:41 +00:00
|
|
|
var ids = self.widget_parent.get_selected_ids();
|
|
|
|
if (ids.length == 0) {
|
|
|
|
//TODO: make prettier warning?
|
|
|
|
$("<div />").text(_t("You must choose at least one record.")).dialog({
|
|
|
|
title: _t("Warning"),
|
|
|
|
modal: true
|
|
|
|
});
|
|
|
|
return false;
|
|
|
|
}
|
2011-11-21 14:09:08 +00:00
|
|
|
var additional_context = _.extend({
|
|
|
|
active_id: ids[0],
|
|
|
|
active_ids: ids,
|
|
|
|
active_model: self.widget_parent.dataset.model
|
|
|
|
}, context);
|
|
|
|
self.rpc("/web/action/load", {
|
|
|
|
action_id: item.action.id,
|
|
|
|
context: additional_context
|
|
|
|
}, function(result) {
|
|
|
|
result.result.context = _.extend(result.result.context || {},
|
|
|
|
additional_context);
|
|
|
|
result.result.flags = result.result.flags || {};
|
|
|
|
result.result.flags.new_window = true;
|
2011-12-21 14:19:53 +00:00
|
|
|
self.do_action(result.result, function () {
|
|
|
|
// reload view
|
|
|
|
self.widget_parent.reload();
|
|
|
|
});
|
2011-11-21 14:09:08 +00:00
|
|
|
});
|
2011-11-14 11:02:39 +00:00
|
|
|
});
|
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
do_fold: function() {
|
|
|
|
this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
|
|
|
|
},
|
|
|
|
do_unfold: function() {
|
|
|
|
this.$element.addClass('open-sidebar').removeClass('closed-sidebar');
|
|
|
|
},
|
|
|
|
do_toggle: function() {
|
|
|
|
this.$element.toggleClass('open-sidebar closed-sidebar');
|
2011-04-04 13:47:05 +00:00
|
|
|
}
|
2011-04-01 12:10:42 +00:00
|
|
|
});
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.TranslateDialog = session.web.Dialog.extend({
|
2011-12-15 10:40:31 +00:00
|
|
|
dialog_title: {toString: function () { return _t("Translations"); }},
|
2011-08-24 15:13:57 +00:00
|
|
|
init: function(view) {
|
2011-08-29 14:08:39 +00:00
|
|
|
// TODO fme: should add the language to fields_view_get because between the fields view get
|
|
|
|
// and the moment the user opens the translation dialog, the user language could have been changed
|
|
|
|
this.view_language = view.session.user_context.lang;
|
2011-08-24 15:13:57 +00:00
|
|
|
this['on_button' + _t("Save")] = this.on_button_Save;
|
|
|
|
this['on_button' + _t("Close")] = this.on_button_Close;
|
|
|
|
this._super(view, {
|
|
|
|
width: '80%',
|
|
|
|
height: '80%'
|
|
|
|
});
|
|
|
|
this.view = view;
|
|
|
|
this.view_type = view.fields_view.type || '';
|
|
|
|
this.$fields_form = null;
|
|
|
|
this.$view_form = null;
|
|
|
|
this.$sidebar_form = null;
|
|
|
|
this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
|
|
|
|
this.languages = null;
|
|
|
|
this.languages_loaded = $.Deferred();
|
2011-10-24 22:54:31 +00:00
|
|
|
(new session.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
|
2011-08-24 15:13:57 +00:00
|
|
|
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
|
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
|
|
|
$.when(this.languages_loaded).then(function() {
|
2011-10-24 22:54:31 +00:00
|
|
|
self.$element.html(session.web.qweb.render('TranslateDialog', { widget: self }));
|
2011-08-24 15:13:57 +00:00
|
|
|
self.$fields_form = self.$element.find('.oe_translation_form');
|
2011-08-29 14:08:39 +00:00
|
|
|
self.$fields_form.find('.oe_trad_field').change(function() {
|
|
|
|
$(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
|
|
|
|
});
|
2011-08-24 15:13:57 +00:00
|
|
|
});
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
on_languages_loaded: function(langs) {
|
|
|
|
this.languages = langs;
|
|
|
|
this.languages_loaded.resolve();
|
|
|
|
},
|
|
|
|
do_load_fields_values: function(callback) {
|
|
|
|
var self = this,
|
|
|
|
deffered = [];
|
|
|
|
this.$fields_form.find('.oe_trad_field').val('').removeClass('touched');
|
|
|
|
_.each(self.languages, function(lg) {
|
|
|
|
var deff = $.Deferred();
|
|
|
|
deffered.push(deff);
|
2011-08-29 14:08:39 +00:00
|
|
|
var callback = function(values) {
|
2011-08-24 15:13:57 +00:00
|
|
|
_.each(self.translatable_fields_keys, function(f) {
|
2011-08-29 14:08:39 +00:00
|
|
|
self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(values[0][f] || '').attr('data-value', values[0][f] || '');
|
2011-08-24 15:13:57 +00:00
|
|
|
});
|
|
|
|
deff.resolve();
|
2011-09-06 08:58:53 +00:00
|
|
|
};
|
2011-08-29 14:08:39 +00:00
|
|
|
if (lg.code === self.view_language) {
|
|
|
|
var values = {};
|
|
|
|
_.each(self.translatable_fields_keys, function(field) {
|
|
|
|
values[field] = self.view.fields[field].get_value();
|
|
|
|
});
|
|
|
|
callback([values]);
|
|
|
|
} else {
|
2011-09-05 11:03:09 +00:00
|
|
|
self.rpc('/web/dataset/get', {
|
2011-08-29 14:08:39 +00:00
|
|
|
model: self.view.dataset.model,
|
|
|
|
ids: [self.view.datarecord.id],
|
|
|
|
fields: self.translatable_fields_keys,
|
|
|
|
context: self.view.dataset.get_context({
|
|
|
|
'lang': lg.code
|
|
|
|
})}, callback);
|
|
|
|
}
|
2011-08-24 15:13:57 +00:00
|
|
|
});
|
|
|
|
$.when.apply(null, deffered).then(callback);
|
|
|
|
},
|
|
|
|
open: function(field) {
|
|
|
|
var self = this,
|
2011-08-25 10:06:43 +00:00
|
|
|
sup = this._super;
|
2011-08-24 15:13:57 +00:00
|
|
|
$.when(this.languages_loaded).then(function() {
|
|
|
|
if (self.view.translatable_fields && self.view.translatable_fields.length) {
|
|
|
|
self.do_load_fields_values(function() {
|
2011-08-25 10:06:43 +00:00
|
|
|
sup.call(self);
|
2011-08-24 15:13:57 +00:00
|
|
|
if (field) {
|
2011-11-09 11:58:32 +00:00
|
|
|
var $field_input = self.$element.find('tr[data-field="' + field.name + '"] td:nth-child(2) *:first-child');
|
|
|
|
self.$element.scrollTo($field_input);
|
|
|
|
$field_input.focus();
|
2011-08-24 15:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
} else {
|
2011-08-25 10:06:43 +00:00
|
|
|
sup.call(self);
|
2011-08-24 15:13:57 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
|
|
|
on_button_Save: function() {
|
2011-08-29 14:08:39 +00:00
|
|
|
var trads = {},
|
|
|
|
self = this;
|
|
|
|
self.$fields_form.find('.oe_trad_field.touched').each(function() {
|
|
|
|
var field = $(this).attr('name').split('-');
|
|
|
|
if (!trads[field[0]]) {
|
|
|
|
trads[field[0]] = {};
|
|
|
|
}
|
|
|
|
trads[field[0]][field[1]] = $(this).val();
|
|
|
|
});
|
|
|
|
_.each(trads, function(data, code) {
|
|
|
|
if (code === self.view_language) {
|
|
|
|
_.each(data, function(value, field) {
|
|
|
|
self.view.fields[field].set_value(value);
|
|
|
|
});
|
|
|
|
} else {
|
|
|
|
self.view.dataset.write(self.view.datarecord.id, data, { 'lang': code });
|
|
|
|
}
|
|
|
|
});
|
2011-08-24 15:13:57 +00:00
|
|
|
this.close();
|
|
|
|
},
|
|
|
|
on_button_Close: function() {
|
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2011-10-24 22:54:31 +00:00
|
|
|
session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
|
2011-09-15 09:42:46 +00:00
|
|
|
template: "EmptyComponent",
|
2011-12-16 11:20:54 +00:00
|
|
|
// name displayed in view switchers
|
|
|
|
display_name: '',
|
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,
|
2011-08-08 17:32:30 +00:00
|
|
|
sidebar: true,
|
|
|
|
action: null,
|
|
|
|
action_views_ids: {}
|
2011-07-26 21:00:05 +00:00
|
|
|
});
|
|
|
|
},
|
2011-08-24 15:13:57 +00:00
|
|
|
open_translate_dialog: function(field) {
|
|
|
|
if (!this.translate_dialog) {
|
2011-10-24 22:54:31 +00:00
|
|
|
this.translate_dialog = new session.web.TranslateDialog(this).start();
|
2011-08-24 15:13:57 +00:00
|
|
|
}
|
|
|
|
this.translate_dialog.open(field);
|
|
|
|
},
|
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
|
2011-10-24 22:54:31 +00:00
|
|
|
* @param {session.web.DataSet} dataset a dataset object used to communicate with the server
|
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-09-14 12:13:05 +00:00
|
|
|
do_execute_action: function (action_data, dataset, record_id, on_closed) {
|
2011-06-28 12:43:55 +00:00
|
|
|
var self = this;
|
2011-09-14 12:13:05 +00:00
|
|
|
var result_handler = function () {
|
|
|
|
if (on_closed) { on_closed.apply(null, arguments); }
|
2011-10-10 09:57:54 +00:00
|
|
|
if (self.widget_parent && self.widget_parent.on_action_executed) {
|
|
|
|
return self.widget_parent.on_action_executed.apply(null, arguments);
|
|
|
|
}
|
2011-09-14 12:13:05 +00:00
|
|
|
};
|
2011-10-24 22:54:31 +00:00
|
|
|
var context = new session.web.CompoundContext(dataset.get_context(), action_data.context || {});
|
2011-11-18 07:30:41 +00:00
|
|
|
|
2011-05-11 14:49:10 +00:00
|
|
|
var handler = function (r) {
|
2011-06-21 14:38:04 +00:00
|
|
|
var action = r.result;
|
|
|
|
if (action && action.constructor == Object) {
|
2011-10-24 22:54:31 +00:00
|
|
|
var ncontext = new session.web.CompoundContext(context);
|
2011-10-18 15:57:33 +00:00
|
|
|
if (record_id) {
|
|
|
|
ncontext.add({
|
|
|
|
active_id: record_id,
|
|
|
|
active_ids: [record_id],
|
2011-10-18 15:15:34 +00:00
|
|
|
active_model: dataset.model
|
2011-10-18 15:57:33 +00:00
|
|
|
});
|
|
|
|
}
|
2011-10-19 09:56:12 +00:00
|
|
|
ncontext.add(action.context || {});
|
2011-10-18 15:57:33 +00:00
|
|
|
return self.rpc('/web/session/eval_domain_and_context', {
|
|
|
|
contexts: [ncontext],
|
2011-09-28 09:35:53 +00:00
|
|
|
domains: []
|
2011-09-30 16:15:06 +00:00
|
|
|
}).pipe(function (results) {
|
2011-10-18 15:57:33 +00:00
|
|
|
action.context = results.context;
|
|
|
|
/* niv: previously we were overriding once more with action_data.context,
|
|
|
|
* I assumed this was not a correct behavior and removed it
|
|
|
|
*/
|
2011-09-30 16:15:06 +00:00
|
|
|
return self.do_action(action, result_handler);
|
2011-10-17 07:24:01 +00:00
|
|
|
}, null);
|
2011-09-14 12:13:05 +00:00
|
|
|
} else {
|
2011-09-30 16:15:06 +00:00
|
|
|
return result_handler();
|
2011-05-11 14:49:10 +00:00
|
|
|
}
|
|
|
|
};
|
2011-03-30 14:00:48 +00:00
|
|
|
|
2011-08-10 01:34:48 +00:00
|
|
|
if (action_data.special) {
|
2011-09-30 16:15:06 +00:00
|
|
|
return handler({result: {"type":"ir.actions.act_window_close"}});
|
2011-08-10 01:34:48 +00:00
|
|
|
} else if (action_data.type=="object") {
|
2011-12-06 17:31:42 +00:00
|
|
|
var args = [[record_id]], additional_args = [];
|
|
|
|
if (action_data.args) {
|
|
|
|
try {
|
|
|
|
// Warning: quotes and double quotes problem due to json and xml clash
|
|
|
|
// Maybe we should force escaping in xml or do a better parse of the args array
|
|
|
|
additional_args = JSON.parse(action_data.args.replace(/'/g, '"'));
|
|
|
|
args = args.concat(additional_args);
|
|
|
|
} catch(e) {
|
|
|
|
console.error("Could not JSON.parse arguments", action_data.args);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
args.push(context);
|
|
|
|
return dataset.call_button(action_data.name, args, handler);
|
2011-08-10 01:34:48 +00:00
|
|
|
} else if (action_data.type=="action") {
|
2011-10-18 15:57:33 +00:00
|
|
|
return this.rpc('/web/action/load', { action_id: parseInt(action_data.name, 10), context: context, do_not_eval: true}, handler);
|
2011-08-10 01:34:48 +00:00
|
|
|
} else {
|
|
|
|
return dataset.exec_workflow(record_id, action_data.name, handler);
|
2011-09-06 13:05:25 +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
|
2011-10-24 22:54:31 +00:00
|
|
|
* of session.web.View must use the provided view instead of any other one.
|
2011-09-06 13:05:25 +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-08-08 17:32:30 +00:00
|
|
|
this.options.sidebar = false;
|
2011-07-28 15:15:45 +00:00
|
|
|
},
|
2011-12-14 17:18:11 +00:00
|
|
|
do_show: function () {
|
|
|
|
this.$element.show();
|
|
|
|
},
|
|
|
|
do_hide: function () {
|
|
|
|
this.$element.hide();
|
|
|
|
},
|
2011-12-14 18:04:42 +00:00
|
|
|
do_push_state: function(state) {
|
|
|
|
if (this.widget_parent && this.widget_parent.do_push_state) {
|
|
|
|
this.widget_parent.do_push_state(state);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
do_load_state: function(state) {
|
|
|
|
},
|
2011-12-07 10:45:03 +00:00
|
|
|
/**
|
|
|
|
* Switches to a specific view type
|
|
|
|
*
|
|
|
|
* @param {String} view view type to switch to
|
|
|
|
*/
|
2011-12-14 17:18:11 +00:00
|
|
|
do_switch_view: function(view) {
|
|
|
|
},
|
2011-12-07 10:45:03 +00:00
|
|
|
/**
|
|
|
|
* Cancels the switch to the current view, switches to the previous one
|
|
|
|
*/
|
2011-12-14 17:18:11 +00:00
|
|
|
do_prev_view: function () {
|
|
|
|
},
|
2011-09-28 10:44:58 +00:00
|
|
|
do_search: function(view) {
|
|
|
|
},
|
2011-07-28 15:15:45 +00:00
|
|
|
set_common_sidebar_sections: function(sidebar) {
|
2011-10-10 12:34:32 +00:00
|
|
|
sidebar.add_default_sections();
|
2011-07-28 15:15:45 +00:00
|
|
|
},
|
2011-07-28 16:18:53 +00:00
|
|
|
on_sidebar_import: function() {
|
2011-10-24 22:54:31 +00:00
|
|
|
var import_view = new session.web.DataImport(this, this.dataset);
|
2011-09-08 10:24:00 +00:00
|
|
|
import_view.start();
|
2011-07-28 16:18:53 +00:00
|
|
|
},
|
|
|
|
on_sidebar_export: function() {
|
2011-10-24 22:54:31 +00:00
|
|
|
var export_view = new session.web.DataExport(this, this.dataset);
|
2011-08-10 12:05:48 +00:00
|
|
|
export_view.start();
|
2011-07-28 16:18:53 +00:00
|
|
|
},
|
|
|
|
on_sidebar_translate: function() {
|
2011-11-09 10:47:00 +00:00
|
|
|
return this.do_action({
|
|
|
|
res_model : 'ir.translation',
|
|
|
|
domain : [['type', '!=', 'object'], '|', ['name', '=', this.dataset.model], ['name', 'ilike', this.dataset.model + ',']],
|
|
|
|
views: [[false, 'list'], [false, 'form']],
|
|
|
|
type : 'ir.actions.act_window',
|
|
|
|
view_type : "list",
|
|
|
|
view_mode : "list"
|
|
|
|
});
|
2011-07-28 16:18:53 +00:00
|
|
|
},
|
|
|
|
on_sidebar_view_log: function() {
|
2011-11-21 14:09:08 +00:00
|
|
|
},
|
|
|
|
sidebar_context: function () {
|
2011-12-21 14:19:53 +00:00
|
|
|
return $.when();
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Asks the view to reload itself, if the reloading is asynchronous should
|
|
|
|
* return a {$.Deferred} indicating when the reloading is done.
|
|
|
|
*/
|
|
|
|
reload: function () {
|
|
|
|
return $.when();
|
2011-04-01 09:40:30 +00:00
|
|
|
}
|
2011-03-30 14:00:48 +00:00
|
|
|
});
|
|
|
|
|
2011-10-25 16:35:31 +00:00
|
|
|
session.web.json_node_to_xml = function(node, human_readable, indent) {
|
2011-06-22 11:11:29 +00:00
|
|
|
// For debugging purpose, this function will convert a json node back to xml
|
|
|
|
// Maybe usefull for xml view editor
|
2011-10-25 16:35:31 +00:00
|
|
|
indent = indent || 0;
|
|
|
|
var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''),
|
|
|
|
r = sindent + '<' + node.tag,
|
|
|
|
cr = human_readable ? '\n' : '';
|
2011-07-29 09:04:30 +00:00
|
|
|
|
|
|
|
if (typeof(node) === 'string') {
|
2011-10-25 16:35:31 +00:00
|
|
|
return sindent + node;
|
|
|
|
} else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
|
2011-06-22 11:11:29 +00:00
|
|
|
throw("Node a json node");
|
|
|
|
}
|
|
|
|
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, '"');
|
2011-10-25 16:35:31 +00:00
|
|
|
if (human_readable) {
|
2011-06-22 11:11:29 +00:00
|
|
|
vattr = vattr.replace(/"/g, "'");
|
|
|
|
}
|
|
|
|
r += ' ' + attr + '="' + vattr + '"';
|
|
|
|
}
|
2011-09-05 14:15:45 +00:00
|
|
|
if (node.children && node.children.length) {
|
2011-10-25 16:35:31 +00:00
|
|
|
r += '>' + cr;
|
2011-06-22 11:11:29 +00:00
|
|
|
var childs = [];
|
|
|
|
for (var i = 0, ii = node.children.length; i < ii; i++) {
|
2011-10-25 16:35:31 +00:00
|
|
|
childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
|
2011-06-22 11:11:29 +00:00
|
|
|
}
|
2011-10-25 16:35:31 +00:00
|
|
|
r += childs.join(cr);
|
|
|
|
r += cr + sindent + '</' + node.tag + '>';
|
2011-06-22 11:11:29 +00:00
|
|
|
return r;
|
|
|
|
} else {
|
|
|
|
return r + '/>';
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2011-03-30 14:00:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|