Welcome to mirror list, hosted at ThFree Co, Russian Federation.

popup.trigdesc.view.php « views « app « php « frontends - github.com/zabbix/zabbix.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 85b357f8c95802859fdc044dc8ea7bcae5e131f0 (plain)
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
<?php
/*
** Zabbix
** Copyright (C) 2001-2019 Zabbix SIA
**
** This program is free software; you can redistribute it and/or modify
** it under the terms of the GNU General Public License as published by
** the Free Software Foundation; either version 2 of the License, or
** (at your option) any later version.
**
** This program is distributed in the hope that it will be useful,
** but WITHOUT ANY WARRANTY; without even the implied warranty of
** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
** GNU General Public License for more details.
**
** You should have received a copy of the GNU General Public License
** along with this program; if not, write to the Free Software
** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
**/


$form = (new CForm())
	->setName('trigger_description')
	->addVar('triggerid', $data['trigger']['triggerid'])
	->addVar('comments_unresolved', $data['trigger']['comments'])
	->addItem(array_key_exists('messages', $data) ? $data['messages'] : null)
	->addItem(
		(new CFormList(_('Description')))->addRow(
			_('Description'),
			(new CTextArea('comments', $data['resolved'],
				['rows' => 25, 'readonly' => ($data['isTriggerEditable'] ? $data['isCommentExist'] : true)]
			))
				->setWidth(ZBX_TEXTAREA_BIG_WIDTH)
				->setAttribute('autofocus', 'autofocus')
		));

$script_inline = '';

if ($data['isTriggerEditable']) {
	$buttons = [
		[
			'title' => _('Update'),
			'class' => 'trigger-descr-update-btn',
			'keepOpen' => true,
			'isSubmit' => false,
			'enabled' => !$data['isCommentExist'],
			'action' => 'jQuery("form[name='.$form->getName().']").trigger("submit");'
		]
	];

	$script_inline .=
		'jQuery(document).ready(function() {'.
			'jQuery("form[name='.$form->getName().']").submit(function(e) {'.
				'e.preventDefault();'.
				'var forms = jQuery(this);'.
				'jQuery.ajax({'.
					'url: "zabbix.php?action=trigdesc.update",'.
					'data: {'.
						'"triggerid": '.$data['trigger']['triggerid'].','.
						'"comments": jQuery("[name=comments]", forms).val(),'.
						'"sid": jQuery("[name=sid]", forms).val()'.
					'},'.
					'success: function(r) {'.
						'if (typeof r.errors === "undefined") {'.
							'jQuery(forms).append(jQuery("<input>", {type: "hidden", "name": "success"}).val(1));'.
							'reloadPopup(forms[0], "popup.trigdesc.view");'.
						'}'.
						'else {'.
							'var dialogue_body = jQuery(forms).closest(".overlay-dialogue-body"),'.
								'msg = jQuery(".msg-bad,.msg-good", dialogue_body);'.
							'(msg.length === 0)'.
								'? jQuery(dialogue_body).prepend(r.errors)'.
								': jQuery(msg).replaceWith(r.errors);'.
						'}'.
					'},'.
					'dataType: "json",'.
					'type: "post"'.
				'});'.
			'});'.
		'});';
}

if ($data['isCommentExist'] && $data['isTriggerEditable']) {
	$script_inline .=
		'function makeCommentEditable() {'.
			'var forms = jQuery("form[name='.$form->getName().']");'.
			'jQuery("[name=comments]", forms)'.
				'.text(jQuery("[name=comments_unresolved]", forms).val())'.
				'.removeProp("readonly")'.
				'.focus();'.
			'jQuery(".trigger-descr-update-btn").removeProp("disabled");'.
			'jQuery(".trigger-descr-edit-btn").attr("disabled", "disabled");'.
		'}';
}

if ($data['isCommentExist']) {
	$buttons[] = [
		'title' => _('Edit'),
		'class' => 'btn-alt trigger-descr-edit-btn',
		'keepOpen' => true,
		'enabled' => $data['isTriggerEditable'],
		'action' => $data['isTriggerEditable']
			? 'makeCommentEditable();'
			: 'return false;'
	];
}

$output = [
	'header' => $data['title'],
	'body' => $form->toString(),
	'buttons' => $buttons,
	'script_inline' => $script_inline
];

if ($data['user']['debug_mode'] == GROUP_DEBUG_MODE_ENABLED) {
	CProfiler::getInstance()->stop();
	$output['debug'] = CProfiler::getInstance()->make()->toString();
}

echo (new CJson())->encode($output);