/
command.panel.latte
130 lines (105 loc) · 3.16 KB
/
command.panel.latte
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
{define #toggler}
{default open => false}
{default rel => 'next'}
{default text => ''}
{? if ($rel !== 'next' && substr($rel, 0, 1) != '#') $rel = '#' . $rel}
<a class="nette-toggler" href="#" rel="{$rel}">{$text}<abbr>{if $text} {/if}{if $open}▼{else}►{/if}</abbr></a>
{/define}
<h1>CommandsTool</h1>
<div class="nette-inner nette-addons-command">
<div class="nette-addons-command-status" id="nette-addons-command-status">
</div>
<div class="nette-addons-command-output" id="nette-addons-command-output">
</div>
<table width="100%">
{foreach $commands as $groupname => $group}
{var id = "nette-addons-command-" . md5($groupname)}
{var open => false}
<tr>
<th colspan=2 style="font-size:1.2em;">{include #toggler open=>$open, rel=>$id, text=>$groupname}</th>
</tr>
<tbody id="{$id}" class="nette-hidden">
{foreach $group as $name=>$command}
<tr>
<td style="vertical-align: middle;">
<strong>{$command->title}</strong>
{if $command->description}
<br><span style="font-size:0.8em; font-style: italic;">{$command->description}</span>
{/if}
</td>
<td style="vertical-align: middle;width:10px;"><input type="submit" value="Execute" class="nette-addons-command-ajax" name="{=$groupname . ':::' . $name}"/></td>
</tr>
{/foreach}
</tbody>
{/foreach}
</table>
</div>
<style type="text/css">
#nette-debug .nette-addons-command {
width: 100%;
}
#nette-debug .nette-addons-command input {
padding: 2px;
background: #eee;
border: 1px solid #ccc;
}
#nette-debug .nette-addons-command input:hover {
background: #666;
color: #fff;
border: 1px solid #444;
}
#nette-debug .nette-addons-command .success {
background: #A3F06C;
border: 1px solid #5FA92A;
padding: 1em;
margin-bottom: 5px;
}
#nette-debug .nette-addons-command .error {
background: #FAD3C4;
border: 1px solid #D4C4C9;
padding: 1em;
margin-bottom: 3px;
}
#nette-debug .nette-addons-command-output {
background: #ccc;
margin-bottom:3px;
}
</style>
<script type="text/javascript">
/* <![CDATA[ */
(function(){
var $ = Nette.Q.factory;
var commandPanel = {
init: function () {
$('.nette-addons-command-ajax').bind('click', function (e) {
commandPanel.commit(this.name);
})
},
commit: function (cmd) {
var xmlHttp = window.ActiveXObject ? new ActiveXObject('Microsoft.XMLHTTP') : new XMLHttpRequest();
xmlHttp.onreadystatechange = function() {
if (xmlHttp.readyState == 4) {
var status = $('#nette-addons-command-status').dom();
var output = $('#nette-addons-command-output').dom();
if (xmlHttp.status == 200) {
message = JSON.parse(xmlHttp.responseText);
status.innerHTML = message.text;
status.className = message.cls;
output.innerHTML = message.output;
} else {
status.innerHTML = 'Unhandled exception';
status.className = 'error';
output.innerHTML = '';
}
}
}
xmlHttp.open("POST", <?php echo json_encode($presenter->link('this')); ?>, true);
xmlHttp.setRequestHeader('X-CommandTool-Client', 'devel');
xmlHttp.setRequestHeader('X-Requested-With', 'XMLHttpRequest');
xmlHttp.send(cmd);
}
}
commandPanel.init();
})();
/* ]]> */
</script>