~alexaubin/unifield-web/US-2937

« back to all changes in this revision

Viewing changes to addons/openerp/static/javascript/web_keyboard_shortcuts.js

  • Committer: jf
  • Date: 2017-08-21 08:20:34 UTC
  • mfrom: (4847.1.5 unifield-web)
  • Revision ID: jfb@tempo-consulting.fr-20170821082034-nnik6jj2vq5eccoo
US-2869 [IMP] Keyboard shortcuts

lp:~fabien-morin/unifield-web/fm-us-2869

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*##############################################################################
 
2
#
 
3
#    OpenERP, Open Source Management Solution
 
4
#    Copyright (c) 2010-2012 Elico Corp. All Rights Reserved.
 
5
#    Author: Yannick Gouin <yannick.gouin@elico-corp.com>
 
6
#
 
7
#    This program is free software: you can redistribute it and/or modify
 
8
#    it under the terms of the GNU General Public License as published by
 
9
#    the Free Software Foundation, either version 3 of the License, or
 
10
#    (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 General Public License for more details.
 
16
#
 
17
#    You should have received a copy of the GNU General Public License
 
18
#    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
19
#
 
20
##############################################################################
 
21
*/
 
22
 
 
23
 
 
24
/* some keys cannot be overriden, for example
 
25
* "There is no way to override CTRL-N, CTRL-T, or CTRL-W in Google Chrome since
 
26
* version 4 of Chrome (shipped in 2010)."
 
27
*/
 
28
 
 
29
$.ctrlshift = function(key, callback, args) {
 
30
    $(document).keydown(function(e) {
 
31
        if(!args) args=[]; // IE barks when args is null
 
32
        if((e.keyCode == key.charCodeAt(0) || e.keyCode == key) && e.ctrlKey && e.shiftKey) {
 
33
            e.preventDefault();  // override the browser shortcut keys
 
34
            callback.apply(this, args);
 
35
            return false;
 
36
        }
 
37
    });
 
38
};
 
39
 
 
40
fake_click = function(button) {
 
41
    if($(button).parents('div:hidden').length == 0){
 
42
        if (button.hasAttribute('onclick')) {
 
43
            button.onclick();
 
44
        }
 
45
        else {
 
46
            $(button).trigger('click');
 
47
        }
 
48
    }
 
49
};
 
50
 
 
51
//Save the current object
 
52
$.ctrlshift('S', function() {
 
53
    var saved = false;
 
54
    $('.oe_form_button_save_line').each(function() {
 
55
        if($(this).parents('div:hidden').length == 0){
 
56
            fake_click(this);
 
57
            saved = true;  // if a line is under edition, save only this line, not the whole object
 
58
        }
 
59
    });
 
60
    $('.oe_form_button_save_close').each(function() {
 
61
        if(!saved && $(this).parents('div:hidden').length == 0){
 
62
            fake_click(this);
 
63
            saved = true;
 
64
        }
 
65
    });
 
66
    $('.oe_form_button_save').each(function() {
 
67
        fake_click(this);
 
68
    });
 
69
});
 
70
 
 
71
//Save & Edit the current object
 
72
$.ctrlshift('E', function() {
 
73
    $('.oe_form_button_save_edit').each(function() {
 
74
        fake_click(this);
 
75
    });
 
76
    $('.oe_form_button_edit').each(function() {
 
77
        fake_click(this);
 
78
    });
 
79
});
 
80
 
 
81
//Delete the current object
 
82
$.ctrlshift('46', function() {
 
83
    $('.oe_form_button_delete').each(function() {
 
84
        fake_click(this);
 
85
    });
 
86
});
 
87
 
 
88
//Cancel the modifiactions
 
89
$.ctrlshift('Z', function() {
 
90
    $('.oe_form_button_cancel').each(function() {
 
91
        fake_click(this);
 
92
    });
 
93
});
 
94
 
 
95
//New object
 
96
$.ctrlshift('C', function() {
 
97
    $('.oe_form_button_create').each(function() {
 
98
        fake_click(this);
 
99
    });
 
100
    $('.oe_form_button_save_create').each(function() {
 
101
        fake_click(this);
 
102
    });
 
103
});
 
104
 
 
105
//Duplicate the current object
 
106
$.ctrlshift('D', function() {
 
107
    $('.oe_form_button_duplicate').each(function() {
 
108
        fake_click(this);
 
109
    });
 
110
});
 
111
 
 
112
//Search (enter)
 
113
$.ctrlshift('13', function() {
 
114
    $('.oe_form_button_search').each(function() {
 
115
        fake_click(this);
 
116
    });
 
117
});
 
118
 
 
119
//Clear search
 
120
$.ctrlshift('R', function() {
 
121
    $('.oe_form_button_clear').each(function() {
 
122
        fake_click(this);
 
123
    });
 
124
});
 
125
 
 
126
//First object (arrow up)
 
127
$.ctrlshift('38', function(event) {
 
128
    $('.oe_button_pager[action="first"]').each(function() {
 
129
        fake_click(this);
 
130
    });
 
131
});
 
132
 
 
133
//Previous object (arrow right)
 
134
$.ctrlshift('37', function() {
 
135
    $('.oe_button_pager[action="previous"]').each(function() {
 
136
        fake_click(this);
 
137
    });
 
138
});
 
139
 
 
140
//Next object (arrow left)
 
141
$.ctrlshift('39', function() {
 
142
    $('.oe_button_pager[action="next"]').each(function() {
 
143
        fake_click(this);
 
144
    });
 
145
});
 
146
 
 
147
//Last object (arrow down)
 
148
$.ctrlshift('40', function() {
 
149
    $('.oe_button_pager[action="last"]').each(function() {
 
150
        fake_click(this);
 
151
    });
 
152
});
 
153
 
 
154
//Close ('Q')
 
155
$.ctrlshift('Q', function() {
 
156
    $('.oe_form_button_close').each(function() {
 
157
        fake_click(this);
 
158
    });
 
159
});