@ -3,20 +3,20 @@
odoo . define ( 'web_app_drawer' , function ( require ) {
odoo . define ( 'web_app_drawer' , function ( require ) {
'use strict' ;
'use strict' ;
var $ = require ( '$' ) ;
var $ = require ( '$' ) ;
var Menu = require ( 'web.Menu' ) ;
var Menu = require ( 'web.Menu' ) ;
var Class = require ( 'web.Class' ) ;
var Class = require ( 'web.Class' ) ;
var SearchView = require ( 'web.SearchView' ) ;
var SearchView = require ( 'web.SearchView' ) ;
var core = require ( 'web.core' ) ;
var core = require ( 'web.core' ) ;
Menu . include ( {
Menu . include ( {
// Force all_outside to prevent app icons from going into more menu
// Force all_outside to prevent app icons from going into more menu
reflow : function ( ) {
reflow : function ( ) {
this . _super ( 'all_outside' ) ;
this . _super ( 'all_outside' ) ;
} ,
} ,
/ * O v e r l o a d t o c o l l a p s e u n w a n t e d v i s i b l e s u b m e n u s
/ * O v e r l o a d t o c o l l a p s e u n w a n t e d v i s i b l e s u b m e n u s
* @ param allow_open bool Switch to allow submenus to be opened
* @ param allow_open bool Switch to allow submenus to be opened
* /
* /
@ -26,25 +26,25 @@ odoo.define('web_app_drawer', function(require) {
var $clicked_menu = this . $secondary_menus . find ( 'a[data-menu=' + id + ']' ) ;
var $clicked_menu = this . $secondary_menus . find ( 'a[data-menu=' + id + ']' ) ;
$clicked_menu . parents ( '.oe_secondary_submenu' ) . css ( 'display' , '' ) ;
$clicked_menu . parents ( '.oe_secondary_submenu' ) . css ( 'display' , '' ) ;
} ,
} ,
} ) ;
} ) ;
SearchView . include ( {
SearchView . include ( {
// Prevent focus of search field on mobile devices
// Prevent focus of search field on mobile devices
toggle_visibility : function ( is_visible ) {
toggle_visibility : function ( is_visible ) {
$ ( 'div.oe_searchview_input' ) . last ( )
$ ( 'div.oe_searchview_input' ) . last ( )
. one ( 'focus' , $ . proxy ( this . preventMobileFocus , this ) ) ;
. one ( 'focus' , $ . proxy ( this . preventMobileFocus , this ) ) ;
return this . _super ( is_visible ) ;
return this . _super ( is_visible ) ;
} ,
} ,
// It prevents focusing of search el on mobile
// It prevents focusing of search el on mobile
preventMobileFocus : function ( event ) {
preventMobileFocus : function ( event ) {
if ( this . isMobile ( ) ) {
if ( this . isMobile ( ) ) {
event . preventDefault ( ) ;
event . preventDefault ( ) ;
}
}
} ,
} ,
// For lack of Modernizr, TouchEvent will do
// For lack of Modernizr, TouchEvent will do
isMobile : function ( ) {
isMobile : function ( ) {
try {
try {
@ -54,23 +54,23 @@ odoo.define('web_app_drawer', function(require) {
return false ;
return false ;
}
}
} ,
} ,
} ) ;
} ) ;
var AppDrawer = Class . extend ( {
var AppDrawer = Class . extend ( {
LEFT : 'left' ,
LEFT : 'left' ,
RIGHT : 'right' ,
RIGHT : 'right' ,
UP : 'up' ,
UP : 'up' ,
DOWN : 'down' ,
DOWN : 'down' ,
isOpen : false ,
isOpen : false ,
keyBuffer : '' ,
keyBuffer : '' ,
keyBufferTime : 500 ,
keyBufferTime : 500 ,
keyBufferTimeoutEvent : false ,
keyBufferTimeoutEvent : false ,
dropdownHeightFactor : 0.90 ,
dropdownHeightFactor : 0.90 ,
initialized : false ,
initialized : false ,
init : function ( ) {
init : function ( ) {
this . directionCodes = {
this . directionCodes = {
'left' : this . LEFT ,
'left' : this . LEFT ,
@ -91,7 +91,7 @@ odoo.define('web_app_drawer', function(require) {
core . bus . on ( 'resize' , this , this . handleWindowResize ) ;
core . bus . on ( 'resize' , this , this . handleWindowResize ) ;
core . bus . on ( 'keydown' , this , this . handleNavKeys ) ;
core . bus . on ( 'keydown' , this , this . handleNavKeys ) ;
} ,
} ,
// It provides initialization handlers for Drawer
// It provides initialization handlers for Drawer
initDrawer : function ( ) {
initDrawer : function ( ) {
this . $el = $ ( '.drawer' ) ;
this . $el = $ ( '.drawer' ) ;
@ -109,7 +109,7 @@ odoo.define('web_app_drawer', function(require) {
} ) ;
} ) ;
this . initialized = true ;
this . initialized = true ;
} ,
} ,
// It provides handlers to hide drawer when "unfocused"
// It provides handlers to hide drawer when "unfocused"
handleClickZones : function ( ) {
handleClickZones : function ( ) {
this . $el . drawer ( 'close' ) ;
this . $el . drawer ( 'close' ) ;
@ -117,14 +117,14 @@ odoo.define('web_app_drawer', function(require) {
. parent ( )
. parent ( )
. collapse ( 'hide' ) ;
. collapse ( 'hide' ) ;
} ,
} ,
// It resizes bootstrap dropdowns for screen
// It resizes bootstrap dropdowns for screen
handleWindowResize : function ( ) {
handleWindowResize : function ( ) {
$ ( '.dropdown-scrollable' ) . css (
$ ( '.dropdown-scrollable' ) . css (
'max-height' , $ ( window ) . height ( ) * this . dropdownHeightFactor
'max-height' , $ ( window ) . height ( ) * this . dropdownHeightFactor
) ;
) ;
} ,
} ,
// It provides keyboard shortcuts for app drawer nav
// It provides keyboard shortcuts for app drawer nav
handleNavKeys : function ( e ) {
handleNavKeys : function ( e ) {
if ( ! this . isOpen ) {
if ( ! this . isOpen ) {
@ -144,7 +144,7 @@ odoo.define('web_app_drawer', function(require) {
this . selectAppLink ( this . searchAppLinks ( buffer ) ) ;
this . selectAppLink ( this . searchAppLinks ( buffer ) ) ;
}
}
} ,
} ,
/ * I t a d d s t o k e y b u f f e r , s e t s e x p i r e t i m e r , a n d r e t u r n s b u f f e r
/ * I t a d d s t o k e y b u f f e r , s e t s e x p i r e t i m e r , a n d r e t u r n s b u f f e r
* @ returns str of current buffer
* @ returns str of current buffer
* /
* /
@ -159,11 +159,11 @@ odoo.define('web_app_drawer', function(require) {
) ;
) ;
return this . keyBuffer ;
return this . keyBuffer ;
} ,
} ,
clearKeyBuffer : function ( ) {
clearKeyBuffer : function ( ) {
this . keyBuffer = '' ;
this . keyBuffer = '' ;
} ,
} ,
/ * I t p e r f o r m s c l o s e a c t i o n s
/ * I t p e r f o r m s c l o s e a c t i o n s
* @ fires ` ` drawer . closed ` ` to the ` ` core . bus ` `
* @ fires ` ` drawer . closed ` ` to the ` ` core . bus ` `
* @ listens ` ` drawer . opened ` ` and sends to onDrawerOpen
* @ listens ` ` drawer . opened ` ` and sends to onDrawerOpen
@ -172,8 +172,10 @@ odoo.define('web_app_drawer', function(require) {
core . bus . trigger ( 'drawer.closed' ) ;
core . bus . trigger ( 'drawer.closed' ) ;
this . $el . one ( 'drawer.opened' , $ . proxy ( this . onDrawerOpen , this ) ) ;
this . $el . one ( 'drawer.opened' , $ . proxy ( this . onDrawerOpen , this ) ) ;
this . isOpen = false ;
this . isOpen = false ;
// Remove inline style inserted by drawer.js
this . $el . css ( "overflow" , "" ) ;
} ,
} ,
/ * I t f i n d s a p p l i n k s a n d r e g i s t e r e v e n t h a n d l e r s
/ * I t f i n d s a p p l i n k s a n d r e g i s t e r e v e n t h a n d l e r s
* @ fires ` ` drawer . opened ` ` to the ` ` core . bus ` `
* @ fires ` ` drawer . opened ` ` to the ` ` core . bus ` `
* @ listens ` ` drawer . closed ` ` and sends to : meth : ` ` onDrawerClose ` `
* @ listens ` ` drawer . closed ` ` and sends to : meth : ` ` onDrawerClose ` `
@ -185,14 +187,14 @@ odoo.define('web_app_drawer', function(require) {
core . bus . trigger ( 'drawer.opened' ) ;
core . bus . trigger ( 'drawer.opened' ) ;
this . isOpen = true ;
this . isOpen = true ;
} ,
} ,
// It selects an app link visibly
// It selects an app link visibly
selectAppLink : function ( $appLink ) {
selectAppLink : function ( $appLink ) {
if ( $appLink ) {
if ( $appLink ) {
$appLink . focus ( ) ;
$appLink . focus ( ) ;
}
}
} ,
} ,
/ * I t r e t u r n s f i r s t A p p L i n k b y i t s n a m e a c c o r d i n g t o q u e r y
/ * I t r e t u r n s f i r s t A p p L i n k b y i t s n a m e a c c o r d i n g t o q u e r y
* @ param query str to search
* @ param query str to search
* @ return jQuery obj
* @ return jQuery obj
@ -202,7 +204,7 @@ odoo.define('web_app_drawer', function(require) {
return $ ( this ) . data ( 'menuName' ) . toUpperCase ( ) . startsWith ( query ) ;
return $ ( this ) . data ( 'menuName' ) . toUpperCase ( ) . startsWith ( query ) ;
} ) . first ( ) ;
} ) . first ( ) ;
} ,
} ,
/ * I t r e t u r n s t h e l i n k a d j a c e n t t o $ a p p L i n k i n p r o v i d e d d i r e c t i o n .
/ * I t r e t u r n s t h e l i n k a d j a c e n t t o $ a p p L i n k i n p r o v i d e d d i r e c t i o n .
* It also handles edge cases in the following ways :
* It also handles edge cases in the following ways :
* * Moves to last link if LEFT on first
* * Moves to last link if LEFT on first
@ -216,10 +218,10 @@ odoo.define('web_app_drawer', function(require) {
* @ return jQuery obj for adjacent applink
* @ return jQuery obj for adjacent applink
* /
* /
findAdjacentAppLink : function ( $appLink , direction ) {
findAdjacentAppLink : function ( $appLink , direction ) {
var obj = [ ] ,
var obj = [ ] ,
$objs = this . $appLinks ;
$objs = this . $appLinks ;
switch ( direction ) {
switch ( direction ) {
case this . LEFT :
case this . LEFT :
obj = $objs [ $objs . index ( $appLink ) - 1 ] ;
obj = $objs [ $objs . index ( $appLink ) - 1 ] ;
@ -248,15 +250,15 @@ odoo.define('web_app_drawer', function(require) {
}
}
break ;
break ;
}
}
if ( obj . length ) {
if ( obj . length ) {
event . preventDefault ( ) ;
event . preventDefault ( ) ;
}
}
return $ ( obj ) ;
return $ ( obj ) ;
} ,
} ,
/ * I t r e t u r n s e l s i n t h e s a m e r o w
/ * I t r e t u r n s e l s i n t h e s a m e r o w
* @ param @ obj jQuery object to get row for
* @ param @ obj jQuery object to get row for
* @ param $grid jQuery objects representing grid
* @ param $grid jQuery objects representing grid
@ -275,18 +277,18 @@ odoo.define('web_app_drawer', function(require) {
right = left + $obj . outerWidth ( ) ;
right = left + $obj . outerWidth ( ) ;
return $grid . filter ( filterWithin ( left , right ) ) ;
return $grid . filter ( filterWithin ( left , right ) ) ;
} ,
} ,
} ) ;
} ) ;
// It inits a new AppDrawer when the web client is ready
// It inits a new AppDrawer when the web client is ready
core . bus . on ( 'web_client_ready' , null , function ( ) {
core . bus . on ( 'web_client_ready' , null , function ( ) {
new AppDrawer ( ) ;
new AppDrawer ( ) ;
} ) ;
} ) ;
return {
return {
'AppDrawer' : AppDrawer ,
'AppDrawer' : AppDrawer ,
'SearchView' : SearchView ,
'SearchView' : SearchView ,
'Menu' : Menu ,
'Menu' : Menu ,
} ;
} ;
} ) ;
} ) ;