1<?php 2/* 3** Zabbix 4** Copyright (C) 2001-2021 Zabbix SIA 5** 6** This program is free software; you can redistribute it and/or modify 7** it under the terms of the GNU General Public License as published by 8** the Free Software Foundation; either version 2 of the License, or 9** (at your option) any later version. 10** 11** This program is distributed in the hope that it will be useful, 12** but WITHOUT ANY WARRANTY; without even the implied warranty of 13** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14** GNU General Public License for more details. 15** 16** You should have received a copy of the GNU General Public License 17** along with this program; if not, write to the Free Software 18** Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. 19**/ 20 21 22/** 23 * @var CView $this 24 */ 25?> 26<script type="text/x-jquery-tmpl" id="filter-tag-row-tmpl"> 27 <?= (new CRow([ 28 (new CTextBox('filter_tags[#{rowNum}][tag]')) 29 ->setAttribute('placeholder', _('tag')) 30 ->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 31 (new CRadioButtonList('filter_tags[#{rowNum}][operator]', TAG_OPERATOR_LIKE)) 32 ->addValue(_('Contains'), TAG_OPERATOR_LIKE) 33 ->addValue(_('Equals'), TAG_OPERATOR_EQUAL) 34 ->setModern(true), 35 (new CTextBox('filter_tags[#{rowNum}][value]')) 36 ->setAttribute('placeholder', _('value')) 37 ->setWidth(ZBX_TEXTAREA_FILTER_SMALL_WIDTH), 38 (new CCol( 39 (new CButton('filter_tags[#{rowNum}][remove]', _('Remove'))) 40 ->addClass(ZBX_STYLE_BTN_LINK) 41 ->addClass('element-table-remove') 42 ))->addClass(ZBX_STYLE_NOWRAP) 43 ])) 44 ->addClass('form_row') 45 ->toString() 46 ?> 47</script> 48<script type="text/javascript"> 49 jQuery(function($) { 50 $('#filter-tags').dynamicRows({template: '#filter-tag-row-tmpl'}); 51 52 $('#filter_maintenance_status').on('change', function() { 53 $('#filter_show_suppressed').prop('disabled', !this.checked); 54 }); 55 56 function hostPage() { 57 this.refresh_url = '<?= $data['refresh_url'] ?>'; 58 this.refresh_data = <?= json_encode($data['refresh_data']) ?>; 59 this.refresh_interval = <?= $data['refresh_interval'] ?>; 60 this.running = false; 61 this.timeout = null; 62 } 63 64 hostPage.prototype = { 65 getCurrentForm: function() { 66 return $('form[name=host_view]'); 67 }, 68 addMessages: function(messages) { 69 $('.wrapper main').before(messages); 70 }, 71 removeMessages: function() { 72 $('.wrapper .msg-bad').remove(); 73 }, 74 refresh: function() { 75 this.setLoading(); 76 77 var deferred = $.ajax({ 78 url: this.refresh_url, 79 data: this.refresh_data, 80 type: 'post', 81 dataType: 'json' 82 }); 83 84 return this.bindDataEvents(deferred); 85 }, 86 setLoading: function() { 87 this.getCurrentForm().addClass('is-loading is-loading-fadein delayed-15s'); 88 }, 89 clearLoading: function() { 90 this.getCurrentForm().removeClass('is-loading is-loading-fadein delayed-15s'); 91 }, 92 doRefresh: function(body) { 93 this.getCurrentForm().replaceWith(body); 94 }, 95 bindDataEvents: function(deferred) { 96 var that = this; 97 98 deferred 99 .done(function(response) { 100 that.onDataDone.call(that, response); 101 }) 102 .fail(function(jqXHR) { 103 that.onDataFail.call(that, jqXHR); 104 }) 105 .always(this.onDataAlways.bind(this)); 106 107 return deferred; 108 }, 109 onDataDone: function(response) { 110 this.clearLoading(); 111 this.removeMessages(); 112 this.doRefresh(response.body); 113 114 if ('messages' in response) { 115 this.addMessages(response.messages); 116 } 117 }, 118 onDataFail: function(jqXHR) { 119 // Ignore failures caused by page unload. 120 if (jqXHR.status == 0) { 121 return; 122 } 123 124 this.clearLoading(); 125 126 var messages = $(jqXHR.responseText).find('.msg-global'); 127 128 if (messages.length) { 129 this.getCurrentForm().html(messages); 130 } 131 else { 132 this.getCurrentForm().html(jqXHR.responseText); 133 } 134 }, 135 onDataAlways: function() { 136 if (this.running) { 137 this.scheduleRefresh(); 138 } 139 }, 140 scheduleRefresh: function() { 141 this.unscheduleRefresh(); 142 this.timeout = setTimeout((function() { 143 this.timeout = null; 144 this.refresh(); 145 }).bind(this), this.refresh_interval); 146 }, 147 unscheduleRefresh: function() { 148 if (this.timeout !== null) { 149 clearTimeout(this.timeout); 150 this.timeout = null; 151 } 152 }, 153 start: function() { 154 if (this.refresh_interval != 0) { 155 this.running = true; 156 this.scheduleRefresh(); 157 } 158 }, 159 stop: function() { 160 this.running = false; 161 this.unscheduleRefresh(); 162 } 163 }; 164 165 window.host_page = new hostPage(); 166 }); 167</script> 168