-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmenupopup.js
1624 lines (1397 loc) · 43.4 KB
/
menupopup.js
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
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
** Zabbix
** Copyright (C) 2001-2021 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.
**/
var zabbix_server_ip = '127.0.0.1'
// get MAPID function
function get_map_id(host_id){
var map_id = '';
$.ajax({
type:'POST',
data:{hostid:host_id},
url:'get_map_id.php',
async:false,
success:function(text)
{
map_id = text
}
});
return map_id;
}
/**
* Get menu popup history section data.
*
* @param string options['itemid'] Item ID.
* @param bool options['hasLatestGraphs'] Link to history page with showgraph action (optional).
*
* @return array
*/
function getMenuPopupHistory(options) {
var items = [],
url = new Curl('history.php', false);
url.setArgument('itemids[]', options.itemid);
// latest graphs
if (typeof options.hasLatestGraphs !== 'undefined' && options.hasLatestGraphs) {
url.setArgument('action', 'showgraph');
url.setArgument('to', 'now');
url.setArgument('from', 'now-1h');
items.push({
label: t('Last hour graph'),
url: url.getUrl()
});
url.setArgument('from', 'now-7d');
items.push({
label: t('Last week graph'),
url: url.getUrl()
});
url.setArgument('from', 'now-1M');
items.push({
label: t('Last month graph'),
url: url.getUrl()
});
}
// latest values
url.setArgument('action', 'showvalues');
url.setArgument('from', 'now-1h');
items.push({
label: t('Latest values'),
url: url.getUrl()
});
return [{
label: t('History'),
items: items
}];
}
/**
* Get menu popup host section data.
*
* @param {string} options['hostid'] Host ID.
* @param {array} options['scripts'] Host scripts (optional).
* @param {string} options[]['name'] Script name.
* @param {string} options[]['scriptid'] Script ID.
* @param {string} options[]['confirmation'] Confirmation text.
* @param {bool} options['showGraphs'] Link to Monitoring->Hosts->Graphs page.
* @param {bool} options['showScreens'] Link to Monitoring->Screen page.
* @param {bool} options['showWeb'] Link to Monitoring->Hosts->Web page.
* @param {bool} options['showTriggers'] Link to Monitoring->Problems page.
* @param {bool} options['hasGoTo'] "Go to" block in popup.
* @param {array} options['severities'] (optional)
* @param {bool} options['show_suppressed'] (optional)
* @param {array} options['urls'] (optional)
* @param {string} options['url'][]['label']
* @param {string} options['url'][]['url']
* @param {string} options['filter_application'] (optional) Application name for filter by application.
* @param {object} trigger_elmnt UI element which triggered opening of overlay dialogue.
*
* @return array
*/
function getMenuPopupHost(options, trigger_elmnt) {
var sections = [];
// go to section
if (options.hasGoTo) {
var host_inventory = {
label: t('Inventory')
},
latest_data = {
label: t('Latest data')
},
problems = {
label: t('Problems')
},
graphs = {
label: t('Graphs')
},
screens = {
label: t('Screens')
},
web = {
label: t('Web')
},
// Добавляем новый элемент меню
go_to_map = {
label: t('Перейти на карту')
};
// Добавляем MAP link
var sysmap_url_ = 'http://'+zabbix_server_ip+'/zabbix/sysmaps.php'
var sysmap_id_ = get_map_id(options.hostid);
if (sysmap_id_ !== ''){
sysmap_url_ = 'http://'+zabbix_server_ip+'/zabbix/zabbix.php?action=map.view&sysmapid='
}
go_to_map.url = sysmap_url_+sysmap_id_
// inventory link
var url = new Curl('hostinventories.php', false);
url.setArgument('hostid', options.hostid);
host_inventory.url = url.getUrl();
// latest data link
var url = new Curl('zabbix.php', false);
url.setArgument('action', 'latest.view');
if (typeof options.filter_application !== 'undefined') {
url.setArgument('filter_application', options.filter_application);
}
url.setArgument('filter_hostids[]', options.hostid);
url.setArgument('filter_set', '1');
latest_data.url = url.getUrl();
if (!options.showTriggers) {
problems.disabled = true;
}
else {
var url = new Curl('zabbix.php', false);
url.setArgument('action', 'problem.view');
url.setArgument('filter_hostids[]', options.hostid);
if (typeof options.severities !== 'undefined') {
url.setArgument('filter_severities[]', options.severities);
}
if (typeof options.show_suppressed !== 'undefined' && options.show_suppressed) {
url.setArgument('filter_show_suppressed', '1');
}
if (typeof options.filter_application !== 'undefined') {
url.setArgument('filter_application', options.filter_application);
}
url.setArgument('filter_set', '1');
problems.url = url.getUrl();
}
if (!options.showGraphs) {
graphs.disabled = true;
}
else {
var graphs_url = new Curl('zabbix.php', false);
graphs_url.setArgument('action', 'charts.view')
graphs_url.setArgument('view_as', 'showgraph'); // HISTORY_GRAPH
graphs_url.setArgument('filter_search_type', '0'); // ZBX_SEARCH_TYPE_STRICT
graphs_url.setArgument('filter_hostids[]', options.hostid);
graphs_url.setArgument('filter_set', '1');
graphs.url = graphs_url.getUrl();
}
if (!options.showScreens) {
screens.disabled = true;
}
else {
var screens_url = new Curl('host_screen.php', false);
screens_url.setArgument('hostid', options.hostid);
screens.url = screens_url.getUrl();
}
if (!options.showWeb) {
web.disabled = true;
}
else {
var web_url = new Curl('zabbix.php', false);
web_url.setArgument('action', 'web.view');
web_url.setArgument('filter_hostids[]', options.hostid);
web_url.setArgument('filter_set', '1');
web.url = web_url.getUrl();
}
var items = [
host_inventory,
latest_data,
problems,
graphs,
screens,
web,
go_to_map // Добавляем новый элемент меню
];
if (options.showConfig) {
var config = {
label: t('Configuration')
};
if (options.isWriteable) {
var config_url = new Curl('hosts.php', false);
config_url.setArgument('form', 'update');
config_url.setArgument('hostid', options.hostid);
config.url = config_url.getUrl();
}
else {
config.disabled = true;
}
items.push(config);
}
sections.push({
label: t('Host'),
items: items
});
}
// urls
if (typeof options.urls !== 'undefined') {
sections.push({
label: t('URLs'),
items: options.urls
});
}
// scripts
if (typeof options.scripts !== 'undefined') {
sections.push({
label: t('Scripts'),
items: getMenuPopupScriptData(options.scripts, options.hostid, trigger_elmnt)
});
}
return sections;
}
/**
* Get menu popup submap map element section data.
*
* @param {array} options['sysmapid']
* @param {int} options['severity_min'] (optional)
* @param {int} options['widget_uniqueid'] (optional)
* @param {array} options['urls'] (optional)
* @param {string} options['url'][]['label']
* @param {string} options['url'][]['url']
*
* @return array
*/
function getMenuPopupMapElementSubmap(options) {
var sections = [],
submap_url;
if (typeof options.widget_uniqueid !== 'undefined') {
submap_url = new Curl('javascript: navigateToSubmap(' + options.sysmapid +
', "' + options.widget_uniqueid + '");', false);
}
else {
submap_url = new Curl('zabbix.php', false);
submap_url.setArgument('action', 'map.view');
submap_url.setArgument('sysmapid', options.sysmapid);
if (typeof options.severity_min !== 'undefined') {
submap_url.setArgument('severity_min', options.severity_min);
}
}
sections.push({
label: t('Go to'),
items: [{
label: t('Submap'),
url: submap_url.getUrl()
}]
});
// urls
if (typeof options.urls !== 'undefined') {
sections.push({
label: t('URLs'),
items: options.urls
});
}
return sections;
}
/**
* Get menu popup host group map element section data.
*
* @param {string} options['groupid']
* @param {array} options['severities'] (optional)
* @param {bool} options['show_suppressed'] (optional)
* @param {array} options['urls'] (optional)
* @param {string} options['url'][]['label']
* @param {string} options['url'][]['url']
* @param {string} options['filter_application'] (optional) Application name for filter by application.
*
* @return array
*/
function getMenuPopupMapElementGroup(options) {
var sections = [],
problems_url = new Curl('zabbix.php', false);
problems_url.setArgument('action', 'problem.view');
problems_url.setArgument('filter_groupids[]', options.groupid);
if (typeof options.severities !== 'undefined') {
problems_url.setArgument('filter_severities[]', options.severities);
}
if (typeof options.show_suppressed !== 'undefined' && options.show_suppressed) {
problems_url.setArgument('filter_show_suppressed', '1');
}
if (typeof options.filter_application !== 'undefined') {
problems_url.setArgument('filter_application', options.filter_application);
}
problems_url.setArgument('filter_set', '1');
sections.push({
label: t('Go to'),
items: [{
label: t('Problems'),
url: problems_url.getUrl()
}]
});
// urls
if (typeof options.urls !== 'undefined') {
sections.push({
label: t('URLs'),
items: options.urls
});
}
return sections;
}
/**
* Get menu popup trigger map element section data.
*
* @param {array} options['triggerids']
* @param {array} options['severities'] (optional)
* @param {bool} options['show_suppressed'] (optional)
* @param {array} options['urls'] (optional)
* @param {string} options['url'][]['label']
* @param {string} options['url'][]['url']
*
* @return array
*/
function getMenuPopupMapElementTrigger(options) {
var sections = [],
problems_url = new Curl('zabbix.php', false);
problems_url.setArgument('action', 'problem.view');
problems_url.setArgument('filter_triggerids[]', options.triggerids);
if (typeof options.severities !== 'undefined') {
problems_url.setArgument('filter_severities[]', options.severities);
}
if (typeof options.show_suppressed !== 'undefined' && options.show_suppressed) {
problems_url.setArgument('filter_show_suppressed', '1');
}
problems_url.setArgument('filter_set', '1');
sections.push({
label: t('Go to'),
items: [{
label: t('Problems'),
url: problems_url.getUrl()
}]
});
// urls
if (typeof options.urls !== 'undefined') {
sections.push({
label: t('URLs'),
items: options.urls
});
}
return sections;
}
/**
* Get menu popup image map element section data.
*
* @param {array} options['urls'] (optional)
* @param {string} options['url'][]['label']
* @param {string} options['url'][]['url']
*
* @return array
*/
function getMenuPopupMapElementImage(options) {
// urls
if (typeof options.urls !== 'undefined') {
return [{
label: t('URLs'),
items: options.urls
}];
}
return [];
}
/**
* Get menu popup refresh section data.
*
* @param {integer} options['widgetid'] Widget ID.
* @param {string} options['widgetName'] Widget name.
* @param {string} options['currentRate'] Current rate value.
* @param {bool} options['multiplier'] Multiplier or time mode.
* @param {array} options['params'] Url parameters (optional).
* @param {callback} options['callback'] Callback function on success (optional).
* @param {object} trigger_elmnt UI element which triggered opening of overlay dialogue.
*
* @return array
*/
function getMenuPopupRefresh(options, trigger_elmnt) {
var items = [],
params = (typeof options.params === 'undefined' || options.params.length == 0) ? {} : options.params,
intervals = options.multiplier
? {
'x0.25': 'x0.25',
'x0.5': 'x0.5',
'x1': 'x1',
'x1.5': 'x1.5',
'x2': 'x2',
'x3': 'x3',
'x4': 'x4',
'x5': 'x5'
}
: {
0: t('No refresh'),
10: t('10 seconds'),
30: t('30 seconds'),
60: t('1 minute'),
120: t('2 minutes'),
600: t('10 minutes'),
900: t('15 minutes')
};
jQuery.each(intervals, function(value, label) {
var item = {
label: label,
data: {
value: value
},
clickCallback: function() {
var $obj = jQuery(this),
currentRate = $obj.data('value');
// it is a quick solution for slide refresh multiplier, should be replaced with slide.refresh or similar
if (options.multiplier) {
sendAjaxData('slides.php', {
data: jQuery.extend({}, params, {
widgetName: options.widgetName,
widgetRefreshRate: currentRate
}),
dataType: 'script',
success: function() {
// Set new refresh rate as current in slideshow controls.
trigger_elmnt.data('menu-popup').data.currentRate = currentRate;
}
});
jQuery('a', $obj.closest('.menu-popup')).each(function() {
var link = jQuery(this);
if (link.data('value') == currentRate) {
link
.addClass('selected')
.attr('aria-label', sprintf(t('S_SELECTED_SR'), link.data('aria-label')));
}
else {
link
.removeClass('selected')
.attr('aria-label', link.data('aria-label'));
}
});
$obj.closest('.menu-popup').menuPopup('close', trigger_elmnt);
}
else {
var url = new Curl('zabbix.php');
url.setArgument('action', 'dashboard.widget.rfrate');
jQuery.ajax({
url: url.getUrl(),
method: 'POST',
dataType: 'json',
data: {
'widgetid': options.widgetid,
'rf_rate': currentRate
}
})
.then(function() {
jQuery('a', $obj.closest('.menu-popup')).each(function() {
var link = jQuery(this);
if (link.data('value') == currentRate) {
link
.addClass('selected')
.attr('aria-label', sprintf(t('S_SELECTED_SR'), link.data('aria-label')));
}
else {
link
.removeClass('selected')
.attr('aria-label', link.data('aria-label'));
}
});
// Set new refresh rate as current in widget controls.
trigger_elmnt.data('menu-popup').data.currentRate = currentRate;
$obj.closest('.menu-popup').menuPopup('close', trigger_elmnt);
jQuery('.dashbrd-grid-container')
.dashboardGrid('setWidgetRefreshRate', options.widgetid, parseInt(currentRate));
})
.fail(function() {
$obj.closest('.menu-popup').menuPopup('close', trigger_elmnt);
// TODO: gentle message about failed saving of widget refresh rate
});
}
}
};
if (value == options.currentRate) {
item.selected = true;
}
items[items.length] = item;
});
return [{
label: options.multiplier ? t('Refresh interval multiplier') : t('Refresh interval'),
items: items
}];
}
/**
* Get menu popup widget actions data.
*
* @param {string} options['currentRate'] Current rate value.
* @param {bool} options['multiplier'] Multiplier or time mode.
* @param {callback} options['callback'] Callback function on success (optional).
* @param {string} options['widget_uniqueid'] Widget instance unique id.
* @param {object} trigger_elmnt UI element which triggered opening of overlay dialogue.
*
* @return array
*/
function getMenuPopupWidgetActions(options, trigger_elmnt) {
var $dashboard = jQuery('.dashbrd-grid-container'),
editMode = $dashboard.dashboardGrid('isEditMode'),
widget = $dashboard.dashboardGrid('getWidgetsBy', 'uniqueid', options.widget_uniqueid).pop(),
widgetid = widget.widgetid,
loading = (!widget['ready'] || widget['content_body'].find('.is-loading').length > 0),
widget_actions = [];
options.widgetid = widgetid;
menu = editMode ? [] : getMenuPopupRefresh(options, trigger_elmnt),
widget_actions.push({
label: t('S_COPY'),
clickCallback: function() {
jQuery('.dashbrd-grid-container').dashboardGrid('copyWidget', widget);
jQuery(this).closest('.menu-popup').menuPopup('close', trigger_elmnt);
jQuery('#dashbrd-paste-widget').attr('disabled', false);
}
});
if (editMode) {
widget_actions.push({
label: t('S_PASTE'),
disabled: !$dashboard.dashboardGrid('isWidgetCopied'),
clickCallback: function() {
$dashboard.dashboardGrid('pasteWidget', widget, widget.pos);
jQuery(this).closest('.menu-popup').menuPopup('close', trigger_elmnt);
}
});
widget_actions.push({
label: t('Delete'),
clickCallback: function() {
jQuery('.dashbrd-grid-container').dashboardGrid('deleteWidget', widget);
jQuery(this).closest('.menu-popup').menuPopup('close', trigger_elmnt);
}
});
}
if ('download' in options && !editMode) {
widget_actions.push({
label: t('Download image'),
disabled: loading || !options.download,
clickCallback: function() {
var svg = widget['content_body'].find('svg').first();
if (svg.length) {
downloadSvgImage(svg, 'graph.png');
}
else {
downloadPngImage(widget['content_body'].find('img').first(), 'graph.png');
}
jQuery(this).closest('.menu-popup').menuPopup('close', trigger_elmnt);
},
refreshCallback: function(widget) {
if (widget['widgetid'] == widgetid && options.download) {
this.disabled = !widget['ready'];
}
}
});
}
if (widget_actions.length) {
menu.unshift({
label: t('Actions'),
items: widget_actions
});
}
return menu;
}
/**
* Get menu popup trigger section data.
*
* @param {string} options['dashboardid']
* @param {bool} options['editable']
* @param {object} trigger_elmnt UI element which triggered opening of overlay dialogue.
*
* @return array
*/
function getMenuPopupDashboard(options, trigger_elmnt) {
var url_create = new Curl('zabbix.php', false),
url_clone = new Curl('zabbix.php', false),
url_delete = new Curl('zabbix.php', false);
url_create.setArgument('action', 'dashboard.view');
url_create.setArgument('new', '1');
url_clone.setArgument('action', 'dashboard.view');
url_clone.setArgument('source_dashboardid', options.dashboardid);
url_delete.setArgument('action', 'dashboard.delete');
url_delete.setArgument('dashboardids', [options.dashboardid]);
return [{
label: t('Actions'),
items: [
{
label: t('Sharing'),
clickCallback: function () {
var popup_options = {'dashboardid': options.dashboardid};
PopUp('dashboard.share.edit', popup_options, 'dashboard_share', trigger_elmnt);
jQuery(this).closest('.menu-popup').menuPopup('close', null);
},
disabled: !options.editable
},
{
label: t('Create new'),
url: url_create.getUrl()
},
{
label: t('Clone'),
url: url_clone.getUrl()
},
{
label: t('Delete'),
url: 'javascript:void(0)',
clickCallback: function () {
var obj = jQuery(this);
// hide menu
obj.closest('.menu-popup').hide();
if (!confirm(t('Delete dashboard?'))) {
return false;
}
redirect(url_delete.getUrl(), 'post', 'sid', true, true);
},
disabled: !options.editable
}
]
}];
}
/**
* Get menu popup trigger section data.
*
* @param {string} options['triggerid'] Trigger ID.
* @param {string} options['eventid'] (optional) Required for Acknowledge section.
* @param {object} options['items'] Link to trigger item history page (optional).
* @param {string} options['items'][]['name'] Item name.
* @param {object} options['items'][]['params'] Item URL parameters ("name" => "value").
* @param {bool} options['acknowledge'] (optional) Whether to show Acknowledge section.
* @param {object} options['configuration'] Link to trigger configuration page (optional).
* @param {bool} options['showEvents'] Show Problems item enabled. Default: false.
* @param {string} options['url'] Trigger URL link (optional).
* @param {object} trigger_elmnt UI element which triggered opening of overlay dialogue.
*
* @return array
*/
function getMenuPopupTrigger(options, trigger_elmnt) {
var sections = [],
items = [];
// events
var events = {
label: t('Problems')
};
if (typeof options.showEvents !== 'undefined' && options.showEvents) {
var url = new Curl('zabbix.php', false);
url.setArgument('action', 'problem.view');
url.setArgument('filter_triggerids[]', options.triggerid);
url.setArgument('filter_set', '1');
events.url = url.getUrl();
}
else {
events.disabled = true;
}
items[items.length] = events;
// acknowledge
if (typeof options.acknowledge !== 'undefined' && options.acknowledge) {
items[items.length] = {
label: t('Acknowledge'),
clickCallback: function() {
jQuery(this).closest('.menu-popup-top').menuPopup('close', null);
acknowledgePopUp({eventids: [options.eventid]}, trigger_elmnt);
}
};
}
// configuration
if (typeof options.configuration !== 'undefined' && options.configuration) {
var url = new Curl('triggers.php', false);
url.setArgument('form', 'update');
url.setArgument('triggerid', options.triggerid);
items[items.length] = {
label: t('Configuration'),
url: url.getUrl()
};
}
sections[sections.length] = {
label: t('S_TRIGGER'),
items: items
};
// urls
if ('urls' in options) {
sections[sections.length] = {
label: t('Links'),
items: options.urls
};
}
// items
if (typeof options.items !== 'undefined' && objectSize(options.items) > 0) {
var items = [];
jQuery.each(options.items, function(i, item) {
var url = new Curl('history.php', false);
url.setArgument('action', item.params.action);
url.setArgument('itemids[]', item.params.itemid);
items[items.length] = {
label: item.name,
url: url.getUrl()
};
});
sections[sections.length] = {
label: t('History'),
items: items
};
}
return sections;
}
/**
* Get menu popup trigger log section data.
*
* @param string options['itemid']
* @param string options['hostid']
* @param string options['name']
* @param bool options['show_triggers'] (optional) Show trigger menus.
* @param array options['triggers'] (optional)
* @param string options['triggers'][n]['triggerid']
* @param string options['triggers'][n]['name']
* @param {object} trigger_elmnt UI element that was clicked to open overlay dialogue.
*
* @return array
*/
function getMenuPopupItem(options, trigger_elmnt) {
var items = [];
if (typeof options.show_triggers !== 'undefined' && options.show_triggers) {
// create
items.push({
label: t('Create trigger'),
clickCallback: function() {
jQuery(this).closest('.menu-popup').menuPopup('close', null);
return PopUp('popup.triggerwizard', {
itemid: options.itemid
}, null, trigger_elmnt);
}
});
var edit_trigger = {
label: t('Edit trigger')
};
// edit
if (options.triggers.length > 0) {
var triggers = [];
jQuery.each(options.triggers, function(i, trigger) {
triggers.push({
label: trigger.name,
clickCallback: function() {
jQuery(this).closest('.menu-popup-top').menuPopup('close', null);
return PopUp('popup.triggerwizard', {
itemid: options.itemid,
triggerid: trigger.triggerid
}, null, trigger_elmnt);
}
});
});
edit_trigger.items = triggers;
}
else {
edit_trigger.disabled = true;
}
items.push(edit_trigger);
}
var url = new Curl('items.php', false);
url.setArgument('form', 'create');
url.setArgument('hostid', options.hostid);
url.setArgument('type', 18); // ITEM_TYPE_DEPENDENT
url.setArgument('master_itemid', options.itemid);
items.push({
label: t('Create dependent item'),
url: url.getUrl(),
disabled: !options.create_dependent_item
});
url = new Curl('host_discovery.php');
url.setArgument('form', 'create');
url.setArgument('hostid', options.hostid);
url.setArgument('type', 18); // ITEM_TYPE_DEPENDENT
url.setArgument('master_itemid', options.itemid);
items.push({
label: t('Create dependent discovery rule'),
url: url.getUrl(),
disabled: !options.create_dependent_discovery
});
return [{
label: options.name,
items: items
}];
}
/**
* Get menu structure for item prototypess.
*
* @param array options['name']
* @param array options['itemid']
* @param array options['parent_discoveryid']
*
* @return array
*/
function getMenuPopupItemPrototype(options) {
var url = new Curl('disc_prototypes.php', false);
url.setArgument('form', 'create');
url.setArgument('parent_discoveryid', options.parent_discoveryid);
url.setArgument('type', 18); // ITEM_TYPE_DEPENDENT
url.setArgument('master_itemid', options.itemid);
return [{
label: options.name,
items: [{
label: t('Create dependent item'),
url: url.getUrl()
}]
}];
}
/**
* Get dropdown section data.
*
* @param {array} options
* @param {object} trigger_elem UI element that was clicked to open overlay dialogue.
*
* @returns array
*/
function getMenuPopupDropdown(options, trigger_elem) {
var items = [];
jQuery.each(options.items, function(i, item) {
items.push({
label: item.label,
url: item.url || 'javascript:void(0);',
class: item.class,
clickCallback: () => {
jQuery(trigger_elem)
.removeClass()
.addClass(['btn-alt', 'btn-dropdown-toggle', item.class].join(' '));
jQuery('input[type=hidden]', jQuery(trigger_elem).parent())
.val(item.value)
.trigger('change');
}
});
});
return [{
items: items
}];
}
/**
* Get menu popup submenu section data.
*
* @param object options['submenu'] List of menu sections.
* @param object options['submenu'][section] An individual section definition.
* @param string options['submenu'][section]['label'] Non-clickable section label.
* @param object options['submenu'][section]['items'] List of menu items of the section.
* @param string options['submenu'][section]['items'][url] Menu item label for the given url.
* @param object options['submenu'][section]['items'][key] Menu item with a submenu.
* @param object options['submenu'][section]['items'][key]['label'] Non-clickable subsection label.
* @param object options['submenu'][section]['items'][key]['items'] List of menu items of the subsection.
* @param object options['submenu'][section]['items'][key]['items'][] More levels of submenu.
*
* @returns array
*/
function getMenuPopupSubmenu(options) {
var transform = function(sections) {
var result = [];
for (var key in sections) {
if (typeof sections[key] === 'object') {
var item = {};
for (var item_key in sections[key]) {
if (item_key === 'items') {
item[item_key] = transform(sections[key][item_key]);
}