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
|
|
|
*---------------------------------------------------------*/
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
openerp.web.views = function(instance) {
|
|
|
|
var QWeb = instance.web.qweb,
|
|
|
|
_t = instance.web._t;
|
2011-08-24 15:13:57 +00:00
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.ActionManager = instance.web.Widget.extend({
|
2011-08-10 00:38:57 +00:00
|
|
|
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 01:34:48 +00:00
|
|
|
dialog_stop: function () {
|
2011-08-10 00:38:57 +00:00
|
|
|
if (this.dialog) {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.dialog_viewmanager.destroy();
|
2011-08-10 01:34:48 +00:00
|
|
|
this.dialog_viewmanager = null;
|
2012-02-21 16:29:12 +00:00
|
|
|
this.dialog.destroy();
|
2011-08-10 00:38:57 +00:00
|
|
|
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) {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.inner_viewmanager.destroy();
|
2011-08-10 01:34:48 +00:00
|
|
|
this.inner_viewmanager = null;
|
|
|
|
}
|
2011-08-19 14:39:47 +00:00
|
|
|
if (this.client_widget) {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.client_widget.destroy();
|
2011-08-19 14:39:47 +00:00
|
|
|
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) {
|
2012-02-21 15:30:23 +00:00
|
|
|
if (this.getParent() && this.getParent().do_push_state) {
|
2011-12-21 14:18:26 +00:00
|
|
|
if (this.inner_action) {
|
2012-03-08 16:52:25 +00:00
|
|
|
state['title'] = this.inner_action.name;
|
2012-01-27 13:24:38 +00:00
|
|
|
state['model'] = this.inner_action.res_model;
|
2011-12-21 14:18:26 +00:00
|
|
|
if (this.inner_action.id) {
|
|
|
|
state['action_id'] = this.inner_action.id;
|
|
|
|
}
|
2011-12-14 16:09:58 +00:00
|
|
|
}
|
2012-02-21 15:30:23 +00:00
|
|
|
this.getParent().do_push_state(state);
|
2011-12-14 16:09:58 +00:00
|
|
|
}
|
2011-12-12 14:20:12 +00:00
|
|
|
},
|
2012-02-01 15:44:42 +00:00
|
|
|
do_load_state: function(state, warm) {
|
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);
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.webclient.menu.has_been_loaded.then(function() {
|
|
|
|
instance.webclient.menu.open_action(state.action_id);
|
2012-02-29 13:02:35 +00:00
|
|
|
});
|
2011-12-15 14:29:39 +00:00
|
|
|
}
|
2012-01-27 13:24:38 +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',
|
2012-04-09 20:53:34 +00:00
|
|
|
views: [[false, 'form']]
|
2011-12-21 14:18:26 +00:00
|
|
|
};
|
|
|
|
action_loaded = this.do_action(action);
|
2012-01-31 20:51:52 +00:00
|
|
|
} else if (state.sa) {
|
2012-01-13 11:36:08 +00:00
|
|
|
// load session action
|
|
|
|
var self = this;
|
|
|
|
this.null_action();
|
|
|
|
action_loaded = this.rpc('/web/session/get_session_action', {key: state.sa}).pipe(function(action) {
|
|
|
|
if (action) {
|
|
|
|
return self.do_action(action);
|
|
|
|
}
|
|
|
|
});
|
2012-01-27 13:24:38 +00:00
|
|
|
} else if (state.client_action) {
|
2011-12-13 10:41:00 +00:00
|
|
|
this.null_action();
|
2012-06-14 16:41:41 +00:00
|
|
|
var action = state.client_action;
|
|
|
|
if(_.isString(action)) {
|
|
|
|
action = {
|
|
|
|
tag: action,
|
2012-06-14 16:53:45 +00:00
|
|
|
params: state,
|
2012-06-14 16:41:41 +00:00
|
|
|
};
|
|
|
|
}
|
|
|
|
this.ir_actions_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) {
|
2012-02-01 15:44:42 +00:00
|
|
|
self.inner_viewmanager.do_load_state(state, warm);
|
2011-12-15 14:29:39 +00:00
|
|
|
}
|
|
|
|
});
|
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';
|
2012-04-05 10:18:23 +00:00
|
|
|
var inline = action.target === 'inline';
|
2011-05-11 13:36:55 +00:00
|
|
|
action.flags = _.extend({
|
2012-04-05 10:18:23 +00:00
|
|
|
views_switcher : !popup && !inline,
|
|
|
|
search_view : !popup && !inline,
|
|
|
|
action_buttons : !popup && !inline,
|
|
|
|
sidebar : !popup && !inline,
|
|
|
|
pager : !popup && !inline,
|
2012-01-09 10:58:32 +00:00
|
|
|
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 () {
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.webclient.do_reload().then(old_close);
|
2011-11-28 14:47:26 +00:00
|
|
|
};
|
|
|
|
}
|
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-04-17 12:15:59 +00:00
|
|
|
this.dialog = new instance.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 00:38:57 +00:00
|
|
|
} else {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.dialog_viewmanager.destroy();
|
2011-07-14 10:22:43 +00:00
|
|
|
}
|
2012-01-10 10:02:49 +00:00
|
|
|
this.dialog.dialog_title = action.name;
|
2012-04-17 12:15:59 +00:00
|
|
|
this.dialog_viewmanager = new instance.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 {
|
2012-04-25 10:11:50 +00:00
|
|
|
this.dialog_stop();
|
|
|
|
this.content_stop();
|
2011-12-21 11:49:04 +00:00
|
|
|
if(action.menu_id) {
|
2012-02-21 15:30:23 +00:00
|
|
|
return this.getParent().do_action(action, function () {
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.webclient.menu.open_menu(action.menu_id);
|
2011-12-22 15:34:49 +00:00
|
|
|
});
|
2011-12-21 11:49:04 +00:00
|
|
|
}
|
2011-12-13 14:26:08 +00:00
|
|
|
this.inner_action = action;
|
2012-04-17 12:15:59 +00:00
|
|
|
this.inner_viewmanager = new instance.web.ViewManagerAction(this, action);
|
2011-08-10 00:38:57 +00:00
|
|
|
this.inner_viewmanager.appendTo(this.$element);
|
2012-06-15 15:54:25 +00:00
|
|
|
this.inner_viewmanager.$element.addClass("oe_view_manager_global");
|
2011-08-10 00:38:57 +00:00
|
|
|
}
|
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();
|
2012-04-17 12:15:59 +00:00
|
|
|
var ClientWidget = instance.web.client_actions.get_object(action.tag);
|
2012-02-29 13:18:26 +00:00
|
|
|
(this.client_widget = new ClientWidget(this, action.params)).appendTo(this.$element);
|
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();
|
2012-01-19 14:48:37 +00:00
|
|
|
},
|
2012-04-17 12:15:59 +00:00
|
|
|
error: instance.webclient.crashmanager.on_rpc_error
|
2011-11-21 09:14:51 +00:00
|
|
|
})
|
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) {
|
2012-02-21 15:30:23 +00:00
|
|
|
this.getParent().do_action(action);
|
2011-07-19 10:27:07 +00:00
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.ViewManager = instance.web.Widget.extend({
|
2011-09-12 10:53:25 +00:00
|
|
|
template: "ViewManager",
|
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) {
|
2012-04-17 12:15:59 +00:00
|
|
|
var View = instance.web.views.get_object(x[1], true);
|
2011-12-16 11:20:54 +00:00
|
|
|
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 || {};
|
2012-04-17 12:15:59 +00:00
|
|
|
this.registry = instance.web.views;
|
2011-12-07 10:45:03 +00:00
|
|
|
this.views_history = [];
|
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;
|
2012-04-09 22:10:56 +00:00
|
|
|
this.$element.find('.oe_view_manager_switch a').click(function() {
|
2011-04-05 10:10:08 +00:00
|
|
|
self.on_mode_switch($(this).data('view-type'));
|
2012-04-27 22:33:54 +00:00
|
|
|
}).tipsy();
|
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({
|
2012-04-09 18:44:45 +00:00
|
|
|
$buttons : self.$element.find('.oe_view_manager_buttons'),
|
2012-04-19 14:28:14 +00:00
|
|
|
$sidebar : self.flags.sidebar ? self.$element.find('.oe_view_manager_sidebar') : undefined,
|
2012-04-09 18:44:45 +00:00
|
|
|
$pager : self.$element.find('.oe_view_manager_pager'),
|
2011-08-08 17:32:30 +00:00
|
|
|
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) {
|
2012-04-09 19:31:37 +00:00
|
|
|
this.$element.find('.oe_view_manager_switch').hide();
|
2011-05-17 09:26:27 +00:00
|
|
|
}
|
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
|
|
|
|
*/
|
2012-06-07 16:08:01 +00:00
|
|
|
on_mode_switch: function(view_type, no_store, view_options) {
|
2012-04-09 18:44:45 +00:00
|
|
|
var self = this;
|
|
|
|
var view = this.views[view_type];
|
|
|
|
var 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);
|
2012-04-10 10:14:15 +00:00
|
|
|
var options = _.clone(view.options);
|
2012-04-18 15:17:05 +00:00
|
|
|
if (view_type === "form" && this.action) {
|
2012-04-10 10:14:15 +00:00
|
|
|
switch (this.action.target) {
|
|
|
|
case 'new':
|
|
|
|
case 'inline':
|
|
|
|
options.initial_mode = 'edit';
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
var controller = new controllerclass(this, this.dataset, view.view_id, options);
|
2011-06-06 07:04:51 +00:00
|
|
|
if (view.embedded_view) {
|
|
|
|
controller.set_embedded_view(view.embedded_view);
|
|
|
|
}
|
2012-05-16 10:16:34 +00:00
|
|
|
controller.do_switch_view.add_last(_.bind(this.switch_view, this));
|
2011-12-07 10:45:03 +00:00
|
|
|
controller.do_prev_view.add_last(this.on_prev_view);
|
2012-04-09 23:44:40 +00:00
|
|
|
var container = this.$element.find(".oe_view_manager_view_" + view_type);
|
2011-09-14 14:30:28 +00:00
|
|
|
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);
|
2012-01-18 14:48:26 +00:00
|
|
|
if (self.searchview
|
2012-01-25 14:19:45 +00:00
|
|
|
&& self.flags.auto_search
|
2012-01-18 14:48:26 +00:00
|
|
|
&& 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
|
|
|
});
|
2012-01-18 14:48:26 +00:00
|
|
|
} else if (this.searchview
|
2012-01-25 14:19:45 +00:00
|
|
|
&& self.flags.auto_search
|
2012-01-18 14:48:26 +00:00
|
|
|
&& 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
|
2012-06-18 11:36:59 +00:00
|
|
|
.find('.oe_view_manager_switch a').parent().removeClass('active');
|
2012-04-09 22:10:56 +00:00
|
|
|
this.$element
|
|
|
|
.find('.oe_view_manager_switch a').filter('[data-view-type="' + view_type + '"]')
|
|
|
|
.parent().addClass('active');
|
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) {
|
2012-06-18 11:36:59 +00:00
|
|
|
var container = self.$element.find(".oe_view_manager_view_" + view_name + ":first");
|
2011-12-20 17:37:42 +00:00
|
|
|
if (view_name === view_type) {
|
2012-06-18 11:36:59 +00:00
|
|
|
container.show();
|
2012-06-07 16:08:01 +00:00
|
|
|
controller.do_show(view_options || {});
|
2011-12-20 17:37:42 +00:00
|
|
|
} else {
|
2012-06-18 11:36:59 +00:00
|
|
|
container.hide();
|
2011-12-20 17:37:42 +00:00
|
|
|
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
|
|
|
},
|
2012-05-16 10:52:51 +00:00
|
|
|
/**
|
|
|
|
* Method used internally when a view asks to switch view. This method is meant
|
|
|
|
* to be extended by child classes to change the default behavior, which simply
|
|
|
|
* consist to switch to the asked view.
|
|
|
|
*/
|
2012-06-07 16:08:01 +00:00
|
|
|
switch_view: function(view_type, no_store, options) {
|
|
|
|
return this.on_mode_switch(view_type, no_store, options);
|
2012-05-16 10:16:34 +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)
|
|
|
|
*
|
2012-01-24 09:30:33 +00:00
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {Boolean} [options.created=false] resource was created
|
|
|
|
* @param {String} [options.default=null] view to switch to if no previous view
|
2011-12-07 15:31:01 +00:00
|
|
|
* @returns {$.Deferred} switching end signal
|
|
|
|
*/
|
2012-01-24 09:30:33 +00:00
|
|
|
on_prev_view: function (options) {
|
2012-04-18 15:58:31 +00:00
|
|
|
options = options || {};
|
2011-12-07 15:31:01 +00:00
|
|
|
var current_view = this.views_history.pop();
|
2012-01-24 09:30:33 +00:00
|
|
|
var previous_view = this.views_history[this.views_history.length - 1] || options['default'];
|
|
|
|
if (options.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)"
|
2012-04-09 20:53:34 +00:00
|
|
|
return this.on_mode_switch('form');
|
2012-01-24 09:30:33 +00:00
|
|
|
} else if (options.created && !previous_view && this.action && this.action.flags.default_view === 'form') {
|
2012-01-09 14:15:34 +00:00
|
|
|
// APR special case: "If creation from dashboard, we have no previous view
|
2012-04-09 20:53:34 +00:00
|
|
|
return this.on_mode_switch('form');
|
2011-12-07 15:31:01 +00:00
|
|
|
}
|
|
|
|
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) {
|
2012-02-21 16:29:12 +00:00
|
|
|
this.searchview.destroy();
|
2011-09-28 15:32:54 +00:00
|
|
|
}
|
2012-04-17 12:15:59 +00:00
|
|
|
this.searchview = new instance.web.SearchView(this, this.dataset, view_id, search_defaults, this.flags.search_view === false);
|
2011-09-28 15:32:54 +00:00
|
|
|
|
|
|
|
this.searchview.on_search.add(this.do_searchview_search);
|
2012-04-09 23:44:40 +00:00
|
|
|
return this.searchview.appendTo(this.$element.find(".oe_view_manager_view_search"));
|
2011-09-28 15:32:54 +00:00
|
|
|
},
|
|
|
|
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) {
|
2012-04-23 09:02:32 +00:00
|
|
|
self.dataset._model = new instance.web.Model(
|
|
|
|
self.dataset.model, results.context, results.domain);
|
2011-12-12 14:16:56 +00:00
|
|
|
var groupby = results.group_by.length
|
|
|
|
? results.group_by
|
|
|
|
: action_context.group_by;
|
2012-03-06 20:59:55 +00:00
|
|
|
if (_.isString(groupby)) {
|
|
|
|
groupby = [groupby];
|
|
|
|
}
|
2011-12-12 14:16:56 +00:00
|
|
|
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
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.ViewManagerAction = instance.web.ViewManager.extend({
|
2011-09-13 06:33:46 +00:00
|
|
|
template:"ViewManagerAction",
|
2011-09-13 06:32:38 +00:00
|
|
|
/**
|
2012-04-17 12:15:59 +00:00
|
|
|
* @constructs instance.web.ViewManagerAction
|
|
|
|
* @extends instance.web.ViewManager
|
2011-09-13 06:32:38 +00:00
|
|
|
*
|
2012-04-17 12:15:59 +00:00
|
|
|
* @param {instance.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 || {};
|
2012-01-25 14:20:43 +00:00
|
|
|
if (!('auto_search' in flags)) {
|
|
|
|
flags.auto_search = action.auto_search !== false;
|
|
|
|
}
|
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;
|
2012-04-17 12:15:59 +00:00
|
|
|
var dataset = new instance.web.DataSetSearch(this, action.res_model, action.context, action.domain);
|
2011-12-14 15:29:03 +00:00
|
|
|
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) {
|
2012-04-17 12:15:59 +00:00
|
|
|
var Users = new instance.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-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-04-17 12:15:59 +00:00
|
|
|
var dialog = new instance.web.Dialog(this, { title: _t("Fields View Get"), width: '95%' }).open();
|
|
|
|
$('<pre>').text(instance.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-24 17:01:11 +00:00
|
|
|
case 'perm_read':
|
|
|
|
var ids = current_view.get_selected_ids();
|
|
|
|
if (ids.length === 1) {
|
|
|
|
this.dataset.call('perm_read', [ids]).then(function(result) {
|
2012-04-17 12:15:59 +00:00
|
|
|
var dialog = new instance.web.Dialog(this, {
|
2012-01-24 17:01:11 +00:00
|
|
|
title: _.str.sprintf(_t("View Log (%s)"), self.dataset.model),
|
|
|
|
width: 400
|
|
|
|
}, QWeb.render('ViewManagerDebugViewLog', {
|
|
|
|
perm : result[0],
|
2012-04-17 12:15:59 +00:00
|
|
|
format : instance.web.format_value
|
2012-01-24 17:01:11 +00:00
|
|
|
})).open();
|
|
|
|
});
|
|
|
|
}
|
|
|
|
break;
|
2012-04-10 11:28:34 +00:00
|
|
|
case 'toggle_layout_outline':
|
|
|
|
current_view.rendering_engine.toggle_layout_debugging();
|
|
|
|
break;
|
2012-01-13 17:54:05 +00:00
|
|
|
case 'fields':
|
|
|
|
this.dataset.call_and_eval(
|
|
|
|
'fields_get', [false, {}], null, 1).then(function (fields) {
|
|
|
|
var $root = $('<dl>');
|
|
|
|
_(fields).each(function (attributes, name) {
|
|
|
|
$root.append($('<dt>').append($('<h4>').text(name)));
|
|
|
|
var $attrs = $('<dl>').appendTo(
|
|
|
|
$('<dd>').appendTo($root));
|
|
|
|
_(attributes).each(function (def, name) {
|
|
|
|
if (def instanceof Object) {
|
|
|
|
def = JSON.stringify(def);
|
|
|
|
}
|
|
|
|
$attrs
|
|
|
|
.append($('<dt>').text(name))
|
|
|
|
.append($('<dd style="white-space: pre-wrap;">').text(def));
|
|
|
|
});
|
|
|
|
});
|
2012-04-17 12:15:59 +00:00
|
|
|
new instance.web.Dialog(self, {
|
2012-01-13 17:54:05 +00:00
|
|
|
title: _.str.sprintf(_t("Model %s fields"),
|
|
|
|
self.dataset.model),
|
|
|
|
width: '95%'}, $root).open();
|
|
|
|
});
|
|
|
|
break;
|
2012-01-10 11:23:28 +00:00
|
|
|
case 'manage_views':
|
|
|
|
if (current_view.fields_view && current_view.fields_view.arch) {
|
2012-04-17 12:15:59 +00:00
|
|
|
var view_editor = new instance.web.ViewEditor(current_view, current_view.$element, this.dataset, current_view.fields_view.arch);
|
2012-01-10 11:23:28 +00:00
|
|
|
view_editor.start();
|
|
|
|
} else {
|
2012-01-13 17:55:29 +00:00
|
|
|
this.do_warn(_t("Manage Views"),
|
|
|
|
_t("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;
|
2012-05-18 14:00:01 +00:00
|
|
|
case 'manage_filters':
|
|
|
|
this.do_action({
|
|
|
|
res_model: 'ir.filters',
|
|
|
|
views: [[false, 'list'], [false, 'form']],
|
|
|
|
type: 'ir.actions.act_window',
|
|
|
|
context: {
|
|
|
|
search_default_my_filters: true,
|
|
|
|
search_default_model_id: this.dataset.model
|
|
|
|
}
|
|
|
|
});
|
|
|
|
break;
|
2011-12-13 11:35:21 +00:00
|
|
|
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);
|
|
|
|
},
|
2012-06-07 16:08:01 +00:00
|
|
|
on_mode_switch: function (view_type, no_store, options) {
|
2011-09-14 09:13:19 +00:00
|
|
|
var self = this;
|
2011-12-09 14:46:38 +00:00
|
|
|
|
2012-06-07 16:08:01 +00:00
|
|
|
return $.when(this._super.apply(this, arguments)).then(function () {
|
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);
|
|
|
|
}
|
|
|
|
|
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) {
|
2012-02-21 15:30:23 +00:00
|
|
|
if (this.getParent() && this.getParent().do_push_state) {
|
2011-12-14 18:04:42 +00:00
|
|
|
state["view_type"] = this.active_view;
|
2012-02-21 15:30:23 +00:00
|
|
|
this.getParent().do_push_state(state);
|
2011-12-14 16:09:58 +00:00
|
|
|
}
|
2011-12-12 14:20:12 +00:00
|
|
|
},
|
2012-02-01 15:44:42 +00:00
|
|
|
do_load_state: function(state, warm) {
|
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() {
|
2012-02-01 15:44:42 +00:00
|
|
|
self.views[self.active_view].controller.do_load_state(state, warm);
|
2011-12-12 16:44:55 +00:00
|
|
|
});
|
2011-12-12 14:20:12 +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
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.Sidebar = instance.web.Widget.extend({
|
2012-04-01 23:12:12 +00:00
|
|
|
init: function(parent) {
|
2012-06-13 14:10:16 +00:00
|
|
|
var self = this;
|
2012-04-01 23:12:12 +00:00
|
|
|
this._super(parent);
|
2012-04-09 13:14:38 +00:00
|
|
|
var view = this.getParent();
|
|
|
|
this.sections = [
|
|
|
|
{ 'name' : 'print', 'label' : _t('Print'), },
|
2012-05-09 13:42:00 +00:00
|
|
|
{ 'name' : 'files', 'label' : _t('Attachment'), },
|
2012-04-09 13:14:38 +00:00
|
|
|
{ 'name' : 'other', 'label' : _t('More'), }
|
|
|
|
];
|
|
|
|
this.items = {
|
|
|
|
'print' : [],
|
|
|
|
'files' : [],
|
2012-06-07 14:39:26 +00:00
|
|
|
'other' : []
|
|
|
|
};
|
2012-04-09 13:14:38 +00:00
|
|
|
if (this.session.uid === 1) {
|
|
|
|
var item = { label: _t("Translate"), callback: view.on_sidebar_translate, title: _t("Technical translation") };
|
|
|
|
this.items.other.push(item);
|
|
|
|
}
|
2012-06-13 14:10:16 +00:00
|
|
|
this.fileupload_id = _.uniqueId('oe_fileupload');
|
|
|
|
$(window).on(this.fileupload_id, function() {
|
|
|
|
var args = [].slice.call(arguments).slice(1);
|
|
|
|
if (args[0] && args[0].error) {
|
|
|
|
alert(args[0].error);
|
|
|
|
} else {
|
|
|
|
self.do_attachement_update(self.dataset, self.model_id);
|
|
|
|
}
|
|
|
|
$.unblockUI();
|
|
|
|
});
|
2011-04-04 16:08:13 +00:00
|
|
|
},
|
2011-07-26 21:00:05 +00:00
|
|
|
start: function() {
|
2012-04-02 15:56:50 +00:00
|
|
|
var self = this;
|
2011-08-26 12:44:18 +00:00
|
|
|
this._super(this);
|
2012-04-09 13:14:38 +00:00
|
|
|
this.redraw();
|
2012-06-20 15:14:53 +00:00
|
|
|
this.$element.on('click','.oe_dropdown_menu li a', function(event) {
|
2012-04-09 13:14:38 +00:00
|
|
|
var section = $(this).data('section');
|
|
|
|
var index = $(this).data('index');
|
|
|
|
var item = self.items[section][index];
|
|
|
|
if (item.callback) {
|
|
|
|
item.callback.apply(self, [item]);
|
2012-04-17 01:19:33 +00:00
|
|
|
} else if (item.action) {
|
2012-04-09 13:14:38 +00:00
|
|
|
self.on_item_action_clicked(item);
|
2012-04-17 01:19:33 +00:00
|
|
|
} else if (item.url) {
|
|
|
|
return true;
|
2012-04-09 13:14:38 +00:00
|
|
|
}
|
2012-06-20 10:21:26 +00:00
|
|
|
event.preventDefault();
|
2012-04-02 15:56:50 +00:00
|
|
|
});
|
2011-07-26 21:00:05 +00:00
|
|
|
},
|
2012-04-09 13:14:38 +00:00
|
|
|
redraw: function() {
|
|
|
|
var self = this;
|
|
|
|
self.$element.html(QWeb.render('Sidebar', {widget: self}));
|
2012-06-07 14:49:35 +00:00
|
|
|
|
|
|
|
// Hides Sidebar sections when item list is empty
|
|
|
|
this.$('.oe_form_dropdown_section').each(function() {
|
|
|
|
$(this).toggle(!!$(this).find('li').length);
|
|
|
|
});
|
2012-04-09 13:14:38 +00:00
|
|
|
},
|
2012-02-08 12:21:53 +00:00
|
|
|
/**
|
|
|
|
* For each item added to the section:
|
|
|
|
*
|
|
|
|
* ``label``
|
2012-04-09 13:14:38 +00:00
|
|
|
* will be used as the item's name in the sidebar, can be html
|
2012-02-08 12:21:53 +00:00
|
|
|
*
|
|
|
|
* ``action``
|
|
|
|
* descriptor for the action which will be executed, ``action`` and
|
|
|
|
* ``callback`` should be exclusive
|
|
|
|
*
|
|
|
|
* ``callback``
|
|
|
|
* function to call when the item is clicked in the sidebar, called
|
|
|
|
* with the item descriptor as its first argument (so information
|
|
|
|
* can be stored as additional keys on the object passed to
|
|
|
|
* ``add_items``)
|
|
|
|
*
|
|
|
|
* ``classname`` (optional)
|
|
|
|
* ``@class`` set on the sidebar serialization of the item
|
|
|
|
*
|
|
|
|
* ``title`` (optional)
|
|
|
|
* will be set as the item's ``@title`` (tooltip)
|
|
|
|
*
|
|
|
|
* @param {String} section_code
|
|
|
|
* @param {Array<{label, action | callback[, classname][, title]}>} items
|
|
|
|
*/
|
2011-10-12 09:54:26 +00:00
|
|
|
add_items: function(section_code, items) {
|
2012-04-09 13:14:38 +00:00
|
|
|
var self = this;
|
2011-07-26 21:00:05 +00:00
|
|
|
if (items) {
|
2012-04-09 18:44:45 +00:00
|
|
|
this.items[section_code].push.apply(this.items[section_code],items);
|
2012-04-09 13:14:38 +00:00
|
|
|
this.redraw();
|
2011-07-26 21:00:05 +00:00
|
|
|
}
|
|
|
|
},
|
2012-04-27 23:18:52 +00:00
|
|
|
add_toolbar: function(toolbar) {
|
|
|
|
var self = this;
|
|
|
|
_.each(['print','action','relate'], function(type) {
|
|
|
|
var items = toolbar[type];
|
|
|
|
if (items) {
|
|
|
|
for (var i = 0; i < items.length; i++) {
|
|
|
|
items[i] = {
|
|
|
|
label: items[i]['name'],
|
|
|
|
action: items[i],
|
|
|
|
classname: 'oe_sidebar_' + type
|
|
|
|
}
|
|
|
|
}
|
|
|
|
self.add_items(type=='print' ? 'print' : 'other', items);
|
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2011-11-14 11:02:39 +00:00
|
|
|
on_item_action_clicked: function(item) {
|
|
|
|
var self = this;
|
2012-02-21 15:30:23 +00:00
|
|
|
self.getParent().sidebar_context().then(function (context) {
|
|
|
|
var ids = self.getParent().get_selected_ids();
|
2011-11-21 16:34:41 +00:00
|
|
|
if (ids.length == 0) {
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.dialog($("<div />").text(_t("You must choose at least one record.")), { title: _t("Warning"), modal: true });
|
2011-11-21 16:34:41 +00:00
|
|
|
return false;
|
|
|
|
}
|
2011-11-21 14:09:08 +00:00
|
|
|
var additional_context = _.extend({
|
|
|
|
active_id: ids[0],
|
|
|
|
active_ids: ids,
|
2012-02-21 15:30:23 +00:00
|
|
|
active_model: self.getParent().dataset.model
|
2011-11-21 14:09:08 +00:00
|
|
|
}, 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
|
2012-02-21 15:30:23 +00:00
|
|
|
self.getParent().reload();
|
2011-12-21 14:19:53 +00:00
|
|
|
});
|
2011-11-21 14:09:08 +00:00
|
|
|
});
|
2011-11-14 11:02:39 +00:00
|
|
|
});
|
|
|
|
},
|
2012-04-17 01:19:33 +00:00
|
|
|
do_attachement_update: function(dataset, model_id) {
|
2012-06-13 14:10:16 +00:00
|
|
|
this.dataset = dataset;
|
|
|
|
this.model_id = model_id;
|
2012-04-17 01:19:33 +00:00
|
|
|
if (!model_id) {
|
|
|
|
this.on_attachments_loaded([]);
|
|
|
|
} else {
|
|
|
|
var dom = [ ['res_model', '=', dataset.model], ['res_id', '=', model_id], ['type', 'in', ['binary', 'url']] ];
|
2012-04-17 12:15:59 +00:00
|
|
|
var ds = new instance.web.DataSetSearch(this, 'ir.attachment', dataset.get_context(), dom);
|
2012-04-17 01:19:33 +00:00
|
|
|
ds.read_slice(['name', 'url', 'type'], {}).then(this.on_attachments_loaded);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
on_attachments_loaded: function(attachments) {
|
|
|
|
var self = this;
|
|
|
|
var items = [];
|
2012-06-13 14:10:16 +00:00
|
|
|
var prefix = this.session.origin + '/web/binary/saveas?session_id=' + self.session.session_id + '&model=ir.attachment&field=datas&filename_field=name&id=';
|
2012-04-17 01:19:33 +00:00
|
|
|
_.each(attachments,function(a) {
|
|
|
|
a.label = a.name;
|
|
|
|
if(a.type === "binary") {
|
|
|
|
a.url = prefix + a.id + '&t=' + (new Date().getTime());
|
|
|
|
}
|
|
|
|
});
|
2012-04-17 01:43:23 +00:00
|
|
|
self.items['files'] = attachments;
|
|
|
|
self.redraw();
|
2012-06-13 14:10:16 +00:00
|
|
|
this.$('.oe_sidebar_add_attachment .oe-binary-file').change(this.on_attachment_changed);
|
2012-06-13 16:17:12 +00:00
|
|
|
this.$element.find('.oe_sidebar_delete_item').click(this.on_attachment_delete);
|
2012-04-17 01:19:33 +00:00
|
|
|
},
|
|
|
|
on_attachment_changed: function(e) {
|
|
|
|
var $e = $(e.target);
|
2012-06-13 14:10:16 +00:00
|
|
|
if ($e.val() !== '') {
|
2012-04-17 01:19:33 +00:00
|
|
|
this.$element.find('form.oe-binary-form').submit();
|
|
|
|
$e.parent().find('input[type=file]').prop('disabled', true);
|
|
|
|
$e.parent().find('button').prop('disabled', true).find('img, span').toggle();
|
2012-06-13 14:10:16 +00:00
|
|
|
this.$('.oe_sidebar_add_attachment span').text(_t('Uploading...'));
|
|
|
|
$.blockUI();
|
2012-04-17 01:19:33 +00:00
|
|
|
}
|
|
|
|
},
|
|
|
|
on_attachment_delete: function(e) {
|
2012-06-13 16:17:12 +00:00
|
|
|
var self = this;
|
|
|
|
e.preventDefault();
|
|
|
|
e.stopPropagation();
|
|
|
|
var self = this;
|
|
|
|
var $e = $(e.currentTarget);
|
|
|
|
if (confirm(_t("Do you really want to delete this attachment ?"))) {
|
|
|
|
(new instance.web.DataSet(this, 'ir.attachment')).unlink([parseInt($e.attr('data-id'), 10)]).then(function() {
|
|
|
|
self.do_attachement_update(self.dataset, self.model_id);
|
2012-04-17 01:19:33 +00:00
|
|
|
});
|
|
|
|
}
|
|
|
|
}
|
2011-04-01 12:10:42 +00:00
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.TranslateDialog = instance.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;
|
2012-05-16 05:52:37 +00:00
|
|
|
this['on_button_' + _t("Save")] = this.on_btn_save;
|
|
|
|
this['on_button_' + _t("Close")] = this.on_btn_close;
|
2011-08-24 15:13:57 +00:00
|
|
|
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();
|
2012-04-17 12:15:59 +00:00
|
|
|
(new instance.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
|
2012-01-10 16:54:51 +00:00
|
|
|
[['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }).then(this.on_languages_loaded);
|
2011-08-24 15:13:57 +00:00
|
|
|
},
|
|
|
|
start: function() {
|
|
|
|
var self = this;
|
|
|
|
this._super();
|
|
|
|
$.when(this.languages_loaded).then(function() {
|
2012-04-17 12:15:59 +00:00
|
|
|
self.$element.html(instance.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
|
|
|
}
|
|
|
|
});
|
|
|
|
},
|
2012-05-16 05:52:37 +00:00
|
|
|
on_btn_save: function() {
|
2011-08-29 14:08:39 +00:00
|
|
|
var trads = {},
|
2012-02-14 14:01:15 +00:00
|
|
|
self = this,
|
|
|
|
trads_mutex = new $.Mutex();
|
2011-08-29 14:08:39 +00:00
|
|
|
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);
|
2012-02-14 14:01:15 +00:00
|
|
|
});
|
2011-08-29 14:08:39 +00:00
|
|
|
}
|
2012-02-14 17:05:13 +00:00
|
|
|
trads_mutex.exec(function() {
|
|
|
|
return self.view.dataset.write(self.view.datarecord.id, data, { context : { 'lang': code } });
|
|
|
|
});
|
2011-08-29 14:08:39 +00:00
|
|
|
});
|
2011-08-24 15:13:57 +00:00
|
|
|
this.close();
|
|
|
|
},
|
2012-05-16 05:52:37 +00:00
|
|
|
on_btn_close: function() {
|
2011-08-24 15:13:57 +00:00
|
|
|
this.close();
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.View = instance.web.Widget.extend({
|
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: '',
|
2012-04-05 16:03:15 +00:00
|
|
|
/**
|
|
|
|
* Define a view type for each view to allow automatic call to fields_view_get.
|
|
|
|
*/
|
|
|
|
view_type: undefined,
|
2012-01-18 13:06:52 +00:00
|
|
|
init: function(parent, dataset, view_id, options) {
|
|
|
|
this._super(parent);
|
|
|
|
this.dataset = dataset;
|
|
|
|
this.view_id = view_id;
|
|
|
|
this.set_default_options(options);
|
|
|
|
},
|
2012-04-05 16:03:15 +00:00
|
|
|
start: function() {
|
|
|
|
return this.load_view();
|
|
|
|
},
|
|
|
|
load_view: function() {
|
|
|
|
if (this.embedded_view) {
|
2012-04-06 12:03:47 +00:00
|
|
|
var def = $.Deferred();
|
2012-04-05 16:03:15 +00:00
|
|
|
var self = this;
|
|
|
|
$.async_when().then(function() {def.resolve(self.embedded_view);});
|
2012-04-06 12:03:47 +00:00
|
|
|
return def.pipe(this.on_loaded);
|
2012-04-05 16:03:15 +00:00
|
|
|
} else {
|
2012-04-17 12:15:59 +00:00
|
|
|
var context = new instance.web.CompoundContext(this.dataset.get_context());
|
2012-04-05 16:03:15 +00:00
|
|
|
if (! this.view_type)
|
2012-04-05 16:21:31 +00:00
|
|
|
console.warn("view_type is not defined", this);
|
2012-04-05 16:03:15 +00:00
|
|
|
return this.rpc("/web/view/load", {
|
|
|
|
"model": this.dataset.model,
|
|
|
|
"view_id": this.view_id,
|
|
|
|
"view_type": this.view_type,
|
2012-04-18 14:24:39 +00:00
|
|
|
toolbar: !!this.options.$sidebar,
|
2012-04-05 16:03:15 +00:00
|
|
|
context: context
|
|
|
|
}).pipe(this.on_loaded);
|
|
|
|
}
|
|
|
|
},
|
|
|
|
/**
|
|
|
|
* Called after a successful call to fields_view_get.
|
|
|
|
* Must return a promise.
|
|
|
|
*/
|
2012-04-09 18:44:45 +00:00
|
|
|
on_loaded: function(fields_view_get) {
|
|
|
|
},
|
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
|
2012-04-09 16:10:00 +00:00
|
|
|
$sidebar: null,
|
2011-07-26 21:00:05 +00:00
|
|
|
sidebar_id: null,
|
2011-08-08 17:32:30 +00:00
|
|
|
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) {
|
2012-04-17 12:15:59 +00:00
|
|
|
this.translate_dialog = new instance.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
|
2012-04-17 12:15:59 +00:00
|
|
|
* @param {instance.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); }
|
2012-02-21 15:30:23 +00:00
|
|
|
if (self.getParent() && self.getParent().on_action_executed) {
|
|
|
|
return self.getParent().on_action_executed.apply(null, arguments);
|
2011-10-10 09:57:54 +00:00
|
|
|
}
|
2011-09-14 12:13:05 +00:00
|
|
|
};
|
2012-04-17 12:15:59 +00:00
|
|
|
var context = new instance.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) {
|
2012-04-17 12:15:59 +00:00
|
|
|
var ncontext = new instance.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
|
2012-04-17 12:15:59 +00:00
|
|
|
* of instance.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-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) {
|
2012-02-21 15:30:23 +00:00
|
|
|
if (this.getParent() && this.getParent().do_push_state) {
|
|
|
|
this.getParent().do_push_state(state);
|
2011-12-14 18:04:42 +00:00
|
|
|
}
|
|
|
|
},
|
2012-02-01 15:44:42 +00:00
|
|
|
do_load_state: function(state, warm) {
|
2011-12-14 18:04:42 +00:00
|
|
|
},
|
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
|
2012-01-24 09:30:33 +00:00
|
|
|
*
|
|
|
|
* @param {Object} [options]
|
|
|
|
* @param {Boolean} [options.created=false] resource was created
|
|
|
|
* @param {String} [options.default=null] view to switch to if no previous view
|
2011-12-07 10:45:03 +00:00
|
|
|
*/
|
2012-01-24 09:30:33 +00:00
|
|
|
do_prev_view: function (options) {
|
2011-12-14 17:18:11 +00:00
|
|
|
},
|
2011-09-28 10:44:58 +00:00
|
|
|
do_search: function(view) {
|
|
|
|
},
|
2011-07-28 16:18:53 +00:00
|
|
|
on_sidebar_import: function() {
|
2012-04-17 12:15:59 +00:00
|
|
|
var import_view = new instance.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() {
|
2012-04-17 12:15:59 +00:00
|
|
|
var export_view = new instance.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
|
|
|
},
|
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
|
|
|
});
|
|
|
|
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.xml_to_json = function(node) {
|
2012-03-14 17:09:49 +00:00
|
|
|
switch (node.nodeType) {
|
|
|
|
case 3:
|
|
|
|
case 4:
|
|
|
|
return node.data;
|
|
|
|
break;
|
|
|
|
case 1:
|
2012-03-19 14:53:32 +00:00
|
|
|
var attrs = $(node).getAttributes();
|
|
|
|
_.each(['domain', 'filter_domain', 'context', 'default_get'], function(key) {
|
|
|
|
if (attrs[key]) {
|
|
|
|
try {
|
|
|
|
attrs[key] = JSON.parse(attrs[key]);
|
|
|
|
} catch(e) { }
|
|
|
|
}
|
|
|
|
});
|
2012-03-14 17:09:49 +00:00
|
|
|
return {
|
|
|
|
tag: node.tagName.toLowerCase(),
|
2012-03-19 14:53:32 +00:00
|
|
|
attrs: attrs,
|
2012-04-17 12:15:59 +00:00
|
|
|
children: _.map(node.childNodes, instance.web.xml_to_json)
|
2012-03-14 17:09:49 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.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
|
2012-01-24 10:10:43 +00:00
|
|
|
// Maybe useful 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++) {
|
2012-04-17 12:15:59 +00:00
|
|
|
childs.push(instance.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 + '/>';
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.xml_to_str = function(node) {
|
2012-03-12 15:34:52 +00:00
|
|
|
if (window.ActiveXObject) {
|
|
|
|
return node.xml;
|
|
|
|
} else {
|
|
|
|
return (new XMLSerializer()).serializeToString(node);
|
|
|
|
}
|
|
|
|
}
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.str_to_xml = function(s) {
|
2012-04-16 14:45:42 +00:00
|
|
|
if (window.DOMParser) {
|
|
|
|
var dp = new DOMParser();
|
|
|
|
var r = dp.parseFromString(s, "text/xml");
|
|
|
|
if (r.body && r.body.firstChild && r.body.firstChild.nodeName == 'parsererror') {
|
|
|
|
throw new Error("Could not parse string to xml");
|
|
|
|
}
|
|
|
|
return r;
|
|
|
|
}
|
|
|
|
var xDoc;
|
|
|
|
try {
|
|
|
|
xDoc = new ActiveXObject("MSXML2.DOMDocument");
|
|
|
|
} catch (e) {
|
|
|
|
throw new Error("Could not find a DOM Parser: " + e.message);
|
|
|
|
}
|
|
|
|
xDoc.async = false;
|
|
|
|
xDoc.preserveWhiteSpace = true;
|
|
|
|
xDoc.loadXML(s);
|
|
|
|
return xDoc;
|
|
|
|
}
|
2011-06-22 11:11:29 +00:00
|
|
|
|
2012-04-09 10:37:08 +00:00
|
|
|
/**
|
|
|
|
* Registry for all the main views
|
|
|
|
*/
|
2012-04-17 12:15:59 +00:00
|
|
|
instance.web.views = new instance.web.Registry();
|
2012-04-09 10:37:08 +00:00
|
|
|
|
2011-03-30 14:00:48 +00:00
|
|
|
};
|
|
|
|
|
|
|
|
// vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax:
|