1 /*---------------------------------------------------------
3 *---------------------------------------------------------*/
5 openerp.web.views = function(session) {
7 var _t = session.web._t;
10 * Registry for all the client actions key: tag value: widget
12 session.web.client_actions = new session.web.Registry();
15 * Registry for all the main views
17 session.web.views = new session.web.Registry();
19 session.web.ActionManager = session.web.Widget.extend({
20 identifier_prefix: "actionmanager",
21 init: function(parent) {
23 this.inner_viewmanager = null;
25 this.dialog_viewmanager = null;
26 this.client_widget = null;
29 return "<div id='"+this.element_id+"'></div>";
31 dialog_stop: function () {
33 this.dialog_viewmanager.stop();
34 this.dialog_viewmanager = null;
39 content_stop: function () {
40 if (this.inner_viewmanager) {
41 this.inner_viewmanager.stop();
42 this.inner_viewmanager = null;
44 if (this.client_widget) {
45 this.client_widget.stop();
46 this.client_widget = null;
49 url_update: function(action) {
52 url.action_id = action.id;
54 // "model": action.res_model,
55 // "domain": action.domain,
65 this.do_url_set_hash(url);
67 do_url_set_hash: function(url) {
69 on_url_hashchange: function(url) {
71 if(url && url.action_id) {
72 self.rpc("/web/action/load", { action_id: url.action_id }, function(result) {
73 self.do_action(result.result);
77 do_action: function(action, on_close) {
78 var type = action.type.replace(/\./g,'_');
79 var popup = action.target === 'new';
80 action.flags = _.extend({
81 views_switcher : !popup,
83 action_buttons : !popup,
86 }, action.flags || {});
87 if (!(type in this)) {
88 console.log("Action manager can't handle action of type " + action.type, action);
91 return this[type](action, on_close);
93 ir_actions_act_window: function (action, on_close) {
94 if (action.target === 'new') {
95 if (this.dialog == null) {
96 this.dialog = new session.web.Dialog(this, { title: action.name, width: '80%' });
98 this.dialog.on_close.add(on_close);
101 this.dialog_viewmanager.stop();
103 this.dialog_viewmanager = new session.web.ViewManagerAction(this, action);
104 this.dialog_viewmanager.appendTo(this.dialog.$element);
109 this.inner_viewmanager = new session.web.ViewManagerAction(this, action);
110 this.inner_viewmanager.appendTo(this.$element);
111 this.url_update(action);
114 this.rpc("/web/session/save_session_action", { the_action : action}, function(key) {
115 var url = window.location.protocol + "//" + window.location.host + window.location.pathname + "?" + jQuery.param({ s_action : "" + key });
116 window.open(url,'_blank');
120 ir_actions_act_window_close: function (action, on_closed) {
121 if (!this.dialog && on_closed) {
124 if (this.dialog && action.context) {
125 var model = action.context.active_model;
126 if (model === 'base.module.upgrade' || model === 'base.setup.installer' || model === 'base.module.upgrade') {
127 session.webclient.do_reload();
132 ir_actions_server: function (action, on_closed) {
134 this.rpc('/web/action/run', {
135 action_id: action.id,
136 context: action.context || {}
137 }).then(function (action) {
138 self.do_action(action, on_closed)
141 ir_actions_client: function (action) {
143 var ClientWidget = session.web.client_actions.get_object(action.tag);
144 (this.client_widget = new ClientWidget(this, action.params)).appendTo(this);
146 ir_actions_report_xml: function(action) {
149 self.rpc("/web/session/eval_domain_and_context", {
150 contexts: [action.context],
152 }).then(function(res) {
153 action = _.clone(action);
154 action.context = res.context;
155 self.session.get_file({
157 data: {action: JSON.stringify(action)},
158 complete: $.unblockUI
162 ir_actions_act_url: function (action) {
163 window.open(action.url, action.target === 'self' ? '_self' : '_blank');
167 session.web.ViewManager = session.web.Widget.extend(/** @lends session.web.ViewManager# */{
168 identifier_prefix: "viewmanager",
169 template: "ViewManager",
171 * @constructs session.web.ViewManager
172 * @extends session.web.Widget
178 init: function(parent, dataset, views) {
180 this.model = dataset ? dataset.model : undefined;
181 this.dataset = dataset;
182 this.searchview = null;
183 this.last_search = false;
184 this.active_view = null;
185 this.views_src = _.map(views, function(x) {return x instanceof Array? {view_id: x[0], view_type: x[1]} : x;});
187 this.flags = this.flags || {};
188 this.registry = session.web.views;
191 return session.web.qweb.render(this.template, {
193 prefix: this.element_id,
194 views: this.views_src});
197 * @returns {jQuery.Deferred} initial view loading promise
202 this.$element.find('.oe_vm_switch button').click(function() {
203 self.on_mode_switch($(this).data('view-type'));
206 _.each(this.views_src, function(view) {
207 self.views[view.view_type] = $.extend({}, view, {
210 sidebar_id : self.element_id + '_sidebar_' + view.view_type,
211 action : self.action,
212 action_views_ids : views_ids
213 }, self.flags, view.options || {})
215 views_ids[view.view_type] = view.view_id;
217 if (this.flags.views_switcher === false) {
218 this.$element.find('.oe_vm_switch').hide();
220 // switch to the first one in sequence
221 return this.on_mode_switch(this.views_src[0].view_type);
224 * Asks the view manager to switch visualization mode.
226 * @param {String} view_type type of view to display
227 * @returns {jQuery.Deferred} new view loading promise
229 on_mode_switch: function(view_type) {
232 this.active_view = view_type;
233 var view = this.views[view_type];
234 if (!view.controller) {
235 // Lazy loading of views
236 var controllerclass = this.registry.get_object(view_type);
237 var controller = new controllerclass(this, this.dataset, view.view_id, view.options);
238 if (view.embedded_view) {
239 controller.set_embedded_view(view.embedded_view);
241 controller.do_switch_view.add_last(this.on_mode_switch);
242 var container = $("#" + this.element_id + '_view_' + view_type);
243 view_promise = controller.appendTo(container);
244 this.views[view_type].controller = controller;
245 $.when(view_promise).then(function() {
246 self.on_controller_inited(view_type, controller);
247 if (self.searchview && view.controller.searchable !== false) {
248 self.do_searchview_search();
251 } else if (this.searchview && view.controller.searchable !== false) {
252 self.do_searchview_search();
255 if (this.searchview) {
256 this.searchview[(view.controller.searchable === false || this.searchview.hidden) ? 'hide' : 'show']();
260 .find('.views-switchers button').removeAttr('disabled')
261 .filter('[data-view-type="' + view_type + '"]')
262 .attr('disabled', true);
264 for (var view_name in this.views) {
265 if (!this.views.hasOwnProperty(view_name)) { continue; }
266 if (this.views[view_name].controller) {
267 if (view_name === view_type) {
268 $.when(view_promise).then(this.views[view_name].controller.do_show);
270 this.views[view_name].controller.do_hide();
274 $.when(view_promise).then(function () {
275 self.$element.find('.oe_view_title:first').text(
276 self.display_title());
281 * Sets up the current viewmanager's search view.
283 * @param {Number|false} view_id the view to use or false for a default one
284 * @returns {jQuery.Deferred} search view startup deferred
286 setup_search_view: function(view_id, search_defaults) {
288 if (this.searchview) {
289 this.searchview.stop();
291 this.searchview = new session.web.SearchView(
293 view_id, search_defaults, this.flags.search_view === false);
295 this.searchview.on_search.add(this.do_searchview_search);
296 return this.searchview.appendTo($("#" + this.element_id + "_search"));
298 do_searchview_search: function(domains, contexts, groupbys) {
300 controller = this.views[this.active_view].controller;
301 if (domains || contexts) {
302 this.rpc('/web/session/eval_domain_and_context', {
303 domains: [this.action.domain || []].concat(domains || []),
304 contexts: [this.action.context || {}].concat(contexts || []),
305 group_by_seq: groupbys || []
306 }, function (results) {
307 self.dataset.context = results.context;
308 self.dataset.domain = results.domain;
309 self.last_search = [results.domain, results.context, results.group_by];
310 controller.do_search(results.domain, results.context, results.group_by);
312 } else if (this.last_search) {
313 controller.do_search.apply(controller, this.last_search);
317 * Event launched when a controller has been inited.
319 * @param {String} view_type type of view
320 * @param {String} view the inited controller
322 on_controller_inited: function(view_type, view) {
325 * Called when one of the view want to execute an action
327 on_action: function(action) {
329 on_create: function() {
331 on_remove: function() {
333 on_edit: function() {
336 * Called by children view after executing an action
338 on_action_executed: function () {},
339 display_title: function () {
340 var view = this.views[this.active_view];
343 return view.controller.fields_view.arch.attrs.string;
349 session.web.ViewManagerAction = session.web.ViewManager.extend(/** @lends oepnerp.web.ViewManagerAction# */{
350 template:"ViewManagerAction",
352 * @constructs session.web.ViewManagerAction
353 * @extends session.web.ViewManager
355 * @param {session.web.ActionManager} parent parent object/widget
356 * @param {Object} action descriptor for the action this viewmanager needs to manage its views.
358 init: function(parent, action) {
359 // dataset initialization will take the session from ``this``, so if we
360 // do not have it yet (and we don't, because we've not called our own
361 // ``_super()``) rpc requests will blow up.
362 this._super(parent, null, action.views);
363 this.session = parent.session;
364 this.action = action;
365 var dataset = new session.web.DataSetSearch(this, action.res_model, action.context, action.domain);
367 dataset.ids.push(action.res_id);
370 this.dataset = dataset;
371 this.flags = this.action.flags || {};
372 if (action.res_model == 'board.board' && action.views.length == 1 && action.views) {
373 // Not elegant but allows to avoid form chrome (pager, save/new
374 // buttons, sidebar, ...) displaying
375 this.flags.search_view = this.flags.pager = this.flags.sidebar = this.flags.action_buttons = false;
378 // setup storage for session-wise menu hiding
379 if (this.session.hidden_menutips) {
382 this.session.hidden_menutips = {}
385 * Initializes the ViewManagerAction: sets up the searchview (if the
386 * searchview is enabled in the manager's action flags), calls into the
387 * parent to initialize the primary view and (if the VMA has a searchview)
388 * launches an initial search after both views are done rendering.
393 search_defaults = {};
394 _.each(this.action.context, function (value, key) {
395 var match = /^search_default_(.*)$/.exec(key);
397 search_defaults[match[1]] = value;
401 var searchview_id = this.action['search_view_id'] && this.action['search_view_id'][0];
403 searchview_loaded = this.setup_search_view(searchview_id || false, search_defaults);
405 var main_view_loaded = this._super();
407 var manager_ready = $.when(searchview_loaded, main_view_loaded);
408 if (searchview_loaded && this.action['auto_search'] !== false) {
409 // schedule auto_search
410 manager_ready.then(this.searchview.do_search);
413 this.$element.find('.oe_get_xml_view').click(function () {
414 // TODO: add search view?
415 $('<pre>').text(session.web.json_node_to_xml(
416 self.views[self.active_view].controller.fields_view.arch, true))
417 .dialog({ width: '95%'});
419 if (this.action.help && !this.flags.low_profile) {
420 var Users = new session.web.DataSet(self, 'res.users'),
421 header = this.$element.find('.oe-view-manager-header');
422 header.delegate('blockquote button', 'click', function() {
424 //noinspection FallthroughInSwitchStatementJS
425 switch ($this.attr('name')) {
427 Users.write(self.session.uid, {menu_tips:false});
429 $this.closest('blockquote').hide();
430 self.session.hidden_menutips[self.action.id] = true;
433 if (!(self.action.id in self.session.hidden_menutips)) {
434 Users.read_ids([this.session.uid], ['menu_tips'], function(users) {
436 if (!(user && user.id === self.session.uid)) {
439 header.find('blockquote').toggle(user.menu_tips);
444 var log_view = this.$element.find('.oe-view-manager-logs:first');
445 log_view.delegate('a.oe-more-logs', 'click', function () {
446 log_view.removeClass('oe-folded');
450 return manager_ready;
452 on_mode_switch: function (view_type) {
455 this._super(view_type),
456 this.shortcut_check(this.views[view_type])
458 var controller = self.views[self.active_view].controller,
459 fvg = controller.fields_view,
460 view_id = (fvg && fvg.view_id) || '--';
461 self.$element.find('.oe_get_xml_view span').text(view_id);
462 if (!self.action.name && fvg) {
463 self.$element.find('.oe_view_title').text(fvg.arch.attrs.string || fvg.name);
466 var $title = self.$element.find('.oe_view_title'),
467 $search_prefix = $title.find('span');
468 if (controller.searchable !== false) {
469 if (!$search_prefix.length) {
470 $title.prepend('<span>' + _t("Search:") + '</span>');
473 $search_prefix.remove();
477 shortcut_check : function(view) {
479 var grandparent = this.widget_parent && this.widget_parent.widget_parent;
480 // display shortcuts if on the first view for the action
481 var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
482 if (!(grandparent instanceof session.web.WebClient) ||
483 !(view.view_type === this.views_src[0].view_type
484 && view.view_id === this.views_src[0].view_id)) {
485 $shortcut_toggle.hide();
488 $shortcut_toggle.removeClass('oe-shortcut-remove').show();
489 if (_(this.session.shortcuts).detect(function (shortcut) {
490 return shortcut.res_id === self.session.active_id; })) {
491 $shortcut_toggle.addClass("oe-shortcut-remove");
493 this.shortcut_add_remove();
495 shortcut_add_remove: function() {
497 var $shortcut_toggle = this.$element.find('.oe-shortcut-toggle');
501 if ($shortcut_toggle.hasClass("oe-shortcut-remove")) {
502 $(self.session.shortcuts.binding).trigger('remove-current');
503 $shortcut_toggle.removeClass("oe-shortcut-remove");
505 $(self.session.shortcuts.binding).trigger('add', {
506 'user_id': self.session.uid,
507 'res_id': self.session.active_id,
508 'resource': 'ir.ui.menu',
509 'name': self.action.name
511 $shortcut_toggle.addClass("oe-shortcut-remove");
516 * Intercept do_action resolution from children views
518 on_action_executed: function () {
519 return new session.web.DataSet(this, 'res.log')
520 .call('get', [], this.do_display_log);
523 * @param {Array<Object>} log_records
525 do_display_log: function (log_records) {
528 $logs = this.$element.find('.oe-view-manager-logs:first')
529 .addClass('oe-folded'),
530 $logs_list = $logs.find('ul').empty();
531 $logs.toggleClass('oe-has-more', log_records.length > cutoff);
532 _(log_records.reverse()).each(function (record) {
533 $(_.sprintf('<li><a href="#">%s</a></li>', record.name))
534 .appendTo($logs_list)
535 .delegate('a', 'click', function (e) {
537 type: 'ir.actions.act_window',
538 res_model: record.res_model,
539 res_id: record.res_id,
540 // TODO: need to have an evaluated context here somehow
541 //context: record.context,
542 views: [[false, 'form']]
548 display_title: function () {
549 return this.action.name;
553 session.web.Sidebar = session.web.Widget.extend({
554 init: function(parent, element_id) {
555 this._super(parent, element_id);
562 this.$element.html(session.web.qweb.render('Sidebar'));
563 this.$element.find(".toggle-sidebar").click(function(e) {
568 call_default_on_sidebar: function(item) {
569 var func_name = 'on_sidebar_' + _.underscored(item.label);
570 var fn = this.widget_parent[func_name];
571 if(typeof fn === 'function') {
576 add_default_sections: function() {
577 this.add_section(_t('Customize'), 'customize');
578 this.add_items('customize', [
580 label: _t("Manage Views"),
581 callback: this.call_default_on_sidebar,
582 title: _t("Manage views of the current object")
584 label: _t("Edit Workflow"),
585 callback: this.call_default_on_sidebar,
586 title: _t("Manage views of the current object"),
587 classname: 'oe_hide oe_sidebar_edit_workflow'
589 label: _t("Customize Object"),
590 callback: this.call_default_on_sidebar,
591 title: _t("Manage views of the current object")
595 this.add_section(_t('Other Options'), 'other');
596 this.add_items('other', [
599 callback: this.call_default_on_sidebar
602 callback: this.call_default_on_sidebar
604 label: _t("Translate"),
605 callback: this.call_default_on_sidebar,
606 classname: 'oe_sidebar_translate oe_hide'
608 label: _t("View Log"),
609 callback: this.call_default_on_sidebar,
610 classname: 'oe_hide oe_sidebar_view_log'
615 add_toolbar: function(toolbar) {
617 _.each([['print', _t("Reports")], ['action', _t("Actions")], ['relate', _t("Links")]], function(type) {
618 var items = toolbar[type[0]];
620 for (var i = 0; i < items.length; i++) {
622 label: items[i]['name'],
624 classname: 'oe_sidebar_' + type[0]
627 self.add_section(type[1], type[0]);
628 self.add_items(type[0], items);
633 add_section: function(name, code) {
634 if(!code) code = _.underscored(name);
635 var $section = this.sections[code];
638 var section_id = _.uniqueId(this.element_id + '_section_' + code + '_');
639 $section = $(session.web.qweb.render("Sidebar.section", {
640 section_id: section_id,
642 classname: 'oe_sidebar_' + code
644 $section.appendTo(this.$element.find('div.sidebar-actions'));
645 this.sections[code] = $section;
650 add_items: function(section_code, items) {
651 // An item is a dictonary : {
652 // label: label to be displayed for the link,
653 // action: action to be launch when the link is clicked,
654 // callback: a function to be executed when the link is clicked,
655 // classname: optional dom class name for the line,
656 // title: optional title for the link
658 // Note: The item should have one action or/and a callback
662 $section = this.add_section(_.titleize(section_code.replace('_', ' ')), section_code),
663 section_id = $section.attr('id');
666 for (var i = 0; i < items.length; i++) {
667 items[i].element_id = _.uniqueId(section_id + '_item_');
668 this.items[items[i].element_id] = items[i];
671 var $items = $(session.web.qweb.render("Sidebar.section.items", {items: items}));
673 $items.find('a.oe_sidebar_action_a').click(function() {
674 var item = self.items[$(this).attr('id')];
676 item.callback.apply(self, [item]);
679 var ids = self.widget_parent.get_selected_ids();
680 if (ids.length == 0) {
681 //TODO: make prettier warning?
682 $("<div />").text(_t("You must choose at least one record.")).dialog({
683 title: _t("Warning"),
688 var additional_context = {
691 active_model: self.widget_parent.dataset.model
693 self.rpc("/web/action/load", {
694 action_id: item.action.id,
695 context: additional_context
696 }, function(result) {
697 result.result.context = _.extend(result.result.context || {},
699 result.result.flags = result.result.flags || {};
700 result.result.flags.new_window = true;
701 self.do_action(result.result);
707 var $ul = $section.find('ul');
709 $ul = $('<ul/>').appendTo($section);
711 $items.appendTo($ul);
714 do_fold: function() {
715 this.$element.addClass('closed-sidebar').removeClass('open-sidebar');
717 do_unfold: function() {
718 this.$element.addClass('open-sidebar').removeClass('closed-sidebar');
720 do_toggle: function() {
721 this.$element.toggleClass('open-sidebar closed-sidebar');
725 session.web.TranslateDialog = session.web.Dialog.extend({
726 dialog_title: _t("Translations"),
727 init: function(view) {
728 // TODO fme: should add the language to fields_view_get because between the fields view get
729 // and the moment the user opens the translation dialog, the user language could have been changed
730 this.view_language = view.session.user_context.lang;
731 this['on_button' + _t("Save")] = this.on_button_Save;
732 this['on_button' + _t("Close")] = this.on_button_Close;
738 this.view_type = view.fields_view.type || '';
739 this.$fields_form = null;
740 this.$view_form = null;
741 this.$sidebar_form = null;
742 this.translatable_fields_keys = _.map(this.view.translatable_fields || [], function(i) { return i.name });
743 this.languages = null;
744 this.languages_loaded = $.Deferred();
745 (new session.web.DataSetSearch(this, 'res.lang', this.view.dataset.get_context(),
746 [['translatable', '=', '1']])).read_slice(['code', 'name'], { sort: 'id' }, this.on_languages_loaded);
751 $.when(this.languages_loaded).then(function() {
752 self.$element.html(session.web.qweb.render('TranslateDialog', { widget: self }));
753 self.$element.tabs();
754 if (!(self.view.translatable_fields && self.view.translatable_fields.length)) {
755 self.hide_tabs('fields');
756 self.select_tab('view');
758 self.$fields_form = self.$element.find('.oe_translation_form');
759 self.$fields_form.find('.oe_trad_field').change(function() {
760 $(this).toggleClass('touched', ($(this).val() != $(this).attr('data-value')));
765 on_languages_loaded: function(langs) {
766 this.languages = langs;
767 this.languages_loaded.resolve();
769 do_load_fields_values: function(callback) {
772 this.$fields_form.find('.oe_trad_field').val('').removeClass('touched');
773 _.each(self.languages, function(lg) {
774 var deff = $.Deferred();
776 var callback = function(values) {
777 _.each(self.translatable_fields_keys, function(f) {
778 self.$fields_form.find('.oe_trad_field[name="' + lg.code + '-' + f + '"]').val(values[0][f] || '').attr('data-value', values[0][f] || '');
782 if (lg.code === self.view_language) {
784 _.each(self.translatable_fields_keys, function(field) {
785 values[field] = self.view.fields[field].get_value();
789 self.rpc('/web/dataset/get', {
790 model: self.view.dataset.model,
791 ids: [self.view.datarecord.id],
792 fields: self.translatable_fields_keys,
793 context: self.view.dataset.get_context({
798 $.when.apply(null, deffered).then(callback);
800 show_tabs: function() {
801 for (var i = 0; i < arguments.length; i++) {
802 this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().show();
805 hide_tabs: function() {
806 for (var i = 0; i < arguments.length; i++) {
807 this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().hide();
810 select_tab: function(name) {
811 this.show_tabs(name);
812 var index = this.$element.find('ul.oe_translate_tabs li a[href$="' + arguments[i] + '"]').parent().index() - 1;
813 this.$element.tabs('select', index);
815 open: function(field) {
818 $.when(this.languages_loaded).then(function() {
819 if (self.view.translatable_fields && self.view.translatable_fields.length) {
820 self.do_load_fields_values(function() {
823 // TODO: focus and scroll to field
831 on_button_Save: function() {
834 self.$fields_form.find('.oe_trad_field.touched').each(function() {
835 var field = $(this).attr('name').split('-');
836 if (!trads[field[0]]) {
837 trads[field[0]] = {};
839 trads[field[0]][field[1]] = $(this).val();
841 _.each(trads, function(data, code) {
842 if (code === self.view_language) {
843 _.each(data, function(value, field) {
844 self.view.fields[field].set_value(value);
847 self.view.dataset.write(self.view.datarecord.id, data, { 'lang': code });
852 on_button_Close: function() {
857 session.web.View = session.web.Widget.extend(/** @lends session.web.View# */{
858 template: "EmptyComponent",
859 set_default_options: function(options) {
860 this.options = options || {};
861 _.defaults(this.options, {
862 // All possible views options should be defaulted here
869 open_translate_dialog: function(field) {
870 if (!this.translate_dialog) {
871 this.translate_dialog = new session.web.TranslateDialog(this).start();
873 this.translate_dialog.open(field);
876 * Fetches and executes the action identified by ``action_data``.
878 * @param {Object} action_data the action descriptor data
879 * @param {String} action_data.name the action name, used to uniquely identify the action to find and execute it
880 * @param {String} [action_data.special=null] special action handlers (currently: only ``'cancel'``)
881 * @param {String} [action_data.type='workflow'] the action type, if present, one of ``'object'``, ``'action'`` or ``'workflow'``
882 * @param {Object} [action_data.context=null] additional action context, to add to the current context
883 * @param {session.web.DataSet} dataset a dataset object used to communicate with the server
884 * @param {Object} [record_id] the identifier of the object on which the action is to be applied
885 * @param {Function} on_closed callback to execute when dialog is closed or when the action does not generate any result (no new action)
887 do_execute_action: function (action_data, dataset, record_id, on_closed) {
889 var result_handler = function () {
890 if (on_closed) { on_closed.apply(null, arguments); }
891 if (self.widget_parent && self.widget_parent.on_action_executed) {
892 return self.widget_parent.on_action_executed.apply(null, arguments);
895 var context = new session.web.CompoundContext(dataset.get_context(), action_data.context || {});
897 var handler = function (r) {
898 var action = r.result;
899 if (action && action.constructor == Object) {
900 var ncontext = new session.web.CompoundContext(context);
903 active_id: record_id,
904 active_ids: [record_id],
905 active_model: dataset.model
908 ncontext.add(action.context || {});
909 return self.rpc('/web/session/eval_domain_and_context', {
910 contexts: [ncontext],
912 }).pipe(function (results) {
913 action.context = results.context;
914 /* niv: previously we were overriding once more with action_data.context,
915 * I assumed this was not a correct behavior and removed it
917 return self.do_action(action, result_handler);
920 return result_handler();
924 if (action_data.special) {
925 return handler({result: {"type":"ir.actions.act_window_close"}});
926 } else if (action_data.type=="object") {
927 return dataset.call_button(action_data.name, [[record_id], context], handler);
928 } else if (action_data.type=="action") {
929 return this.rpc('/web/action/load', { action_id: parseInt(action_data.name, 10), context: context, do_not_eval: true}, handler);
931 return dataset.exec_workflow(record_id, action_data.name, handler);
935 * Directly set a view to use instead of calling fields_view_get. This method must
936 * be called before start(). When an embedded view is set, underlying implementations
937 * of session.web.View must use the provided view instead of any other one.
939 * @param embedded_view A view.
941 set_embedded_view: function(embedded_view) {
942 this.embedded_view = embedded_view;
943 this.options.sidebar = false;
945 do_switch_view: function(view) {
947 do_search: function(view) {
950 set_common_sidebar_sections: function(sidebar) {
951 sidebar.add_default_sections();
953 on_sidebar_manage_views: function() {
954 if (this.fields_view && this.fields_view.arch) {
955 var view_editor = new session.web.ViewEditor(this, this.$element, this.dataset, this.fields_view.arch);
958 this.do_warn("Manage Views", "Could not find current view declaration");
961 on_sidebar_edit_workflow: function() {
964 on_sidebar_customize_object: function() {
967 on_sidebar_import: function() {
968 var import_view = new session.web.DataImport(this, this.dataset);
971 on_sidebar_export: function() {
972 var export_view = new session.web.DataExport(this, this.dataset);
975 on_sidebar_translate: function() {
976 this.open_translate_dialog();
978 on_sidebar_view_log: function() {
982 session.web.json_node_to_xml = function(node, human_readable, indent) {
983 // For debugging purpose, this function will convert a json node back to xml
984 // Maybe usefull for xml view editor
985 indent = indent || 0;
986 var sindent = (human_readable ? (new Array(indent + 1).join('\t')) : ''),
987 r = sindent + '<' + node.tag,
988 cr = human_readable ? '\n' : '';
990 if (typeof(node) === 'string') {
991 return sindent + node;
992 } else if (typeof(node.tag) !== 'string' || !node.children instanceof Array || !node.attrs instanceof Object) {
993 throw("Node a json node");
995 for (var attr in node.attrs) {
996 var vattr = node.attrs[attr];
997 if (typeof(vattr) !== 'string') {
999 vattr = JSON.stringify(vattr);
1001 vattr = vattr.replace(/&/g, '&').replace(/</g, '<').replace(/>/g, '>').replace(/"/g, '"');
1002 if (human_readable) {
1003 vattr = vattr.replace(/"/g, "'");
1005 r += ' ' + attr + '="' + vattr + '"';
1007 if (node.children && node.children.length) {
1010 for (var i = 0, ii = node.children.length; i < ii; i++) {
1011 childs.push(session.web.json_node_to_xml(node.children[i], human_readable, indent + 1));
1013 r += childs.join(cr);
1014 r += cr + sindent + '</' + node.tag + '>';
1023 // vim:et fdc=0 fdl=0 foldnestmax=3 fdm=syntax: