Merge lp:~therp-nl/web-addons/7.0-add_autoswitch into lp:~webaddons-core-editors/web-addons/7.0

Proposed by Stefan Rijnhart (Opener)
Status: Work in progress
Proposed branch: lp:~therp-nl/web-addons/7.0-add_autoswitch
Merge into: lp:~webaddons-core-editors/web-addons/7.0
Diff against target: 187 lines (+173/-0)
2 files modified
web_autoswitch_to_form/__openerp__.py (+56/-0)
web_autoswitch_to_form/static/src/js/web_autoswitch_to_form.js (+117/-0)
To merge this branch: bzr merge lp:~therp-nl/web-addons/7.0-add_autoswitch
Reviewer Review Type Date Requested Status
Web-Addons Core Editors Pending
Review via email: mp+194539@code.launchpad.net

Description of the change

Experimental, don't merge yet.

To post a comment you must log in.
18. By Stefan Rijnhart (Opener)

[RFR] Additional line break

19. By Stefan Rijnhart (Opener)

[IMP] Variable name

20. By Stefan Rijnhart (Opener)

[RFR] Comments

21. By Stefan Rijnhart (Opener)

[ADD] Example XML stanza

22. By Stefan Rijnhart (Opener)

[FIX] Missing, albeit optional colon

23. By Stefan Rijnhart (Opener)

[IMP] Missing colon

Unmerged revisions

23. By Stefan Rijnhart (Opener)

[IMP] Missing colon

22. By Stefan Rijnhart (Opener)

[FIX] Missing, albeit optional colon

21. By Stefan Rijnhart (Opener)

[ADD] Example XML stanza

20. By Stefan Rijnhart (Opener)

[RFR] Comments

19. By Stefan Rijnhart (Opener)

[IMP] Variable name

18. By Stefan Rijnhart (Opener)

[RFR] Additional line break

17. By Stefan Rijnhart (Opener)

[IMP] Comments, spacing

16. By Stefan Rijnhart (Opener)

[RFR] Eliminate unnecessary variable

15. By Stefan Rijnhart (Opener)

[DEL] Debug statements

14. By Stefan Rijnhart (Opener)

[IMP] Restrict autoswitching to search views with the autoswitch attribute

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== added directory 'web_autoswitch_to_form'
=== added file 'web_autoswitch_to_form/__init__.py'
=== added file 'web_autoswitch_to_form/__openerp__.py'
--- web_autoswitch_to_form/__openerp__.py 1970-01-01 00:00:00 +0000
+++ web_autoswitch_to_form/__openerp__.py 2013-11-11 11:35:35 +0000
@@ -0,0 +1,56 @@
1# -*- coding: utf-8 -*-
2##############################################################################
3#
4# OpenERP, Open Source Management Solution
5# This module copyright (C) 2013 Therp BV (<http://therp.nl>).
6#
7# This program is free software: you can redistribute it and/or modify
8# it under the terms of the GNU Affero General Public License as
9# published by the Free Software Foundation, either version 3 of the
10# License, or (at your option) any later version.
11#
12# This program is distributed in the hope that it will be useful,
13# but WITHOUT ANY WARRANTY; without even the implied warranty of
14# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15# GNU Affero General Public License for more details.
16#
17# You should have received a copy of the GNU Affero General Public License
18# along with this program. If not, see <http://www.gnu.org/licenses/>.
19#
20##############################################################################
21{
22 "name" : "Auto-switch to form mode for singleton search results",
23 "version" : "0.1",
24 "author" : "Therp BV",
25 "category": 'Tools',
26 "description": """
27When the 'autoswitch' attribute is defined on a search view, searches with only
28one result will automatically open the form view for the record.
29
30Note that the 'autoswitch' attribute on search elements in XML views is not
31allowed by the RNG validation. You can circumvent the validation by setting
32an attribute version="7.0" as well.
33
34As an example, here is the necessary code to enable this functionality on
35the product view:
36
37 <record id="product_search_form_view" model="ir.ui.view">
38 <field name="name">product.search.form</field>
39 <field name="model">product.product</field>
40 <field name="inherit_id"
41 ref="product.product_search_form_view"/>
42 <field name="arch" type="xml">
43 <xpath expr="/search[@string='Product']" position="attributes">
44 <attribute name="version">7.0</attribute>
45 <attribute name="autoswitch">1</attribute>
46 </xpath>
47 </field>
48 </record>
49
50 """,
51 'website': 'http://therp.nl',
52 'depends' : ['web_kanban'],
53 'js': ['static/src/js/web_autoswitch_to_form.js'],
54 'data': [
55 ],
56}
057
=== added directory 'web_autoswitch_to_form/static'
=== added directory 'web_autoswitch_to_form/static/src'
=== added directory 'web_autoswitch_to_form/static/src/js'
=== added file 'web_autoswitch_to_form/static/src/js/web_autoswitch_to_form.js'
--- web_autoswitch_to_form/static/src/js/web_autoswitch_to_form.js 1970-01-01 00:00:00 +0000
+++ web_autoswitch_to_form/static/src/js/web_autoswitch_to_form.js 2013-11-11 11:35:35 +0000
@@ -0,0 +1,117 @@
1/*
2
3 Copyright (C) 2013 Therp BV
4 License: GNU AFFERO GENERAL PUBLIC LICENSE
5 Version 3 or any later version
6
7*/
8
9openerp.web_autoswitch_to_form = function(instance) {
10
11 instance.web.ViewManager.include({
12 switch_mode: function(view_type, no_store, view_options) {
13 /*
14 Suppress autoswitch after manually changing modes, or
15 it could become annoying when the user attempts to
16 switch to a list view of a single item
17 */
18 this.flags.suppress_autoswitch = true;
19 return this._super(view_type, no_store, view_options);
20 },
21 });
22
23 instance.web.SearchView.include({
24 disable_autoswitch: function() {
25 if (this.__parentedParent && this.__parentedParent.flags !== undefined) {
26 this.__parentedParent.flags.suppress_autoswitch = true;
27 }
28 },
29
30 check_autoswitch: function(data) {
31 if (this.__parentedParent
32 && this.__parentedParent.flags !== undefined
33 && data.arch && data.arch.attrs) {
34 this.__parentedParent.flags.autoswitch = data.arch.attrs.autoswitch;
35 }
36 },
37
38 start: function() {
39 /*
40 When a filter is removed, suppress autoswitch if the search
41 that is then triggered has only one result
42
43 Auto-switching is enabled per search view by the 'autoswitch'
44 attribute on the search element of the search view
45 */
46 res = this._super();
47 this.query.on('remove', this.proxy(this.disable_autoswitch));
48 this.on('search_view_loaded', this, this.check_autoswitch);
49 return res;
50 },
51 });
52
53 instance.web.View.include({
54 start: function() {
55 /*
56 Undo suppressing once a view is loaded
57 */
58 res = this._super();
59 if (this.__parentedParent && this.__parentedParent.flags !== undefined) {
60 this.__parentedParent.flags.suppress_autoswitch = false;
61 }
62 return res;
63 },
64 });
65
66
67 instance.web.ListView.include({
68 do_search: function(domain, context, group_by) {
69 /*
70 Switch from list view to form view in case of a single
71 record when do_search's deferred is resolved
72 */
73 var res = this._super(domain, context, group_by)
74 if ( ! (this.__parentedParent
75 && this.__parentedParent.flags
76 && this.__parentedParent.flags.autoswitch)) {
77 return res;
78 }
79 if (this.__parentedParent.flags.suppress_autoswitch) {
80 this.__parentedParent.flags.suppress_autoswitch = false;
81 return res;
82 }
83 var self = this;
84 return res.done(
85 function() {
86 if (self.records.length === 1) {
87 self.trigger('switch_mode', 'form');
88 }
89 });
90 },
91 });
92
93 instance.web_kanban.KanbanView.include({
94 on_groups_started: function() {
95 /*
96 Switch from kanban view to form view in case of a single
97 record after calling the super of this method.
98 */
99 var res = this._super();
100 if ( ! (this.__parentedParent
101 && this.__parentedParent.flags
102 && this.__parentedParent.flags.autoswitch)) {
103 return res;
104 }
105 if (this.__parentedParent.flags.suppress_autoswitch) {
106 this.__parentedParent.flags.suppress_autoswitch = false;
107 return res;
108 }
109 if (this.dataset.size() === 1) {
110 this.dataset.select_id(this.dataset.ids[0]);
111 this.do_switch_view('form', null, { mode: undefined });
112 }
113 return res;
114 },
115 });
116
117};

Subscribers

People subscribed via source and target branches