Completed
Push — master ( a08ca9...0939e1 )
by Song
02:47
created

ContextMenuActions   A

Complexity

Total Complexity 2

Size/Duplication

Total Lines 58
Duplicated Lines 0 %

Coupling/Cohesion

Components 1
Dependencies 3

Importance

Changes 0
Metric Value
dl 0
loc 58
rs 10
c 0
b 0
f 0
wmc 2
lcom 1
cbo 3

2 Methods

Rating   Name   Duplication   Size   Complexity  
A addScript() 0 41 1
A display() 0 7 1
1
<?php
2
3
namespace Encore\Admin\Grid\Displayers;
4
5
use Encore\Admin\Admin;
6
7
class ContextMenuActions extends DropdownActions
8
{
9
    /**
10
     * {@inheritdoc}
11
     */
12
    protected function addScript()
13
    {
14
        parent::addScript();
15
16
        $script = <<<SCRIPT
17
(function () {
18
    $("body").on("contextmenu", "table#{$this->grid->tableID} tr", function(e) {
19
        $('#grid-context-menu .dropdown-menu').hide();
20
    
21
        var menu = $(this).find('td.column-__actions__ .dropdown-menu');
22
        var index = $(this).index();
23
        
24
        if (menu.length) {
25
            menu.attr('index', index).detach().appendTo('#grid-context-menu');
26
        } else {
27
            menu = $('#grid-context-menu .dropdown-menu[index='+index+']');
28
        }
29
    
30
        var height = 0;
31
    
32
        if (menu.height() > (document.body.clientHeight - e.pageY)) {
33
            menu.css({left: e.pageX+10, top: e.pageY - menu.height()}).show();
34
        } else {
35
            menu.css({left: e.pageX+10, top: e.pageY-10}).show();
36
        }
37
    
38
        return false;
39
    });
40
    
41
    $(document).on('click',function(){
42
        $('#grid-context-menu .dropdown-menu').hide();
43
    })
44
    
45
    $('#grid-context-menu').click('a', function () {
46
        $('#grid-context-menu .dropdown-menu').hide();
47
    });
48
})();
49
SCRIPT;
50
51
        Admin::script($script);
52
    }
53
54
    /**
55
     * {@inheritdoc}
56
     */
57
    public function display($callback = null)
58
    {
59
        Admin::html('<div id="grid-context-menu"></div>');
60
        Admin::style(".column-__actions__ {display: none !important;}");
61
62
        return parent::display($callback);
63
    }
64
}